-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReworked_SkillsSubModule.cs
256 lines (237 loc) · 15.4 KB
/
Reworked_SkillsSubModule.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using System;
using HarmonyLib;
using System.Collections.Generic;
using TaleWorlds.MountAndBlade;
using System.Linq;
using System.Reflection;
using TaleWorlds.Core;
using System.Windows.Forms;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.SandBox.GameComponents;
using TaleWorlds.Localization;
using TaleWorlds.CampaignSystem.ViewModelCollection.CharacterDeveloper;
using TaleWorlds.CampaignSystem.ViewModelCollection;
using TaleWorlds.Core.ViewModelCollection;
using TaleWorlds.Library;
using System.Xml;
namespace Reworked_Skills {
public class Reworked_SkillsSubModule : MBSubModuleBase {
public static float __ATTR_VALUE = 5;
public static float __FOCUS_VALUE = 10;
public static bool __DEFAULTLEARNING = false;
public static bool __DEFAULTNORMALIZEDLEARNING = true;
public static bool __FIXEDRATE = false;
public static float __FIXEDLEARNINGRATE = 9;
public static float __SKILLPNLT = 100;
public static float __SKILLPNLTDV = 15;
public static int __LEANRINGLIMIT = 240;
public static MethodInfo GetTooltipForAccumulatingPropertyWithResult;
protected override void OnSubModuleLoad() {
base.OnSubModuleLoad();
try {
XmlDocument xmlDocument = new XmlDocument();
string appSettings = String.Concat(BasePath.Name, "Modules/Reworked_Skills/config.xml");
xmlDocument.Load(appSettings);
XmlNode xmlNodes = xmlDocument.SelectSingleNode("ReworkedSkills");
foreach (XmlNode n in xmlNodes.ChildNodes) {
switch (n.Name.ToLower()) {
case "bonusperattribute":
float.TryParse(n.InnerText, out __ATTR_VALUE);
break;
case "bonusperfocus":
float.TryParse(n.InnerText, out __FOCUS_VALUE);
break;
case "experiencemultipliermode":
switch (n.InnerText.ToLower()) {
case "default":
__FIXEDRATE = false;
__DEFAULTNORMALIZEDLEARNING = false;
__DEFAULTLEARNING = true;
break;
case "defaultnormalized":
__DEFAULTLEARNING = false;
__FIXEDRATE = false;
__DEFAULTNORMALIZEDLEARNING = true;
break;
case "fixed":
__DEFAULTLEARNING = false;
__DEFAULTNORMALIZEDLEARNING = false;
__FIXEDRATE = true;
break;
}
break;
case "fixedlearningrate":
float.TryParse(n.InnerText, out __FIXEDLEARNINGRATE);
break;
case "normalizedbasepenalty":
float.TryParse(n.InnerText, out __SKILLPNLT);
break;
case "normalizeddivider":
float.TryParse(n.InnerText, out __SKILLPNLTDV);
break;
case "learninglimit":
int.TryParse(n.InnerText, out __LEANRINGLIMIT);
break;
}
}
if (GetTooltipForAccumulatingPropertyWithResult == null) {
GetTooltipForAccumulatingPropertyWithResult = typeof(CampaignUIHelper).GetMethod("GetTooltipForAccumulatingPropertyWithResult", BindingFlags.NonPublic | BindingFlags.Static);
}
Harmony patcher = new Harmony("Reworked_SkillsSubModulePatcher");
patcher.PatchAll();
} catch (Exception exception1) {
string message;
Exception exception = exception1;
string str = exception.Message;
Exception innerException = exception.InnerException;
if (innerException != null) {
message = innerException.Message;
} else {
message = null;
}
MessageBox.Show(string.Concat("Reworked_SkillsSubModule Error patching:\n", str, " \n\n", message));
}
}
}
[HarmonyPatch(typeof(CharacterObject), "GetSkillValue")]
class Patch1 {
static bool Prefix(CharacterObject __instance, CharacterSkills ____characterSkills, ref int __result, SkillObject skill) {
int focus = 0;
int attr = 0;
if (__instance.HeroObject != null) {
focus = __instance.HeroObject.HeroDeveloper.GetFocus(skill);
attr = __instance.HeroObject.GetAttributeValue(skill.CharacterAttributesEnum);
}
if (__instance.IsHero) {
__result = (int)(__instance.HeroObject.GetSkillValue(skill) + focus * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
} else {
__result = (int)(____characterSkills.GetPropertyValue(skill) + focus * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
}
return false;
}
}
[HarmonyPatch(typeof(BasicCharacterObject), "GetSkillValue")]
class Patch2 {
static bool Prefix(CharacterObject __instance, CharacterSkills ____characterSkills, ref int __result, SkillObject skill) {
int focus = __instance.HeroObject.HeroDeveloper.GetFocus(skill);
int attr = __instance.HeroObject.GetAttributeValue(skill.CharacterAttributesEnum);
__result = (int)(____characterSkills.GetPropertyValue(skill) + focus * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
return false;
}
}
[HarmonyPatch(typeof(DefaultCharacterDevelopmentModel), "CalculateLearningLimit", typeof(Hero), typeof(SkillObject), typeof(StatExplainer))]
public class Patch3 {
public static TextObject desription = new TextObject("{=MRktqZwu}Skill Focus", (Dictionary<string, TextObject>)null);
static bool Prefix(DefaultCharacterDevelopmentModel __instance, Hero hero, SkillObject skill, StatExplainer explainer, ref int __result) {
__result = Reworked_SkillsSubModule.__LEANRINGLIMIT;
return false; // make sure you only skip if really necessary
}
}
[HarmonyPatch(typeof(DefaultCharacterDevelopmentModel), "CalculateLearningLimit", typeof(int), typeof(int), typeof(TextObject), typeof(StatExplainer))]
class Patch4 {
private static TextObject _LevelText = new TextObject("{=RSaSKILV}Base Skill", (Dictionary<string, TextObject>)null);
public static int SKILLLEVEL;
static bool Prefix(DefaultCharacterDevelopmentModel __instance, int attributeValue, int focusValue, TextObject attributeName, StatExplainer explainer, ref int __result) {
if (explainer != null) {
ExplainedNumber explainedNumber = new ExplainedNumber(0.0f, explainer, (TextObject)null);
explainedNumber.Add(SKILLLEVEL, _LevelText);
explainedNumber.Add(attributeValue * Reworked_SkillsSubModule.__ATTR_VALUE, attributeName);
explainedNumber.Add(focusValue * Reworked_SkillsSubModule.__FOCUS_VALUE, Patch3.desription);
explainedNumber.LimitMin(0.0f);
__result = (int)explainedNumber.ResultNumber;
return false;
}
__result = (int)Reworked_SkillsSubModule.__LEANRINGLIMIT;
return false;
}
}
[HarmonyPatch(typeof(DefaultCharacterDevelopmentModel), "CalculateLearningRate",
typeof(int), typeof(int), typeof(int), typeof(int), typeof(TextObject), typeof(StatExplainer))]
class Patch6 {
private static TextObject _LevelText = new TextObject("{=RSaFRMLV}From Level", (Dictionary<string, TextObject>)null);
private static TextObject _NormalizedPenaltyText = new TextObject("{=RSaNRLPT}Normalized Penalty", (Dictionary<string, TextObject>)null);
private static TextObject _FixedRateText = new TextObject("{=RSaFXDRT}Fixed Rate", (Dictionary<string, TextObject>)null);
private static TextObject _skillFocusText = new TextObject("{=MRktqZwu}Skill Focus", (Dictionary<string, TextObject>)null);
private static TextObject _overLimitText = new TextObject("{=bcA7ZuyO}Learning Limit Exceeded", (Dictionary<string, TextObject>)null);
static bool Prefix(DefaultCharacterDevelopmentModel __instance,
int attributeValue, int focusValue, int skillValue, int characterLevel, TextObject attributeName, StatExplainer explainer, ref float __result) {
if (attributeValue == 11) {
skillValue -= (int)(attributeValue * Reworked_SkillsSubModule.__ATTR_VALUE + focusValue * Reworked_SkillsSubModule.__FOCUS_VALUE);
}
ExplainedNumber explainedNumber = new ExplainedNumber(0, explainer, (TextObject)null);
float BaseByLevel = (float)(20.0 / (10.0 + (double)characterLevel));
float Attribute = 0.4f * (float)10;
float Focus = (float)5 * 1f;
if (Reworked_SkillsSubModule.__DEFAULTLEARNING) {
explainedNumber.Add(BaseByLevel, _LevelText);
explainedNumber.Add(Attribute, attributeName);
explainedNumber.Add(Focus, _skillFocusText);
} else if (Reworked_SkillsSubModule.__DEFAULTNORMALIZEDLEARNING) {
float penalty = Math.Max(0, Reworked_SkillsSubModule.__SKILLPNLT - skillValue) / Reworked_SkillsSubModule.__SKILLPNLTDV;
explainedNumber.Add(BaseByLevel, _LevelText);
explainedNumber.Add(Attribute, attributeName);
explainedNumber.Add(Focus, _skillFocusText);
explainedNumber.Add(-penalty, _NormalizedPenaltyText);
} else if (Reworked_SkillsSubModule.__FIXEDRATE) {
explainedNumber.Add(Reworked_SkillsSubModule.__FIXEDLEARNINGRATE, _FixedRateText);
}
int learningLimit = Reworked_SkillsSubModule.__LEANRINGLIMIT;// __instance.CalculateLearningLimit(10, 5, (TextObject)null, (StatExplainer)null);
if (skillValue > learningLimit) {
int num = skillValue - learningLimit;
explainedNumber.AddFactor((float)(-1.0 - 0.100000001490116 * (double)num), _overLimitText);
}
explainedNumber.LimitMin(0.0f);
__result = explainedNumber.ResultNumber;
return false; // make sure you only skip if really necessary
}
}
[HarmonyPatch(typeof(SkillVM), "RefreshValues")]
class Patch7 {
private static TextObject _learningLimitStr = new TextObject("{=RWaLRNLM}Effective Skill", (Dictionary<string, TextObject>)null);
private static TextObject _learningRateStr = new TextObject("{=RWaLRNRT}Learning Rate", (Dictionary<string, TextObject>)null);
static void Postfix(SkillVM __instance, ref int ____fullLearningRateLevel, CharacterVM ____developerVM) {
int attr = ____developerVM.GetCurrentAttributePoint(__instance.Skill.CharacterAttributesEnum);
____fullLearningRateLevel = (int)(__instance.Level + __instance.CurrentFocusLevel * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
TextObject attrname = CharacterAttributes.GetCharacterAttribute(__instance.Skill.CharacterAttributeEnum).Name;
__instance.LearningRateTooltip = new BasicTooltipViewModel(() => GetLearningRateTooltip(attr, __instance.CurrentFocusLevel, __instance.Level, ____developerVM.Hero.CharacterObject.Level, attrname));
__instance.LearningLimitTooltip = new BasicTooltipViewModel(() => {
Patch4.SKILLLEVEL = __instance.Level;
return GetLearningLimitTooltip(attr, __instance.CurrentFocusLevel, attrname);
});
}
public static List<TooltipProperty> GetLearningLimitTooltip(int attributeValue, int focusValue, TextObject attributeName) {
StatExplainer statExplainer = new StatExplainer();
int learningLimit = Campaign.Current.Models.CharacterDevelopmentModel.CalculateLearningLimit(attributeValue, focusValue, attributeName, statExplainer);
var ret = (List<TooltipProperty>)Reworked_SkillsSubModule.GetTooltipForAccumulatingPropertyWithResult.Invoke(null, new object[] { _learningLimitStr.ToString(), (float)learningLimit, statExplainer });
return ret;
}
public static List<TooltipProperty> GetLearningRateTooltip(int attributeValue, int focusValue, int skillValue, int characterLevel, TextObject attributeName) {
StatExplainer statExplainer = new StatExplainer();
float learningRate = Campaign.Current.Models.CharacterDevelopmentModel.CalculateLearningRate(attributeValue, focusValue, skillValue, characterLevel, attributeName, statExplainer);
var ret = (List<TooltipProperty>)Reworked_SkillsSubModule.GetTooltipForAccumulatingPropertyWithResult.Invoke(null, new object[] { _learningRateStr.ToString(), learningRate, statExplainer });
return ret;
}
[HarmonyPatch(typeof(SkillVM), "RefreshWithCurrentValues")]
class Patch8 {
static void Postfix(SkillVM __instance, ref int ____fullLearningRateLevel, CharacterVM ____developerVM) {
int attr = ____developerVM.GetCurrentAttributePoint(__instance.Skill.CharacterAttributeEnum);
____fullLearningRateLevel = (int)(__instance.Level + __instance.CurrentFocusLevel * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
__instance.OnPropertyChanged(nameof(__instance.FullLearningRateLevel));
__instance.SkillEffects.Clear();
int skillValue = (int)(__instance.Level + __instance.CurrentFocusLevel * Reworked_SkillsSubModule.__FOCUS_VALUE + attr * Reworked_SkillsSubModule.__ATTR_VALUE);
foreach (SkillEffect effect in DefaultSkillEffects.GetAllSkillEffects().Where<SkillEffect>((Func<SkillEffect, bool>)(x => ((IEnumerable<SkillObject>)x.EffectedSkills).Contains<SkillObject>(__instance.Skill))))
__instance.SkillEffects.Add(new BindingListStringItem(CampaignUIHelper.GetSkillEffectText(effect, skillValue)));
}
}
}
//[HarmonyPatch(typeof(CampaignUIHelper), "GetLearningLimitTooltip")]
//class Patch9 {
// private static readonly TextObject _learningLimitStr2 = new TextObject("{=RWaEFFSK}Effective Skill", (Dictionary<string, TextObject>)null);
// static bool Prefix(int attributeValue, int focusValue, TextObject attributeName, ref List<TooltipProperty> __result) {
// StatExplainer statExplainer = new StatExplainer();
// int learningLimit = Campaign.Current.Models.CharacterDevelopmentModel.CalculateLearningLimit(attributeValue, focusValue, attributeName, statExplainer);
// __result = (List<TooltipProperty>)Reworked_SkillsSubModule.GetTooltipForAccumulatingPropertyWithResult.Invoke(null, new object[] { _learningLimitStr2.ToString(), (float)learningLimit, statExplainer });
// return false;
// }
//}
}