public static int GetMaxCounts(ref CraftingCampaignBehavior instance, Hero hero, EquipmentElement equipmentElement) { ItemRoster itemRoster = MobileParty.MainParty.ItemRoster; int energyCostForSmelting = Campaign.Current.Models.SmithingModel.GetEnergyCostForSmelting(equipmentElement.Item, hero); int result; if (energyCostForSmelting <= 0) { result = 2147483647; } else { result = instance.GetHeroCraftingStamina(hero) / energyCostForSmelting; } int[] smeltingOutputForItem = Campaign.Current.Models.SmithingModel.GetSmeltingOutputForItem(equipmentElement.Item); for (int i = 0; i < 9; i++) { if (smeltingOutputForItem[i] < 0) { result = Math.Min(result, MaxForInput(itemRoster, Campaign.Current.Models.SmithingModel.GetCraftingMaterialItem((CraftingMaterials)i), smeltingOutputForItem[i])); } } //return Math.Min(result, MaxForInput(itemRoster, item, 1)); return(result); }
static bool Prefix(CraftingCampaignBehavior __instance) { if (recordsInfo == null) { GetRecordsInfo(); } //Get the list of hero records IDictionary records = (IDictionary)recordsInfo.GetValue(__instance); foreach (Hero hero in records.Keys) { int curCraftingStamina = __instance.GetHeroCraftingStamina(hero); if (curCraftingStamina < Settings.Instance.MaxCraftingStamina) { int staminaGainAmount = Settings.Instance.CraftingStaminaGainAmount; if (Settings.Instance.CraftingStaminaGainOutsideSettlementMultiplier < 1 && hero.PartyBelongedTo?.CurrentSettlement == null) { staminaGainAmount = (int)Math.Ceiling(staminaGainAmount * Settings.Instance.CraftingStaminaGainOutsideSettlementMultiplier); } int diff = Settings.Instance.MaxCraftingStamina - curCraftingStamina; if (diff < staminaGainAmount) { staminaGainAmount = diff; } __instance.SetHeroCraftingStamina(hero, Math.Min(Settings.Instance.MaxCraftingStamina, curCraftingStamina + staminaGainAmount)); } } return(false); }
static bool Prefix(CraftingCampaignBehavior __instance) { try { IDictionary records = (IDictionary)(typeof(CraftingCampaignBehavior).GetField("_heroCraftingRecords", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance)); foreach (Hero hero in records.Keys) { int curCraftingStamina = __instance.GetHeroCraftingStamina(hero); if (curCraftingStamina < Settings.Instance.MaxCraftingStamina) { int staminaGainAmount = Settings.Instance.CraftingStaminaGainAmount; if (Settings.Instance.CraftingStaminaGainOutsideSettlementMultiplier < 1 && hero.PartyBelongedTo?.CurrentSettlement == null) { staminaGainAmount = (int)Math.Ceiling(staminaGainAmount * Settings.Instance.CraftingStaminaGainOutsideSettlementMultiplier); } int diff = Settings.Instance.MaxCraftingStamina - curCraftingStamina; if (diff < staminaGainAmount) { staminaGainAmount = diff; } __instance.SetHeroCraftingStamina(hero, Math.Min(Settings.Instance.MaxCraftingStamina, curCraftingStamina + staminaGainAmount)); //MessageBox.Show($"Hero: {hero.Name}\n\nCrafting Stamina: {__instance.GetHeroCraftingStamina(hero)}"); } } } catch (Exception ex) { MessageBox.Show($"An exception happened during the HourlyTick patch:\n\n{ex.Message}\n\n{ex.InnerException?.Message}", "Exception"); } return(false); }
public static int GetMaxCounts(ref CraftingCampaignBehavior instance, Hero hero, Crafting.RefiningFormula refineFormula) { ItemRoster itemRoster = MobileParty.MainParty.ItemRoster; int energyCostForRefining = Campaign.Current.Models.SmithingModel.GetEnergyCostForRefining(ref refineFormula, hero); int result; if (energyCostForRefining <= 0) { result = 2147483647; } else { result = instance.GetHeroCraftingStamina(hero) / energyCostForRefining; } if (refineFormula.Input1Count > 0) { ItemObject craftingMaterialItem1; int input1result; craftingMaterialItem1 = Campaign.Current.Models.SmithingModel.GetCraftingMaterialItem(refineFormula.Input1); input1result = MaxForInput(itemRoster, craftingMaterialItem1, refineFormula.Input1Count); result = input1result; } if (refineFormula.Input2Count > 0) { ItemObject craftingMaterialItem2; int input2result; craftingMaterialItem2 = Campaign.Current.Models.SmithingModel.GetCraftingMaterialItem(refineFormula.Input2); input2result = MaxForInput(itemRoster, craftingMaterialItem2, refineFormula.Input2Count); return(Math.Min(result, input2result)); } return(result); }
private static bool Prefix(CraftingCampaignBehavior __instance) { if (!ForgeOverhaulConfig.ConfigSettings.RestrictPartUnlockPerCategoryEnabled) //meh code { return(true); } Traverse.Create(__instance).Method("EnsureParts").GetValue(); var allParts = (CraftingPiece[])Traverse.Create(__instance).Field("_allCraftingParts").GetValue(); var openedParts = (List <CraftingPiece>)Traverse.Create(__instance).Field("_openedParts").GetValue(); int totalPartCount = allParts.Length; int unlockedPartCount = openedParts.Count; SmithingModel smithingModel = Campaign.Current.Models.SmithingModel; CraftingPiece[] array = (from x in allParts where !openedParts.Contains(x) && RememberLastDesignFix.LastWeaponCrafted.WeaponDesign.Template.Pieces.Contains(x) select x).ToArray <CraftingPiece>(); if (array.Length != 0) { CraftingPiece craftingPiece = MBRandom.ChooseWeighted <CraftingPiece>(array, (CraftingPiece x) => smithingModel.GetProbabalityToOpenPart(x)); if (craftingPiece != null) { Traverse.Create(__instance).Method("OpenPart", craftingPiece).GetValue(); } } return(false); }
public static void Postfix(ref CraftingCampaignBehavior __instance, Hero hero, WeaponDesign weaponDesign, int modifierTier, Crafting.OverrideData overrideData) { ScreenBase topScreen = ScreenManager.TopScreen; if (topScreen != null && Input.IsKeyDown(InputKey.LeftShift) && !TLSmithingFasterOperationCounts.Flag) { TLSmithingFasterOperationCounts.Flag = true; int maxcounts = TLSmithingFasterOperationCounts.GetMaxCounts(ref __instance, hero, weaponDesign, modifierTier, overrideData); maxcounts = Math.Min(maxcounts, 4); for (int i = 0; i < maxcounts; i++) { __instance.CreateCraftedWeapon(hero, weaponDesign, modifierTier, overrideData); } TLSmithingFasterOperationCounts.Flag = false; } if (topScreen != null && Input.IsKeyDown(InputKey.LeftControl) && !TLSmithingFasterOperationCounts.Flag) { TLSmithingFasterOperationCounts.Flag = true; int maxcounts = TLSmithingFasterOperationCounts.GetMaxCounts(ref __instance, hero, weaponDesign, modifierTier, overrideData); for (int i = 0; i < maxcounts; i++) { __instance.CreateCraftedWeapon(hero, weaponDesign, modifierTier, overrideData); } TLSmithingFasterOperationCounts.Flag = false; } }
static void Postfix(CraftingCampaignBehavior __instance, ItemObject item) { foreach (CraftingPiece piece in SmeltingHelper.GetNewPartsFromSmelting(item)) { methodInfo.Invoke(__instance, new object[] { piece }); } }
private static void Postfix(CraftingCampaignBehavior __instance) { if (stopWhenFull && MobileParty.MainParty.CurrentSettlement != null && MobileParty.MainParty.CurrentSettlement.IsTown && __instance.GetHeroCraftingStamina(Hero.MainHero) >= 100) { stopWhenFull = false; InformationManager.AddQuickInformation(new TextObject("Full stamina")); GameMenu.SwitchToMenu("town"); Campaign.Current.TimeControlMode = CampaignTimeControlMode.Stop; } }
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); }
private static bool HourlyTickPrefix(CraftingCampaignBehavior __instance) { if (ModSettings.Settings.CraftingConfig.Enabled) { var instanceType = __instance.GetType(); var craftingRecords = instanceType.GetField("_heroCraftingRecords", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance); var heroKeyCollection = craftingRecords.GetType().GetProperty("Keys", BindingFlags.Instance | BindingFlags.Public).GetValue(craftingRecords); var heroKeyCount = (int)heroKeyCollection.GetType().GetProperty("Count", BindingFlags.Instance | BindingFlags.Public).GetValue(heroKeyCollection); var heroKeyArray = new Hero[heroKeyCount]; heroKeyCollection.GetType().GetMethod("CopyTo", BindingFlags.Instance | BindingFlags.Public).Invoke(heroKeyCollection, new object[] { heroKeyArray, 0 }); foreach (var heroKey in heroKeyArray) { var tryGetValueParams = new object[] { heroKey, null }; var tryGetValueResult = craftingRecords.GetType().GetMethod("TryGetValue", BindingFlags.Instance | BindingFlags.Public).Invoke(craftingRecords, tryGetValueParams); if ((bool)tryGetValueResult) { var heroCraftingRecord = tryGetValueParams[1]; var craftingStaminaField = heroCraftingRecord.GetType().GetField("CraftingStamina", BindingFlags.Instance | BindingFlags.Public); var craftingStamina = (int)craftingStaminaField.GetValue(heroCraftingRecord); if (craftingStamina < 100) { int recoveryRate; if (heroKey.PartyBelongedTo?.CurrentSettlement != null) { recoveryRate = ModSettings.Settings.CraftingConfig.HourlySettlementStaminaRecoveryRate; } else { recoveryRate = ModSettings.Settings.CraftingConfig.HourlyMovingStaminaRecoveryRate; } craftingStaminaField.SetValue(heroCraftingRecord, Math.Min(100, craftingStamina + recoveryRate)); } } } return(false); } else { return(true); } }
public static void Prefix(CraftingCampaignBehavior __instance) { XmlNode settings = ClanTweakerSubModule.settings.xmlSettings.ChildNodes[1].SelectSingleNode("CraftingSettings"); int maxStamina = int.Parse(settings.SelectSingleNode("MaxStamina").InnerText); int hourlyGain = int.Parse(settings.SelectSingleNode("StaminaGain").InnerText); IDictionary dictionary = (IDictionary)typeof(CraftingCampaignBehavior).GetField("_heroCraftingRecords", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance); foreach (object obj in dictionary.Keys) { Hero hero = (Hero)obj; int heroCraftingStamina = __instance.GetHeroCraftingStamina(hero); if (heroCraftingStamina < maxStamina) { if (((hero.PartyBelongedTo != null) ? hero.PartyBelongedTo.CurrentSettlement : null) != null) { __instance.SetHeroCraftingStamina(hero, Math.Min(maxStamina, heroCraftingStamina + hourlyGain)); } } } }
public static string UnlockAllParts(List <string> strings) { if (Campaign.Current == null) { return("Campaign was not started."); } CraftingCampaignBehavior campaignBehavior = Campaign.Current.GetCampaignBehavior <CraftingCampaignBehavior>(); MethodInfo method = campaignBehavior.GetType().GetMethod("OpenPart", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { return("Failed to locate method."); } for (int i = 0; i < CraftingPiece.All.Count; i++) { method.Invoke(campaignBehavior, new object[] { CraftingPiece.All[i] }); } return("Unlocked all crafting pieces."); }
private static bool Prefix(CraftingCampaignBehavior __instance, int researchPoints) { var traverseOpenNewPartXP = Traverse.Create(__instance).Field("_openNewPartXP"); var OpenedParts = ((List <CraftingPiece>)Traverse.Create(__instance).Field("_openedParts").GetValue()); traverseOpenNewPartXP.SetValue((int)traverseOpenNewPartXP.GetValue() + researchPoints); if (OpenedParts != null) { var openedPartCount = (from x in OpenedParts where RememberLastDesignFix.LastWeaponCrafted.WeaponDesign.Template.Pieces.Contains(x) select x).Count <CraftingPiece>(); var researchPointsForNewPart = Campaign.Current.Models.SmithingModel.ResearchPointsNeedForNewPart(openedPartCount); var newPartXP = (int)traverseOpenNewPartXP.GetValue(); while (newPartXP > researchPointsForNewPart) { newPartXP -= researchPointsForNewPart; Traverse.Create(__instance).Method("OpenNewPart").GetValue(); researchPointsForNewPart = Campaign.Current.Models.SmithingModel.ResearchPointsNeedForNewPart(++openedPartCount); } traverseOpenNewPartXP.SetValue(newPartXP); } return(false); }
static void Postfix(CraftingCampaignBehavior __instance, ItemObject item) { if (item == null) { return; } if (__instance == null) { throw new ArgumentNullException(nameof(__instance), $"Tried to run postfix for {nameof(CraftingCampaignBehavior)}.DoSmelting but the instance was null."); } if (openPartMethodInfo == null) { GetMethodInfo(); } foreach (CraftingPiece piece in SmeltingHelper.GetNewPartsFromSmelting(item)) { if (piece != null && piece.Name != null) { openPartMethodInfo.Invoke(__instance, new object[] { piece }); } } }
public static int GetMaxCounts(ref CraftingCampaignBehavior instance, Hero hero, WeaponDesign weaponDesign, int modifierTier, Crafting.OverrideData overrideData) { ItemRoster itemRoster = MobileParty.MainParty.ItemRoster; int[] smithingCostsForWeaponDesign = Campaign.Current.Models.SmithingModel.GetSmithingCostsForWeaponDesign(weaponDesign); //Taleworlds may fix "9" in following days CraftingState craftingState; ItemObject currentCraftedItemObject; if ((craftingState = (GameStateManager.Current.ActiveState as CraftingState)) != null) { //false == don't force recreate. shall this effect item creation? currentCraftedItemObject = craftingState.CraftingLogic.GetCurrentCraftedItemObject(false, null); } else { return(0); } int energyCostForSmithing = Campaign.Current.Models.SmithingModel.GetEnergyCostForSmithing(currentCraftedItemObject, hero); int result; if (energyCostForSmithing <= 0) { result = 2147483647; } else { result = instance.GetHeroCraftingStamina(hero) / energyCostForSmithing; } for (int i = 0; i < 9; i++) { if (smithingCostsForWeaponDesign[i] < 0) { result = Math.Min(result, MaxForInput(itemRoster, Campaign.Current.Models.SmithingModel.GetCraftingMaterialItem((CraftingMaterials)i), smithingCostsForWeaponDesign[i])); } } return(result); }
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, ref int __result) { __result = Settings.Instance.MaxCraftingStamina; return(false); }
public static void Postfix(ref CraftingCampaignBehavior __instance, Hero hero, EquipmentElement equipmentElement) { ScreenBase topScreen = ScreenManager.TopScreen; if (topScreen != null && Input.IsKeyDown(InputKey.LeftShift) && !TLSmithingFasterOperationCounts.Flag) { TLSmithingFasterOperationCounts.Flag = true; int maxcounts = TLSmithingFasterOperationCounts.GetMaxCounts(ref __instance, hero, equipmentElement); maxcounts = Math.Min(maxcounts, 4); ItemRoster itemRoster = MobileParty.MainParty.ItemRoster; int item_num = 0; if (itemRoster.FindIndexOfElement(equipmentElement) >= 0) { item_num = itemRoster[itemRoster.FindIndexOfElement(equipmentElement)].Amount; } maxcounts = Math.Min(maxcounts, item_num); for (int i = 0; i < maxcounts; i++) { __instance.DoSmelting(hero, equipmentElement); } TLSmithingFasterOperationCounts.Flag = false; } if (topScreen != null && Input.IsKeyDown(InputKey.LeftControl) && !TLSmithingFasterOperationCounts.Flag) { TLSmithingFasterOperationCounts.Flag = true; IEnumerable <EquipmentElement> locks = Campaign.Current.GetCampaignBehavior <InventoryLockTracker>().GetLocks(); ItemRoster itemRoster = MobileParty.MainParty.ItemRoster; ItemRosterElement[] ItemRosterElements = itemRoster.GetCopyOfAllElements(); bool IsLocked = false; int max_item_count = ItemRosterElements.Length; for (int i = 0; i < max_item_count; i++) { itemRoster = MobileParty.MainParty.ItemRoster; ItemRosterElements = itemRoster.GetCopyOfAllElements(); foreach (EquipmentElement EquipmentElement in locks) { if (EquipmentElement.IsEqualTo(ItemRosterElements[i].EquipmentElement)) { IsLocked = true; break; } } int item_num = ItemRosterElements[i].Amount; int j; for (j = 0; j < item_num && !IsLocked && ItemRosterElements[i].EquipmentElement.Item.IsCraftedWeapon; j++) { int maxcounts = TLSmithingFasterOperationCounts.GetMaxCounts(ref __instance, hero, ItemRosterElements[i].EquipmentElement); if (maxcounts <= 0) { TLSmithingFasterOperationCounts.Flag = false; return; } __instance.DoSmelting(hero, ItemRosterElements[i].EquipmentElement); } if (j == item_num) { i--; max_item_count--; } IsLocked = false; } TLSmithingFasterOperationCounts.Flag = false; } }
private static bool Prefix(CraftingCampaignBehavior __instance, ref int __result) { ref int local = ref __result;
private static bool Prefix(CraftingCampaignBehavior __instance, ref int __result) { __result = BMRandomTweaksConfiguration.Instance.MaxCraftingStamina; return(false); }