Esempio n. 1
0
        private static void AddExiledHero()
        {
            Hero            mainhero = Hero.MainHero;
            CharacterObject wanderer = (from x in CharacterObject.Templates
                                        where x.Occupation == Occupation.Wanderer && x.Culture.StringId == mainhero.Culture.StringId
                                        select x).GetRandomElementInefficiently <CharacterObject>();

            Equipment equipment = (from y in CharacterObject.All
                                   where y.Level > 20 && y.Culture.StringId == wanderer.Culture.StringId && !y.IsHero && y.Tier > 4
                                   select y).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Equipment equipmentMC = (from z in CharacterObject.All
                                     where z.Tier == 4 && z.Culture.StringId == wanderer.Culture.StringId && !z.IsHero
                                     select z).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Settlement randomElement = (from settlement in Settlement.All
                                        where settlement.Culture == wanderer.Culture && settlement.IsTown
                                        select settlement).GetRandomElementInefficiently <Settlement>();
            //wanderer.Equipment.FillFrom(equipment);
            Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);

            Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
            GiveGoldAction.ApplyBetweenCharacters(null, hero, 4000, true);
            hero.BattleEquipment.FillFrom(equipment);
            mainhero.BattleEquipment.FillFrom(equipmentMC);
            hero.HasMet = true;
            hero.Clan   = randomElement.OwnerClan;
            hero.ChangeState(Hero.CharacterStates.Active);
            AddCompanionAction.Apply(Clan.PlayerClan, hero);
            AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
            CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
        }
Esempio n. 2
0
        private static void CSAddCompanion(int NoToAdd)
        {
            Hero mainhero = Hero.MainHero;

            for (int i = 0; i < NoToAdd; i++)
            {
                string          Locculture = CSCharCreationOption.CSOptionSettlement().Culture.StringId;
                CharacterObject wanderer   = (from x in CharacterObject.Templates
                                              where x.Occupation == Occupation.Wanderer && (x.Culture.StringId == mainhero.Culture.StringId || x.Culture.StringId == Locculture)
                                              select x).GetRandomElementInefficiently <CharacterObject>();
                Settlement randomElement = (from settlement in Settlement.All
                                            where settlement.Culture == wanderer.Culture && settlement.IsTown
                                            select settlement).GetRandomElementInefficiently <Settlement>();
                Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);
                Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
                GiveGoldAction.ApplyBetweenCharacters(null, hero, 2000, true);
                CSSetEquip(hero, 4);
                hero.HasMet = true;
                hero.Clan   = randomElement.OwnerClan;
                hero.ChangeState(Hero.CharacterStates.Active);
                AddCompanionAction.Apply(Clan.PlayerClan, hero);
                AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
            }
        }
        private static Hero DealNPC(CharacterObject target, CampaignGameStarter campaignGameStarter)
        {
            Hero hero = null;

            if (null != target)
            {
                CharacterObject character = CharacterObject.OneToOneConversationCharacter;
                hero = HeroCreator.CreateSpecialHero(character, null, Clan.PlayerClan, Clan.PlayerClan);
                // hero.StringId = "sms_npc_" + System.Enum.GetName(typeof(Occupation), character.Occupation) + hero.StringId;


                hero.ChangeState(Hero.CharacterStates.Active);
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
                HeroInitPropertyUtils.InitHeroForNPC(hero);


                AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
                ConversationUtils.ChangeCurrentCharaObject(campaignGameStarter, hero);

                if (hero.Age > 30)
                {
                    hero.SetBirthDay(HeroHelper.GetRandomBirthDayForAge((float)22));
                }
            }
            return(hero);
        }
        private void OnConsequenceRunnedEvent(ConversationSentence sentence)
        {
            if (sentence.OutputToken == lord_talk_speak_diplomacy_2)
            {
                // I have no choice but to remove the dead heroes, otherwise
                // the game will consider them as candidates for marriage.
                RemoveDeadClanMembers(Hero.OneToOneConversationHero.Clan.Lords as ICollection <Hero>);
                RemoveDeadClanMembers(Hero.MainHero.Clan.Lords as ICollection <Hero>);
            }

            if (sentence.Id == "lord_propose_marriage_conv_general_proposal_2" &&
                sentence.InputToken == lord_propose_marriage_to_clan_leader_options &&
                sentence.OutputToken == lord_propose_marriage_to_clan_leader_response)
            {
                CharacterObject characterObject = ConversationSentence.LastSelectedRepeatObject as CharacterObject;
                if (characterObject != null)
                {
                    playerRelative = characterObject.HeroObject;

                    // Bug in MarriageAction:
                    // if hero in party - party will be disbanded.
                    // Remove hero temporarily from the MainParty.
                    if (playerRelative.PartyBelongedTo != null &&
                        playerRelative.PartyBelongedTo == MobileParty.MainParty)
                    {
                        MobileParty.MainParty.AddElementToMemberRoster(playerRelative.CharacterObject, -1);
                        shouldJoinPartyAfterOffer = true;
                    }
                }
            }
            else if (sentence.InputToken == lord_propose_marriage_to_clan_leader_response &&
                     sentence.OutputToken == lord_propose_marriage_to_clan_leader_response_self)
            {
                proposedSpouseForPlayerRelative = Hero.OneToOneConversationHero;
            }
            else if (sentence.InputToken == lord_propose_marriage_to_clan_leader_response_self &&
                     sentence.OutputToken == lord_start_courtship_response &&
                     playerRelative != null && proposedSpouseForPlayerRelative != null)
            {
                StartMarriageBarter();
            }
            else if (sentence.InputToken == lord_propose_marriage_to_clan_leader_response &&
                     sentence.OutputToken == lord_propose_marriage_to_clan_leader_response_other)
            {
                Regex reHref = new Regex("<a .* href=\"event:Hero-(.*)\">");
                var   href   = reHref.Match(sentence.Text.ToString());
                if (href.Success)
                {
                    string id = href.Groups[1].Captures[0].ToString();
                    proposedSpouseForPlayerRelative = Hero.OneToOneConversationHero.Clan.Heroes.FirstOrDefault(h => h.StringId == id);
                }
            }
            else if (sentence.InputToken == lord_propose_marriage_to_clan_leader_response_other &&
                     sentence.OutputToken == lord_propose_marriage_to_clan_leader_confirm &&
                     playerRelative != null && proposedSpouseForPlayerRelative != null)
            {
                StartMarriageBarter();
            }
            else
            {
                if (shouldJoinPartyAfterOffer &&
                    playerRelative != null &&
                    playerRelative.PartyBelongedTo == null)
                {
                    AddHeroToPartyAction.Apply(playerRelative, MobileParty.MainParty);
                    shouldJoinPartyAfterOffer = false;
                }

                proposedSpouseForPlayerRelative = null;
                playerRelative = null;
            }
        }
