Example #1
0
 private void DoTellStories(ToldStoriesTo village)
 {
     if (village._battleStoriesTold < _notableBattlesWon)
     {
         float _renownToGive = CalculateRenownToGive();
         GainRenownAction.Apply(Hero.MainHero, _renownToGive, true);
         InformationManager.DisplayMessage(new InformationMessage("You told the villagers a story about a notable battle, gained " + _renownToGive + " renown."));
         village._daysToResetStories = CampaignTime.DaysFromNow(RandomizeDays());
         village._hasToldStories     = true;
         village._battleStoriesTold++;
         Hero.MainHero.AddSkillXp(DefaultSkills.Charm, MBRandom.RandomInt(1, 3));
         if (_renownToGive >= 0.9)
         {
             if (Settlement.CurrentSettlement.Notables.Count >= 1)
             {
                 InformationManager.DisplayMessage(new InformationMessage("Notable people in village were impressed by your feats and like you more."));
                 foreach (Hero notablePerson in Settlement.CurrentSettlement.Notables)
                 {
                     ChangeRelationAction.ApplyPlayerRelation(notablePerson, +1, false, true);
                 }
             }
         }
     }
     else
     {
         InformationManager.DisplayMessage(new InformationMessage("You do not have new stories to tell to these villagers."));
     }
 }
Example #2
0
        private void IncreaseLocalRelations(MapEvent m)
        {
            float FinalRelationshipIncrease = KBRRModLibSettings.Instance.RelationshipIncrease;

            if (KBRRModLibSettings.Instance.SizeBonusEnabled)
            {
                FinalRelationshipIncrease = KBRRModLibSettings.Instance.RelationshipIncrease * this.BanditDeathCounter * KBRRModLibSettings.Instance.SizeBonus;
            }
            int FinalRelationshipIncreaseInt = (int)Math.Floor(FinalRelationshipIncrease);

            FinalRelationshipIncreaseInt = FinalRelationshipIncreaseInt < 1 ? 1 : FinalRelationshipIncreaseInt;
            InformationManager.DisplayMessage(new InformationMessage("Final Relationship Increase: " + FinalRelationshipIncreaseInt.ToString(), Color.FromUint(4282569842U)));

            List <Settlement> list = new List <Settlement>();

            foreach (Settlement settlement in Settlement.All)
            {
                if ((settlement.IsVillage || settlement.IsTown) && settlement.Position2D.DistanceSquared(m.Position) <= KBRRModLibSettings.Instance.Radius)
                {
                    list.Add(settlement);
                }
            }
            foreach (Settlement settlement2 in list)
            {
                if (settlement2.Notables.Any <Hero>())
                {
                    Hero h = settlement2.Notables.GetRandomElement <Hero>();
                    ChangeRelationAction.ApplyPlayerRelation(h, relation: FinalRelationshipIncreaseInt, affectRelatives: true, showQuickNotification: false);
                }
            }
            InformationManager.DisplayMessage(new InformationMessage("Your relationship increased with nearby notables.", Color.FromUint(4282569842U)));
        }
 public static void GetCreditForHelping(int relationChange)
 {
     foreach (Hero notable in Settlement.CurrentSettlement.Notables)
     {
         ChangeRelationAction.ApplyPlayerRelation(notable, relationChange);
         notable.AddPower(relationChange);
     }
 }
        private void OnHourlyTickEvent(MobileParty mobileParty)
        {
            Hero companion = mobileParty.LeaderHero;

            if (mobileParty == MobileParty.MainParty ||
                companion == null ||
                !mobileParty.IsLordParty ||
                companion.Clan != Clan.PlayerClan)
            {
                return;
            }

            Settlement target = mobileParty.TargetSettlement;

            if (mobileParty.DefaultBehavior != AiBehavior.PatrolAroundPoint ||
                target.OwnerClan != Clan.PlayerClan)
            {
                return;
            }

            if (mobileParty.Position2D.DistanceSquared(target.Position2D) > MinPatrolDistance)
            {
                //InformationManager.DisplayMessage(new InformationMessage(companion.Name + " too far away from " + target.Name));
                mobileParty.SetMoveGoToSettlement(target);
                return;
            }
            //InformationManager.DisplayMessage(new InformationMessage(companion.Name + " patrolling around " + target.Name));

            int companion_relation;

            foreach (Hero notable in target.Notables)
            {
                companion_relation = CharacterRelationManager.GetHeroRelation(companion, notable) + 1;
                if (companion_relation % HoursRequirement == 0)
                {
                    // reset companion personal relation
                    companion_relation = 0;

                    // increase player relation
                    int oldRelation = notable.GetRelation(Hero.MainHero);
                    ChangeRelationAction.ApplyPlayerRelation(notable, 1, false, false);
                    int newRelation     = notable.GetRelation(Hero.MainHero);
                    int relation_change = newRelation - oldRelation;

                    if (relation_change > 0)
                    {
                        TextObject textObject = GameTexts.FindText("str_your_relation_increased_with_notable", null);
                        TextObject heroText   = new TextObject();
                        ZenDzeeCompatibilityHelper.SetTextVariable(heroText, "NAME", notable.Name);
                        ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "HERO", heroText);
                        ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "VALUE", newRelation);
                        ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "MAGNITUDE", relation_change);
                        InformationManager.DisplayMessage(new InformationMessage(textObject.ToString()));
                    }
                }
                CharacterRelationManager.SetHeroRelation(companion, notable, companion_relation);
            }
        }
        private void town_notable_political_bribe_consequence()
        {
            int required = (int)((Hero.MainHero.GetPerkValue(DefaultPerks.Charm.Diplomacy) ? 0.85 : 1.0f) * (Hero.MainHero.Culture == Hero.OneToOneConversationHero.Culture ? 0.9f : 1.1f) * (100 + 50 * (int)Math.Min(2, Math.Max(0, (Hero.OneToOneConversationHero.Power / 100)))));

            Hero.MainHero.Clan.Influence -= required;
            ChangeRelationAction.ApplyPlayerRelation(Hero.OneToOneConversationHero, 20);
            Hero.OneToOneConversationHero.AddPower(25);
            Hero.OneToOneConversationHero.SupporterOf = Hero.MainHero.Clan;
            InformationManager.DisplayMessage(new InformationMessage(required + GameTexts.FindText("str_html_influence_icon").ToString() + " influence spent giving political support to " + Hero.OneToOneConversationHero.Name.ToString()));
        }
        private void town_notable_cash_bribe_consequence()
        {
            int required = (int)((Hero.MainHero.GetPerkValue(DefaultPerks.Charm.Diplomacy) ? 0.85 : 1.0f) * (Hero.MainHero.Culture == Hero.OneToOneConversationHero.Culture ? 0.9f : 1.1f) * (10000 + 5000 * (int)Math.Min(2, Math.Max(0, (Hero.OneToOneConversationHero.Power / 100)))));

            Hero.MainHero.Gold -= required;
            InformationManager.DisplayMessage(new InformationMessage(required + " <img src=\"Icons\\Coin@2x\">gold spent giving finical support to " + Hero.OneToOneConversationHero.Name.ToString()));
            ChangeRelationAction.ApplyPlayerRelation(Hero.OneToOneConversationHero, 20);
            Hero.OneToOneConversationHero.AddPower(25);
            Hero.OneToOneConversationHero.SupporterOf = Hero.MainHero.Clan;
        }
