Exemple #1
0
        public override void OnGameInitializationFinished(Game game)
        {
            base.OnGameInitializationFinished(game);
            if (!(game.GameType is Campaign))
            {
                return;
            }

            PatchManager.ApplyPatches();

            try
            {
                // TODO Check how to handle the ClearLastInstances

                // Spawn Data Init (Read from XML)
                // ClearLastInstances();
                Data.SpawnDataManager.ClearInstance(this);
                Data.NameSignifierData.ClearInstance(this);
                DynamicSpawnData.ClearInstance(this);
                SpawnDataManager.Init();
                DynamicSpawnData.Init();
            }
            catch (Exception e)
            {
                ErrorHandler.HandleException(e, "Could not create an instance of SpawnDataManager. Might have encountered an " +
                                             "issue while parsing the XML file or invalid parameters/values have been found");
            }
        }
Exemple #2
0
        public static void ReportSpawn(MobileParty spawned, float chanceOfSpawnBeforeSpawn)
        {
            if (Singleton == null || spawned.Party.TotalStrength < Singleton.campaignConfig.MinimumSpawnLogValue || chanceOfSpawnBeforeSpawn > Singleton.campaignConfig.MinimumRarityToLog)
            {
                return;
            }

            string msg = "New Spawn: " + spawned.StringId +
                         "\nTotal Strength:" + spawned.Party.TotalStrength.ToString() +
                         "\nChance of Spawn: " + chanceOfSpawnBeforeSpawn.ToString();

            var spawnData = DynamicSpawnData.GetDynamicSpawnData(spawned).spawnBaseData;

            if (spawnData.DynamicSpawnChanceEffect > 0)
            {
                msg += "\nDynamic Spawn Chance Effect: " + spawnData.DynamicSpawnChanceEffect;
                msg += "\nDynamic Spawn Chance Base Value During Spawn: " + DataUtils.GetCurrentDynamicSpawnCoeff(spawnData.DynamicSpawnChancePeriod);
            }

            var spawnSettlement = DynamicSpawnData.GetDynamicSpawnData(spawned).latestClosestSettlement;

            if (spawnSettlement.IsVillage)
            {
                msg += "\nDevestation at spawn settlement: " +
                       DevestationMetricData.Singleton.GetDevestation(spawnSettlement);
            }


            msg += "\n";

            Singleton.WriteString(msg);
        }
Exemple #3
0
 public SpawnBehaviour(Data.SpawnDataManager data_manager)
 {
     DynamicSpawnData.FlushSpawnData();
     lastRedundantDataUpdate = 0;
     dataManager             = data_manager;
     Data.DataUtils.EnsureWarnIDQUalities(dataManager.Data);
     dataGottenAtStart = false;
 }