Esempio n. 5
0
        private void OnChangeClanLeader(float dt)
        {
            MobileParty leaderParty    = leader.PartyBelongedTo;
            MobileParty newLeaderParty = newLeader.PartyBelongedTo;

            Utils.Print($"[OnChangeClanLeader] current leader {leader.Name} new leader {newLeader.Name}");

            if (leader == null || newLeader == null || leaderParty == null || newLeaderParty == null)
            {
                return;
            }

            if (newLeader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(newLeader);
            }
            if (leader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(leader);
            }

            string evt;

            while ((evt = newLeader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                newLeader.RemoveEventFromOccupiedHero(evt);
            }
            while ((evt = leader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                leader.RemoveEventFromOccupiedHero(evt);
            }

            GiveGoldAction.ApplyBetweenCharacters(leader, newLeader, leader.Gold, true);

            leader.Clan.SetLeader(newLeader);

            Settlement currentSettlement = newLeaderParty.CurrentSettlement;

            ChangePlayerCharacterAction.Apply(newLeader);

            if (newLeaderParty != leaderParty)
            {
                if (newLeaderParty.CurrentSettlement == null)
                {
                    EnterSettlementAction.ApplyForParty(newLeaderParty, currentSettlement);
                }

                foreach (var troop in leaderParty.MemberRoster.GetTroopRoster())
                {
                    if (troop.Character == leader.CharacterObject)
                    {
                        continue;
                    }

                    leaderParty.MemberRoster.AddToCounts(troop.Character, -troop.Number);
                    newLeaderParty.MemberRoster.AddToCounts(troop.Character, troop.Number);
                }

                foreach (var troop in leaderParty.PrisonRoster.GetTroopRoster())
                {
                    if (troop.Character == leader.CharacterObject)
                    {
                        continue;
                    }

                    leaderParty.PrisonRoster.AddToCounts(troop.Character, -troop.Number);
                    newLeaderParty.PrisonRoster.AddToCounts(troop.Character, troop.Number);
                }

                ItemRosterElement i;
                while (leaderParty.ItemRoster.Count() > 0)
                {
                    i = leaderParty.ItemRoster.First();
                    leaderParty.ItemRoster.AddToCounts(i.EquipmentElement, -i.Amount);
                    newLeaderParty.ItemRoster.AddToCounts(i.EquipmentElement, i.Amount);
                }

                leaderParty.RemoveParty();
                AddHeroToPartyAction.Apply(leader, newLeaderParty);
            }
            else
            {
                leaderParty.Party.Owner = newLeader;
                var partyList = leaderParty.Party.MemberRoster;
                partyList.RemoveTroop(newLeader.CharacterObject);
                partyList.AddToCounts(newLeader.CharacterObject, 1, true);
                var newPartyName = new TextObject("{=shL0WElC}{TROOP.NAME}'s Party");
                newPartyName.SetCharacterProperties("TROOP", newLeader.CharacterObject);
                leaderParty.SetCustomName(newPartyName);
            }

            leader.HasMet = true;

            newLeader.Clan.Influence = Math.Max(0, newLeader.Clan.Influence - 100);

            HeroFixHelper.FixHeroStats(newLeader);
            HeroFixHelper.FixEquipment(newLeader);

            newLeaderParty.Party.Visuals.SetMapIconAsDirty();
            CampaignEventDispatcher.Instance.OnArmyOverlaySetDirty();

            newLeader = null;
            leader    = null;
            CampaignEvents.RemoveListeners(this);
            Utils.Print($"[OnChangeClanLeader] changed over");
        }
Esempio n. 6
0
        private void OnChangeClanLeader(float dt)
        {
            MobileParty leaderParty    = leader.PartyBelongedTo;
            MobileParty newLeaderParty = newLeader.PartyBelongedTo;

            if (leader == null || newLeader == null || leaderParty == null || newLeaderParty == null || leaderParty == newLeaderParty)
            {
                return;
            }

            if (newLeader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(newLeader);
            }
            if (leader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(leader);
            }

            var qm = Campaign.Current.QuestManager;

            if (qm != null)
            {
                QuestBase q;
                while ((q = qm.Quests.FirstOrDefault(s => !s.IsSpecialQuest)) != null)
                {
                    q.CompleteQuestWithFail();
                }
            }

            string evt;

            while ((evt = newLeader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                newLeader.RemoveEventFromOccupiedHero(evt);
            }
            while ((evt = leader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                leader.RemoveEventFromOccupiedHero(evt);
            }

            GiveGoldAction.ApplyBetweenCharacters(leader, newLeader, leader.Gold, true);

            leader.Clan.SetLeader(newLeader);
            ChangePlayerCharacterAction.Apply(newLeader);

            TroopRosterElement t;

            while (leaderParty.MemberRoster.Count(x => x.Character != leader.CharacterObject) > 0)
            {
                t = leaderParty.MemberRoster.First(x => x.Character != leader.CharacterObject);
                leaderParty.MemberRoster.AddToCounts(t.Character, -t.Number);
                newLeaderParty.MemberRoster.AddToCounts(t.Character, t.Number);
            }

            while (leaderParty.PrisonRoster.Count() > 0)
            {
                t = leaderParty.PrisonRoster.First();
                leaderParty.PrisonRoster.AddToCounts(t.Character, -t.Number);
                newLeaderParty.PrisonRoster.AddToCounts(t.Character, t.Number);
            }

            ItemRosterElement i;

            while (leaderParty.ItemRoster.Count() > 0)
            {
                i = leaderParty.ItemRoster.First();
                leaderParty.ItemRoster.AddToCounts(i.EquipmentElement, -i.Amount);
                newLeaderParty.ItemRoster.AddToCounts(i.EquipmentElement, i.Amount);
            }

            leaderParty.RemoveParty();
            AddHeroToPartyAction.Apply(leader, newLeaderParty);

            newLeader.Clan.Influence = Math.Max(0, newLeader.Clan.Influence - 100);

            HeroFixHelper.FixHeroStats(newLeader);
            HeroFixHelper.FixEquipment(newLeader);

            newLeader = null;
            leader    = null;
            CampaignEvents.RemoveListeners(this);
        }
Esempio n. 7
0
        private void conversation_courtship_success_on_consequence()
        {
            ISettingsProvider settings = new MASettings();
            Hero hero          = Hero.MainHero;
            Hero spouse        = Hero.OneToOneConversationHero;
            Hero oldSpouse     = hero.Spouse;
            Hero cheatedSpouse = spouse.Spouse;

            // If you are marrying a kingdom ruler as a kingdom ruler yourself,
            // the kingdom ruler will have to give up being clan head.
            // Apparently causes issues if this is not done.
            if (spouse.IsFactionLeader && !spouse.IsMinorFactionHero)
            {
                if (hero.Clan.Kingdom != spouse.Clan.Kingdom)
                {
                    if (hero.Clan.Kingdom?.Leader != hero)
                    {
                        // Join kingdom due to lowborn status
                        if (hero.Clan.Leader == Hero.MainHero)
                        {
                            ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(hero.Clan);
                            if (hero.Clan.Leader == Hero.MainHero)
                            {
                                MAHelper.Print("No Heirs");
                                DestroyClanAction.Apply(hero.Clan);
                                MAHelper.Print("Eliminated Player Clan");
                            }
                        }
                        foreach (Hero companion in hero.Clan.Companions.ToList())
                        {
                            bool inParty = false;
                            if (companion.PartyBelongedTo == MobileParty.MainParty)
                            {
                                inParty = true;
                            }
                            RemoveCompanionAction.ApplyByFire(hero.Clan, companion);
                            AddCompanionAction.Apply(spouse.Clan, companion);
                            if (inParty)
                            {
                                AddHeroToPartyAction.Apply(companion, MobileParty.MainParty, true);
                            }
                        }
                        hero.Clan = spouse.Clan;
                        var current = Traverse.Create <Campaign>().Property("Current").GetValue <Campaign>();
                        Traverse.Create(current).Property("PlayerDefaultFaction").SetValue(spouse.Clan);
                        MAHelper.Print("Lowborn Player Married to Kingdom Ruler");
                    }
                    else
                    {
                        ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(spouse.Clan);
                        MAHelper.Print("Kingdom Ruler Stepped Down and Married to Player");
                    }
                }
            }
            // New nobility
            MAHelper.OccupationToLord(spouse.CharacterObject);
            if (!spouse.IsNoble)
            {
                spouse.IsNoble = true;
                MAHelper.Print("Spouse to Noble");
            }
            // Dodge the party crash for characters part 1
            bool dodge = false;

            if (spouse.PartyBelongedTo == MobileParty.MainParty)
            {
                AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, null, null);
                MAHelper.Print("Spouse Already in Player's Party");
                dodge = true;
            }
            // Apply marriage
            ChangeRomanticStateAction.Apply(hero, spouse, Romance.RomanceLevelEnum.Marriage);
            MAHelper.Print("Marriage Action Applied");
            if (oldSpouse is not null)
            {
                MAHelper.RemoveExSpouses(oldSpouse);
            }
            // Dodge the party crash for characters part 2
            if (dodge)
            {
                AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, MobileParty.MainParty, null);
            }
            // Activate character if not already activated
            if (!spouse.HasMet)
            {
                spouse.HasMet = true;
            }
            if (!spouse.IsActive)
            {
                spouse.ChangeState(Hero.CharacterStates.Active);
                MAHelper.Print("Activated Spouse");
            }
            if (spouse.IsPlayerCompanion)
            {
                spouse.CompanionOf = null;
                MAHelper.Print("Spouse No Longer Companion");
            }
            if (settings.Cheating && cheatedSpouse is not null)
            {
                MAHelper.RemoveExSpouses(cheatedSpouse, true);
                MAHelper.RemoveExSpouses(spouse, true);
                MAHelper.Print("Spouse Broke Off Past Marriage");
            }
            MAHelper.RemoveExSpouses(hero);
            MAHelper.RemoveExSpouses(spouse);
            PlayerEncounter.LeaveEncounter = true;
            // New fix to stop some kingdom rulers from disappearing
            if (spouse.PartyBelongedTo != MobileParty.MainParty)
            {
                AddHeroToPartyAction.Apply(spouse, MobileParty.MainParty, true);
            }
        }
Esempio n. 8
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);
                }
            }
        }