Пример #1
0
        internal void ConsequenceChangeCaptorGold(Companion companion, Hero hero)
        {
            if (!companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.ChangeCaptorGold))
            {
                return;
            }

            if (hero.PartyBelongedToAsPrisoner.LeaderHero == null)
            {
                return;
            }

            try
            {
                int level = 0;

                if (!string.IsNullOrEmpty(companion.GoldTotal))
                {
                    level = new CEVariablesLoader().GetIntFromXML(companion.GoldTotal);
                }
                else
                {
                    CECustomHandler.LogToFile("Missing GoldTotal");
                }

                GiveGoldAction.ApplyBetweenCharacters(null, hero.PartyBelongedToAsPrisoner.LeaderHero, level);
            }
            catch (Exception) { CECustomHandler.LogToFile("Invalid GoldTotal"); }
        }
Пример #2
0
        internal void ConsequenceChangeSkill(Companion companion, Hero hero)
        {
            try
            {
                int level = 0;
                int xp    = 0;

                if (companion.SkillsToLevel != null && companion.SkillsToLevel.Count(SkillToLevel => SkillToLevel.Ref.ToLower() == "hero") != 0)
                {
                    foreach (SkillToLevel skillToLevel in companion.SkillsToLevel)
                    {
                        if (skillToLevel.Ref.ToLower() == "captor" && hero.PartyBelongedToAsPrisoner.LeaderHero == null)
                        {
                            continue;
                        }
                        if (!string.IsNullOrWhiteSpace(skillToLevel.ByLevel))
                        {
                            level = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByLevel);
                        }
                        else if (!string.IsNullOrWhiteSpace(skillToLevel.ByXP))
                        {
                            xp = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByXP);
                        }

                        new Dynamics().SkillModifier(skillToLevel.Ref.ToLower() != "hero" ? hero.PartyBelongedToAsPrisoner.LeaderHero : hero, skillToLevel.Id, level, xp, !skillToLevel.HideNotification, skillToLevel.Color);
                    }
                }
            }
            catch (Exception) { CECustomHandler.LogToFile("Invalid Skill Flags"); }
        }
Пример #3
0
        public static void CELoadRandomEvent(CampaignGameStarter gameStarter, CEEvent listedEvent, List <CEEvent> eventList)
        {
            CEVariablesLoader          variablesLoader = new CEVariablesLoader();
            MenuCallBackDelegateRandom rcb             = new MenuCallBackDelegateRandom(listedEvent, eventList);

            if (listedEvent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.ProgressMenu))
            {
                gameStarter.AddWaitGameMenu(listedEvent.Name,
                                            listedEvent.Text,
                                            rcb.RandomProgressInitWaitGameMenu,
                                            rcb.RandomProgressConditionWaitGameMenu,
                                            rcb.RandomProgressConsequenceWaitGameMenu,
                                            rcb.RandomProgressTickWaitGameMenu,
                                            CEProgressMode(variablesLoader.GetIntFromXML(listedEvent.ProgressEvent.DisplayProgressMode)),
                                            TaleWorlds.CampaignSystem.Overlay.GameOverlays.MenuOverlayType.None,
                                            variablesLoader.GetFloatFromXML(listedEvent.ProgressEvent.TimeToTake),
                                            GameMenu.MenuFlags.none,
                                            "CEEVENTS");
            }
            else
            {
                gameStarter.AddGameMenu(
                    listedEvent.Name,
                    listedEvent.Text,
                    rcb.RandomEventGameMenu,
                    TaleWorlds.CampaignSystem.Overlay.GameOverlays.MenuOverlayType.None,
                    GameMenu.MenuFlags.none,
                    "CEEVENTS");
            }

            if (listedEvent.Options == null)
            {
                return;                                                                                                     // Leave if no Options
            }
            List <Option> sorted = listedEvent.Options.OrderBy(item => variablesLoader.GetIntFromXML(item.Order)).ToList(); // Sort Options

            foreach (Option op in sorted)
            {
                MenuCallBackDelegateRandom mcb = new MenuCallBackDelegateRandom(listedEvent, op, eventList);
                gameStarter.AddGameMenuOption(
                    listedEvent.Name,
                    listedEvent.Name + op.Order,
                    op.OptionText,
                    mcb.RandomEventConditionMenuOption,
                    mcb.RandomEventConsequenceMenuOption,
                    false, variablesLoader.GetIntFromXML(op.Order));
            }
        }