Example #7
0
        private void ApplyAddRelation(Hero hero, Clan clan, int daysToNow)
        {
            var relation = GetExpectRelation(hero, clan, daysToNow);
            var cost     = GetExpectGoldCostOfRelation(clan, relation);

            if (Hero.MainHero.Gold > cost * 1.2 && CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader) < 100)
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, GetExpectRelation(hero, clan, daysToNow, false));
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, clan.Leader, cost);
            }
        }
Example #8
0
 private void TransferSettlementAction(Clan clan)
 {
     ChangeOwnerOfSettlementAction.ApplyByBarter(clan.Leader, Settlement.CurrentSettlement);
     if (Settlement.CurrentSettlement.IsTown)
     {
         ChangeRelationAction.ApplyPlayerRelation(clan.Leader, 40);
     }
     else if (Settlement.CurrentSettlement.IsCastle)
     {
         ChangeRelationAction.ApplyPlayerRelation(clan.Leader, 20);
     }
 }
        private void ExecutePropose()
        {
            GiveGoldToClanAction.ApplyFromHeroToClan(Hero.MainHero, _clan, IntValue);

            var relationValue = GetBaseRelationValueOfCurrentGoldCost();

            if (relationValue > 0)
            {
                ChangeRelationAction.ApplyPlayerRelation(_clan.Leader, relationValue);
            }

            _onFinalize();
        }
