Beispiel #1
0
        public void GetCurrentData()
        {
            Dictionary <Data.SpawnData, int> oldValues = new Dictionary <Data.SpawnData, int>();

            foreach (Data.SpawnData dat in dataManager.Data)
            {
                oldValues.Add(dat, dat.GetNumberSpawned());
                dat.SetNumberSpawned(0);
            }

            foreach (MobileParty mb in MobileParty.All)
            {
                foreach (var dat in dataManager.Data)
                {
                    if (CampaignUtils.IsolateMobilePartyStringID(mb) == dat.PartyTemplate.StringId)
                    {
                        //increase count
                        dat.IncrementNumberSpawned();
                    }
                }
            }
            if (ConfigLoader.Instance.Config.IsDebugMode)
            {
                //display necessary debug message.
                foreach (var dat in dataManager.Data)
                {
                    if (oldValues[dat] != dat.GetNumberSpawned()) //leave a log only if a change has occured. TODO we can also detect death with these and create custom behaviour/spawn schedules accordingly ;)
                    {
                        ModDebug.ShowMessage(dat.Name + " count: " + dat.GetNumberSpawned());
                    }
                }
            }
        }
Beispiel #2
0
 private void DailyCheckBehaviour(MobileParty mb)
 {
     if (!registeredParties.Contains(mb))
     {
         return;
     }
     if (mb.Ai.AiState == AIState.Undefined || mb.Ai.AiState == AIState.WaitingAtSettlement)
     {
         if (yesterdayIdleParties.Contains(mb))
         {
             Settlement closestHostile = CampaignUtils.GetClosestHostileSettlement(mb);
             if (closestHostile == null)
             {
                 return;
             }
             mb.SetMoveGoToPoint(mb.FindReachablePointAroundPosition(closestHostile.GatePosition, 10));
             yesterdayIdleParties.Remove(mb);
         }
         else
         {
             yesterdayIdleParties.Add(mb);
         }
     }
     else
     {
         yesterdayIdleParties.Remove(mb);
     }
 }
Beispiel #3
0
        public static Settlement GetSpawnSettlement(Data.SpawnData data, Random rand = null, List <Settlement> exceptions = null)
        {
            if (rand == null)
            {
                rand = new Random();
            }

            if (exceptions == null)
            {
                exceptions = new List <Settlement>();
            }

            Clan spawnClan = data.SpawnClan;

            //deal with override of spawn clan.
            if (data.OverridenSpawnClan.Count != 0)
            {
                spawnClan = data.OverridenSpawnClan[rand.Next(0, data.OverridenSpawnClan.Count)];
            }
            //check for one hideout
            Settlement firstHideout = null;

            if (ConfigLoader.Instance.Config.SpawnAtOneHideout)
            {
                foreach (Settlement s in Settlement.All)
                {
                    if (s.IsHideout)
                    {
                        firstHideout = s;
                        break;
                    }
                }
            }

            //deal with town spawn
            Settlement spawnOverride = null;

            if (data.OverridenSpawnSettlements.Count != 0)
            {
                spawnOverride = CampaignUtils.PickRandomSettlementAmong(new List <Settlement>(data.OverridenSpawnSettlements.Where(s => !exceptions.Contains(s))),
                                                                        data.TrySpawnAtList, rand);
            }

            if (spawnOverride == null && data.OverridenSpawnCultures.Count != 0)
            {
                //spawn at overriden spawn instead!
                spawnOverride = CampaignUtils.PickRandomSettlementOfCulture(data.OverridenSpawnCultures, data.TrySpawnAtList, exceptions);
            }

            if (spawnOverride != null)
            {
                return(spawnOverride);
            }

            //get settlement
            Settlement spawnSettlement = ConfigLoader.Instance.Config.SpawnAtOneHideout ? firstHideout : (data.TrySpawnAtList.Count == 0 ? CampaignUtils.GetPreferableHideout(spawnClan) : null);

            return(spawnSettlement);
        }
        private static bool PartyIDEndsWith(DialogueParams param, string ID)
        {
            if (param.AdversaryParty == null)
            {
                return(false);
            }

            return(CampaignUtils.IsolateMobilePartyStringID(param.AdversaryParty).EndsWith(ID));
        }
 static void Postfix(MobileParty party, ref bool __result)
 {
     if (__result)
     {
         var isolatedPartyStringId = CampaignUtils.IsolateMobilePartyStringID(party);
         if (SpawnDataManager.Instance.Data.Any(spawnData =>
                                                isolatedPartyStringId.Equals(spawnData.PartyTemplate.GetName().ToString())))
         {
             __result = false;
         }
     }
 }
        private static bool HasPartyID(DialogueParams param, string ID)
        {
            if (param.AdversaryParty == null)
            {
                return(false);
            }

            if (CampaignUtils.IsolateMobilePartyStringID(param.AdversaryParty.Party.MobileParty) == ID)
            {
                return(true);
            }
            return(false);
        }
        private void OnMapEventEnded(MapEvent e)
        {
            if (e == null)
            {
                return;
            }

            float increase = (e.AttackerSide.CasualtyStrength + e.DefenderSide.CasualtyStrength) * campaignConfig.FightOccuredDevestationPerPower;

            Settlement closestSettlement = CampaignUtils.GetClosestVillage(e.Position);

            ChangeDevestation(closestSettlement, increase);

            ModDebug.ShowMessage("Fight at " + closestSettlement.Name + ". Increasing devestation by " + increase + ". New devestation is: " + settlementToDevestation[closestSettlement], campaignConfig);
        }