Пример #4
0
        public void SpawnTheTroops(SpawnTroop[] variables, PartyBase party)
        {
            foreach (SpawnTroop troop in variables)
            {
                try
                {
                    int             num             = new CEVariablesLoader().GetIntFromXML(troop.Number);
                    int             numWounded      = new CEVariablesLoader().GetIntFromXML(troop.WoundedNumber);
                    CharacterObject characterObject = MBObjectManager.Instance.GetObject <CharacterObject>(troop.Id);

                    if (characterObject == null)
                    {
                        foreach (CharacterObject characterObject2 in MBObjectManager.Instance.GetObjectTypeList <CharacterObject>())
                        {
                            if (characterObject2.Occupation == Occupation.Soldier && string.Equals(characterObject2.Name.ToString(), troop.Id, StringComparison.OrdinalIgnoreCase))
                            {
                                characterObject = characterObject2;
                                break;
                            }
                        }
                    }

                    if (characterObject != null)
                    {
                        if (num > 0)
                        {
                            if (troop.Ref != null && troop.Ref.ToLower() == "troop")
                            {
                                party.MemberRoster.AddToCounts(characterObject, num, false, numWounded, 0, true, -1);
                            }
                            else
                            {
                                party.PrisonRoster.AddToCounts(characterObject, num, false, numWounded, 0, true, -1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    CECustomHandler.ForceLogToFile("Failed to SpawnTheTroops : " + e);
                }
            }
        }
Пример #5
0
        private void SkillObjectModifier(SkillObject skillObject, Color color, Hero hero, string skill, int amount, int xp, bool display = true, bool resetSkill = false)
        {
            if (xp == 0)
            {
                int currentSkillLevel = hero.GetSkillValue(skillObject);
                int newNumber         = resetSkill ? 0 : currentSkillLevel + amount;

                CESkillNode skillNode = CESkills.FindSkillNode(skill);
                if (skillNode != null)
                {
                    int maxLevel = new CEVariablesLoader().GetIntFromXML(skillNode.MaxLevel);

                    int minLevel = new CEVariablesLoader().GetIntFromXML(skillNode.MinLevel);
                    if (maxLevel != 0 && newNumber > maxLevel)
                    {
                        newNumber = maxLevel;
                        amount    = maxLevel - currentSkillLevel;
                    }
                    else if (newNumber < minLevel)
                    {
                        newNumber = minLevel;
                        amount    = minLevel - currentSkillLevel;
                    }
                }
                else if (newNumber < 0)
                {
                    newNumber = 0;
                    amount    = newNumber - currentSkillLevel;
                }

                float xpToSet = Campaign.Current.Models.CharacterDevelopmentModel.GetXpRequiredForSkillLevel(newNumber);
                Campaign.Current.Models.CharacterDevelopmentModel.GetSkillLevelChange(hero, skillObject, xpToSet, out int levels);
                hero.HeroDeveloper.SetPropertyValue(skillObject, xpToSet);

                if (levels > 0)
                {
                    MethodInfo mi = hero.HeroDeveloper.GetType().GetMethod("ChangeSkillLevelFromXpChange", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (mi != null)
                    {
                        mi.Invoke(hero.HeroDeveloper, new object[] { skillObject, levels, false });
                    }
                }
                else
                {
                    hero.SetSkillValue(skillObject, newNumber);
                }

                if (!display)
                {
                    return;
                }

                TextObject textObject = GameTexts.FindText("str_CE_level_skill");
                textObject.SetTextVariable("HERO", hero.Name);

                if (xp == 0)
                {
                    textObject.SetTextVariable("NEGATIVE", amount > 0 ? 0 : 1);
                }
                else
                {
                    textObject.SetTextVariable("NEGATIVE", xp >= 0 ? 0 : 1);
                }

                textObject.SetTextVariable("SKILL_AMOUNT", Math.Abs(amount));

                textObject.SetTextVariable("PLURAL", amount > 1 || amount < 1 ? 1 : 0);
                textObject.SetTextVariable("SKILL", skillObject.Name.ToLower());
                textObject.SetTextVariable("TOTAL_AMOUNT", newNumber);
                InformationManager.DisplayMessage(new InformationMessage(textObject.ToString(), color));
            }
            else
            {
                hero.HeroDeveloper.AddSkillXp(skillObject, xp, true, display);
            }
        }
Пример #6
0
        public static CEEvent ReturnWeightedChoiceOfEventsPartyLeader(CharacterObject captive)
        {
            List <CEEvent> events = new List <CEEvent>();

            CECustomHandler.LogToFile("Number of Filitered events is " + events.Count);

            if (CEPersistence.CECallableEvents == null || CEPersistence.CECallableEvents.Count <= 0)
            {
                return(null);
            }
            CECustomHandler.LogToFile("Having " + CEPersistence.CECallableEvents.Count + " of events to weight and check conditions on.");

            foreach (CEEvent listEvent in CEPersistence.CECallableEvents)
            {
                if (listEvent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.Captor))
                {
                    string result = new CEEventChecker(listEvent).FlagsDoMatchEventConditions(captive, PartyBase.MainParty);

                    if (result == null)
                    {
                        int weightedChance = 10;

                        if (listEvent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.IgnoreAllOther))
                        {
                            CECustomHandler.LogToFile("IgnoreAllOther detected - autofire " + listEvent.Name);
                            return(listEvent);
                        }

                        try
                        {
                            weightedChance = new CEVariablesLoader().GetIntFromXML(listEvent.WeightedChanceOfOccuring);
                        }
                        catch (Exception)
                        {
                            CECustomHandler.LogToFile("Missing WeightedChanceOfOccuring");
                        }

                        for (int a = weightedChance; a > 0; a--)
                        {
                            events.Add(listEvent);
                        }
                    }
                    else
                    {
                        CECustomHandler.LogToFile(result);
                    }
                }
            }

            CECustomHandler.LogToFile("Number of Filtered events is " + events.Count);

            try
            {
                if (events.Count > 0)
                {
                    CEEvent randomEvent = events.GetRandomElement();
                    randomEvent.Captive = captive;
                    return(randomEvent);
                }
            }
            catch (Exception e)
            {
                CECustomHandler.ForceLogToFile("eventNames.Count Broken : " + e);
                PrintDebugInGameTextMessage("eventNames.Count Broken");
            }

            return(null);
        }
Пример #7
0
        public static CEEvent ReturnWeightedChoiceOfEvents()
        {
            List <CEEvent> events = new List <CEEvent>();

            if (CEPersistence.CECallableEvents != null && CEPersistence.CECallableEvents.Count > 0)
            {
                CECustomHandler.LogToFile("Having " + CEPersistence.CECallableEvents.Count + " of events to weight and check conditions on.");

                foreach (CEEvent listEvent in CEPersistence.CECallableEvents)
                {
                    if (listEvent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.Captive))
                    {
                        string result = new CEEventChecker(listEvent).FlagsDoMatchEventConditions(CharacterObject.PlayerCharacter, PlayerCaptivity.CaptorParty);

                        if (result == null)
                        {
                            int weightedChance = 10;

                            if (listEvent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.IgnoreAllOther))
                            {
                                CECustomHandler.LogToFile("IgnoreAllOther detected - autofire " + listEvent.Name);
                                return(listEvent);
                            }

                            try
                            {
                                if (listEvent.WeightedChanceOfOccuring != null)
                                {
                                    weightedChance = new CEVariablesLoader().GetIntFromXML(listEvent.WeightedChanceOfOccuring);
                                }
                            }
                            catch (Exception)
                            {
                                CECustomHandler.LogToFile("Missing WeightedChanceOfOccuring");
                            }

                            for (int a = weightedChance; a > 0; a--)
                            {
                                events.Add(listEvent);
                            }
                        }
                        else
                        {
                            CECustomHandler.LogToFile(result);
                        }
                    }
                }

                CECustomHandler.LogToFile("Number of Filtered events is " + events.Count);

                try
                {
                    if (events.Count > 0)
                    {
                        return(events.GetRandomElement());
                    }
                }
                catch (Exception)
                {
                    CECustomHandler.LogToFile("Something is broken?");
                    PrintDebugInGameTextMessage("Something Broken...?");
                }
            }

            CECustomHandler.LogToFile("Number of Filitered events is " + events.Count);

            return(null);
        }
Пример #8
0
        public string CEWaitingList()
        {
            List <string> eventNames = new List <string>();

            if (CEPersistence.CEWaitingList != null && CEPersistence.CEWaitingList.Count > 0)
            {
                CECustomHandler.LogToFile("Having " + CEPersistence.CEWaitingList.Count + " of events to weight and check conditions on.");

                foreach (CEEvent listEvent in CEPersistence.CEWaitingList)
                {
                    string result = new CEEventChecker(listEvent).FlagsDoMatchEventConditions(CharacterObject.PlayerCharacter, PlayerCaptivity.CaptorParty);

                    if (result == null)
                    {
                        int weightedChance = 10;

                        try
                        {
                            if (listEvent.WeightedChanceOfOccuring != null)
                            {
                                weightedChance = new CEVariablesLoader().GetIntFromXML(listEvent.WeightedChanceOfOccuring);
                            }
                        }
                        catch (Exception)
                        {
                            CECustomHandler.LogToFile("Missing WeightedChanceOfOccuring");
                        }

                        for (int a = weightedChance; a > 0; a--)
                        {
                            eventNames.Add(listEvent.Name);
                        }
                    }
                    else
                    {
                        CECustomHandler.LogToFile(result);
                    }
                }

                CECustomHandler.LogToFile("Number of Filtered events is " + eventNames.Count);

                try
                {
                    if (eventNames.Count > 0)
                    {
                        int    test = MBRandom.Random.Next(0, eventNames.Count);
                        string randomWeightedChoice = eventNames[test];
                        CECustomHandler.LogToFile("CEWaitingList Choice is " + randomWeightedChoice);
                        return(randomWeightedChoice);
                    }
                }
                catch (Exception)
                {
                    CECustomHandler.ForceLogToFile("Waiting Menu: Something is broken?");
                }
            }

            CECustomHandler.LogToFile("Number of Filtered events is " + eventNames.Count);

            return(null);
        }
Пример #9
0
        public void SpawnTheHero(SpawnHero[] variables, PartyBase party)
        {
            foreach (SpawnHero heroVariables in variables)
            {
                try
                {
                    bool isFemale = heroVariables.Gender != null && heroVariables.Gender.ToLower() == "female";

                    string culture = null;
                    if (heroVariables.Culture != null)
                    {
                        switch (heroVariables.Culture.ToLower())
                        {
                        case "player":
                            culture = Hero.MainHero.Culture.StringId;
                            break;

                        case "captor":
                            culture = party.Culture.StringId;
                            break;

                        default:
                            culture = heroVariables.Culture;
                            break;
                        }
                    }
                    else
                    {
                        culture = heroVariables.Culture;
                    }

                    CharacterObject wanderer = (from x in CharacterObject.Templates
                                                where x.Occupation == Occupation.Wanderer && (culture == null || x.Culture != null && x.Culture.StringId == culture.ToLower()) && (heroVariables.Gender == null || x.IsFemale == isFemale)
                                                select x).GetRandomElementInefficiently();
                    Settlement randomElement = (from settlement in Settlement.All
                                                where settlement.Culture == wanderer.Culture && settlement.IsTown
                                                select settlement).GetRandomElementInefficiently();

                    Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, Clan.BanditFactions.GetRandomElementInefficiently(), null, -1);

                    GiveGoldAction.ApplyBetweenCharacters(null, hero, 20000, true);
                    hero.HasMet = true;
                    hero.ChangeState(Hero.CharacterStates.Active);
                    if (heroVariables.Clan != null)
                    {
                        switch (heroVariables.Clan.ToLower())
                        {
                        case "captor":
                            AddCompanionAction.Apply(party.Owner.Clan, hero);
                            break;

                        case "player":
                            AddCompanionAction.Apply(Clan.PlayerClan, hero);
                            break;

                        default:
                            break;
                        }
                    }

                    try
                    {
                        int level = 0;
                        int xp    = 0;

                        if (heroVariables.SkillsToLevel != null)
                        {
                            foreach (SkillToLevel skillToLevel in heroVariables.SkillsToLevel)
                            {
                                if (!string.IsNullOrWhiteSpace(skillToLevel.ByLevel))
                                {
                                    level = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByLevel);
                                }
                                else if (!string.IsNullOrWhiteSpace(skillToLevel.ByXP))
                                {
                                    xp = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByXP);
                                }

                                new Dynamics().SkillModifier(hero, skillToLevel.Id, level, xp, !skillToLevel.HideNotification, skillToLevel.Color);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        CECustomHandler.ForceLogToFile("Failed to level spawning Hero" + e);
                    }

                    if (heroVariables.Ref == "Prisoner" || heroVariables.Ref == "prisoner")
                    {
                        TakePrisonerAction.Apply(party, hero);
                    }
                    else
                    {
                        if (!party.IsMobile)
                        {
                            AddHeroToPartyAction.Apply(hero, party.Settlement.Party.MobileParty, true);
                        }
                        else
                        {
                            AddHeroToPartyAction.Apply(hero, party.MobileParty, true);
                        }
                    }

                    CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
                }
                catch (Exception e)
                {
                    CECustomHandler.ForceLogToFile("Failed to SpawnTheHero : " + e);
                }
            }
        }