Example #10
0
        public static void Apply(Settlement settlement, Clan grantedClan)
        {
            ChangeOwnerOfSettlementAction.ApplyByDefault(grantedClan.Leader, settlement);

            int relationChange = CalculateBaseRelationChange(settlement);

            ChangeRelationAction.ApplyPlayerRelation(grantedClan.Leader, relationChange);

            foreach (Clan clan in Clan.PlayerClan.Kingdom.Clans.Where(clan => clan != grantedClan && clan != Clan.PlayerClan))
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, Settings.Instance.GrantFiefRelationPenalty);
            }

            Events.Instance.OnFiefGranted(settlement.Town);
        }
Example #11
0
        public override void OnAgentRemoved(Agent affectedAgent, Agent affectorAgent, AgentState agentState, KillingBlow blow)
        {
            if (!_config.AI.PersonalEffects.Enabled)
            {
                return;
            }
            if (Campaign.Current == null)
            {
                return;
            }
            if (affectedAgent.Character == null)
            {
                return;
            }
            if (!affectedAgent.IsHero)
            {
                return;
            }

            if (_personalDeathEffectAgentList.Contains(affectedAgent) && affectorAgent == Agent.Main)
            {
                try {
                    var killedHero = Hero.FindFirst(x => x.StringId == affectedAgent.Character.StringId);
                    var playerHero = Hero.FindFirst(x => x.StringId == affectorAgent.Character.StringId);

                    ChangeRelationAction.ApplyPlayerRelation(killedHero, _config.AI.PersonalEffects.RelationshipChange, false, true);
                    playerHero.Clan.AddRenown(_config.AI.PersonalEffects.RenownGain);

                    Helpers.Say("{=death_personal_effect}" + _strings.Lord.DeathPersonalEffect
                                .Replace("$NAME$", affectedAgent?.Name ?? "")
                                .Replace("$RENOWN$", _config.AI.PersonalEffects.RenownGain.ToString())
                                .Replace("$RELATIONSHIPHIT$", _config.AI.PersonalEffects.RelationshipChange.ToString()),
                                new Dictionary <string, TextObject> {
                        { "NAME", new TextObject(affectedAgent?.Name ?? "") },
                        { "RENOWN", new TextObject(_config.AI.PersonalEffects.RenownGain.ToString()) },
                        { "RELATIONSHIPHIT", new TextObject(_config.AI.PersonalEffects.RelationshipChange.ToString()) }
                    });
                } catch (Exception ex) {
                    if (_config.Cheering.DebugMode)
                    {
                        Helpers.Log($"{ex.Message}");
                        Helpers.Log($"{ex.StackTrace}");
                    }
                }
            }
        }
        public static void Apply(Settlement settlement, Clan grantedClan)
        {
            ChangeOwnerOfSettlementAction.ApplyByDefault(grantedClan.Leader, settlement);

            var relationChange = CalculateBaseRelationChange(settlement);

            ChangeRelationAction.ApplyPlayerRelation(grantedClan.Leader, relationChange);

            foreach (var clan in Clan.PlayerClan.Kingdom.Clans.Where(c => c != grantedClan && c != Clan.PlayerClan))
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, Settings.Instance !.GrantFiefRelationPenalty);
            }

            // gain generosity when granting fief
            PlayerCharacterTraitEventExperience.FiefGranted.Apply();

            Events.Instance.OnFiefGranted(settlement.Town);
        }
Example #13
0
        private void EndQuestBySidingWithMerchantConsequence()
        {
            var garrisonParty   = QuestGiver.CurrentSettlement.Town.GarrisonParty;
            var jawwalPrisoners = GetJawwalPrisoners();
            var reward          = 0;

            foreach (var prisoner in jawwalPrisoners)
            {
                garrisonParty.AddPrisoner(prisoner, 1);
                EnterSettlementAction.ApplyForPrisoner(prisoner.HeroObject, QuestGiver.CurrentSettlement);
                CampaignEvents.Instance.OnPlayerDonatedHeroPrisoner(prisoner.HeroObject, QuestGiver.CurrentSettlement);
                reward += 1000;
            }

            Hero.MainHero.ChangeHeroGold(reward);
            ChangeRelationAction.ApplyPlayerRelation(QuestGiver, 50);
            CompleteQuestWithSuccess();
        }
