コード例 #1
0
            // Quest Conditions
            protected override void OnCompleteWithSuccess()
            {
                AddLog(OnQuestSucceededLogText);

                foreach (EquipmentCustomIndex index in Enum.GetValues(typeof(EquipmentCustomIndex)))
                {
                    EquipmentIndex i = (EquipmentIndex)index;

                    try
                    {
                        if (!Hero.MainHero.BattleEquipment.GetEquipmentFromSlot(i).IsEmpty)
                        {
                            PartyBase.MainParty.ItemRoster.AddToCounts(Hero.MainHero.BattleEquipment.GetEquipmentFromSlot(i).Item, 1);
                        }
                    }
                    catch (Exception) { }

                    try
                    {
                        if (!Hero.MainHero.CivilianEquipment.GetEquipmentFromSlot(i).IsEmpty)
                        {
                            PartyBase.MainParty.ItemRoster.AddToCounts(Hero.MainHero.CivilianEquipment.GetEquipmentFromSlot(i).Item, 1);
                        }
                    }
                    catch (Exception) { }
                }

                EquipmentHelper.AssignHeroEquipmentFromEquipment(Hero.MainHero, _stolenBattleEquipment);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(Hero.MainHero, _stolenCivilianEquipment);

                RemoveTrackedObject(QuestGiver);
            }
コード例 #2
0
        public void GiveWeapon(string weaponId)
        {
            var weapon    = MBObjectManager.Instance.GetObject <ItemObject>(weaponId);
            var equipment = new Equipment();

            equipment.AddEquipmentToSlotWithoutAgent(EquipmentIndex.Weapon1, new EquipmentElement(weapon));

            EquipmentHelper.AssignHeroEquipmentFromEquipment(ToTwHero(), equipment);
        }
コード例 #3
0
        public void GiveBodyArmor(string bodyArmorId)
        {
            var armor     = MBObjectManager.Instance.GetObject <ItemObject>(bodyArmorId);
            var equipment = new Equipment();

            equipment.AddEquipmentToSlotWithoutAgent(EquipmentIndex.Body, new EquipmentElement(armor));

            EquipmentHelper.AssignHeroEquipmentFromEquipment(ToTwHero(), equipment);
        }
コード例 #4
0
 private void ApplyShouldUndress()
 {
     if (CampaignState.CurrentGameStarted())
     {
         EquipmentHelper.AssignHeroEquipmentFromEquipment(new Hero(GameData.Instance.GameContext.Heroes.Player).ToTwHero(), new Equipment(true));
     }
     else
     {
         GameData.Instance.GameContext.Heroes.Player.Equipments = new List <IEquipments>();
     }
 }
コード例 #5
0
        internal void CECaptorStripVictim(Hero captive)
        {
            if (captive == null)
            {
                return;
            }
            Equipment randomElement = new Equipment(false);

            ItemObject itemObjectBody = captive.IsFemale
                ? MBObjectManager.Instance.GetObject <ItemObject>("burlap_sack_dress")
                : MBObjectManager.Instance.GetObject <ItemObject>("tattered_rags");

            randomElement.AddEquipmentToSlotWithoutAgent(EquipmentIndex.Body, new EquipmentElement(itemObjectBody));
            Equipment randomElement2 = new Equipment(true);

            randomElement2.FillFrom(randomElement, false);

            if (CESettings.Instance != null && CESettings.Instance.EventCaptorGearCaptives)
            {
                CECampaignBehavior.AddReturnEquipment(captive, captive.BattleEquipment, captive.CivilianEquipment);
            }



            foreach (EquipmentCustomIndex index in Enum.GetValues(typeof(EquipmentCustomIndex)))
            {
                EquipmentIndex i = (EquipmentIndex)index;

                try
                {
                    if (!captive.BattleEquipment.GetEquipmentFromSlot(i).IsEmpty)
                    {
                        PartyBase.MainParty.ItemRoster.AddToCounts(captive.BattleEquipment.GetEquipmentFromSlot(i).Item, 1);
                    }
                }
                catch (Exception) { }

                try
                {
                    if (!captive.CivilianEquipment.GetEquipmentFromSlot(i).IsEmpty)
                    {
                        PartyBase.MainParty.ItemRoster.AddToCounts(captive.CivilianEquipment.GetEquipmentFromSlot(i).Item, 1);
                    }
                }
                catch (Exception) { }
            }

            EquipmentHelper.AssignHeroEquipmentFromEquipment(captive, randomElement);
            EquipmentHelper.AssignHeroEquipmentFromEquipment(captive, randomElement2);
        }
