Example #1
0
        /**
         * @detail:  change the seed of the children when delivered. To change children's appearance, make them look different.
         */
        static void Postfix(Hero mother, Hero father, bool isOffspringFemale, Hero __result)
        {
            if (__result == null)
            {
                GrowthDebug.LogError("The offspring is null", "Offspring", null);
                return;
            }

            if (__result.Mother == Hero.MainHero || __result.Father == Hero.MainHero ||
                __result.Clan == Hero.MainHero.Clan)
            {
                BodyProperties bodyPropertiesMinFather = father.CharacterObject.GetBodyPropertiesMin(false);
                BodyProperties bodyPropertiesMinMother = mother.CharacterObject.GetBodyPropertiesMin(false);

                int seed = __result.StringId.GetDeterministicHashCode() * 6791 + 1 * 197;

                Random rd       = new Random();
                int    addition = rd.Next(-5, 5);
                seed += addition;

                seed = (seed >= 0) ? seed : (-seed) % 2000;

                string hairTags   = isOffspringFemale ? mother.CharacterObject.HairTags : father.CharacterObject.HairTags;
                string tattooTags = isOffspringFemale
                    ? mother.CharacterObject.TattooTags
                    : father.CharacterObject.TattooTags;

                __result.CharacterObject.StaticBodyPropertiesMin =
                    BodyProperties.GetRandomBodyProperties(isOffspringFemale, bodyPropertiesMinMother,
                                                           bodyPropertiesMinFather, 1, seed, hairTags, father.CharacterObject.BeardTags, tattooTags)
                    .StaticProperties;
            }
        }
 static bool Prefix(Hero victim,
                    Hero killer,
                    KillCharacterAction.KillCharacterActionDetail actionDetail,
                    bool showNotification)
 {
     GrowthDebug.LogInfo($"KillCharacterActionDetail? --> {actionDetail.ToString()}");
     return(true);
 }
Example #3
0
 static void Finalizer(Exception __exception)
 {
     if (__exception != null)
     {
         GrowthDebug.ShowError($"Mount and Blade Bannerlord has encountered an error and needs to close. See the error information below.",
                               "Mount and Blade Bannerlord has crashed", __exception);
     }
 }
Example #4
0
 static void Postfix()
 {
     if (MobileParty.MainParty.CurrentSettlement == null && MobileParty.MainParty.LastVisitedSettlement == null)
     {
         GrowthDebug.LogInfo("ChangePlayerCharacterAction, two args are null");
         MobileParty.MainParty.CurrentSettlement =
             SettlementHelper.FindNearestSettlement((Func <Settlement, bool>)(sett =>
                                                                              sett.IsCastle || sett.IsTown));
     }
 }
Example #5
0
        public static void Inherit(Hero targetInheriter)
        {
            if (targetInheriter == null)
            {
                return;
            }

            try
            {
                GrowthDebug.LogInfo($"Enter inherit method, handling inherit of {targetInheriter}");

                targetInheriter.ClearSkills();
                targetInheriter.HeroDeveloper.ClearHeroLevel();
                int fatherInheritDivider = 0;
                int motherInheritDivider = 0;

                if (targetInheriter.IsFemale == true)
                {
                    fatherInheritDivider = 10;
                    motherInheritDivider = 5;
                }
                else
                {
                    fatherInheritDivider = 5;
                    motherInheritDivider = 10;
                }

                foreach (SkillObject skillIT in DefaultSkills.GetAllSkills())
                {
                    Hero InheritFather = targetInheriter.Father != null ? targetInheriter.Father : targetInheriter;
                    Hero InheritMother = targetInheriter.Mother != null ? targetInheriter.Mother : targetInheriter;
                    targetInheriter.HeroDeveloper.ChangeSkillLevel(skillIT,
                                                                   InheritFather.GetSkillValue(skillIT) / fatherInheritDivider +
                                                                   InheritMother.GetSkillValue(skillIT) / motherInheritDivider, false);
                }

                targetInheriter.Level = 0;

                targetInheriter.HeroDeveloper.UnspentFocusPoints     = 10;
                targetInheriter.HeroDeveloper.UnspentAttributePoints = 10;
            }
            catch (Exception e)
            {
                GrowthDebug.ShowError($"Error during inheritance", "Error During Inheritance", e);
            }
        }
