Beispiel #1
0
        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, 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);
        }
        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);
        }
Beispiel #5
0
 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;
     }
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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 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);
        }