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);
                }
            }
        }
        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
            }
        }
Exemple #3
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);
            }
        }
 public void DestroyCharacter(CharacterObject character)
 {
     KillCharacterAction.ApplyByRemove(character.HeroObject);
     RemoveCharacter(character);
 }