Exemple #4
0
 private void HourlyPartyBehaviour(MobileParty mb)
 {
     if (DynamicSpawnData.GetDynamicSpawnData(mb) == null) //check if it is a custom spawns party
     {
         return;
     }
     UpdateDynamicData(mb);
     if (lastRedundantDataUpdate >= CsSettings.UpdatePartyRedundantDataPerHour)
     {
         UpdateRedundantDynamicData(mb);
     }
     //for now for all
     Economics.PartyEconomicUtils.PartyReplenishFood(mb);
 }
        private void RegularBanditSpawn()
        {
            try
            {
                var    list = dataManager.Data;
                Random rand = new Random();
                foreach (Data.SpawnData data in list)
                {
                    int j = 0;
                    for (int i = 0; i < data.RepeatSpawnRolls; i++)
                    {
                        if (data.CanSpawn() && (data.MinimumNumberOfDaysUntilSpawn < (int)Math.Ceiling(Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow)))
                        {
                            if (ConfigLoader.Instance.Config.IsAllSpawnMode || (float)rand.NextDouble() < data.ChanceOfSpawn)
                            {
                                var spawnSettlement = Spawner.GetSpawnSettlement(data, rand);
                                //spawn nao!
                                MobileParty spawnedParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, data.PartyTemplate, data.PartyType, new TextObject(data.Name));
                                data.IncrementNumberSpawned(); //increment for can spawn and chance modifications
                                //dynamic data registration
                                DynamicSpawnData.AddDynamicSpawnData(spawnedParty, new CSPartyData(data, spawnSettlement));

                                j++;
                                //AI Checks!
                                Spawner.HandleAIChecks(spawnedParty, data, spawnSettlement);
                                //accompanying spawns
                                foreach (var accomp in data.SpawnAlongWith)
                                {
                                    MobileParty juniorParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, accomp.templateObject, data.PartyType, new TextObject(accomp.name));
                                    Spawner.HandleAIChecks(juniorParty, data, spawnSettlement); //junior party has same AI behaviour as main party. TODO in future add some junior party AI and reconstruction.
                                }
                                //message if available
                                if (data.spawnMessage != null)
                                {
                                    UX.ShowParseSpawnMessage(data.spawnMessage, spawnSettlement.Name.ToString());
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorHandler.HandleException(e);
            }
        }
Exemple #6
0
        //deal with our parties being removed! Also this is more efficient ;)
        private void OnPartyRemoved(PartyBase p)
        {
            MobileParty mb = p.MobileParty;

            if (mb == null)
            {
                return;
            }

            CSPartyData partyData = DynamicSpawnData.GetDynamicSpawnData(mb);

            if (partyData != null)
            {
                partyData.spawnBaseData.DecrementNumberSpawned();
                //this is a custom spawns party!!
                OnPartyDeath(mb, partyData);
                ModDebug.ShowMessage(mb.StringId + " has died at " + partyData.latestClosestSettlement + ", reducing the total number to: " + partyData.spawnBaseData.GetNumberSpawned(), DebugMessageType.DeathTrack);
                DynamicSpawnData.RemoveDynamicSpawnData(mb);
            }
        }
Exemple #7
0
 public void GetCurrentData()
 {
     foreach (MobileParty mb in MobileParty.All)
     {
         if (mb == null)
         {
             return;
         }
         foreach (var dat in dataManager.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
                 DynamicSpawnData.AddDynamicSpawnData(mb, new CSPartyData(dat, null));
                 dat.IncrementNumberSpawned();
                 UpdateDynamicData(mb);
                 UpdateRedundantDynamicData(mb);
             }
         }
     }
 }
Exemple #8
0
 public void UpdateRedundantDynamicData(MobileParty mb)
 {
     DynamicSpawnData.GetDynamicSpawnData(mb).latestClosestSettlement = CampaignUtils.GetClosestHabitedSettlement(mb);
 }
Exemple #9
0
        private void RegularSpawn()
        {
            try
            {
                var    list = dataManager.Data;
                Random rand = new Random();
                var    isSpawnSoundPlaying = false;
                foreach (Data.SpawnData data in list)
                {
                    int j = 0;
                    for (int i = 0; i < data.RepeatSpawnRolls; i++)
                    {
                        if (data.CanSpawn() && (data.MinimumNumberOfDaysUntilSpawn < (int)Math.Ceiling(Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow)))
                        {
                            if (CsSettings.IsAllSpawnMode || (float)rand.NextDouble() < data.ChanceOfSpawn)
                            {
                                var spawnSettlement = Spawner.GetSpawnSettlement(data, rand);
                                //spawn nao!
                                MobileParty spawnedParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, data.PartyTemplate, data.PartyType, new TextObject(data.Name), data.PartyTemplatePrisoner, data.InheritClanFromSettlement);
                                data.IncrementNumberSpawned(); //increment for can spawn and chance modifications
                                //dynamic data registration
                                DynamicSpawnData.AddDynamicSpawnData(spawnedParty, new CSPartyData(data, spawnSettlement));

                                j++;
                                //AI Checks!
                                Spawner.HandleAIChecks(spawnedParty, data, spawnSettlement);
                                //accompanying spawns
                                foreach (var accomp in data.SpawnAlongWith)
                                {
                                    MobileParty juniorParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, accomp.templateObject, data.PartyType, new TextObject(accomp.name), data.PartyTemplatePrisoner, data.InheritClanFromSettlement);
                                    Spawner.HandleAIChecks(juniorParty, data, spawnSettlement); //junior party has same AI behaviour as main party. TODO in future add some junior party AI and reconstruction.
                                }
                                //message if available
                                if (data.spawnMessage != null && data.inquiryMessage == null)
                                {
                                    UX.ShowParseSpawnMessage(data.spawnMessage, spawnSettlement.Name.ToString());
                                    if (data.SoundEvent != -1 && !isSpawnSoundPlaying && CsSettings.SpawnSoundEnabled)
                                    {
                                        var        sceneEmpty = Scene.CreateNewScene(false);
                                        SoundEvent sound      = SoundEvent.CreateEvent(data.SoundEvent, sceneEmpty);
                                        sound.Play();
                                        isSpawnSoundPlaying = true;
                                    }
                                }
                                //default spawn message type always takes priority over the inquiry type if they're both present
                                else if (data.spawnMessage != null && data.inquiryMessage != null)
                                {
                                    UX.ShowParseSpawnMessage(data.spawnMessage, spawnSettlement.Name.ToString());
                                }
                                //only if the spawn message EXPLICITLY doesn't exist does it choose the inquiry message
                                else if (data.spawnMessage == null && data.inquiryMessage != null)
                                {
                                    UX.ShowParseSpawnInquiryMessage(data.inquiryMessage, spawnSettlement.Name.ToString(), data.inquiryPause);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorHandler.HandleException(e);
            }
        }
        private void RegularSpawn()
        {
            try
            {
                var    list = dataManager.Data;
                Random rand = new Random();
                var    isSpawnSoundPlaying = false;
                foreach (Data.SpawnData data in list)
                {
                    int j = 0;
                    for (int i = 0; i < data.RepeatSpawnRolls; i++)
                    {
                        if (data.CanSpawn() && (data.MinimumNumberOfDaysUntilSpawn < (int)Math.Ceiling(Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow)))
                        {
                            float currentChanceOfSpawn = data.ChanceOfSpawn;
                            if (!ConfigLoader.Instance.Config.IsAllSpawnMode &&
                                (float)rand.NextDouble() >= currentChanceOfSpawn * ConfigLoader.Instance.Config.SpawnChanceFlatMultiplier)
                            {
                                continue;
                            }

                            var spawnSettlement = Spawner.GetSpawnSettlement(data, (s => data.MinimumDevestationToSpawn > DevestationMetricData.Singleton.GetDevestation(s)), rand);
                            //spawn nao!

                            if (spawnSettlement == null)
                            {
                                //no valid spawn settlement

                                break;
                            }

                            MobileParty spawnedParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, data.PartyTemplate, data.PartyType, new TextObject(data.Name));
                            if (spawnedParty == null)
                            {
                                return;
                            }
                            data.IncrementNumberSpawned(); //increment for can spawn and chance modifications
                                                           //dynamic data registration
                            DynamicSpawnData.AddDynamicSpawnData(spawnedParty, new CSPartyData(data, spawnSettlement));

                            j++;
                            //AI Checks!
                            Spawner.HandleAIChecks(spawnedParty, data, spawnSettlement);
                            //accompanying spawns
                            foreach (var accomp in data.SpawnAlongWith)
                            {
                                MobileParty juniorParty = Spawner.SpawnParty(spawnSettlement, data.SpawnClan, accomp.templateObject, data.PartyType, new TextObject(accomp.name));
                                if (juniorParty == null)
                                {
                                    continue;
                                }
                                Spawner.HandleAIChecks(juniorParty, data, spawnSettlement); //junior party has same AI behaviour as main party. TODO in future add some junior party AI and reconstruction.
                            }
                            //message if available
                            if (data.spawnMessage != null)
                            {
                                UX.ShowParseSpawnMessage(data.spawnMessage, spawnSettlement.Name.ToString());
                                //if (data.SoundEvent != -1 && !isSpawnSoundPlaying && ConfigLoader.Instance.Config.SpawnSoundEnabled)
                                //{
                                //    var sceneEmpty = Scene.CreateNewScene(false);
                                //    SoundEvent sound = SoundEvent.CreateEvent(data.SoundEvent, sceneEmpty);
                                //    sound.Play();
                                //    isSpawnSoundPlaying = true;
                                //}
                            }

                            DailyLogger.ReportSpawn(spawnedParty, currentChanceOfSpawn);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorHandler.HandleException(e);
            }
        }