private void RetireWanderers()   // TODO ideally this should be outright "delete", but a safe one, of course
        // heroes are naturally ordered by creation time
        // take first wanderer who is not already "retired", and who is not currently accompanying us and do the job
        {
            foreach (var hero in Hero.All.Where(hero => HeroIsAvailableWanderer(hero))
                     .Take(wanderersToSpawn))
            {
#if !RETIRE_BY_KILLING
                hero.ChangeState(Hero.CharacterStates.Disabled);
#else
                // KillCharacterAction -> MakeDead() will change state
                // LeaveSettlementAction is still required because it removes a guy from the actual tavern
#endif
                // apparently a wanderer may get so unlucky (recall that a random wanderer with culture preference is settled only when
                // MainHero enters an eligible town) that she's still in limbo by the time of retirement
                if (hero.StayingInSettlementOfNotable != null)
                {
                    LeaveSettlementAction.ApplyForCharacterOnly(hero);
                }
#if !RETIRE_BY_KILLING
                var urbanRemoved = urbanCharsBhvCompanions.Remove(hero);
                InformationManager.DisplayMessage(new InformationMessage($"\"Retired\" wanderer {hero} (urbanRemoved={urbanRemoved})"));
#else
                KillCharacterAction.ApplyByRemove(hero); // UrbanCharactersCampaignBehavior.OnHeroKilled() will Remove() from urbanCharsBhvCompanions
                // superfluous since Native v1.2.0:
                //InformationManager.DisplayMessage(new InformationMessage($"\"Retired\" wanderer {hero}"));
#endif
            }
        }
Ejemplo n.º 2
0
        private void ConsequenceKillPrisoner(Companion companion, Hero hero)
        {
            if (hero.IsPrisoner && companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.KillPrisoner))
            {
                if (hero?.PartyBelongedToAsPrisoner?.LeaderHero != null)
                {
                    KillCharacterAction.ApplyByExecution(hero, hero?.PartyBelongedToAsPrisoner?.LeaderHero);
                }
                else
                {
                    KillCharacterAction.ApplyByMurder(hero);
                }
            }

            if (companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.KillCaptor))
            {
                if (!hero.IsPrisoner)
                {
                    KillCharacterAction.ApplyByMurder(hero);
                }
                else if (hero?.PartyBelongedToAsPrisoner?.LeaderHero != null)
                {
                    KillCharacterAction.ApplyByMurder(hero?.PartyBelongedToAsPrisoner?.LeaderHero);
                }
            }
        }
