Beispiel #1
0
        public static void Apply(Hero hero, float delta, float floor)
        {
            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.GainRenownAction);

            // TODO do qualifying check
            if (delta >= 0.1f | delta <= -0.1f)
            {
                if (hero.Clan.Renown + delta > 0)
                {
                    if (hero.Clan.Renown + delta > floor)
                    {
                        hero.Clan.Renown += delta;
                    }
                    else
                    {
                        delta            = hero.Clan.Renown - floor;
                        hero.Clan.Renown = floor;
                    }

                    if (hero == Hero.MainHero)
                    {
                        GUI.Notifications.ClanStatChanged.Show("renown", delta);
                    }

                    // Change clan tier if needed
                    int tier = Campaign.Current.Models.ClanTierModel.CalculateTier(hero.Clan);
                    if (tier != hero.Clan.Tier)
                    {
                        ChangeClanTier.Apply(hero.Clan, tier);
                    }
                }
            }
        }
Beispiel #2
0
        public static void Apply(Hero hero, float delta)
        {
            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.GainKingdomInfluenceAction);
            float oldInfluence = hero.Clan.Influence;

            hero.Clan.Influence += delta;
            if (hero == Hero.MainHero)
            {
                // notify user
                GUI.Notifications.ClanStatChanged.Show("influence", delta);
            }
        }
        public static void EndContract(Hero mercenary)
        {
            var mercenaryClan    = mercenary.Clan;
            var mercenaryKingdom = mercenaryClan.Kingdom;
            var mercenaryFaction = mercenary.MapFaction;

            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, new object[]
            {
                mercenaryClan,
                mercenaryKingdom,
                (Kingdom)null !,
                true
            });
Beispiel #4
0
        public static void EndContract(Hero mercenary)
        {
            var mercenaryClan    = mercenary.Clan;
            var mercenaryKingdom = mercenaryClan.Kingdom;
            var mercenaryFaction = mercenary.MapFaction;

            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, new object[]
            {
                mercenaryClan,
                mercenaryKingdom,
                (Kingdom)null,
                true
            });
            mercenaryClan.ClanLeaveKingdom(false);

            OnMercenaryClanChangedKingdomMethod.Invoke(CampaignEventDispatcher.Instance, new object[]
            {
                mercenaryClan,
                mercenaryKingdom,
                (Kingdom)null
            });
            mercenaryClan.IsUnderMercenaryService = false;

            if (mercenary == Hero.MainHero)
            {
                mercenaryClan.ClanLeaveKingdom(true);
            }

            CheckIfPartyIconIsDirtyMethod.Invoke(null, new object[] { mercenaryClan, mercenaryKingdom });

            if (mercenary == Hero.MainHero)
            {
                InformationManager.DisplayMessage(new InformationMessage(GameTexts.FindText("str_mercenary_contract_ended", null).ToString()));
            }

            LogEntry.AddLogEntry(new MercenaryContractEndedLogEntry(mercenary, mercenaryFaction));
        }
