Example #1
0
 private void HeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
 {
     if (null != this._sneaker && victim == this._sneaker)
     {
         ///this._sneaker = null;
     }
 }
 public void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification)
 {
     if (victim.IsFemale && _heroPregnancies.Any(pregnancy => pregnancy.Mother == victim))
     {
         _heroPregnancies.RemoveAll(pregnancy => pregnancy.Mother == victim);
     }
 }
        private static void OnBeforeHeroKilled(Hero victim, Hero killer,
                                               KillCharacterAction.KillCharacterActionDetail detail,
                                               bool showNotification = true)
        {
            if (victim.IsHumanPlayerCharacter)
            {
                return;
            }
            if (victim.Clan == null)
            {
                return;
            }

            var clanHasMembers = victim.Clan.Heroes.Any(x =>
            {
                if (x.IsChild || x == victim || !x.IsAlive)
                {
                    return(false);
                }
                return(x.IsNoble || x.IsMinorFactionHero);
            });

            var isClanDestroyed = !clanHasMembers && !victim.Clan.IsEliminated && !victim.Clan.IsBanditFaction &&
                                  !victim.Clan.IsNeutralClan &&
                                  (victim.Clan.Leader == victim || victim.Clan.Leader == null);

            if (isClanDestroyed)
            {
                AdoptAction.ApplyByClanDestroyed(victim.Clan);
            }
        }
 static bool Prefix(Hero victim,
                    Hero killer,
                    KillCharacterAction.KillCharacterActionDetail actionDetail,
                    bool showNotification)
 {
     GrowthDebug.LogInfo($"KillCharacterActionDetail? --> {actionDetail.ToString()}");
     return(true);
 }
 public void OnHeroKilled(
     Hero victim,
     Hero killer,
     KillCharacterAction.KillCharacterActionDetail detail,
     bool showNotification = true
     )
 {
 }
Example #6
0
        static void ApplyInternalPrefix(
            Hero victim,
            Hero killer,
            KillCharacterAction.KillCharacterActionDetail actionDetail,
            bool showNotification)
        {
            _ = showNotification;

            if (victim is null || victim == Hero.MainHero)
            {
                return;
            }

            var clan = victim.Clan;

            // Only interested in the death of regular clan leaders where there's no other adult noble to succeed them:
            if (clan is null ||
                clan.Leader != victim ||
                clan.Kingdom is null ||
                clan.Kingdom.IsEliminated ||
                clan.IsClanTypeMercenary ||
                // Start extreme paranoia:
                clan.IsRebelFaction ||
                clan.IsBanditFaction ||
                // End extreme paranoia!
                clan.Lords.Where(h => h.IsAlive && !h.IsChild && h.IsActive && h.IsNoble && h != victim).Any())
            {
                return;
            }

            if (Config.AllowPlayerExecutionToEliminateClan &&
                killer == Hero.MainHero &&
                actionDetail == KillCharacterAction.KillCharacterActionDetail.Executed)
            {
                return;
            }

            var deathReasonStr = Enum.GetName(typeof(KillCharacterAction.KillCharacterActionDetail), actionDetail);

            Util.Log.Print($"[{CampaignTime.Now}] CLAN EXTINCTION PREVENTION: Leader of clan {clan.Name}, " +
                           $"{victim.Name} of age {victim.Age:F0}, died without a valid heir (reason: {deathReasonStr})!");

            // Spawn a male noble "distant relative" into the clan
            var ageMin    = Campaign.Current.Models.AgeModel.HeroComesOfAge + 1;
            var successor = HeroUtil.SpawnNoble(clan, ageMin, ageMax: ageMin + 10, isFemale: MBRandom.RandomFloat < 0.5);

            if (successor is null)
            {
                Util.Log.Print(" -> ERROR: Could not find a noble character template to spawn lord!");
            }
            else
            {
                Util.Log.Print($" -> Summoned distant relative {successor.Name} of age {successor.Age:F0} " +
                               $"to assume leadership of clan {successor.Clan.Name}.");
            }
        }
Example #7
0
 private static void ApplyInternal(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
 {
     if (!victim.IsAlive)
     {
         return;
     }
     //victim.EncyclopediaText = KillCharacterAction.CreateObituary(victim, actionDetail);
     victim.EncyclopediaText = (TextObject)Traverse.Create(typeof(KillCharacterAction)).Method("CreateObituary").GetValue(new object[] { victim, actionDetail });
     //KillCharacterAction.MakeDead(victim, true);
     Traverse.Create(typeof(KillCharacterAction)).Method("MakeDead").GetValue(new object[] { victim, true });
     victim.MakeWounded(actionDetail);
 }
 private static void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
 {
     ZenDzeeRomanceHelper.EndLoverRomances(victim);
 }
        public static void Postfix(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
        {
            if (victim.IsAlive || actionDetail != KillCharacterAction.KillCharacterActionDetail.Executed)
            {
                return;
            }

            var multiplier = killer.Clan.IsUnderMercenaryService
                ? MercenarySettings.Instance.MercenaryMultiplier
                : MercenarySettings.Instance.VassalMultiplier;

            var contractorKingdom = killer.Clan.Kingdom;

            // If victim was an enemy of a hero of ContractorClan, increase relationship with hero
            foreach (var contractorKingdomHero in contractorKingdom.Heroes)
            {
                if (victim.IsEnemy(contractorKingdomHero))
                {
                    AragasChangeRelationAction.ApplyRelation(
                        killer,
                        contractorKingdomHero,
                        5 * multiplier,
                        MercenarySettings.Instance.EnemyCap,
                        true);
                }
            }

            // If victim was a friend of a hero of ContractorClan, decrease relationship with hero
            // ALREADY IN VANILLA

            // If victim had negative honor, increase relationship with ContractorClan
            var victimHonor = victim.GetTraitLevel(DefaultTraits.Honor);

            if (victimHonor < 0)
            {
                foreach (var contractorKingdomHero in contractorKingdom.Heroes)
                {
                    var contractorKingdomHeroHonor = victim.GetTraitLevel(DefaultTraits.Honor);
                    if (contractorKingdomHeroHonor > 0)
                    {
                        AragasChangeRelationAction.ApplyRelation(
                            killer,
                            contractorKingdomHero,
                            2 * contractorKingdomHeroHonor * multiplier,
                            MercenarySettings.Instance.TraitCap,
                            false);
                    }
                }
            }

            // If victim was merciful, decrease relationship with ContractorClan?
            var victimMercy = victim.GetTraitLevel(DefaultTraits.Mercy);

            if (victimMercy > 0)
            {
                foreach (var contractorKingdomHero in contractorKingdom.Heroes)
                {
                    var contractorKingdomHeroMercy = victim.GetTraitLevel(DefaultTraits.Mercy);
                    if (contractorKingdomHeroMercy > 0)
                    {
                        AragasChangeRelationAction.ApplyRelation(
                            killer,
                            contractorKingdomHero,
                            -2 * contractorKingdomHeroMercy * multiplier,
                            -MercenarySettings.Instance.TraitCap,
                            false);
                    }
                }
            }
        }
Example #10
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);
        }