Example #14
0
 private void DoTellStories(ToldStoriesTo village)
 {
     if (village._battleStoriesTold < _notableBattlesWon)
     {
         SkillObject skill;
         int         num;
         skill = SkillObject.FindFirst((x) => { return(x.StringId == "Charm"); });
         num   = (int)Math.Ceiling(MobileParty.MainParty.LeaderHero.GetSkillValue(skill) * 0.03f);
         float _renownToGive = CalculateRenownToGive(num);
         GainRenownAction.Apply(Hero.MainHero, _renownToGive, true);
         if ((double)_renownToGive <= 0.2)
         {
             village._daysToResetStories = CampaignTime.DaysFromNow(this.RandomizeDays());
             village._hasToldStories     = true;
             ++village._battleStoriesTold;
             Hero.MainHero.AddSkillXp(DefaultSkills.Charm, 1);
             InformationManager.DisplayMessage(new InformationMessage("Your story failed to inspire the villagers."));
             return;
         }
         InformationManager.DisplayMessage(new InformationMessage("You told the villagers a story about a notable battle, gained " + _renownToGive + " renown."));
         village._daysToResetStories = CampaignTime.DaysFromNow(RandomizeDays());
         village._hasToldStories     = true;
         village._battleStoriesTold++;
         Hero.MainHero.AddSkillXp(DefaultSkills.Charm, MBRandom.RandomInt(1, 3));
         if (_renownToGive >= 2.0)
         {
             if (Settlement.CurrentSettlement.Notables.Count >= 1)
             {
                 InformationManager.DisplayMessage(new InformationMessage("Notable people in village were impressed by your feats and like you more."));
                 foreach (Hero notablePerson in Settlement.CurrentSettlement.Notables)
                 {
                     int _relationToGive = CalculateRelationToGive(_renownToGive);
                     ChangeRelationAction.ApplyPlayerRelation(notablePerson, _relationToGive, false, true);
                 }
             }
         }
     }
     else
     {
         InformationManager.DisplayMessage(new InformationMessage("You do not have new stories to tell to these villagers."));
     }
 }
        private void ArmSeperatists()
        {
            List <InquiryElement> inquiryElements = new List <InquiryElement>();

            foreach (ItemRosterElement item in PartyBase.MainParty.ItemRoster)
            {
                if (isWeapon(item.EquipmentElement.Item))
                {
                    inquiryElements.Add(new InquiryElement((object)new Tuple <EquipmentElement, int>(item.EquipmentElement, item.Amount), (item.EquipmentElement.ItemModifier == null ? item.EquipmentElement.Item.Name.ToString() : (item.EquipmentElement.ItemModifier.Name.ToString()) + item.EquipmentElement.Item.Name.ToString()) + " - " + item.Amount, new ImageIdentifier(item.EquipmentElement.Item)));
                }
            }
            if (inquiryElements.Count < 1)
            {
                InformationManager.ShowInquiry(new InquiryData("No weapons in inventory", "", true, false, "OK", "", (Action)null, (Action)null), true);
                GameMenu.SwitchToMenu("town");
            }
            else
            {
                InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData("", "Select Weapons to give seperatists", inquiryElements, true, 1000, "Continue", (string)null, (Action <List <InquiryElement> >)(args =>
                {
                    List <InquiryElement> source = args;
                    if (source != null && !source.Any <InquiryElement>())
                    {
                        return;
                    }
                    InformationManager.HideInquiry();
                    float WeaponsValue = 0;
                    IEnumerable <Tuple <EquipmentElement, int> > selected = args.Select <InquiryElement, Tuple <EquipmentElement, int> >((Func <InquiryElement, Tuple <EquipmentElement, int> >)(element => element.Identifier as Tuple <EquipmentElement, int>));
                    foreach (Tuple <EquipmentElement, int> pair in selected)
                    {
                        WeaponsValue += pair.Item2 * (2 + Math.Min((int)pair.Item1.Item.Tierf, 6));
                        PartyBase.MainParty.ItemRoster.Remove(new ItemRosterElement(pair.Item1, pair.Item2));
                    }
                    Settlement.CurrentSettlement.Militia += WeaponsValue / 2;
                    float loyaltyChange = Math.Min(100 * (WeaponsValue / Math.Max(Settlement.CurrentSettlement.Town.Prosperity, 1)), Settlement.CurrentSettlement.Town.Loyalty);
                    Settlement.CurrentSettlement.Town.Loyalty -= loyaltyChange;
                    ChangeRelationAction.ApplyPlayerRelation(Settlement.CurrentSettlement.OwnerClan.Leader, (int)(-1 * loyaltyChange));
                    ChangeCrimeRatingAction.Apply(Settlement.CurrentSettlement.MapFaction, loyaltyChange);
                    Hero.MainHero.AddSkillXp(DefaultSkills.Roguery, WeaponsValue * 10);
                }), (Action <List <InquiryElement> >)null));
            }
        }
