public static void Prefix(CraftingCampaignBehavior __instance) { Type HeroCraftingRecords = Traverse.Create <CraftingCampaignBehavior>().Type("HeroCraftingRecords").GetType(); var heroCraftingRecords = Traverse.Create(__instance).Field("_heroCraftingRecords").GetValue(); var enumerator = Traverse.Create(heroCraftingRecords).Method("GetEnumerator").GetValue(); var enumNext = Traverse.Create(enumerator).Method("MoveNext"); var enumGet = Traverse.Create(enumerator).Property("Current"); while (true) { if (!(enumNext.GetValue <bool>())) { break; } var current = enumGet.GetValue(); var currentValue = Traverse.Create(current).Property("Value").GetValue(); var craftingStamina = Traverse.Create(currentValue).Field <int>("CraftingStamina"); var hero = Traverse.Create(current).Property <Hero>("Key").Value; if (craftingStamina.Value < __instance.GetMaxHeroCraftingStamina(hero)) { MobileParty partyBelongedTo = hero.PartyBelongedTo; if (((partyBelongedTo != null) ? partyBelongedTo.CurrentSettlement : null) != null) { craftingStamina.Value = Math.Min(__instance.GetMaxHeroCraftingStamina(hero), craftingStamina.Value + ((__instance.GetMaxHeroCraftingStamina(hero) / 100) * 10)); } else { craftingStamina.Value = Math.Min(__instance.GetMaxHeroCraftingStamina(hero), craftingStamina.Value + ((__instance.GetMaxHeroCraftingStamina(hero) / 100) * 5)); } if (craftingStamina.Value == __instance.GetMaxHeroCraftingStamina(hero)) { var heroCharacter = Campaign.Current.Characters.First(x => x.IsHero && x.HeroObject.StringId == hero.StringId); InformationManager.DisplayMessage(new InformationMessage($"{(heroCharacter != null ? heroCharacter.Name : hero.GetName())}'s smithy stamina is full")); } } } }
static bool Prefix(CraftingCampaignBehavior __instance) { Hero hero = PartyBase.MainParty.LeaderHero; if (hero != null) { int heroCraftingStamina = __instance.GetHeroCraftingStamina(hero); int maxCraftingStamina = __instance.GetMaxHeroCraftingStamina(hero); int newStamina = Math.Min(maxCraftingStamina, heroCraftingStamina + SMITHING_STAMINA_GAIN); __instance.SetHeroCraftingStamina(hero, newStamina); } return(true); }