-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regrowth.cs
89 lines (80 loc) · 2.9 KB
/
Regrowth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using UnityEngine;
namespace FarmDoctor;
[HarmonyPatch]
public class Regrowth
{
[HarmonyPostfix, HarmonyPatch(typeof(Zone), "OnActivate")]
static void OnActivate()
{
if (!EClass._zone.IsPCFaction) return;
foreach (var plantPair in EClass._map.plants)
{
PlantData plant = plantPair.Value.IsNull() ? null : plantPair.Value;
if (plant.seed != null)
{
string[] fruit_trees = ["banana", "fruit", "fruit_pear", "fruit_orange"];
if (!fruit_trees.Contains(plant.seed.Cell.growth.source.GetAlias))
{
return;
}
if (plant.seed.Cell.IsFarmField && plant.seed.Cell.gatherCount > 0)
{
if (plant.seed.Cell.growth.source.GetAlias == "banana")
{
plant.seed.Cell.growth.stages[3].tiles[0] = 157;
}
else
{
plant.seed.Cell.growth.stages[3].tiles[0] = 195;
}
}
}
}
}
[HarmonyPrefix, HarmonyPatch(typeof(TraitFertilizer), "OnSimulateHour")]
public static bool OnSimulateHourPrefix(TraitFertilizer __instance, VirtualDate date, out Cell __state)
{
//Hmm, could probably run everything on prefix, but i'll leave like this for now.
__state = __instance.owner.Cell;
return true;
}
[HarmonyPostfix, HarmonyPatch(typeof(TraitFertilizer), "OnSimulateHour")]
public static void OnSimulateHour(TraitFertilizer __instance, VirtualDate date, Cell __state)
{
if (!EClass._zone.IsPCFaction) return;
if (Plugin.minLevelRegrowth.Value > EClass.pc.elements.Value(286)) return;
try
{
Cell cell = __state;
if (cell.growth == null || !cell.IsFarmField) return;
string[] fruit_trees = ["banana", "fruit", "fruit_pear", "fruit_orange"];
if (!fruit_trees.Contains(cell.growth.source.GetAlias))
{
return;
}
if (cell.isHarvested)
{
if (cell.growth.source.GetAlias == "banana")
{
cell.growth.stages[3].tiles[0] = 157;
}
else
{
cell.growth.stages[3].tiles[0] = 195;
}
cell.objVal = 90;
cell.isHarvested = false;
cell.gatherCount++;
}
}
catch (NullReferenceException)
{
Plugin.Log.LogError("Congratulations! You've triggered a NullReferenceException! I have no idea how to fix it, but don’t worry—it causes no harm. All is good. May Kumiromi be with you!");
}
}
}