Example #16
0
        public void CreateVassal()
        {
            //Settlement settlement = GetCandidateSettlements().FirstOrDefault<Settlement>();
            if (targetSettlement == null)
            {
                return;
            }
            Hero hero = Hero.OneToOneConversationHero;

            if (hero == null)
            {
                return;
            }
            Kingdom kingdom = Hero.MainHero.MapFaction as Kingdom;

            if (kingdom == null)
            {
                return;
            }

            CultureObject culture  = targetSettlement.Culture;
            TextObject    clanName = NameGenerator.Current.GenerateClanName(culture, targetSettlement);
            string        str      = Guid.NewGuid().ToString().Replace("-", "");

            if (null == hero.LastSeenPlace)
            {
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
            }
            //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, hero);
            //for  1.4.3 200815
            HeroOperation.DealApplyByFire(Hero.MainHero.Clan, hero);

            HeroOperation.SetOccupationToLord(hero);
            hero.ChangeState(Hero.CharacterStates.Active);
            Clan   clan   = TaleWorlds.ObjectSystem.MBObjectManager.Instance.CreateObject <Clan>("sue_clan_" + str);
            Banner banner = Banner.CreateRandomClanBanner(-1);

            clan.InitializeClan(clanName, clanName, culture, banner);
            clan.SetLeader(hero);

            //clan.Tier = 5; 修改家族等级
            FieldInfo fieldInfoId = clan.GetType().GetField("_tier", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (null != fieldInfoId)
            {
                fieldInfoId.SetValue(clan, selectClanTier);
            }
            //增加一些影响力
            clan.AddRenown(50 * selectClanTier, true);


            hero.Clan        = clan;
            hero.CompanionOf = null;
            hero.IsNoble     = true;
            hero.SetTraitLevel(DefaultTraits.Commander, 1);

            MobileParty mobileParty = clan.CreateNewMobileParty(hero);

            mobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
            mobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

            ChangeOwnerOfSettlementAction.ApplyByKingDecision(hero, targetSettlement);
            clan.UpdateHomeSettlement(targetSettlement);


            int takeMoney = TakeMoneyByTier(selectClanTier);

            if (targetSpouse != null)
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney / 2, false);
            }
            else
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney, false);
            }

            //关系处理
            //新晋家族关系增加
            int shipIncreate = ShipIncreateByTier(selectClanTier);

            ChangeRelationAction.ApplyPlayerRelation(hero, shipIncreate, true, true);
            if (targetSpouse != null)
            {
                ChangeRelationAction.ApplyPlayerRelation(targetSpouse, shipIncreate, true, true);
            }

            //以前家族关系减低,
            int     shipReduce = ShipReduceByTier(selectClanTier);
            Kingdom kindom     = Hero.MainHero.MapFaction as Kingdom;

            if (null != kindom && shipReduce > 0)
            {
                kindom.Clans.ToList().ForEach((obj) =>
                {
                    if (obj != Clan.PlayerClan)
                    {
                        ChangeRelationAction.ApplyPlayerRelation(obj.Leader, shipReduce * -1, true, true);
                    }
                }
                                              );
            }

            if (targetSpouse != null)
            {
                targetSpouse.Spouse = hero;
                InformationManager.AddQuickInformation(new TextObject($"{hero.Name} marry with {targetSpouse.Name}"), 0, null, "event:/ui/notification/quest_finished");

                HeroOperation.DealApplyByFire(Hero.MainHero.Clan, targetSpouse);
                //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, targetSpouse);

                targetSpouse.ChangeState(Hero.CharacterStates.Active);
                targetSpouse.IsNoble = true;
                HeroOperation.SetOccupationToLord(targetSpouse);
                targetSpouse.CompanionOf = null;
                targetSpouse.Clan        = clan;
                targetSpouse.SetTraitLevel(DefaultTraits.Commander, 1);
                //AddCompanionAction.Apply(clan, targetSpouse);

                MobileParty targetSpouseMobileParty = clan.CreateNewMobileParty(targetSpouse);

                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, targetSpouse, takeMoney / 2, false);
            }

            // 他们孩子处理
            if (isTogetherWithThireChildren)
            {
                DealTheirChildren(hero, clan);
            }


            //加入王国
            ChangeKingdomAction.ApplyByJoinToKingdom(clan, kingdom, true);
        }
        //REVISIT - convert to transpiler patch to just change our prize payment
        // All we really need to change is instead of giving an ItemObject - which has no ItemModifers, we give them an ItemRosterEquipement, which can have ItemModifiers
        private static bool Prefix(ref TournamentBehavior __instance)
        {
            //Override Standard behavior
            if (Campaign.Current.GameMode != CampaignGameMode.Campaign)
            {
                return(false);
            }
            var tournamentInfo = TournamentsXPandedBehavior.GetTournamentInfo(__instance.TournamentGame.Town);
            var settlement     = __instance.Settlement;

            /* Give Gold, Influence, Renown */
            if (__instance.OverallExpectedDenars > 0)
            {
                GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, __instance.OverallExpectedDenars, false);
            }
            GainRenownAction.Apply(Hero.MainHero, __instance.TournamentGame.TournamentWinRenown, false);
            if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero)
            {
                GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, tournamentInfo.Rewards.BonusInfluence);
            }
            /* Give Reputation */
            try
            {
                if (TournamentXPSettings.Instance.BonusReputationForTournamentWin > 0)
                {
                    List <Hero> heros = new List <Hero>();

                    foreach (var n in settlement.Notables)
                    {
                        if (!heros.Contains(n))
                        {
                            heros.Add(n);
                        }
                    }
                    foreach (var v in settlement.BoundVillages)
                    {
                        foreach (var n in v.Settlement.Notables)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }
                    if (settlement.OwnerClan.Heroes.Any <Hero>())
                    {
                        foreach (var n in settlement.OwnerClan.Heroes)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }
                    if (settlement.HeroesWithoutParty.Count > 0)
                    {
                        foreach (var n in settlement.HeroesWithoutParty)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }

                    foreach (var h in heros)
                    {
                        if (MBRandom.RandomFloat < .51f)
                        {
                            ChangeRelationAction.ApplyPlayerRelation(h, TournamentXPSettings.Instance.BonusReputationForTournamentWin, true, false);
                        }
                    }
                }

                MBTextManager.SetTextVariable("RELATION_VALUE", TournamentXPSettings.Instance.BonusReputationForTournamentWin, false);
                InformationManager.AddQuickInformation(new TextObject("{=o0qwDa0q}Your relation increased by {RELATION_VALUE} with nearby notables.", null), 0, null, "");
            }
            catch (Exception ex)
            {
                ErrorLog.Log("Error giving Reputation:\n" + ex.ToStringFull());
            }

            /* Give Item Prize */
            if (!TournamentXPSettings.Instance.EnableItemModifiersForPrizes)
            {
                if (!tournamentInfo.Rewards.PrizeGiven)
                {
                    try
                    {
                        Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true);
                        tournamentInfo.Rewards.PrizeGiven = true;
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull());
                    }
                }
            }
            else
            {
                try
                {
                    if (!tournamentInfo.Rewards.PrizeGiven)
                    {
                        try
                        {
                            if (!String.IsNullOrWhiteSpace(tournamentInfo.SelectedPrizeStringId))
                            {
                                Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(tournamentInfo.SelectedPrizeItem.ToItemRosterElement().EquipmentElement, 1, true);
                                tournamentInfo.Rewards.PrizeGiven = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull());
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("ERROR: Tournament XPanded: OnPlayerWinTournament\nError Awarding Prize");
                    ErrorLog.Log("TournamentPrizePool:\n");
                    if (tournamentInfo != null)
                    {
                        ErrorLog.Log(Newtonsoft.Json.JsonConvert.SerializeObject(tournamentInfo));
                    }
                    ErrorLog.Log(ex.ToStringFull());
                }
            }

            if (!tournamentInfo.Rewards.PrizeGiven)
            {
                try
                {
                    Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true);
                    tournamentInfo.Rewards.PrizeGiven = true;
                }
                catch (Exception ex2)
                {
                    ErrorLog.Log("Error assigning prize\n" + ex2.ToStringFull());
                }
            }

            tournamentInfo.ReRollsUsed = 0;
            Campaign.Current.TournamentManager.OnPlayerWinTournament(__instance.TournamentGame.GetType());

            return(false);
        }