Example #6
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();
            try
            {
                Harmony harmony = new Harmony("mod.growupandwork.kleinersilver");
                harmony.PatchAll();

                // GrowthDebug.LogInfo("Mod Loaded");
                // GrowthDebug.LogInfo($"Current Language: {BannerlordConfig.Language}");
                // CommunityPatchSubModule.Print("abc");
                Module.CurrentModule.GlobalTextManager.LoadGameTexts($"{BasePath.Name}/Modules/{ModuleFolderName}/ModuleData/module_strings.xml");
            }
            catch (Exception e)
            {
                GrowthDebug.ShowError($"An error occured whilst initializing the GrowUpAndWork",
                                      "Error during initialization", e);
            }
        }
Example #7
0
        protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
        {
            if (gameStarterObject == null)
            {
                return;
            }

            try
            {
                base.OnGameStart(game, gameStarterObject);
                if (!(game.GameType is Campaign))
                {
                    return;
                }
                CampaignGameStarter gameInitializer = (CampaignGameStarter)gameStarterObject;
                gameInitializer.AddBehavior(GrowUpAndWorkAgingCampaignBehavior.Instance);
            }
            catch (Exception e)
            {
                GrowthDebug.ShowError($"An error occured whilst game starting initializing the GrowUpAndWork",
                                      "Game Starting GrowUpAndWork Error", e);
            }
        }
        public static int GrowSibling(Hero hero)
        {
            int currentAge = (int)hero.Age;

            hero.BirthDay = HeroHelper.GetRandomBirthDayForAge((int)hero.Age + 1);

            if ((SettingClass.Instance.NPCChildrenGrowthBoostEnabled || hero.Clan == Clan.PlayerClan) &&
                (int)hero.Age == SettingClass.Instance.BecomeHeroAge)
            {
                if (hero.Clan == Clan.PlayerClan)
                {
                    GrowthDebug.LogInfo(
                        $"Your child {hero.Name} has now become a hero and is ready to fight for his clan!",
                        "Grow Sibling");

                    InformationManager.AddQuickInformation(
                        SettingClass.CurrentLanguage == "zh"
                            ? new TextObject($"你的孩子{hero.Name}已经成年, 成为了一个可以为家族而战的英雄")
                            : new TextObject(
                            $"Your child {hero.Name} has become a hero and is ready to fight for his clan!"),
                        0, null, "event:/ui/notification/quest_finished");

                    InformationManager.AddQuickInformation(
                        SettingClass.CurrentLanguage == "zh"
                            ? new TextObject($"你的孩子{hero.Name}从父母那里继承了部分能力, 在许多方面都突出常人")
                            : new TextObject(
                            $"Your child{hero.Name} inherits from its parents and become capable in many fields"),
                        0, null, "event:/ui/notification/quest_finished");
                }

                InheritHelper.Inherit(hero);
            }

            currentAge = (int)hero.Age;
            return(currentAge);
        }
 public override void SyncData(IDataStore dataStore)
 {
     GrowthDebug.LogInfo("Entering SyncData", "Tracking SyncData");
 }
 public override void RegisterEvents()
 {
     CampaignEvents.DailyTickEvent.AddNonSerializedListener(this, new Action(this.DailyTick));
     GrowthDebug.LogInfo("Run RegisterEvents", "Tracing RegisterEvents");
 }
        public static int GrowTargetHero(Hero hero)
        {
            if (hero == null)
            {
                return(-1);
            }

            int  currentAge = (int)hero.Age;
            bool notified   = false;

            if ((int)hero.Age > SettingClass.Instance.BecomeHeroAge)
            {
                foreach (var heroSibling in hero.Siblings)
                {
                    if (heroSibling.Age >= currentAge)
                    {
                        GrowSibling(heroSibling);

                        GrowthDebug.LogInfo(
                            $"${hero.Name}'s older siblings are 1 year older due to the growth of {hero.Name}");

                        if (heroSibling.Clan == Clan.PlayerClan && !notified)
                        {
                            InformationManager.AddQuickInformation(
                                SettingClass.CurrentLanguage == "zh"
                                    ? new TextObject($"因为{hero.Name}的成长,他的哥哥姐姐都长大了一岁")
                                    : new TextObject(
                                    $"{hero.Name}'s older siblings are 1 year older due to the growth of {hero.Name}"),
                                0, null, "event:/ui/notification/quest_update");
                            notified = true;
                        }
                    }
                }
            }

            hero.BirthDay = HeroHelper.GetRandomBirthDayForAge((int)hero.Age + 1);

            if (hero.Father == Hero.MainHero || hero.Mother == Hero.MainHero)
            {
                InformationManager.AddQuickInformation(
                    SettingClass.CurrentLanguage == "zh"
                        ? new TextObject($"你的孩子:{hero.Name} 现在已经{(int) hero.Age}岁了")
                        : new TextObject($"Now your child: {hero.Name} is {(int) hero.Age} years old"), 0,
                    null, "event:/ui/notification/quest_update");


                if (hero.Age >= SettingClass.Instance.BecomeHeroAge && hero.Age <= SettingClass.Instance.GrowthStopAge)
                {
                    // Only Main Heros get the notification
                    InformationManager.AddQuickInformation(
                        SettingClass.CurrentLanguage == "zh"
                            ? new TextObject($"因为你的孩子的成长,你和你的配偶都老了一岁")
                            : new TextObject(
                            "You and your spouse are 1 year older due to the growth of your children"),
                        0, null, "event:/ui/notification/quest_update");
                }
            }

            if ((int)hero.Age >= SettingClass.Instance.BecomeHeroAge &&
                (int)hero.Age <= SettingClass.Instance.GrowthStopAge)
            {
                if (hero.Mother != null)
                {
                    GrowTargetHero(hero.Mother);
                }

                if (hero.Father != null)
                {
                    GrowTargetHero(hero.Father);
                }
            }

            if ((int)hero.Age == SettingClass.Instance.BecomeHeroAge)
            {
                InheritHelper.Inherit(hero);
                if (hero.Clan == Clan.PlayerClan)
                {
                    GrowthDebug.LogInfo(
                        $"Your child {hero.Name} has now become a hero and is ready to fight for his clan!",
                        "Grow Target");

                    InformationManager.AddQuickInformation(
                        SettingClass.CurrentLanguage == "zh"
                            ? new TextObject($"你的孩子{hero.Name}已经成年, 成为了一个可以为家族而战的英雄")
                            : new TextObject(
                            $"Your child {hero.Name} has become a hero and is ready to fight for his clan!"),
                        0, null, "event:/ui/notification/quest_finished");

                    InformationManager.AddQuickInformation(
                        SettingClass.CurrentLanguage == "zh"
                            ? new TextObject($"你的孩子{hero.Name}从父母那里继承了部分能力, 在许多方面都突出常人")
                            : new TextObject(
                            $"Your child {hero.Name} inherits from its parents and become capable in many fields"),
                        0, null, "event:/ui/notification/quest_finished");
                }
            }

            currentAge = (int)hero.Age;
            return(currentAge);
        }
        static void Postfix()
        {
            // if setting enabled, grow npc children
            if (SettingClass.Instance.NPCChildrenGrowthBoostEnabled)
            {
                int numberOfNobleChildrenGrow   = 0;
                int numberOfNotableChildrenGrow = 0;

                if ((int)(Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow %
                          SettingClass.Instance.ChildrenGrowthCycle) == 0)
                {
                    Hero.All.ToList <Hero>().ForEach((heroEle) =>
                    {
                        if (heroEle.IsNoble && heroEle.Clan != Clan.PlayerClan)
                        {
                            if ((int)heroEle.Age < SettingClass.Instance.GrowthStopAge)
                            {
                                AgingSystemHelper.GrowTargetHero(heroEle);
                                numberOfNobleChildrenGrow += 1;
                            }
                        }

                        if (heroEle.IsNotable || heroEle.IsRuralNotable)
                        {
                            if ((int)heroEle.Age < SettingClass.Instance.GrowthStopAge)
                            {
                                GrowthDebug.LogInfo($"Handling Notable {heroEle.Name}", "Handling, notable");
                                AgingSystemHelper.GrowTargetHeroWithoutSideEffect(heroEle);
                                numberOfNotableChildrenGrow += 1;
                            }
                        }
                    });
                }

                if (numberOfNobleChildrenGrow > 0)
                {
                    InformationManager.DisplayMessage(SettingClass.CurrentLanguage == "zh"
                        ? new InformationMessage($"今天卡拉迪亚大陆有{numberOfNobleChildrenGrow}个贵族孩子又长大了一岁", Colors.Cyan)
                        : new InformationMessage(
                                                          $"Today, {numberOfNobleChildrenGrow} noble children grow up faster in the world of Calradia",
                                                          Colors.Cyan));
                    GrowthDebug.LogInfo($"Today, {numberOfNobleChildrenGrow} noble children grow faster in Calradia");
                }

                if (numberOfNotableChildrenGrow > 0)
                {
                    InformationManager.DisplayMessage(SettingClass.CurrentLanguage == "zh"
                        ? new InformationMessage($"今天卡拉迪亚大陆有{numberOfNotableChildrenGrow}个要人孩子又长大了一岁", Colors.Cyan)
                        : new InformationMessage(
                                                          $"Today, {numberOfNotableChildrenGrow} notable children grow up faster in the world of Calradia",
                                                          Colors.Cyan));
                    GrowthDebug.LogInfo(
                        $"Today, {numberOfNotableChildrenGrow} notable children grow faster in Calradia");
                }
            }

            if (Hero.MainHero.Children.Count != 0)
            {
                int cycleCeiling = SettingClass.Instance.ChildrenGrowthCycle;

                if ((int)(Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow % cycleCeiling) == 0)
                {
                    Hero.MainHero.Children.ForEach((Hero child) =>
                    {
                        GrowthDebug.LogInfo($"Handling Your child {child.Name}");
                        GrowthDebug.LogInfo($"Your child is {child.Age} years old before");
                        GrowthDebug.LogInfo("Entering ForEach");

                        if (child.Age < SettingClass.Instance.GrowthStopAge)
                        {
                            AgingSystemHelper.GrowTargetHero(child);
                        }
                    });
                }
            }
        }