Beispiel #8
0
        public static Settlement GetSpawnSettlement(Data.SpawnData data, Random rand = null)
        {
            if (rand == null)
            {
                rand = new Random();
            }
            Clan spawnClan = data.SpawnClan;

            //deal with override of spawn clan.
            if (data.OverridenSpawnClan.Count != 0)
            {
                spawnClan = data.OverridenSpawnClan[rand.Next(0, data.OverridenSpawnClan.Count)];
            }
            //check for one hideout
            Settlement firstHideout = null;

            if (CsSettings.SpawnAtOneHideout)
            {
                foreach (Settlement s in Settlement.All)
                {
                    if (s.IsHideout())
                    {
                        firstHideout = s;
                        break;
                    }
                }
            }
            //deal with town spawn
            Settlement spawnOverride = null;

            if (data.OverridenSpawnSettlements.Count != 0)
            {
                spawnOverride = CampaignUtils.PickRandomSettlementAmong(data.OverridenSpawnSettlements, data.TrySpawnAtList, rand);
            }
            if (spawnOverride == null && data.OverridenSpawnCultures.Count != 0)
            {
                //spawn at overriden spawn instead!
                spawnOverride = CampaignUtils.PickRandomSettlementOfCulture(data.OverridenSpawnCultures, data.TrySpawnAtList);
            }
            if (spawnOverride == null && data.OverridenSpawnKingdoms.Count != 0)
            {
                spawnOverride = CampaignUtils.PickRandomSettlementOfKingdom(data.OverridenSpawnKingdoms, data.TrySpawnAtList);
            }
            //get settlement
            Settlement spawnSettlement = CsSettings.SpawnAtOneHideout ? firstHideout : (spawnOverride == null ? CampaignUtils.GetPreferableHideout(spawnClan) : spawnOverride);

            return(spawnSettlement);
        }
        static void Postfix(MobileParty mobileParty, ref ExplainedNumber __result)
        {
            if (!Main.PartySpeedContext.IsPartySpeedBonusAllowedByUser())
            {
                return;
            }

            string partyId = CampaignUtils.IsolateMobilePartyStringID(mobileParty); //TODO if this is non-trivial make it more efficient

            if (Main.PartySpeedContext.IsPartyMinimumSpeedOverriden(partyId))       //minimum adjustment
            {
                __result.LimitMin(Main.PartySpeedContext.GetMinimumSpeed(partyId));
            }

            if (Main.PartySpeedContext.IsPartyMaximumSpeedOverriden(partyId))//maximum adjustment
            {
                __result.LimitMax(Main.PartySpeedContext.GetMaximumSpeed(partyId));
            }
        }