コード例 #6
0
        private void ConsequenceStrip(Companion companion, Hero hero)
        {
            if (companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.Strip))
            {
                if (hero == null)
                {
                    return;
                }
                Equipment randomElement = new Equipment(false);

                ItemObject itemObjectBody = hero.IsFemale
                    ? MBObjectManager.Instance.GetObject <ItemObject>("burlap_sack_dress")
                    : MBObjectManager.Instance.GetObject <ItemObject>("tattered_rags");
                randomElement.AddEquipmentToSlotWithoutAgent(EquipmentIndex.Body, new EquipmentElement(itemObjectBody));
                Equipment randomElement2 = new Equipment(true);
                randomElement2.FillFrom(randomElement, false);

                if (CESettings.Instance != null && CESettings.Instance.EventCaptorGearCaptives)
                {
                    CECampaignBehavior.AddReturnEquipment(hero, hero.BattleEquipment, hero.CivilianEquipment);
                }

                foreach (EquipmentCustomIndex index in Enum.GetValues(typeof(EquipmentCustomIndex)))
                {
                    EquipmentIndex i = (EquipmentIndex)index;

                    try
                    {
                        if (!hero.BattleEquipment.GetEquipmentFromSlot(i).IsEmpty)
                        {
                            PartyBase.MainParty.ItemRoster.AddToCounts(hero.BattleEquipment.GetEquipmentFromSlot(i).Item, 1);
                        }
                    }
                    catch (Exception) { }

                    try
                    {
                        if (!hero.CivilianEquipment.GetEquipmentFromSlot(i).IsEmpty)
                        {
                            PartyBase.MainParty.ItemRoster.AddToCounts(hero.CivilianEquipment.GetEquipmentFromSlot(i).Item, 1);
                        }
                    }
                    catch (Exception) { }
                }

                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, randomElement);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, randomElement2);
            }
        }
コード例 #7
0
        // modified from 1.5.8 copy
        public static Hero CreateBanditHero(Clan mostPrevalent, MobileParty mobileParty)
        {
            var settlement = Hideouts.GetRandomElement();
            var num1       = 0;

            foreach (var characterObject in Source)
            {
                var num2 = characterObject.GetTraitLevel(DefaultTraits.Frequency) * 10;
                num1 += num2 > 0 ? num2 : 100;
            }

            if (!Source.Any())
            {
                return(null);
            }
            CharacterObject characterObject1 = null;
            var             num3             = 1 + (int)(settlement.Random.GetValueNormalized(settlement.Notables.Count) * (double)(num1 - 1));

            foreach (var characterObject2 in Source)
            {
                var num2 = characterObject2.GetTraitLevel(DefaultTraits.Frequency) * 10;
                num3 -= num2 > 0 ? num2 : 100;
                if (num3 < 0)
                {
                    characterObject1 = characterObject2;
                    break;
                }
            }

            var specialHero = HeroCreator.CreateSpecialHero(characterObject1, settlement);

            specialHero.SupporterOf = Clan.BanditFactions.ToList().GetRandomElement();
            Traverse.Create(typeof(HeroCreator)).Method("AddRandomVarianceToTraits", specialHero).GetValue();
            // 1.4.3b doesn't have these wired up really, but I patched prisoners with it... kinda
            specialHero.NeverBecomePrisoner = true;
            specialHero.AlwaysDie           = true;
            var partyStrength = Traverse.Create(mobileParty.Party).Method("CalculateStrength").GetValue <float>();

            specialHero.Gold = Convert.ToInt32(partyStrength * GoldMap[Globals.Settings.GoldReward]);
            //var hideout = Hideouts.Where(x => x.MapFaction != CampaignData.NeutralFaction).GetRandomElement();
            // home has to be set to a hideout to make party aggressive (see PartyBase.MapFaction)
            // 1.4.3b changed this now we also have to set ActualClan
            specialHero.Clan = mostPrevalent;
            // why is this not accessed?
            // ReSharper disable once NotAccessedVariable
            var lastSeenPlace = Traverse.Create(specialHero).Field <Hero.HeroLastSeenInformation>("_lastSeenInformationKnownToPlayer").Value;

            lastSeenPlace.LastSeenPlace = settlement;
            EquipmentHelper.AssignHeroEquipmentFromEquipment(specialHero, BanditEquipment.GetRandomElement());
            Traverse.Create(specialHero).Field("_homeSettlement").SetValue(settlement);
            Traverse.Create(specialHero.Clan).Field("_warParties").Method("Add", mobileParty).GetValue();
            mobileParty.MemberRoster.AddToCounts(specialHero.CharacterObject, 1, false, 0, 0, true, 0);
            if (Globals.Settings.CanTrain)
            {
                specialHero.SetSkillValue(Leadership, 150);
                specialHero.SetPerkValue(VeteransRespect, true);
            }

            MBObjectManager.Instance.RegisterObject(specialHero);
            return(specialHero);
        }