Example #13
0
        public static void FixCappedKids()
        {
            Hero.MainHero.Children.ForEach((kid) =>
            {
                if (!kid.IsChild && kid.Age < 30)
                {
                    bool ShouldFixChildrenFlag = false;
                    int CappedSkillCounter     = 0;
                    int SkillTotal             = 0;

                    foreach (var skillObject in DefaultSkills.GetAllSkills())
                    {
                        SkillTotal += kid.GetSkillValue(skillObject);
                        if (kid.HeroDeveloper.GetSkillXpProgress(skillObject) < 0)
                        {
                            CappedSkillCounter++;
                        }

                        if (CappedSkillCounter > 5)
                        {
                            ShouldFixChildrenFlag = true;
                        }
                    }

                    if (SkillTotal <= 10 && kid.Level > 5)
                    {
                        ShouldFixChildrenFlag = true;
                    }

                    if (kid.HeroDeveloper.GetTotalSkillPoints() < 80 && kid.Level >= 5)
                    {
                        ShouldFixChildrenFlag = true;
                    }


                    int attrAccumulator = 0;
                    foreach (var VARIABLE in  CharacterAttributes.All)
                    {
                        attrAccumulator += kid.GetAttributeValue(VARIABLE.AttributeEnum);
                    }

                    attrAccumulator += kid.HeroDeveloper.UnspentAttributePoints;
                    GrowthDebug.LogInfo($"Kids{kid.Name} attribute sum: {attrAccumulator}");

                    if (attrAccumulator < 9 && kid.Level > 8)
                    {
                        ShouldFixChildrenFlag = true;
                    }

                    if (attrAccumulator >= 10 || kid.Level == 0)
                    {
                        ShouldFixChildrenFlag = false;
                    }

                    if (ShouldFixChildrenFlag)
                    {
                        InformationManager.DisplayMessage(new InformationMessage(
                                                              SettingClass.CurrentLanguage == "zh"
                                ? $"检测到你的孩子{kid.Name}属性异常, 已经修复"
                                : $"Detected Your Child {kid.Name}'s stats are abnormal, already fixed", Colors.Magenta));
                        GrowthDebug.LogInfo($"Detected Your Child{kid.Name}'s stats are abnormal, already fixed", "Fixed");
                        Inherit(kid);
                    }
                }
            });
        }