Beispiel #10
0
        private void OnMapEventEnded(MapEvent e)
        {
            if (e == null)
            {
                return;
            }

            float increase = (e.AttackerSide.CasualtyStrength + e.DefenderSide.CasualtyStrength) * campaignConfig.FightOccuredDevestationPerPower;

            Settlement closestSettlement = CampaignUtils.GetClosestVillage(e.Position);

            if (!settlementToDevestation.ContainsKey(closestSettlement))
            {
                ErrorHandler.HandleException(new Exception("Devestation value for settlement could not be found!"));
            }

            ChangeDevestation(closestSettlement, increase);

            ModDebug.ShowMessage("Fight at " + closestSettlement.Name + ". Increasing devestation by " + increase + ". New devestation is: " + settlementToDevestation[closestSettlement], campaignConfig);
        }
Beispiel #11
0
        private void OnMobilePartyHourlyTick(MobileParty mb)
        {
            if (mb == null)
            {
                return;
            }

            Settlement closest = CampaignUtils.GetClosestSettlement(mb);

            if (!dailyPresences.ContainsKey(mb))
            {
                dailyPresences.Add(mb, new List <Settlement>());
            }

            if (!dailyPresences[mb].Contains(closest))
            {
                dailyPresences[mb].Add(closest);
                settlementDailyPresences[closest].Add(mb);
            }
        }
Beispiel #12
0
 private DynamicSpawnData()
 {
     foreach (MobileParty mb in MobileParty.All)
     {
         if (mb == null)
         {
             return;
         }
         foreach (var dat in SpawnDataManager.Instance.Data)
         {
             if (CampaignUtils.IsolateMobilePartyStringID(mb) == dat.PartyTemplate.StringId) //TODO could deal with sub parties in the future as well!
             {
                 //this be a custom spawns party :O
                 AddDynamicSpawnData(mb, new CSPartyData(dat, null));
                 dat.IncrementNumberSpawned();
                 UpdateDynamicData(mb);
                 UpdateRedundantDynamicData(mb);
             }
         }
     }
 }
        static bool Prefix(MobileParty mobileParty, ref ExplainedNumber finalSpeed)
        {
            if (!Main.PartySpeedContext.IsPartySpeedBonusAllowedByUser())
            {
                return(true);
            }

            string partyId = CampaignUtils.IsolateMobilePartyStringID(mobileParty); //TODO if this is non-trivial make it more efficient

            if (Main.PartySpeedContext.IsPartyEligibleForExtraSpeed(partyId))
            {
                float extraSpeed = Main.PartySpeedContext.GetSpeedWithExtraBonus(partyId);
                finalSpeed.Add(extraSpeed, _extraSpeedExplanationText);
            }
            else if (Main.PartySpeedContext.IsBasePartySpeedOverriden(partyId))
            {
                float overridenBaseSpeed = Main.PartySpeedContext.GetBaseSpeed(partyId);
                finalSpeed = new ExplainedNumber(overridenBaseSpeed);
                return(true);
            }

            return(true);
        }
 private Settlement GetSettlementToPatrol(PatrolAroundClosestLestInterruptedAndSwitchBehaviourData dat)
 {
     return(CampaignUtils.GetClosestNonHostileCityAmong(dat.party, dat.preferredSettlements, dat.currentPatrolledSettlement));
 }