Beispiel #5
0
        private static bool Prefix(Hero prisoner, EndCaptivityDetail detail)
        {
            if (prisoner.Clan != Hero.MainHero.Clan || prisoner.PartyBelongedToAsPrisoner == null || (prisoner.IsActive || !prisoner.IsAlive) || prisoner.PartyBelongedTo != null && prisoner.PartyBelongedTo.Party.Owner == prisoner || detail != EndCaptivityDetail.ReleasedAfterBattle && detail != EndCaptivityDetail.ReleasedAfterPeace && detail != EndCaptivityDetail.RemovedParty || (prisoner.Clan.CommanderLimit <= prisoner.Clan.WarParties.Count <MobileParty>((Func <MobileParty, bool>)(p => !p.IsGarrison && !p.IsMilitia && !p.IsVillager && !p.IsCaravan)) || (double)prisoner.PartyBelongedToAsPrisoner.Position2D.DistanceSquared(MobileParty.MainParty.VisualPosition2DWithoutError) >= 25.0))
            {
                return(true);
            }
            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.EndCaptivityAction);
            PartyBase belongedToAsPrisoner = prisoner.PartyBelongedToAsPrisoner;
            IFaction  faction = belongedToAsPrisoner != null ? belongedToAsPrisoner.MapFaction : (IFaction)CampaignData.NeutralFaction;

            Traverse.Create((object)CampaignEventDispatcher.Instance).Method("OnHeroPrisonerReleased", new Type[4]
            {
                typeof(Hero),
                typeof(PartyBase),
                typeof(IFaction),
                typeof(EndCaptivityDetail)
            }, (object[])null).GetValue((object)prisoner, (object)belongedToAsPrisoner, (object)faction, (object)detail);
            EndCaptivityActionPatch.SpawnPartyAtPosition(prisoner, MobileParty.MainParty.VisualPosition2DWithoutError);
            if (prisoner.PartyBelongedTo != null && (prisoner != null ? prisoner.getOrder() : (PartyOrder)null) != null)
            {
                PartyOrder order = prisoner.getOrder();
                if (order.Behavior == AiBehavior.EscortParty && (double)order.ScoreMinimum > 1.0)
                {
                    if ((double)Campaign.Current.Models.MapDistanceModel.GetDistance(prisoner.PartyBelongedTo, MobileParty.MainParty) > 15.0)
                    {
                        prisoner.PartyBelongedTo.SetInititave(0.0f, 1f, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow);
                    }
                    else
                    {
                        prisoner.PartyBelongedTo.SetInititave(order.AttackInitiative, order.AvoidInitiative, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow);
                    }
                    prisoner.PartyBelongedTo.SetMoveEscortParty(order.TargetParty);
                }
            }
            return(false);
        }
        static bool Prefix(Clan clan, Kingdom kingdom, int detail, int awardMultiplier, bool byRebellion, bool showNotification)
        {
            //MessageBox.Show($"Detail: {detail}");
            //MessageBox.Show(SharedObjects.Instance.RebellionRelationsChange.ToString());

            var  onClanChangedKingdom          = typeof(CampaignEventDispatcher).GetMethod("OnClanChangedKingdom", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var  onMercenaryClanChangedKingdom = typeof(CampaignEventDispatcher).GetMethod("OnMercenaryClanChangedKingdom", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            Type type = typeof(ChangeKingdomAction).Assembly.GetType("TaleWorlds.CampaignSystem.Actions.ChangeKingdomAction+ChangeKingdomActionDetail");

            int joinMerc       = (int)Enum.ToObject(type, 0);
            int joinKingdom    = (int)Enum.ToObject(type, 1);
            int leaveKingdom   = (int)Enum.ToObject(type, 2);
            int leaveRebellion = (int)Enum.ToObject(type, 3);
            int leaveMerc      = (int)Enum.ToObject(type, 4);

            Kingdom oldKingdom = clan.Kingdom;

            if (kingdom != null)
            {
                foreach (Kingdom kingdom3 in Kingdom.All)
                {
                    if (object.ReferenceEquals(kingdom3, kingdom) || !kingdom.IsAtWarWith(kingdom3))
                    {
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(clan, kingdom3);
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(kingdom3, clan);
                    }
                }
                foreach (Clan clan2 in Clan.All)
                {
                    if (!object.ReferenceEquals(clan2, clan) && ((clan2.Kingdom == null) && !kingdom.IsAtWarWith(clan2)))
                    {
                        FactionHelper.FinishAllRelatedHostileActions(clan, clan2);
                    }
                }
            }
            if (detail == joinKingdom)   //ChangeKingdomActionDetail.JoinKingdom
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, false };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                clan.IsUnderMercenaryService = false;
                if (oldKingdom != null)
                {
                    clan.ClanLeaveKingdom(!byRebellion);
                }
                clan.ClanJoinFaction(kingdom);
                onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, clan.Kingdom, byRebellion, showNotification });
            }
            else if (detail == joinMerc)   //ChangeKingdomActionDetail.JoinAsMercenary
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, false };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                if (clan.IsUnderMercenaryService)
                {
                    clan.ClanLeaveKingdom(false);
                }
                clan.MercenaryAwardMultiplier = MathF.Round((float)awardMultiplier);
                clan.IsUnderMercenaryService  = true;
                clan.ClanJoinFaction(kingdom);
                //CampaignEventDispatcher.Instance.OnMercenaryClanChangedKingdom(clan, null, kingdom);
                onMercenaryClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, null, kingdom });
            }
            else if (detail == leaveRebellion || detail == leaveKingdom || detail == leaveMerc)   //ChangeKingdomActionDetail.LeaveAsMercenary = 4
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, true };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                clan.ClanLeaveKingdom(false);
                if (detail == leaveMerc)   //ChangeKingdomActionDetail.LeaveAsMercenary
                {
                    onMercenaryClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, kingdom, null });
                    clan.IsUnderMercenaryService = false;
                }
                if (detail == leaveRebellion)   //ChangeKingdomActionDetail.LeaveWithRebellion
                {
                    if (object.ReferenceEquals(clan, Clan.PlayerClan))
                    {
                        foreach (Clan clan3 in oldKingdom.Clans)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, clan3.Leader, SharedObjects.Instance.RebellionRelationsChange, true);
                        }
                        if (SharedObjects.Instance.DeclareWarOnRebellion)
                        {
                            DeclareWarAction.Apply(oldKingdom, clan);
                        }
                    }
                    onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, null, true, true });
                }
                else if (detail == leaveKingdom)   //ChangeKingdomActionDetail.LeaveKingdom
                {
                    if (object.ReferenceEquals(clan, Clan.PlayerClan))
                    {
                        foreach (Clan clan4 in oldKingdom.Clans)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, clan4.Leader, SharedObjects.Instance.ForfeitSettlementsRelationsChange, true);
                        }
                    }
                    foreach (Settlement settlement in new List <Settlement>(clan.Settlements))
                    {
                        ChangeOwnerOfSettlementAction.ApplyByLeaveFaction(oldKingdom.Leader, settlement);
                        foreach (Hero hero in new List <Hero>((IEnumerable <Hero>)settlement.HeroesWithoutParty))
                        {
                            if ((hero.CurrentSettlement != null) && object.ReferenceEquals(hero.Clan, clan))
                            {
                                if (hero.PartyBelongedTo != null)
                                {
                                    LeaveSettlementAction.ApplyForParty(hero.PartyBelongedTo);
                                    EnterSettlementAction.ApplyForParty(hero.PartyBelongedTo, clan.Leader.HomeSettlement);
                                    continue;
                                }
                                LeaveSettlementAction.ApplyForCharacterOnly(hero);
                                EnterSettlementAction.ApplyForCharacterOnly(hero, clan.Leader.HomeSettlement);
                            }
                        }
                    }
                    onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, null, false, false });
                }
            }
            if (object.ReferenceEquals(clan, Clan.PlayerClan))
            {
                Campaign.Current.UpdateDecisions();
            }
            typeof(ChangeKingdomAction).GetMethod("CheckIfPartyIconIsDirty", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
            .Invoke(null, new object[] { clan, kingdom });
            return(false);
        }