コード例 #8
0
        /// <summary>
        /// Behavior Duplicate found In PregnancyCampaignBehavior
        /// </summary>
        /// <param name="mother"></param>
        /// <param name="father"></param>
        /// <param name="isOffspringFemale"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        private Hero DeliverOffSpring(Hero mother, Hero father, bool isOffspringFemale, int age = 1)
        {
            CharacterObject characterObject = isOffspringFemale ? mother.CharacterObject : father.CharacterObject;

            characterObject.Culture = mother.Culture;

            // Reflection One
            MethodInfo mi = typeof(HeroCreator).GetMethod("CreateNewHero", BindingFlags.NonPublic | BindingFlags.Static);

            if (mi == null)
            {
                return(HeroCreator.DeliverOffSpring(mother, father, isOffspringFemale, null, 0));
            }
            Hero hero = (Hero)mi.Invoke(null, new object[] { characterObject, age });

            // For Wanderer Pregnancy
            hero.SetBirthDay(CampaignTime.Now);

            int             becomeChildAge   = Campaign.Current.Models.AgeModel.BecomeChildAge;
            CharacterObject characterObject2 = CharacterObject.ChildTemplates.FirstOrDefault((CharacterObject t) => t.Culture == mother.Culture && t.Age <= becomeChildAge && t.IsFemale == isOffspringFemale && t.Occupation == Occupation.Lord);

            if (characterObject2 != null)
            {
                Equipment equipment  = characterObject2.FirstCivilianEquipment.Clone(false);
                Equipment equipment2 = new Equipment(false);
                // TaleWorld's Bug
                if (hero.BattleEquipment == null)
                {
                    PropertyInfo fi = hero.GetType().GetProperty("BattleEquipment", BindingFlags.Instance | BindingFlags.Public);
                    if (fi != null)
                    {
                        fi.SetValue(hero, new Equipment(false));
                    }
                }
                if (hero.CivilianEquipment == null)
                {
                    PropertyInfo fi = hero.GetType().GetProperty("CivilianEquipment", BindingFlags.Instance | BindingFlags.Public);
                    if (fi != null)
                    {
                        fi.SetValue(hero, new Equipment(true));
                    }
                }
                equipment2.FillFrom(equipment, false);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment2);
            }

            hero.FirstName            = NameGenerator.Current.GenerateHeroFirstName(hero, true);
            hero.CharacterObject.Name = hero.FirstName;

            // Reflection Two
            mi = hero.HeroDeveloper.GetType().GetMethod("CheckInitialLevel", BindingFlags.NonPublic | BindingFlags.Instance);
            if (mi != null)
            {
                mi.Invoke(hero.HeroDeveloper, new object[] { });
            }

            Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, characterObject);
            hero.CharacterObject.IsFemale = isOffspringFemale;

            if (hero.CharacterObject.Occupation != Occupation.Lord)
            {
                PropertyInfo fi = hero.CharacterObject.GetType().GetProperty("Occupation", BindingFlags.Instance | BindingFlags.Public);
                if (fi != null)
                {
                    fi.SetValue(hero.CharacterObject, Occupation.Lord);
                }
            }

            BodyProperties bodyPropertiesMin  = mother.CharacterObject.GetBodyPropertiesMin(false);
            BodyProperties bodyPropertiesMin2 = father.CharacterObject.GetBodyPropertiesMin(false);
            int            seed       = isOffspringFemale ? mother.CharacterObject.GetDefaultFaceSeed(1) : father.CharacterObject.GetDefaultFaceSeed(1);
            string         hairTags   = isOffspringFemale ? mother.CharacterObject.HairTags : father.CharacterObject.HairTags;
            string         tattooTags = isOffspringFemale ? mother.CharacterObject.TattooTags : father.CharacterObject.TattooTags;

            PropertyInfo         pi         = hero.GetType().GetProperty("StaticBodyProperties", BindingFlags.Instance | BindingFlags.NonPublic);
            StaticBodyProperties staticBody = BodyProperties.GetRandomBodyProperties(isOffspringFemale, bodyPropertiesMin, bodyPropertiesMin2, 1, seed, hairTags, father.CharacterObject.BeardTags, tattooTags).StaticProperties;

            if (pi != null)
            {
                pi.SetValue(hero, staticBody);
            }

            hero.Mother = mother;
            hero.Father = father;

            // Reflection Two
            MethodInfo mi2 = typeof(HeroCreator).GetMethod("DecideBornSettlement", BindingFlags.NonPublic | BindingFlags.Static);

            if (mi == null)
            {
                return(HeroCreator.DeliverOffSpring(mother, father, isOffspringFemale, null, 0));
            }
            hero.BornSettlement = (Settlement)mi2.Invoke(null, new object[] { hero });

            hero.IsNoble = true;

            if (mother == Hero.MainHero || father == Hero.MainHero)
            {
                hero.HasMet = true;
                hero.Clan   = Clan.PlayerClan;
            }
            else
            {
                hero.Clan = father.Clan;
            }
            CampaignEventDispatcher.Instance.OnHeroCreated(hero, true);
            return(hero);
        }