Example #18
0
 private void ExecutePropose()
 {
     GiveGoldToClanAction.ApplyFromHeroToClan(Hero.MainHero, _clan, this.IntValue);
     ChangeRelationAction.ApplyPlayerRelation(_clan.Leader, GetBaseRelationValueOfCurrentGoldCost());
     this._onFinalize();
 }
Example #19
0
        static bool Prefix(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
        {
            bool mapEvent;
            bool siegeEvent;

            if (!victim.IsAlive)
            {
                return(false);
            }
            victim.EncyclopediaText = (TextObject)typeof(KillCharacterAction).GetMethod("CreateObituary", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim, actionDetail });
            MobileParty partyBelongedTo = victim.PartyBelongedTo;

            if (partyBelongedTo != null)
            {
                mapEvent = partyBelongedTo.MapEvent != null;
            }
            else
            {
                mapEvent = false;
            }
            if (!mapEvent)
            {
                MobileParty mobileParty = victim.PartyBelongedTo;
                if (mobileParty != null)
                {
                    siegeEvent = mobileParty.SiegeEvent != null;
                }
                else
                {
                    siegeEvent = false;
                }
                if (!siegeEvent)
                {
                    if (victim.IsHumanPlayerCharacter && victim.DeathMark == KillCharacterAction.KillCharacterActionDetail.None)
                    {
                        victim.MakeWounded(killer, actionDetail);
                        typeof(CampaignEventDispatcher).GetMethod("OnBeforeMainCharacterDied", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Invoke(CampaignEventDispatcher.Instance, null);
                        //CampaignEventDispatcher.Instance.OnBeforeMainCharacterDied();
                        return(false);
                    }
                    StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.KillCharacterAction, new Object[] { victim });
                    if (victim.Clan.Leader == victim && victim != Hero.MainHero)
                    {
                        if (victim.Clan.Heroes.Any <Hero>((Hero x) => {
                            if (x.IsChild || x == victim || !x.IsAlive)
                            {
                                return(false);
                            }
                            return(x.IsNoble);
                        }))
                        {
                            ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(victim.Clan);
                        }
                        else if (victim.Clan.Kingdom != null && victim.Clan.Kingdom.RulingClan == victim.Clan)
                        {
                            Clan clan = (Clan)typeof(KillCharacterAction).GetMethod("SelectHeirClanForKingdom", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim.Clan.Kingdom, true });
                            //Clan clan = KillCharacterAction.SelectHeirClanForKingdom(victim.Clan.Kingdom, true);
                            if (clan == null)
                            {
                                DestroyKingdomAction.Apply(victim.Clan.Kingdom);
                            }
                            else
                            {
                                victim.Clan.Kingdom.RulingClan = clan;
                            }
                        }
                    }
                    if (victim.PartyBelongedTo != null && victim.PartyBelongedTo.Leader == victim.CharacterObject)
                    {
                        if (victim.PartyBelongedTo.Army != null)
                        {
                            if (victim.PartyBelongedTo.Army.LeaderParty != victim.PartyBelongedTo)
                            {
                                victim.PartyBelongedTo.Army = null;
                            }
                            else
                            {
                                victim.PartyBelongedTo.Army.DisperseArmy(Army.ArmyDispersionReason.ArmyLeaderIsDead);
                            }
                        }
                        victim.PartyBelongedTo.SetMoveModeHold();
                    }
                    typeof(KillCharacterAction).GetMethod("MakeDead", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim, true });
                    //KillCharacterAction.MakeDead(victim, true);
                    if (victim.GovernorOf != null)
                    {
                        ChangeGovernorAction.ApplyByGiveUpCurrent(victim);
                    }
                    if (actionDetail != KillCharacterAction.KillCharacterActionDetail.Executed)
                    {
                        if (killer != null && !victim.Clan.IsMapFaction)
                        {
                            foreach (Hero all in Hero.All)
                            {
                                if (!all.IsAlive || all == victim || all.IsNoble && all.Clan.Leader != all)
                                {
                                    continue;
                                }
                                if (all.Clan != victim.Clan)
                                {
                                    if (!victim.IsFriend(all))
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(killer, all, -10, all.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(killer, all, -40, true);
                                }
                            }
                        }
                    }
                    else if (actionDetail == KillCharacterAction.KillCharacterActionDetail.Executed && killer == Hero.MainHero)
                    {
                        if (victim.GetTraitLevel(DefaultTraits.Honor) >= 0)
                        {
                            //TraitLevelingHelper.OnLordExecuted();
                            foreach (Hero hero in Hero.All)
                            {
                                if (!hero.IsAlive || hero == victim || hero.IsNoble && hero.Clan.Leader != hero)
                                {
                                    continue;
                                }
                                if (hero.Clan == victim.Clan)
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -60, true, true);
                                }
                                else if (victim.IsFriend(hero))
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -30, true, hero.IsNoble);
                                }
                                else if (hero.MapFaction != victim.MapFaction || hero.CharacterObject.Occupation != Occupation.Lord)
                                {
                                    if (hero.GetTraitLevel(DefaultTraits.Honor) <= 0 || !hero.IsNoble)
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -10, true, hero.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -10, true, false);
                                }
                            }
                        }
                        else
                        {
                            foreach (Hero all1 in Hero.All)
                            {
                                if (!all1.IsAlive || all1 == victim || all1.IsNoble && all1.Clan.Leader != all1)
                                {
                                    continue;
                                }
                                if (all1.Clan == victim.Clan)
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -30, true, true);
                                }
                                else if (!victim.IsFriend(all1))
                                {
                                    if (all1.MapFaction != victim.MapFaction || all1.CharacterObject.Occupation != Occupation.Lord)
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -5, true, all1.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -15, true, all1.IsNoble);
                                }
                            }
                        }
                    }
                    if (!victim.Clan.IsDeactivated && !victim.Clan.Heroes.Any <Hero>((Hero x) => {
                        if (x.IsChild || x == victim)
                        {
                            return(false);
                        }
                        //return x.IsAlive;
                        return(false);
                    }))
                    {
                        DestroyClanAction.Apply(victim.Clan);
                    }

                    typeof(CampaignEventDispatcher).GetMethod("OnHeroKilled", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Invoke(CampaignEventDispatcher.Instance, new object[] { victim, killer, actionDetail, showNotification });
                    //CampaignEventDispatcher.Instance.OnHeroKilled(victim, killer, actionDetail, showNotification);
                    if (victim.CurrentSettlement != null && victim.StayingInSettlementOfNotable != null)
                    {
                        victim.StayingInSettlementOfNotable = null;
                    }
                    return(false);
                }
            }
            victim.MakeWounded(killer, actionDetail);
            return(false);
        }
 private void LowerRelationConsequence()
 {
     ChangeRelationAction.ApplyPlayerRelation(Hero.OneToOneConversationHero, -5);
     PlayerEncounter.LeaveEncounter = true;
 }
