-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStat.cs
More file actions
137 lines (128 loc) · 6.59 KB
/
Stat.cs
File metadata and controls
137 lines (128 loc) · 6.59 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using UnityEngine;
using static CstiDetailedCardProgress.Utils;
namespace CstiDetailedCardProgress;
internal class Stat
{
[HarmonyPostfix]
[HarmonyPatch(typeof(StatStatusGraphics), "Update")]
public static void StatStatusGraphicsPatch(StatStatusGraphics __instance)
{
if (Plugin.Enabled)
__instance.SetTooltip(__instance.Title,
$"{(string.IsNullOrWhiteSpace(__instance.ModelStatus.Description) ? "" : $"{__instance.ModelStatus.Description.ToString()}\n")}{FormatInGameStat(__instance.ModelStatus.ParentStat)}",
"");
else
//Reset the tool tip to the base game settings.
__instance.SetTooltip(__instance.ModelStatus.GameName, __instance.ModelStatus.Description, "");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AffectedStatInfo), "Setup")]
public static void PatchAffectedStatInfoInteractable(AffectedStatInfo __instance, GameStat _Stat)
{
if (!Plugin.Enabled || !Plugin.ForceInspectStatInfos) return;
_Stat.CannotBeInspected = false;
__instance.InteractionButton.interactable = true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StatInfluenceInfo), "SetupStatSource")]
public static void PatchStatInfluenceInfoInteractable(StatInfluenceInfo __instance, InGameStat _Stat)
{
if (!Plugin.Enabled || !Plugin.ForceInspectStatInfos) return;
_Stat.StatModel.CannotBeInspected = false;
__instance.InteractionButton.interactable = true;
}
public static string FormatInGameStat(InGameStat stat)
{
List<string> texts = new();
List<string> valueModsTexts = new();
List<string> rateModsTexts = new();
if (stat.CurrentBaseValue != 0)
valueModsTexts.Add(FormatBasicEntry($"{stat.CurrentBaseValue:0.##}",
new LocalizedString { LocalizationKey = "CstiDetailedCardProgress.Stat.Base", DefaultText = "Base" }.ToString(),
indent: 2));
GameManager gm = MBSingleton<GameManager>.Instance;
// Seems deplicated with some sources in stat.ModifierSources
//if (gm != null && !gm.NotInBase)
//{
// if (stat.AtBaseModifiedValue != 0) valueModsTexts.Add(FormatTooltipEntry(stat.AtBaseModifiedValue, "At base", 2));
// if (stat.AtBaseModifiedRate != 0) rateModsTexts.Add(FormatRateEntry(stat.AtBaseModifiedRate, "At base"));
//}
if (stat.CurrentBaseRate != 0)
rateModsTexts.Add(FormatRateEntry(stat.CurrentBaseRate,
new LocalizedString { LocalizationKey = "CstiDetailedCardProgress.Stat.Base", DefaultText = "Base" }.ToString()));
foreach (StatModifierSource modifierSource in stat.ModifierSources)
if (modifierSource.ValidNumbers && modifierSource.ValidSource)
{
string source = GetModifierSourceName(modifierSource);
if (modifierSource.Rate != 0) rateModsTexts.Add(FormatRateEntry(modifierSource.Rate, source));
if (modifierSource.Value != 0) valueModsTexts.Add(FormatTooltipEntry(modifierSource.Value, source, 2));
}
texts.Add(FormatBasicEntry(
$"{stat.SimpleCurrentValue:0.##}: [{stat.StatModel.MinMaxValue.x:0.##}, {stat.StatModel.MinMaxValue.y:0.##}]",
stat.StatModel.GameName));
if (valueModsTexts.Count > 0) texts.Add(valueModsTexts.Join(delimiter: "\n"));
texts.Add(FormatRate(stat.SimpleRatePerTick, stat.SimpleCurrentValue, stat.StatModel.MinMaxValue.y,
stat.StatModel.MinMaxValue.x));
if (rateModsTexts.Count > 0) texts.Add(rateModsTexts.Join(delimiter: "\n"));
if (stat.CurrentStatuses != null && stat.CurrentStatuses.Count > 0)
{
foreach (var status in stat.CurrentStatuses)
{
if (status?.EffectsOnActions == null || status.EffectsOnActions.Length == 0) continue;
texts.Add(FormatBasicEntry(new LocalizedString()
{
LocalizationKey = "CstiDetailedCardProgress.TimeCostModifiers",
DefaultText = "Time Cost Modifiers"
}, ""));
foreach (var effect in status.EffectsOnActions)
{
if (effect.DurationModifier == 0) continue;
texts.Add(FormatActionDurationModifiers(effect, 2));
}
}
}
if (stat.StatModel.UsesNovelty && stat.StalenessValues.Count > 0)
{
List<string> stalenessText = new();
foreach (var staleness in stat.StalenessValues)
{
if (staleness.Quantity > -1 && stat.StatModel.StalenessMultiplier != 0)
stalenessText.Add(FormatBasicEntry(
$"{Mathf.Pow(stat.StatModel.StalenessMultiplier, staleness.Quantity + 1):G3}x",
$"(est. {stat.StatModel.NoveltyCooldownDuration - gm.CurrentTickInfo.z + staleness.LastTick + Math.Max(0, staleness.Quantity) * stat.StatModel.NoveltyCooldownDuration}t) {staleness.ModifierSource}",
indent: 2));
};
if (stalenessText.Count > 0)
{
texts.Add(FormatBasicEntry(
new LocalizedString
{
LocalizationKey = "CstiDetailedCardProgress.Stat.ActionStaleness",
DefaultText = "Action Staleness"
}, $"(×{1 / stat.StatModel.StalenessMultiplier:0.##}/{stat.StatModel.NoveltyCooldownDuration}t)"));
texts.Add(stalenessText.Join(delimiter: "\n"));
}
}
return $"<size=75%>{texts.Join(delimiter: "\n")}</size>";
}
public static string GetModifierSourceName(StatModifierSource modifierSource)
{
string sourceName = "";
if (modifierSource.Stat != null)
sourceName = modifierSource.Stat.StatModel.GameName;
else if (modifierSource.Card != null)
sourceName = modifierSource.Card.CardModel.CardName.ToString();
else if (modifierSource.Character != null)
sourceName = modifierSource.Character.CharacterName;
else if (modifierSource.Perk != null)
sourceName = modifierSource.Perk.PerkName;
else if (modifierSource.TimeOfDay != null)
sourceName =
$"{new LocalizedString { LocalizationKey = "CstiDetailedCardProgress.Stat.Time", DefaultText = "Time" }.ToString()} {modifierSource.TimeOfDay.EffectStartingTime}~{modifierSource.TimeOfDay.EffectEndTime}";
return sourceName;
}
}