public void SetupScript() { Logger.AddMsg("Loading Settings From Spawner Version: " + ModVersion.ToString()); //Save File Validation SaveName = MyAPIGateway.Session.Name; //Some Faction BS - Temporary if (1 == 0) { var factions = MyDefinitionManager.Static.GetDefaultFactions(); var sb = new StringBuilder(); sb.Append("Faction Data: ").AppendLine().AppendLine(); foreach (var faction in factions) { sb.Append(faction.Tag).AppendLine(); sb.Append(faction.DefaultRelation).AppendLine(); sb.Append(faction.DefaultRelationToPlayers).AppendLine().AppendLine(); } Logger.AddMsg(sb.ToString()); } //Rival AI Stuff Logger.AddMsg("Initializing RivalAI Helper"); RivalAIHelper.SetupRivalAIHelper(); //Setup Watchers and Handlers MyAPIGateway.Multiplayer.RegisterMessageHandler(8877, ChatCommand.MESMessageHandler); MyAPIGateway.Utilities.MessageEntered += ChatCommand.MESChatCommand; var thisPlayer = MyAPIGateway.Session.LocalHumanPlayer; //Disable Vanilla Spawners Logger.AddMsg("Checking World Settings."); if (MyAPIGateway.Session.SessionSettings.CargoShipsEnabled == true) { Logger.AddMsg("Disabling Cargo Ships World Setting. Spawner Handles This Functionality."); MyAPIGateway.Session.SessionSettings.CargoShipsEnabled = false; } if (MyAPIGateway.Session.SessionSettings.EnableEncounters == true) { Logger.AddMsg("Disabling Random Encounters World Setting. Spawner Handles This Functionality."); MyAPIGateway.Session.SessionSettings.EnableEncounters = false; } /* * if(MyAPIGateway.Multiplayer.IsServer == false){ * * if(thisPlayer == null){ * * Logger.AddMsg("Player Doesn't Exist. Cannot Search For Existing Boss GPS."); * return; * * } * * Logger.AddMsg("Searching For Existing Boss Encounter GPS."); * var chatMsg = "MESClientGetBossGPS\n" + thisPlayer.IdentityId.ToString() + "\n" + thisPlayer.SteamUserId.ToString() + "\n" + "Msg"; * var sendData = MyAPIGateway.Utilities.SerializeToBinary<string>(chatMsg); * var sendMsg = MyAPIGateway.Multiplayer.SendMessageToServer(8877, sendData); * * return; * * } */ //All Block SubtypeIds try{ var allDefs = MyDefinitionManager.Static.GetAllDefinitions(); foreach (MyDefinitionBase definition in allDefs.Where(x => x is MyCubeBlockDefinition)) { var blockDef = definition as MyCubeBlockDefinition; SpawnResources.BlockDefinitionIdList.Add(definition.Id.SubtypeName); if (ChatCommand.BlockDefinitionList.Contains(blockDef) == false) { ChatCommand.BlockDefinitionList.Add(blockDef); } } }catch (Exception exc) { Logger.AddMsg("Something Failed While Building List Of CubeBlock SubtypeIds."); } //Drop Containers Names var dropContainerErrorLog = new StringBuilder(); try{ dropContainerErrorLog.Append("Getting List of DropContainer Definitions").AppendLine(); var dropContainerDefs = MyDefinitionManager.Static.GetDropContainerDefinitions(); dropContainerErrorLog.Append("Beginning Loop Of Definition List").AppendLine(); foreach (var dropContainer in dropContainerDefs.Keys) { dropContainerErrorLog.Append("Checking Drop Container Prefab: ").Append(dropContainerDefs[dropContainer].Id.SubtypeName).AppendLine(); foreach (var grid in dropContainerDefs[dropContainer].Prefab.CubeGrids) { dropContainerErrorLog.Append("Checking Drop Container Prefab Name...").AppendLine(); if (string.IsNullOrEmpty(grid.DisplayName) == true) { dropContainerErrorLog.Append("Prefab Grid Name Null Or Empty - Skipping").AppendLine(); continue; } dropContainerErrorLog.Append("Added Prefab Grid Name To DropContainerNames: ").Append(grid.DisplayName).AppendLine(); NPCWatcher.DropContainerNames.Add(grid.DisplayName); } } }catch (Exception exc) { Logger.AddMsg("Something Failed While Building List Of Drop Container (Unknown Signal) Prefab Names. See Below:"); Logger.AddMsg(dropContainerErrorLog.ToString()); } //Economy Stations Logger.AddMsg("The Following Economy Stations Will Not Be Monitored By Spawner Mod:", true); try { NPCWatcher.EconomyStationNames.Add("Economy_MiningStation_1"); NPCWatcher.EconomyStationNames.Add("Economy_MiningStation_2"); NPCWatcher.EconomyStationNames.Add("Economy_MiningStation_3"); NPCWatcher.EconomyStationNames.Add("Economy_OrbitalStation_1"); NPCWatcher.EconomyStationNames.Add("Economy_OrbitalStation_2"); NPCWatcher.EconomyStationNames.Add("Economy_OrbitalStation_3"); NPCWatcher.EconomyStationNames.Add("Economy_OrbitalStation_4"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_1"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_2"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_3"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_4"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_5"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_6"); NPCWatcher.EconomyStationNames.Add("Economy_Outpost_7"); NPCWatcher.EconomyStationNames.Add("Economy_SpaceStation_1"); NPCWatcher.EconomyStationNames.Add("Economy_SpaceStation_2"); NPCWatcher.EconomyStationNames.Add("Economy_SpaceStation_3"); NPCWatcher.EconomyStationNames.Add("Economy_SpaceStation_4"); NPCWatcher.EconomyStationNames.Add("Economy_SpaceStation_5"); /* * var ecoStationsDefs = new List<MyStationsListDefinition>(MyDefinitionManager.Static.GetDefinitionsOfType<MyStationsListDefinition>().ToList()); * * foreach(var station in ecoStationsDefs) { * * foreach(var stationPrefabName in station.StationNames) { * * var stationNameString = stationPrefabName.ToString(); * * if(string.IsNullOrWhiteSpace(stationNameString) == true) { * * continue; * * } * * if(NPCWatcher.EconomyStationNames.Contains(stationNameString) == false) { * * NPCWatcher.EconomyStationNames.Add(stationNameString); * Logger.AddMsg("Economy Station: " + stationNameString); * * } * * } * * } */ } catch (Exception exc) { Logger.AddMsg("Something Failed While Building List Of Economy Station Prefab Names. See Below:"); Logger.AddMsg(dropContainerErrorLog.ToString()); } Logger.AddMsg("Registering Mod Message Handlers."); Logger.AddMsg("Mod Channel: " + MyAPIGateway.Utilities.GamePaths.ModScopeName); MyAPIGateway.Utilities.RegisterMessageHandler(1521905890, ModMessages.ModMessageHandler); MyAPIGateway.Utilities.RegisterMessageHandler(1521905890001, ModMessages.ModMessageReceiverBlockReplace); MyAPIGateway.Utilities.RegisterMessageHandler(1521905890002, ModMessages.ModMessageReceiverSpawnRequest); MyAPIGateway.Utilities.RegisterMessageHandler(1521905890003, ModMessages.ModMessageReceiverRivalAISpawnRequest); Logger.AddMsg("Initiating Main Settings."); Settings.InitSettings(); NPCWatcher.InitFactionData(); SpawnResources.PopulateNpcFactionLists(); TerritoryManager.TerritoryRefresh(); SpawnGroupManager.CreateSpawnLists(); string[] uniqueSpawnedArray = new string[0]; if (MyAPIGateway.Utilities.GetVariable <string[]>("MES-UniqueGroupsSpawned", out uniqueSpawnedArray) == true) { SpawnGroupManager.UniqueGroupsSpawned = new List <string>(uniqueSpawnedArray.ToList()); } else { Logger.AddMsg("Failed To Retrieve Previously Spawned Unique Encounters List or No Unique Encounters Have Spawned Yet."); } //Setup Existing Boss Encounters string storedBossData = ""; if (MyAPIGateway.Utilities.GetVariable <string>("MES-ActiveBossEncounters", out storedBossData) == true) { if (storedBossData != "") { try{ var byteArray = Convert.FromBase64String(storedBossData); var storedData = MyAPIGateway.Utilities.SerializeFromBinary <BossEncounter[]>(byteArray); NPCWatcher.BossEncounters = new List <BossEncounter>(storedData.ToList()); bool listChange = false; if (NPCWatcher.BossEncounters.Count > 0) { for (int i = NPCWatcher.BossEncounters.Count - 1; i >= 0; i--) { var bossEncounter = NPCWatcher.BossEncounters[i]; bossEncounter.SpawnGroup = SpawnGroupManager.GetSpawnGroupByName(bossEncounter.SpawnGroupName); if (bossEncounter.SpawnGroup == null) { bossEncounter.RemoveGpsForPlayers(); listChange = true; NPCWatcher.BossEncounters.RemoveAt(i); } } } if (listChange == true) { if (NPCWatcher.BossEncounters.Count > 0) { BossEncounter[] encounterArray = NPCWatcher.BossEncounters.ToArray(); byteArray = MyAPIGateway.Utilities.SerializeToBinary <BossEncounter[]>(encounterArray); storedBossData = Convert.ToBase64String(byteArray); MyAPIGateway.Utilities.SetVariable <string>("MES-ActiveBossEncounters", storedBossData); } else { MyAPIGateway.Utilities.SetVariable <string>("MES-ActiveBossEncounters", ""); } } }catch (Exception e) { Logger.AddMsg("Something went wrong while getting Boss Encounter Data from Storage."); Logger.AddMsg(e.ToString(), true); } } } //Get Active Mods Logger.AddMsg("Getting Active Mods."); foreach (var mod in MyAPIGateway.Session.Mods) { if (mod.PublishedFileId != 0) { ActiveMods.Add(mod.PublishedFileId); } /*if(mod.PublishedFileId == 1135484377 || mod.PublishedFileId == 973528334){ * * string msgA = "Conflicting Mod Detected: " + mod.FriendlyName; * MyVisualScriptLogicProvider.ShowNotificationToAll(msgA, 15000, "Red"); * Logger.AddMsg(msgA); * conflictingSettings = true; * * }*/ } if (ActiveMods.Contains(1555044803) == true) { Logger.AddMsg("NPC Weapon Upgrades Mod Detected. Enabling Weapon Randomization."); NPCWeaponUpgradesModDetected = true; } if (ActiveMods.Contains(1773965697) == true) { Logger.AddMsg("Wave Spawner (Space) Mod Detected. Enabling Wave Spawning for SpaceCargoShips."); SpaceWaveSpawnerModDetected = true; } bool suppressCargo = false; bool suppressEncounter = false; if (ActiveMods.Contains(888457124) == true) { suppressCargo = true; } if (ActiveMods.Contains(888457381) == true) { suppressEncounter = true; } SuppressGroups.ApplySuppression(suppressCargo, suppressEncounter); //Init Timers PlayerWatcherTimer = Settings.General.PlayerWatcherTimerTrigger; NPCWatcher.NpcDistanceCheckTimer = Settings.General.NpcDistanceCheckTimerTrigger; NPCWatcher.NpcOwnershipCheckTimer = Settings.General.NpcOwnershipCheckTimerTrigger; NPCWatcher.NpcCleanupCheckTimer = Settings.General.NpcCleanupCheckTimerTrigger; NPCWatcher.SpawnedVoxelCheckTimer = Settings.General.SpawnedVoxelCheckTimerTrigger; SpawnResources.RefreshEntityLists(); //Setup Watchers and Handlers MyAPIGateway.Entities.OnEntityAdd += NPCWatcher.NewEntityDetected; //Get Initial Players PlayerList.Clear(); MyAPIGateway.Players.GetPlayers(PlayerList); //Get Existing NPCs Logger.AddMsg("Check For Existing NPC Grids"); NPCWatcher.StartupScan(); //Setup Wave Spawners SpaceCargoShipWaveSpawner = new WaveSpawner("SpaceCargoShip"); //Init Economy Stuff Logger.AddMsg("Initializing Economy Resources"); EconomyHelper.Setup(); //Get Spawned Voxels From Save try{ string[] tempSpawnedVoxels = new string[0]; if (MyAPIGateway.Utilities.GetVariable <string[]>("MES-SpawnedVoxels", out tempSpawnedVoxels) == true) { foreach (var voxelId in tempSpawnedVoxels) { long tempId = 0; if (long.TryParse(voxelId, out tempId) == false) { continue; } IMyEntity voxelEntity = null; if (MyAPIGateway.Entities.TryGetEntityById(tempId, out voxelEntity) == false) { continue; } if (NPCWatcher.SpawnedVoxels.ContainsKey(voxelId) == false) { NPCWatcher.SpawnedVoxels.Add(voxelId, voxelEntity); } } } }catch (Exception exc) { Logger.AddMsg("Something went wrong while trying to retrieve previously spawned voxels."); } }
public override void UpdateBeforeSimulation() { if (scriptInit == false) { scriptInit = true; SetupScript(); } if (scriptFail == true) { return; } //Voxels to Remove Get Processed Twice - Sometimes game misses some cells. if (VoxelsToRemove == true) { if (OtherTick == false) { if (RemoveVoxels.Count > 0) { var index = RemoveVoxels.Count - 1; CutVoxelsAtAirtightPositions(RemoveVoxels[index]); RemoveVoxelsAgain.Add(RemoveVoxels[index]); RemoveVoxels.RemoveAt(index); } else { OtherTick = true; } } else { if (RemoveVoxelsAgain.Count > 0) { var index = RemoveVoxelsAgain.Count - 1; CutVoxelsAtAirtightPositions(RemoveVoxelsAgain[index]); RemoveVoxelsAgain.RemoveAt(index); } else { OtherTick = false; VoxelsToRemove = false; } } } if (NPCWatcher.DeleteGrids == true && MyAPIGateway.Multiplayer.IsServer == true) { NPCWatcher.DeletionTimer++; if (NPCWatcher.DeletionTimer >= 10) { NPCWatcher.DeletionTimer = 0; NPCWatcher.DeleteGridsProcessing(); } } tickCounter += tickCounterIncrement; if (tickCounter < 60) { return; } tickCounter = 0; if (MyAPIGateway.Multiplayer.IsServer == false) { return; } if (SaveName != MyAPIGateway.Session.Name) { Logger.AddMsg("New Save Detected. Applying Existing Settings To Save File."); SaveName = MyAPIGateway.Session.Name; Settings.General.SaveSettings(Settings.General); Settings.SpaceCargoShips.SaveSettings(Settings.SpaceCargoShips); Settings.RandomEncounters.SaveSettings(Settings.RandomEncounters); Settings.PlanetaryCargoShips.SaveSettings(Settings.PlanetaryCargoShips); Settings.PlanetaryInstallations.SaveSettings(Settings.PlanetaryInstallations); Settings.BossEncounters.SaveSettings(Settings.BossEncounters); Settings.OtherNPCs.SaveSettings(Settings.OtherNPCs); Settings.CustomBlocks.SaveSettings(Settings.CustomBlocks); } //Temporary Until Keen Fixes NPCs Randomly Stopping CargoShipWatcher.ProcessCargoShipSpeedWatcher(); if (NPCWatcher.PendingNPCs.Count == 0) { bool waveSpawnerActive = false; //WaveSpawner - SpaceCargoShip if (Settings.SpaceCargoShips.EnableWaveSpawner == true || SpaceWaveSpawnerModDetected == true) { SpaceCargoShipWaveSpawner.WaveSpawnerRun(); if (SpaceCargoShipWaveSpawner.SpawnWaves == true) { waveSpawnerActive = true; } } //Regular Spawners if (waveSpawnerActive == false) { PlayerWatcherTimer--; if (PlayerWatcherTimer <= 0) { RelationManager.InitialReputationFixer(); PlayerWatcherTimer = Settings.General.PlayerWatcherTimerTrigger; ProcessPlayerWatchList(); } } } TerritoryManager.TerritoryWatcher(); NPCWatcher.BossSignalWatcher(); NPCWatcher.ActiveNpcMonitor(); }
public static void ServerChatProcessing(SyncData receivedData) { if (receivedData.ChatMessage.StartsWith("/MES.SSCS") == true) { receivedData.ChatMessage = receivedData.ChatMessage.Replace("/MES.SSCS", "/MES.Spawn.SpaceCargoShip"); } if (receivedData.ChatMessage.StartsWith("/MES.SRE") == true) { receivedData.ChatMessage = receivedData.ChatMessage.Replace("/MES.SRE", "/MES.Spawn.RandomEncounter"); } if (receivedData.ChatMessage.StartsWith("/MES.SPCS") == true) { receivedData.ChatMessage = receivedData.ChatMessage.Replace("/MES.SPCS", "/MES.Spawn.PlanetaryCargoShip"); } if (receivedData.ChatMessage.StartsWith("/MES.SPI") == true) { receivedData.ChatMessage = receivedData.ChatMessage.Replace("/MES.SPI", "/MES.Spawn.PlanetaryInstallation"); } if (receivedData.ChatMessage.StartsWith("/MES.SBE") == true) { receivedData.ChatMessage = receivedData.ChatMessage.Replace("/MES.SBE", "/MES.Spawn.BossEncounter"); } //Debug Commands if (receivedData.ChatMessage.StartsWith("/MES.") == true) { //Enable Debug Mode if (receivedData.ChatMessage.StartsWith("/MES.EnableDebugMode.") == true) { var msgSplit = receivedData.ChatMessage.Split('.'); if (msgSplit.Length != 3) { MyVisualScriptLogicProvider.ShowNotification("Invalid Command Received", 5000, "White", receivedData.PlayerId); return; } bool mode = false; if (bool.TryParse(msgSplit[2], out mode) == false) { MyVisualScriptLogicProvider.ShowNotification("Invalid Command Received", 5000, "White", receivedData.PlayerId); return; } Logger.LoggerDebugMode = mode; MyVisualScriptLogicProvider.ShowNotification("Debug Mode Enabled: " + mode.ToString(), 5000, "White", receivedData.PlayerId); return; } //Debug: InitStoreBlocks if (receivedData.ChatMessage.StartsWith("/MES.Debug.InitStoreBlocks") == true) { Debug.InitStoreBlocks(); } if (receivedData.ChatMessage.StartsWith("/MES.Debug.Reputation.") == true) { Debug.ReputationCheck(receivedData); } if (receivedData.ChatMessage.StartsWith("/MES.Debug.MoreEcMad") == true) { var player = SpawnResources.GetPlayerById(receivedData.PlayerId); if (player != null) { foreach (var faction in MyAPIGateway.Session.Factions.Factions.Keys) { var npcFaction = MyAPIGateway.Session.Factions.Factions[faction]; MyAPIGateway.Session.Factions.SetReputationBetweenPlayerAndFaction(player.IdentityId, npcFaction.FactionId, -501); } } } if (receivedData.ChatMessage.StartsWith("/MES.Debug.MoreEcHostile") == true) { var player = SpawnResources.GetPlayerById(receivedData.PlayerId); if (player != null) { foreach (var faction in MyAPIGateway.Session.Factions.Factions.Keys) { var npcFaction = MyAPIGateway.Session.Factions.Factions[faction]; MyAPIGateway.Session.Factions.SetReputationBetweenPlayerAndFaction(player.IdentityId, npcFaction.FactionId, -1500); } } } if (receivedData.ChatMessage.StartsWith("/MES.Debug.MoreEcNeutral") == true) { var player = SpawnResources.GetPlayerById(receivedData.PlayerId); if (player != null) { foreach (var faction in MyAPIGateway.Session.Factions.Factions.Keys) { var npcFaction = MyAPIGateway.Session.Factions.Factions[faction]; MyAPIGateway.Session.Factions.SetReputationBetweenPlayerAndFaction(player.IdentityId, npcFaction.FactionId, 0); } } } //Debug.CheckNight if (receivedData.ChatMessage.StartsWith("/MES.Debug.CheckNight") == true) { MyVisualScriptLogicProvider.ShowNotification("Is Night: " + SpawnResources.IsNight(MyAPIGateway.Session.LocalHumanPlayer.GetPosition()).ToString(), 5000, "White", receivedData.PlayerId); MyVisualScriptLogicProvider.ShowNotification("Time: " + MyAPIGateway.Session.GameDateTime.ToString(), 5000, "White", receivedData.PlayerId); var gameTime = MyAPIGateway.Session.GameDateTime - new DateTime(2081, 1, 1, 0, 0, 0, DateTimeKind.Utc); MyVisualScriptLogicProvider.ShowNotification("Seconds: " + gameTime.TotalSeconds.ToString(), 5000, "White", receivedData.PlayerId); } //Debug.CheckRemovalStatus if (receivedData.ChatMessage.StartsWith("/MES.Debug.CheckRemovalStatus") == true) { MyVisualScriptLogicProvider.ShowNotification("Number Of Pending Deletions: " + NPCWatcher.DeleteGridList.Count.ToString(), 5000, "White", receivedData.PlayerId); MyVisualScriptLogicProvider.ShowNotification("Deletion Process Status: " + NPCWatcher.DeleteGrids.ToString(), 5000, "White", receivedData.PlayerId); } //Debug.Debug.CreateKPL if (receivedData.ChatMessage.StartsWith("/MES.Debug.CreateKPL") == true) { KnownPlayerLocationManager.AddKnownPlayerLocation(MyAPIGateway.Session.LocalHumanPlayer.GetPosition(), "SPRT", 200, 1, -1); } //Joke: ComeAtMeBro if (receivedData.ChatMessage.StartsWith("/MES.ComeAtMeBro") == true) { var playerList = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(playerList); IMyPlayer thisPlayer = null; foreach (var player in playerList) { if (player.IdentityId == receivedData.PlayerId) { thisPlayer = player; break; } } if (thisPlayer == null) { return; } int bros = 0; foreach (var cubeGrid in NPCWatcher.ActiveNPCs.Keys.ToList()) { if (cubeGrid == null || MyAPIGateway.Entities.Exist(cubeGrid) == false) { continue; } if (cubeGrid.Physics == null) { continue; } if (NPCWatcher.ActiveNPCs[cubeGrid].SpawnType == "SpaceCargoShip") { cubeGrid.Physics.LinearVelocity = Vector3D.Normalize(thisPlayer.GetPosition() - cubeGrid.GetPosition()) * 100; bros++; } } MyVisualScriptLogicProvider.ShowNotification(bros.ToString() + " Bros Coming At You!", 5000, "Red", thisPlayer.IdentityId); } //RemoveAllNPCs if (receivedData.ChatMessage.StartsWith("/MES.RemoveAllNPCs") == true) { foreach (var cubeGrid in NPCWatcher.ActiveNPCs.Keys.ToList()) { if (cubeGrid == null || MyAPIGateway.Entities.Exist(cubeGrid) == false) { continue; } if (cubeGrid.Physics == null) { continue; } if (NPCWatcher.ActiveNPCs[cubeGrid].CleanupIgnore == false) { NPCWatcher.ActiveNPCs[cubeGrid].FlagForDespawn = true; } } MyVisualScriptLogicProvider.ShowNotification("All Eligible NPC Grids Processed For Removal", 5000, "White", receivedData.PlayerId); } //Settings if (receivedData.ChatMessage.StartsWith("/MES.Settings.") == true) { var result = SettingsEditor.EditSettings(receivedData.ChatMessage); MyVisualScriptLogicProvider.ShowNotification(result, 5000, "White", receivedData.PlayerId); return; } //TryRandomSpawn if (receivedData.ChatMessage.StartsWith("/MES.Spawn.") == true) { var playerList = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(playerList); IMyPlayer thisPlayer = null; foreach (var player in playerList) { if (player.IdentityId == receivedData.PlayerId) { thisPlayer = player; break; } } if (thisPlayer == null) { MyVisualScriptLogicProvider.ShowNotification("Could Not Spawn Encounter: Player Not In Watch List", 5000, "White", receivedData.PlayerId); return; } bool success = false; if (receivedData.ChatMessage.Contains("SpaceCargoShip") == true || receivedData.ChatMessage.Contains("AllSpawns") == true) { if (MES_SessionCore.playerWatchList.ContainsKey(thisPlayer) == true) { SpawnGroupManager.AdminSpawnGroup = SpecificSpawnGroupRequest(receivedData.ChatMessage, "SpaceCargoShip"); MES_SessionCore.PlayerWatcherTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].SpaceCargoShipTimer = 0; MyVisualScriptLogicProvider.ShowNotification("Attempting Random Spawn: Space Cargo Ship", 5000, "White", receivedData.PlayerId); success = true; } } if (receivedData.ChatMessage.Contains("PlanetaryCargoShip") == true) { if (MES_SessionCore.playerWatchList.ContainsKey(thisPlayer) == true) { SpawnGroupManager.AdminSpawnGroup = SpecificSpawnGroupRequest(receivedData.ChatMessage, "PlanetaryCargoShip"); MES_SessionCore.playerWatchList[thisPlayer].AtmoCargoShipTimer = 0; MES_SessionCore.PlayerWatcherTimer = 0; MyVisualScriptLogicProvider.ShowNotification("Attempting Random Spawn: Planetary Cargo Ship", 5000, "White", receivedData.PlayerId); success = true; } } if (receivedData.ChatMessage.Contains("RandomEncounter") == true) { if (MES_SessionCore.playerWatchList.ContainsKey(thisPlayer) == true) { SpawnGroupManager.AdminSpawnGroup = SpecificSpawnGroupRequest(receivedData.ChatMessage, "RandomEncounter"); MES_SessionCore.PlayerWatcherTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].RandomEncounterCheckTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].RandomEncounterCoolDownTimer = 0; var fakeDistance = Settings.RandomEncounters.PlayerTravelDistance + 1000; MES_SessionCore.playerWatchList[thisPlayer].RandomEncounterDistanceCoordCheck = fakeDistance * Vector3D.Up + thisPlayer.GetPosition(); MyVisualScriptLogicProvider.ShowNotification("Attempting Random Spawn: Random Encounter", 5000, "White", receivedData.PlayerId); success = true; } } if (receivedData.ChatMessage.Contains("PlanetaryInstallation") == true) { if (MES_SessionCore.playerWatchList.ContainsKey(thisPlayer) == true) { SpawnGroupManager.AdminSpawnGroup = SpecificSpawnGroupRequest(receivedData.ChatMessage, "PlanetaryInstallation"); MES_SessionCore.PlayerWatcherTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].PlanetaryInstallationCheckTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].PlanetaryInstallationCooldownTimer = 0; var fakeDistance = Settings.PlanetaryInstallations.PlayerDistanceSpawnTrigger + 1000; var randomDir = SpawnResources.GetRandomCompassDirection(thisPlayer.GetPosition(), SpawnResources.GetNearestPlanet(thisPlayer.GetPosition())); MES_SessionCore.playerWatchList[thisPlayer].InstallationDistanceCoordCheck = fakeDistance * randomDir + thisPlayer.GetPosition(); MyVisualScriptLogicProvider.ShowNotification("Attempting Random Spawn: Planetary Installation", 5000, "White", receivedData.PlayerId); success = true; } } if (receivedData.ChatMessage.Contains("BossEncounter") == true) { if (BossEncounterSpawner.IsPlayerInBossEncounter(thisPlayer.IdentityId) == true) { MyVisualScriptLogicProvider.ShowNotification("Boss Encounter Already Active", 5000, "White", receivedData.PlayerId); } if (MES_SessionCore.playerWatchList.ContainsKey(thisPlayer) == true) { SpawnGroupManager.AdminSpawnGroup = SpecificSpawnGroupRequest(receivedData.ChatMessage, "BossEncounter"); MES_SessionCore.PlayerWatcherTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].BossEncounterCooldownTimer = 0; MES_SessionCore.playerWatchList[thisPlayer].BossEncounterCheckTimer = 0; MyVisualScriptLogicProvider.ShowNotification("Attempting Random Spawn: Boss Encounter", 5000, "White", receivedData.PlayerId); success = true; } } if (success == false) { MyVisualScriptLogicProvider.ShowNotification("Could Not Spawn Encounter: Player Not In Watch List", 5000, "White", receivedData.PlayerId); } return; } //WaveSpawner if (receivedData.ChatMessage.StartsWith("/MES.WaveSpawner.") == true) { bool success = false; if (receivedData.ChatMessage.Contains("SpaceCargoShip") == true && Settings.SpaceCargoShips.EnableWaveSpawner == true) { MyVisualScriptLogicProvider.ShowNotification("Wave Spawner (Space Cargo Ship) Activated.", 5000, "White", receivedData.PlayerId); MES_SessionCore.SpaceCargoShipWaveSpawner.CurrentWaveTimer = Settings.SpaceCargoShips.MaxWaveSpawnTime; success = true; } if (success == false) { MyVisualScriptLogicProvider.ShowNotification("Wave Spawner Could Not Be Triggered. Please Enable In Configuration.", 5000, "White", receivedData.PlayerId); } } //Enable Territory if (receivedData.ChatMessage.StartsWith("/MES.EnableTerritory.") == true) { var messageReplace = receivedData.ChatMessage.Replace("/MES.EnableTerritory.", ""); if (messageReplace == "") { MyVisualScriptLogicProvider.ShowNotification("Invalid Command Received: No Territory Name Provided", 5000, "White", receivedData.PlayerId); return; } MyAPIGateway.Utilities.SetVariable <bool>("MES-Territory-" + messageReplace, true); TerritoryManager.TerritoryRefresh(); MyVisualScriptLogicProvider.ShowNotification("Territory Enabled: " + messageReplace, 5000, "White", receivedData.PlayerId); return; } //Disable Territory if (receivedData.ChatMessage.StartsWith("/MES.DisableTerritory.") == true) { var messageReplace = receivedData.ChatMessage.Replace("/MES.DisableTerritory.", ""); if (messageReplace == "") { MyVisualScriptLogicProvider.ShowNotification("Invalid Command Received: No Territory Name Provided", 5000, "White", receivedData.PlayerId); return; } MyAPIGateway.Utilities.SetVariable <bool>("MES-Territory-" + messageReplace, false); TerritoryManager.TerritoryRefresh(); MyVisualScriptLogicProvider.ShowNotification("Territory Disabled: " + messageReplace, 5000, "White", receivedData.PlayerId); return; } //Get SpawnGroups if (receivedData.ChatMessage.StartsWith("/MES.GetSpawnGroups") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.SpawnGroupResults(); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Spawn Group Data To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Active NPCs if (receivedData.ChatMessage.StartsWith("/MES.GetActiveNPCs") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.GetActiveNPCs(); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Active NPC Data To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Block Definition Info if (receivedData.ChatMessage.StartsWith("/MES.GetBlockDefinitions") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.GetBlockDefinitionInfo(); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Block Data To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Block Definition Info if (receivedData.ChatMessage.StartsWith("/MES.GetColorsFromGrid") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.GetColorListFromGrid(SpawnResources.GetPlayerById(syncData.PlayerId)); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); return; } //Get Player Watch Lists if (receivedData.ChatMessage.StartsWith("/MES.GetPlayerWatchList") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.GetPlayerWatcherData(); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Player Watch Data To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Local Threat Score if (receivedData.ChatMessage.StartsWith("/MES.GetThreatScore") == true || receivedData.ChatMessage.StartsWith("/MES.GTS") == true) { var messageReplace = receivedData.ChatMessage.Replace("/MES.GetThreatScore.", ""); ImprovedSpawnGroup selectedSpawnGroup = null; if (messageReplace == "") { MyVisualScriptLogicProvider.ShowNotification("Default Threat Check Range Of 5000 Used. Spawngroup Not Provided or Detected.", 5000, "White", receivedData.PlayerId); //return; selectedSpawnGroup = new ImprovedSpawnGroup(); } var playerList = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(playerList); IMyPlayer thisPlayer = null; foreach (var player in playerList) { if (player.IdentityId == receivedData.PlayerId) { thisPlayer = player; break; } } if (thisPlayer == null) { MyVisualScriptLogicProvider.ShowNotification("Command Failed: Apparently you don't exist?", 5000, "White", receivedData.PlayerId); return; } if (selectedSpawnGroup == null) { foreach (var spawnGroup in SpawnGroupManager.SpawnGroups) { if (spawnGroup.SpawnGroup.Id.SubtypeName == messageReplace) { selectedSpawnGroup = spawnGroup; break; } } } if (selectedSpawnGroup == null) { MyVisualScriptLogicProvider.ShowNotification("Default Threat Check Range Of 5000 Used. Spawngroup Not Provided or Detected.", 5000, "White", receivedData.PlayerId); //return; selectedSpawnGroup = new ImprovedSpawnGroup(); } SpawnResources.RefreshEntityLists(); SpawnResources.LastThreatRefresh = SpawnResources.GameStartTime; var threatLevel = SpawnResources.GetThreatLevel(selectedSpawnGroup, thisPlayer.GetPosition()); MyVisualScriptLogicProvider.ShowNotification("Threat Level Score Near You: " + threatLevel.ToString(), 5000, "White", receivedData.PlayerId); return; } //Reset Active Territories if (receivedData.ChatMessage.StartsWith("/MES.ResetActiveTerritories") == true) { TerritoryManager.TerritoryRefresh(true); var syncData = receivedData; syncData.Instruction = "MESResetActiveTerritories"; var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Active Territories Reset To Default Values.", 5000, "White", receivedData.PlayerId); return; } //Get Spawned Unique Encounters if (receivedData.ChatMessage.StartsWith("/MES.GetSpawnedUniqueEncounters") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.GetSpawnedUniqueEncounters(); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Spawned Unique Encounters List Sent To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Spawn Group Eligibility At Position if (receivedData.ChatMessage.StartsWith("/MES.GetEligibleSpawnsAtPosition") == true || receivedData.ChatMessage.StartsWith("/MES.GESAP") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; syncData.ClipboardContents = Logger.EligibleSpawnGroupsAtPosition(receivedData.PlayerPosition); var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("List of Eligible Spawn Groups At Position Sent To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } //Get Planet Direction At Position if (receivedData.ChatMessage.StartsWith("/MES.GetDirectionFromPlanetCore") == true) { var syncData = receivedData; syncData.Instruction = "MESClipboard"; var planet = SpawnResources.GetNearestPlanet(receivedData.PlayerPosition); if (planet != null) { var planetEntity = planet as IMyEntity; var dir = Vector3D.Normalize(receivedData.PlayerPosition - planetEntity.GetPosition()); var sb = new StringBuilder(); sb.Append("Direction Vector For ").Append(planet.Generator.Id.SubtypeName).Append(" At Position ").Append(planetEntity.GetPosition().ToString()).AppendLine(); sb.Append("X: ").Append(dir.X.ToString()).AppendLine(); sb.Append("Y: ").Append(dir.Y.ToString()).AppendLine(); sb.Append("Z: ").Append(dir.Z.ToString()).AppendLine(); syncData.ClipboardContents = sb.ToString(); } else { syncData.ClipboardContents = "No Planets In Game World."; } var sendData = MyAPIGateway.Utilities.SerializeToBinary <SyncData>(syncData); bool sendStatus = MyAPIGateway.Multiplayer.SendMessageTo(8877, sendData, receivedData.SteamUserId); MyVisualScriptLogicProvider.ShowNotification("Direction From Planet Core Values Sent To Clipboard. Success: " + sendStatus.ToString(), 5000, "White", receivedData.PlayerId); return; } } //Settings Commands }