Example #21
0
        private void CastleAbandonSettlementMenuOption(CampaignGameStarter campaignGameStarter)
        {
            campaignGameStarter.AddGameMenuOption("ruler_castle_menu", "ruler_castle_abandon", "Abandon Rulership of Castle", (GameMenuOption.OnConditionDelegate)(args =>
            {
                args.optionLeaveType = GameMenuOption.LeaveType.Manage;
                if (Settlement.CurrentSettlement.OwnerClan.Kingdom != null && Settlement.CurrentSettlement.OwnerClan.Kingdom.Leader != Hero.MainHero)
                {
                    args.Tooltip   = new TextObject("You must be the faction leader to abandon a settlement");
                    args.IsEnabled = false;
                }

                args.Tooltip = new TextObject("A minor noble will take control of the settlement");

                return(true);
            }), (GameMenuOption.OnConsequenceDelegate)(args => {
                InformationManager.ShowInquiry(new InquiryData("Abandon Castle", "Are you sure you want to abandon this castle?", true, true, "Yes", "No", (Action)(() => {
                    List <CharacterObject> source = new List <CharacterObject>();
                    CultureObject culture = Settlement.CurrentSettlement.Culture;
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source.Add(characterObject);
                        }
                    }
                    CharacterObject template = source[rng.Next(0, source.Count - 1)];
                    Hero NewHero = HeroCreator.CreateSpecialHero(template, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero.ChangeState(Hero.CharacterStates.Active);
                    HeroCreationCampaignBehavior herocreationbehavior = new HeroCreationCampaignBehavior();
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero, template);

                    List <CharacterObject> source2 = new List <CharacterObject>();
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source2.Add(characterObject);
                        }
                    }
                    CharacterObject template2 = source2[rng.Next(0, source2.Count - 1)];
                    template2.IsFemale = true;
                    Hero NewHero2 = HeroCreator.CreateSpecialHero(template2, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero2.ChangeState(Hero.CharacterStates.Active);
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero2, template2);
                    template2.IsFemale = false;

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

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

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

                    ChangeOwnerOfSettlementAction.ApplyByKingDecision(NewHero, Settlement.CurrentSettlement);
                    clan.UpdateHomeSettlement(Settlement.CurrentSettlement);

                    MarriageAction.Apply(NewHero, NewHero2);
                    ChangeRelationAction.ApplyPlayerRelation(NewHero, 40);
                }), (Action)(() => {
                    GameMenu.SwitchToMenu("castle");
                })), true);
            }), index: 1);;;
        }