コード例 #9
0
        private void conversation_adopt_child_on_consequence()
        {
            // Similar system from Recruit Everyone
            if (_notAdoptableAgents is not null)
            {
                _notAdoptableAgents.Add(_agent);
            }
            Agent           agent     = (Agent)Campaign.Current.ConversationManager.OneToOneConversationAgent;
            CharacterObject character = CharacterObject.OneToOneConversationCharacter;

            // Add a bit of the DeliverOffspring method into the mix
            Hero            hero            = HeroCreator.CreateSpecialHero(character, Settlement.CurrentSettlement, null, null, (int)agent.Age);
            int             becomeChildAge  = Campaign.Current.Models.AgeModel.BecomeChildAge;
            CharacterObject characterObject = CharacterObject.ChildTemplates.FirstOrDefault((CharacterObject t) => t.Culture == character.Culture && t.Age <= becomeChildAge && t.IsFemale == character.IsFemale && t.Occupation == Occupation.Lord);

            if (characterObject is not null)
            {
                Equipment equipment  = characterObject.FirstCivilianEquipment.Clone(false);
                Equipment equipment2 = new(false);
                equipment2.FillFrom(equipment, false);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment2);
            }
            MAHelper.OccupationToLord(hero.CharacterObject);
            hero.Clan = Clan.PlayerClan;
            AccessTools.Method(typeof(HeroDeveloper), "CheckInitialLevel").Invoke(hero.HeroDeveloper, null);
            hero.CharacterObject.IsFemale = character.IsFemale;
            BodyProperties bodyPropertiesValue = agent.BodyPropertiesValue;

            AccessTools.Property(typeof(Hero), "StaticBodyProperties").SetValue(hero, bodyPropertiesValue.StaticProperties);
            // Selects player as the parent
            if (Hero.MainHero.IsFemale)
            {
                hero.Mother = Hero.MainHero;
            }
            else
            {
                hero.Father = Hero.MainHero;
            }
            hero.IsNoble = true;
            hero.HasMet  = true;

            // Too much work to try and implement the log

            /*
             * CharacterAdoptedLogEntry characterAdoptedLogEntry = new(hero, Hero.MainHero);
             * Campaign.Current.CampaignInformationManager.NewMapNoticeAdded(new AdoptionMapNotification(hero, Hero.MainHero, characterAdoptedLogEntry.GetEncyclopediaText()));
             */

            // Cool idea. Might put this into Recruit Everyone, too!
            AccessTools.Field(typeof(Agent), "_name").SetValue(agent, hero.Name);
            OnHeroAdopted(Hero.MainHero, hero);
            // Follows you! I like this feature :3
            Campaign.Current.ConversationManager.ConversationEndOneShot += FollowMainAgent;

            int heroComesOfAge = Campaign.Current.Models.AgeModel.HeroComesOfAge;
            var instance       = Traverse.Create <CampaignEventDispatcher>().Property("Instance").GetValue <CampaignEventDispatcher>();

            if (hero.Age > becomeChildAge || (hero.Age == becomeChildAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear))
            {
                // CampaignEventDispatcher.Instance.OnHeroGrowsOutOfInfancy(hero);
                Traverse.Create(instance).Method("OnHeroGrowsOutOfInfancy", new Type[] { typeof(Hero) }).GetValue(new object[] { hero });
            }
            if (hero.Age > heroComesOfAge || (hero.Age == heroComesOfAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear))
            {
                // CampaignEventDispatcher.Instance.OnHeroComesOfAge(hero);
                Traverse.Create(instance).Method("OnHeroComesOfAge", new Type[] { typeof(Hero) }).GetValue(new object[] { hero });
            }
        }