Ejemplo n.º 3
0
        private void OnSettlementOwnerChangedEvent(Settlement settlement, bool openToClaim, Hero newOwner, Hero oldOwner, Hero capturedHero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
        {
            var settlementInfo = Managers.Settlement.Get(settlement);

            settlementInfo.UpdateOwnerRevolt(newOwner.MapFaction);

            if (capturedHero?.PartyBelongedTo?.Party != null)
            {
                var revolt = RevoltManager.Instance.GetRevoltByParty(capturedHero.PartyBelongedTo.Party);
                if (revolt != null && !RevolutionsSettings.Instance.RevoltsMinorFactionsMechanic && revolt.IsMinorFaction)
                {
                    if (revolt.SettlementInfo.CurrentFaction == revolt.SettlementInfo.LoyalFaction)
                    {
                        var previousFactionOwner = BaseManagers.Faction.GetLordWithLeastFiefs(revolt.SettlementInfo.PreviousFaction).HeroObject;
                        ChangeOwnerOfSettlementAction.ApplyByRevolt(previousFactionOwner, settlement);
                    }
                    else
                    {
                        var loyalFactionOwner = BaseManagers.Faction.GetLordWithLeastFiefs(revolt.SettlementInfo.LoyalFaction).HeroObject;
                        ChangeOwnerOfSettlementAction.ApplyByRevolt(loyalFactionOwner, settlement);
                    }

                    Managers.Kingdom.DestroyKingdom(capturedHero.Clan.Kingdom);
                    Managers.Clan.DestroyClan(capturedHero.Clan);
                    capturedHero.PartyBelongedTo.RemoveParty();
                    KillCharacterAction.ApplyByRemove(capturedHero);

                    RevoltManager.Instance.Revolts.Remove(revolt);
                }
            }
        }
        public static int KillOverAgedHero()
        {
            int counter = 0;

            foreach (var hero in Hero.All.ToList <Hero>())
            {
                if (hero != null && !hero.IsDead && hero.IsNoble)
                {
                    if (hero.Age >= SettingClass.Instance.MaxAge)
                    {
                        KillCharacterAction.ApplyByOldAge(hero, true);
                        counter += 1;
                    }
                }
            }

            return(counter);
        }
Ejemplo n.º 5
0
        internal void CEKillPlayer(Hero killer)
        {
            GameMenu.ExitToLast();

            try
            {
                if (killer != null)
                {
                    KillCharacterAction.ApplyByMurder(Hero.MainHero, killer);
                }
                else
                {
                    KillCharacterAction.ApplyByMurder(Hero.MainHero);
                }
            }
            catch (Exception e)
            {
                CECustomHandler.ForceLogToFile("Failed CEKillPlayer " + e);
            }
        }
        public void ApplySuccessfulAssassination(Settlement settlement, Hero assassin, Hero victim)
        {
            var party = victim.OwnedParties.Where(p => p.LeaderHero == victim).FirstOrDefault();

            if (party != null)
            {
                party.MobileParty.RemoveParty();
            }

            KillCharacterAction.ApplyByMurder(victim);

            PrintAssassinatedText(victim);

            _assassinationHistoryService.AddAssassinationEvent(new AssassinationEvent()
            {
                Settlement   = settlement,
                Assassin     = assassin,
                Victim       = victim,
                Succeeded    = true,
                CampaignTime = CampaignTime.Now
            });
        }
Ejemplo n.º 7
0
        internal static void EndFailedRevolt(Revolt revolt)
        {
            var textObject = new TextObject(Localization.GameTexts.RevoltsRevoltEnd);

            textObject.SetTextVariable("SETTLEMENT", revolt.Settlement.Name);
            InformationManager.AddQuickInformation(textObject);

            revolt.SettlementInfo.CurrentFactionInfo.CityRevoltionFailed(revolt.Settlement);

            if (revolt.IsMinorFaction)
            {
                Managers.Kingdom.DestroyKingdom(revolt.Party.Owner.Clan.Kingdom);
                KillCharacterAction.ApplyByExecution(revolt.Party.Owner, revolt.Settlement.OwnerClan?.Kingdom?.Leader ?? revolt.Settlement.OwnerClan.Leader, true);

                if (revolt.Party?.MobileParty != null)
                {
                    DestroyPartyAction.Apply(revolt.SettlementInfo.Garrision, revolt.Party.MobileParty);
                }
            }

            Managers.Revolt.Revolts.Remove(revolt);
        }
        private void OnDailyTickHero(Hero hero)
        {
            if (hero != Hero.MainHero &&
                hero.IsAlive &&
                (hero.IsNoble || hero.IsWanderer) &&
                !hero.IsNotable &&
                hero.Age > (float)Campaign.Current.Models.AgeModel.BecomeOldAge)
            {
                float mult = 1f;

                MobileParty party = hero.PartyBelongedTo;
                if (party != null)
                {
                    if (party.Army != null)
                    {
                        mult *= 0.5f;
                    }

                    if (party.MapEvent != null)
                    {
                        mult *= 0.5f;
                    }
                }

                if (hero.Clan != null &&
                    hero.Clan.Heroes.Count(h => h.IsAlive) < 3)
                {
                    mult *= 0.5f;
                }

                if (MBRandom.RandomFloat < hero.ProbabilityOfDeath * mult)
                {
                    ZenDzeeWorkarounds.PrepareToKillHero(hero);
                    KillCharacterAction.ApplyByOldAge(hero, true);
                }
            }
        }
Ejemplo n.º 9
0
        private void FreeClansFromKingdom()
        {
            try
            {
                foreach (Clan clan in Campaign.Current.Clans)
                {
                    if (clan?.Leader == null)
                    {
                        continue;
                    }

                    if (clan.Leader.IsHumanPlayerCharacter)
                    {
                        continue;
                    }

                    Kingdom kingdom = clan.Kingdom;

                    if (kingdom == null)
                    {
                        continue;
                    }

                    if (!kingdom.IsKingdomFaction || kingdom.IsMinorFaction || kingdom.IsBanditFaction)
                    {
                        continue;
                    }

                    if (clan.IsMinorFaction || clan.IsClanTypeMercenary || clan.IsBanditFaction)
                    {
                        continue;
                    }

                    if (clan.Fortifications.Count > 0)
                    {
                        continue;
                    }

                    if (clan.Leader?.PartyBelongedTo?.BesiegedSettlement != null)
                    {
                        continue;
                    }

                    bool otherClanHasForts = false;
                    foreach (Clan other in kingdom.Clans)
                    {
                        if (other.Fortifications.Count > 0)
                        {
                            otherClanHasForts = true;
                            break;
                        }
                    }

                    if (otherClanHasForts)
                    {
                        continue;
                    }

                    // We have now determined that the clan and possible other clans in the kingdom have no forts
                    // So we can go ahead an make the clan available to join other Kingdoms or die


                    int     lowestClanCount = int.MaxValue;
                    Kingdom newKingdom      = null;

                    Dictionary <string, Kingdom> allKingdoms = new Dictionary <string, Kingdom>();
                    foreach (Clan clan1 in Campaign.Current.Clans)
                    {
                        if (clan1?.Kingdom == null)
                        {
                            continue;
                        }

                        allKingdoms[clan1.Kingdom.StringId] = clan1.Kingdom;
                    }

                    foreach (KeyValuePair <string, Kingdom> weakest in allKingdoms)
                    {
                        if (lowestClanCount > weakest.Value.Clans.Count &&
                            !weakest.Value.StringId.Equals(kingdom.StringId) &&
                            weakest.Value.Clans.Count != 0 &&
                            weakest.Value.Fortifications.Count() != 0)
                        {
                            lowestClanCount = weakest.Value.Clans.Count;
                            newKingdom      = weakest.Value;
                        }
                    }

                    double surviveChance = 50;

                    float diceRoll = Rand.Next(0, 100);

                    if (diceRoll < surviveChance && newKingdom?.Clans.Count <= 3)
                    {
                        ChangeKingdomAction.ApplyByJoinToKingdom(clan, newKingdom, false);
                    }
                    else
                    {
                        clan.ClanLeaveKingdom(true);
                        KillCharacterAction.ApplyByRemove(clan.Leader);

                        // Forces so many annoying popups
                        DestroyClanAction.Apply(clan);
                    }

                    // Forces so many annoying popups
                    //if (kingdom.Clans.Count == 0)
                    //	DestroyKingdomAction.Apply(kingdom);
                }
            }
            catch (Exception e)
            {
                Log.Info("Exception in FreeClansFromKingdom");
                Log.Info(e);
            }
        }
Ejemplo n.º 10
0
 public void DestroyCharacter(CharacterObject character)
 {
     KillCharacterAction.ApplyByRemove(character.HeroObject);
     RemoveCharacter(character);
 }