Beispiel #7
0
        public static void ChangeKingdom(this Clan clan, Kingdom newKingdom, bool rebellion)
        {
            Kingdom oldKingdom = clan.Kingdom;

            if (newKingdom != null)
            {
                foreach (Kingdom k in Kingdom.All)
                {
                    if (k == newKingdom || !newKingdom.IsAtWarWith(k))
                    {
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(clan, k);
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(k, clan);
                    }
                }
                foreach (Clan c in Clan.All)
                {
                    if (c != clan && c.Kingdom == null && !newKingdom.IsAtWarWith(c))
                    {
                        FactionHelper.FinishAllRelatedHostileActions(clan, c);
                    }
                }
            }

            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, new object[]
            {
                clan,
                oldKingdom,
                newKingdom,
                newKingdom == null || rebellion
            });
            clan.IsUnderMercenaryService = false;
            if (oldKingdom != null)
            {
                clan.ClanLeaveKingdom(false);
            }
            if (newKingdom != null)
            {
                clan.ClanJoinFaction(newKingdom);
                NotifyClanChangedKingdom(clan, oldKingdom, newKingdom, rebellion, true);

                if (rebellion)
                {
                    foreach (Clan c in oldKingdom.Clans)
                    {
                        int relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerVassals;
                        if (c.Leader == oldKingdom.Leader)
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRuler;
                        }
                        else if (c.Leader.IsFriend(oldKingdom.Leader))
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerFriendVassals;
                        }
                        else if (c.Leader.IsEnemy(oldKingdom.Leader))
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerEnemyVassals;
                        }

                        if (relationChange != 0)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, c.Leader, relationChange, true);
                        }
                    }

                    newKingdom.InheritsWarsFromKingdom(oldKingdom);
                    DeclareWarAction.Apply(oldKingdom, newKingdom);
                }
                else
                {
                    int relationChange = SeparatismConfig.Settings.RelationChangeUnitedRulers;
                    if (relationChange != 0)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, newKingdom.Leader, relationChange, true);
                    }
                    if (oldKingdom != null)
                    {
                        newKingdom.InheritsWarsFromKingdom(oldKingdom);
                    }
                }
            }
            if (oldKingdom != null && oldKingdom.Clans.Where(x => x.Leader.IsAlive).Count() == 0)             // old kingdom is empty so we destroy it
            {
                if (newKingdom == null)
                {
                    NotifyClanChangedKingdom(clan, oldKingdom, null, false, true);
                }
                Campaign.Current.RemoveEmptyKingdoms();
            }

            CheckIfPartyIconIsDirty(clan, oldKingdom);
        }
Beispiel #8
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);
        }