コード例 #10
0
 public void Undress()
 {
     //TODO: keep equipment somewhere in case we want to return it to player.
     EquipmentHelper.AssignHeroEquipmentFromEquipment(ToTwHero(), new Equipment());
 }
コード例 #11
0
        private static bool Prefix(Settlement settlement)
        {
            bool        hadPlayerSupport          = false;
            List <Hero> NotablesSupportingReveolt = new List <Hero>();

            if (settlement.IsVillage)
            {
                return(true);
            }
            Town town = settlement.Town;

            foreach (var pair in NotableBehavior.RebelliousNotables)
            {
                if (town.Settlement.Notables.Contains(pair.Key))
                {
                    if (town.MapFaction == pair.Value)
                    {
                        hadPlayerSupport = true;
                        NotablesSupportingReveolt.Add(pair.Key);
                    }
                }
                foreach (Village village in town.Villages)
                {
                    if (village.Settlement.Notables.Contains(pair.Key))
                    {
                        hadPlayerSupport = true;
                        NotablesSupportingReveolt.Add(pair.Key);
                    }
                }
            }

            if (hadPlayerSupport)
            {
                InformationManager.ShowInquiry(new InquiryData("Rebellion", "Your supporters have started an uprising in " + settlement.Town.Name.ToString() + ".  Do you want to take direct control of the settlement or let them elect their own leader?  Taking control of the settlement will lead to a war with the previous owners", true, true, "take it", "let them decide", (Action)(() => {
                    DeclareWarAction.ApplyDeclareWarOverSettlement(settlement.MapFaction, Hero.MainHero.MapFaction);
                    ChangeOwnerOfSettlementAction.ApplyByRebellion(Hero.MainHero, settlement);
                }), (Action)(() => {
                    Random rng = new Random();
                    Hero newLeader = NotablesSupportingReveolt[rng.Next(0, NotablesSupportingReveolt.Count - 1)];
                    FieldInfo field2 = newLeader.GetType().GetField("Occupation", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if ((FieldInfo)null != field2)
                    {
                        field2.SetValue((object)newLeader, Occupation.Lord);
                    }

                    Clan clan = MBObjectManager.Instance.CreateObject <Clan>();
                    Banner ClanBanner = Banner.CreateRandomClanBanner();
                    TextObject clanName = newLeader.Culture.ClanNameList[rng.Next(0, newLeader.Culture.ClanNameList.Count)];
                    clan.InitializeClan(clanName, clanName, newLeader.Culture, ClanBanner);
                    clan.SetLeader(newLeader);
                    FieldInfo field = clan.GetType().GetField("_tier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if ((FieldInfo)null != field)
                    {
                        field.SetValue((object)clan, rng.Next(2, 4));
                    }

                    newLeader.Clan = clan;
                    newLeader.IsNoble = true;
                    MobileParty newMobileParty1 = clan.CreateNewMobileParty(newLeader);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

                    List <Equipment> Lordgear = new List <Equipment>();
                    foreach (Hero hero in Campaign.Current.Heroes)
                    {
                        if (hero.Culture == newLeader.Culture && hero.IsNoble && hero.IsFemale == newLeader.IsFemale)
                        {
                            Lordgear.Add(hero.BattleEquipment);
                        }
                    }
                    EquipmentHelper.AssignHeroEquipmentFromEquipment(newLeader, Lordgear[rng.Next(0, Lordgear.Count - 1)]);

                    clan.UpdateHomeSettlement(settlement);

                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.OwnerClan.Leader, -200);
                    if (settlement.OwnerClan.Leader != settlement.MapFaction.Leader)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.MapFaction.Leader, -200);
                    }
                    DeclareWarAction.Apply(settlement.MapFaction, newLeader.MapFaction);
                    ChangeOwnerOfSettlementAction.ApplyByRebellion(newLeader, settlement);
                })));
                return(false);
            }
            else
            {
                return(true);
            }
        }