-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinerVeinCoverage.cs
85 lines (79 loc) · 3.45 KB
/
MinerVeinCoverage.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
using HarmonyLib;
namespace MinerVeinCoverage
{
[HarmonyPatch(typeof(UIMinerWindow))]
[HarmonyPatch("_OnUpdate")]
static class Patch_UIMinerWindow__OnUpdate
{
private static readonly string _coverText = "覆盖矿".Translate();
private static readonly string _veinText =
Localization.isENUS
? " veins"
: "个矿脉".Translate();
private static readonly string _displayUnit = MainPlugin.DisplayAsPerSecond.Value ? "sec" : "min";
private static readonly float _displayFactor = MainPlugin.DisplayAsPerSecond.Value ? 60.0f : 1.0f;
private static readonly float _oreValuePerNode = 30.0f;
static void Postfix(UIMinerWindow __instance)
{
if (__instance.minerId == 0 || __instance.factory == null)
{
__instance._Close();
}
else
{
MinerComponent minerComponent = __instance.factorySystem.minerPool[__instance.minerId];
if (minerComponent.id != __instance.minerId)
{
__instance._Close();
}
else
{
if (minerComponent.type == EMinerType.Vein)
{
var speed = (_oreValuePerNode * GameMain.data.history.miningSpeedScale * minerComponent.veinCount) / _displayFactor;
var speedText = speed.ToString("0.##");
__instance.coverText.text = $"{_coverText}{minerComponent.veinCount}{_veinText} ({speedText}/{_displayUnit})";
}
}
}
}
}
[HarmonyPatch(typeof(UIVeinCollectorPanel))]
[HarmonyPatch("_OnUpdate")]
static class Patch_UIVeinCollectorPanel__OnUpdate
{
private static readonly string _coverText = "覆盖矿".Translate();
private static readonly string _veinText =
Localization.isENUS
? " veins"
: "个矿脉".Translate();
private static readonly string _displayUnit = MainPlugin.DisplayAsPerSecond.Value ? "sec" : "min";
private static readonly float _displayFactor = MainPlugin.DisplayAsPerSecond.Value ? 60.0f : 1.0f;
private static readonly float _oreValuePerNode = 60.0f;
static void Postfix(UIVeinCollectorPanel __instance)
{
if (__instance.minerId == 0 || __instance.factory == null)
{
__instance._Close();
}
else
{
MinerComponent minerComponent = __instance.factorySystem.minerPool[__instance.minerId];
if (minerComponent.id != __instance.minerId)
{
__instance._Close();
}
else
{
if (minerComponent.type == EMinerType.Vein)
{
var speed = (_oreValuePerNode * (float)GameMain.data.history.miningSpeedScale * (float)minerComponent.veinCount * ((float)minerComponent.speed / 10000.0)) / _displayFactor;
var speedText = speed.ToString("0.##");
var coverTextUnlessStacking = minerComponent.productCount > 0 ? "" : _coverText;
__instance.coverText.text = $"{coverTextUnlessStacking}{minerComponent.veinCount}{_veinText} ({speedText}/{_displayUnit})";
}
}
}
}
}
}