-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatch.cs
More file actions
93 lines (79 loc) · 2.27 KB
/
Patch.cs
File metadata and controls
93 lines (79 loc) · 2.27 KB
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
90
91
92
93
using System;
using HarmonyLib;
using UnityEngine;
namespace RemainingLayhand;
[HarmonyPatch]
public static class Patch
{
const int LayhandId = 1408;
static Sprite sprite;
[HarmonyPrefix, HarmonyPatch(typeof(WidgetStatsBar), nameof(WidgetStatsBar.Add))]
public static void WidgetStatsBar_Add_Prefix(WidgetStatsBar __instance, string id)
{
if (Settings.Position == "before")
{
apply(__instance, id);
}
}
[HarmonyPostfix, HarmonyPatch(typeof(WidgetStatsBar), nameof(WidgetStatsBar.Add))]
public static void WidgetStatsBar_Add_Postfix(WidgetStatsBar __instance, string id)
{
if (Settings.Position == "after")
{
apply(__instance, id);
}
}
private static void apply(WidgetStatsBar w, string id)
{
if (id != Settings.Anchor) { return; }
w.Add(null, "layhand", Sprite(), () => $"{remainingLayhand()}/{maxLayhand()}");
w.Refresh();
}
private static int maxLayhand()
{
int ret = 0;
foreach (Chara c in EClass._map.charas)
{
if (layhandable(c)) { ret++; }
}
return ret;
}
private static int remainingLayhand()
{
int ret = 0;
var now = EClass.world.date.GetRawDay();
foreach (Chara c in EClass._map.charas)
{
if (layhandable(c) && now != c.GetInt(58)) { ret++; }
}
return ret;
}
// https://github.com/Elin-Modding-Resources/Elin-Decompiled/blob/72332a1390e68a8de62bca4acbd6ebbaab92257b/Elin/Card.cs#L4317
static bool layhandable(Chara c)
{
return EClass.pc.IsFriendOrAbove(c) && c.HasElement(LayhandId) && c.faith == EClass.game.religions.Healing && c.memberType != FactionMemberType.Livestock;
}
static Sprite Sprite()
{
if (sprite == null)
{
var targetSprite = WidgetStatsBar.Instance.iconMoney;
var orig = CharaGen.Create("turtle").GetSprite();
var tex = orig.texture;
var rect = orig.textureRect;
Rect bottomRect = new Rect(
rect.x,
rect.y,
rect.width,
rect.height / 2f
);
Vector2 pivot = new Vector2(
orig.pivot.x / rect.width,
orig.pivot.y / rect.height
);
var ppu = tex.width / (targetSprite.texture.width / targetSprite.pixelsPerUnit) * 0.6f;
sprite = UnityEngine.Sprite.Create(tex, bottomRect, pivot, ppu);
}
return sprite;
}
}