示例#1
0
 private void ValidateSoundEvent()
 {
     if (this.SoundEvent != null && this.SoundEvent.IsValid || this.SoundName.Length <= 0)
     {
         return;
     }
     if (this.SoundCode == -1)
     {
         this.SoundCode = SoundManager.GetEventGlobalIndex(this.SoundName);
     }
     this.SoundEvent = SoundEvent.CreateEvent(this.SoundCode, this.GameEntity.Scene);
 }
示例#2
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);
            }
        }