Beispiel #15
0
 public void UpdateRedundantDynamicData(MobileParty mb)
 {
     GetDynamicSpawnData(mb).latestClosestSettlement = CampaignUtils.GetClosestHabitedSettlement(mb);
 }
        private void DailyGarrisonRecruitmentEvent(Settlement s)
        {
            try
            {
                if (s.IsCastle || s.IsTown)
                {
                    Town t = s.Town;
                    if (t.IsUnderSiege)
                    {
                        return;
                    }
                    var prisoners = CampaignUtils.GetPrisonersInSettlement(t);
                    if (prisoners.Count > 0)
                    {
                        int   total         = Utils.Utils.GetTotalPrisonerCounts(prisoners);
                        int   totalGarrison = CampaignUtils.GetGarrisonCountInSettlement(t);
                        float recruitChance = 0;
                        float devalueChance = 0;
                        int   capTimes      = 0;

                        Random rand = new Random();

                        recruitChance  = Config.BaseRecruitChance;
                        devalueChance  = Config.BaseDevalueChance;
                        recruitChance += Config.MercifulTraitModifier * (s.OwnerClan.Leader == null ? 0 : s.OwnerClan.Leader.GetTraitLevel(DefaultTraits.Mercy));
                        devalueChance -= Config.MercifulTraitModifier * (s.OwnerClan.Leader == null ? 0 : s.OwnerClan.Leader.GetTraitLevel(DefaultTraits.Mercy));
                        capTimes       = (int)((float)total / ((float)totalGarrison * Config.PrisonerPartyPercentageCap));
                        recruitChance *= (float)Math.Pow(Config.CapReverseFinalCoefficientPerCap, capTimes);

                        List <PrisonerInfo> recruited = new List <PrisonerInfo>();
                        List <PrisonerInfo> devalued  = new List <PrisonerInfo>();
                        foreach (var p in prisoners)
                        {
                            if (p.prisoner.IsHero || p.prisoner.IsPlayerCharacter)
                            {
                                continue;
                            }
                            float particularRecruitChance = recruitChance - (p.prisoner.Level * Config.PrisonerLevelReverseModifierPerLevel);
                            float particularDevalueChance = devalueChance + (p.prisoner.Level * Config.PrisonerLevelDevalueModifierPerLevel);
                            if (p.prisoner.Culture != null && t.Culture != null && p.prisoner.Culture != t.Culture)
                            {
                                particularRecruitChance -= Config.DifferentCultureReverseModifier;
                                particularDevalueChance -= Config.DifferentCultureReverseModifier;
                            }
                            particularRecruitChance  = Math.Max(particularRecruitChance, Config.FinalMinimumChance);
                            particularDevalueChance  = Math.Max(particularDevalueChance, Config.FinalMinimumChance);
                            particularRecruitChance *= Config.GarrisonFinalCoefficient;
                            particularDevalueChance *= Config.GarrisonFinalCoefficient;
                            int troopCount = p.count;

                            int recruitedCount = 0;
                            int devaluedCount  = 0;
                            for (int i = 0; i < troopCount; i++)
                            {
                                if (rand.NextDouble() <= particularRecruitChance)
                                {
                                    //recruit!
                                    recruitedCount++;
                                }
                                if (rand.NextDouble() <= particularDevalueChance)
                                {
                                    //recruit!
                                    devaluedCount++;
                                }
                            }
                            if (recruitedCount > 0 && t.GarrisonParty != null)
                            {
                                recruited.Add(new PrisonerInfo()
                                {
                                    count          = recruitedCount,
                                    prisoner       = p.prisoner,
                                    acquiringParty = t.GarrisonParty.Party,
                                    prisonerParty  = p.prisonerParty
                                });
                            }
                            if (devaluedCount > 0 && t.GarrisonParty != null)
                            {
                                devalued.Add(new PrisonerInfo()
                                {
                                    count          = devaluedCount,
                                    prisoner       = p.prisoner,
                                    acquiringParty = p.prisonerParty,
                                    prisonerParty  = p.prisonerParty
                                });
                            }
                        }
                        recruited.ForEach((PrisonerInfo p) => PartyRecruitAndRemovePrisoner(p.acquiringParty, p.prisonerParty, p.prisoner, p.count));
                        //devalued.ForEach((PrisonerInfo p) => PartyDevaluePrisoner(p.acquiringParty, p.prisonerParty, p.prisoner, p.count)); IMPLEMENT!
                    }
                }
            }catch (Exception e)
            {
                ErrorHandler.HandleException(e, "daily garrison recruitment event of " + s.StringId);
            }
        }