/// <summary> /// Checks all planets of the star system, and whether they are still existent as objects /// in the world. Just to clear up deleted objects from the system at world loading /// </summary> private void CheckIntegrityOfSystem() { foreach (var obj in StarSystem.GetAllObjects()) { if (obj is MySystemPlanet) { if (!MyEntities.EntityExists((obj as MySystemPlanet).EntityId) && (obj as MySystemPlanet).Generated) { MyPluginLog.Debug("Planet " + obj.Id + " does not exist anymore, deleting it", LogLevel.WARNING); StarSystem.RemoveObject(obj.Id); MyGPSManager.Static.RemovePersistentGps(obj.Id); } } else if (obj is MySystemAsteroids) { var instance = obj as MySystemAsteroids; if (MyAsteroidObjectsManager.Static.AsteroidObjectProviders.ContainsKey(instance.AsteroidTypeName)) { var data = MyAsteroidObjectsManager.Static.AsteroidObjectProviders[instance.AsteroidTypeName].GetInstanceData(instance); if (data == null) { MyPluginLog.Debug("Asteroid instance " + obj.Id + " has no data attached, deleting it", LogLevel.WARNING); MyAsteroidObjectsManager.Static.AsteroidObjectProviders[instance.AsteroidTypeName].RemoveInstance(instance); MyGPSManager.Static.RemovePersistentGps(obj.Id); } } } } }
protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId) { if (m_loadedCells.ContainsKey(cellId)) { return(null); } var settings = MySettingsSession.Static.Settings.GeneratorSettings; if (settings.AsteroidGenerator == AsteroidGenerationMethod.VANILLA) { return(null); } MyProceduralCell cell = new MyProceduralCell(cellId, CELL_SIZE); int cellSeed = CalculateCellSeed(cellId); int index = 0; double subCellSize = OBJECT_SIZE_MAX * 1f / settings.AsteroidDensity; int subcells = (int)(CELL_SIZE / subCellSize); using (MyRandom.Instance.PushSeed(cellSeed)) { Vector3I subcellId = Vector3I.Zero; Vector3I max = new Vector3I(subcells - 1); for (var it = new Vector3I_RangeIterator(ref Vector3I.Zero, ref max); it.IsValid(); it.GetNext(out subcellId)) { Vector3D position = new Vector3D(MyRandom.Instance.NextDouble(), MyRandom.Instance.NextDouble(), MyRandom.Instance.NextDouble()); position += (Vector3D)subcellId; position *= subCellSize; position += ((Vector3D)cellId) * CELL_SIZE; if (!MyEntities.IsInsideWorld(position) || (settings.WorldSize >= 0 && position.Length() > settings.WorldSize)) { continue; } var ring = GetAsteroidObjectAt(position); if (ring == null) { continue; } var cellObjectSeed = new MyObjectSeed(cell, position, MyRandom.Instance.Next(ring.AsteroidSize.Min, ring.AsteroidSize.Max)); cellObjectSeed.Params.Type = VRage.Game.MyObjectSeedType.Asteroid; cellObjectSeed.Params.Seed = MyRandom.Instance.Next(); cellObjectSeed.Params.Index = index++; cellObjectSeed.Params.GeneratorSeed = m_definition.UseGeneratorSeed ? MyRandom.Instance.Next() : 0; cell.AddObject(cellObjectSeed); MyPluginLog.Debug("Adding seed"); } } return(cell); }
/// <summary> /// Builds the spawn menu /// </summary> private void BuildSpawnMenu() { MyPluginLog.Debug("Create Spawn Menu"); var topCombo = GetCombo(); Vector2 start = topCombo.Position + new Vector2(0, MARGIN_VERT * 2 + GetCombo().Size.Y); Vector2 end = start + new Vector2(topCombo.Size.X, 0.8f - MARGIN_VERT); MyGuiControlParentTableLayout table = new MyGuiControlParentTableLayout(1, false, Vector2.Zero); table.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP; m_spawnTypeCombo = new MyGuiControlCombobox(); m_spawnTypeCombo.AddItem(0L, "Planet"); m_spawnTypeCombo.AddItem(1L, "Asteroid object"); m_spawnTypeCombo.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP; m_spawnTypeCombo.SelectItemByKey(m_spawnType); m_spawnTypeCombo.ItemSelected += OnSpawnTypeChange; m_spawnTypeCombo.Size = new Vector2(m_usableWidth * 0.9f, m_spawnTypeCombo.Size.Y); m_spawnTypeCombo.SetToolTip(MyPluginTexts.TOOLTIPS.ADMIN_SPAWN_TYPE); table.AddTableRow(m_spawnTypeCombo); table.AddTableSeparator(); switch (m_spawnType) { case 0L: CreatePlanetSpawnMenu(table); break; case 1L: CreateAsteroidSpawnMenu(table); break; } table.AddTableSeparator(); table.ApplyRows(); MyGuiControlScrollablePanel scrollPane = new MyGuiControlScrollablePanel(table); scrollPane.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP; scrollPane.ScrollbarVEnabled = true; scrollPane.Size = end - start; scrollPane.Size = new Vector2(0.315f, scrollPane.Size.Y); scrollPane.Position = new Vector2(0, start.Y); Controls.Add(scrollPane); MyGuiControlSeparatorList sep = new MyGuiControlSeparatorList(); sep.AddHorizontal(new Vector2(scrollPane.Position.X - scrollPane.Size.X / 2, scrollPane.Position.Y + scrollPane.Size.Y), m_usableWidth); Controls.Add(sep); MyPluginLog.Debug("Added spawn menu"); }
private static void SendGetStarSystemClient(MyObjectBuilder_SystemData starSystem, ulong callbackId) { MyPluginLog.Debug("Client: Received star system"); if (Static.m_getSystemCallbacks.ContainsKey(callbackId)) { Static.m_getSystemCallbacks[callbackId](starSystem); Static.m_getSystemCallbacks.Remove(callbackId); } }
/// <summary> /// This method adds the MyEntity to the MyEntityTrackerComponent as a /// tracked Entity. /// </summary> /// <param name="thisEntity">The Entiy this method executes on</param> public static void EntityTracking(this MyEntity thisEntity) { MyPluginLog.Debug("Try Track Entity" + thisEntity.Name); if (thisEntity is MyVoxelBase) { return; } if (MyEntityTrackerComponent.Static != null) { MyPluginLog.Debug("Track Entity"); MyEntityTrackerComponent.Static.TrackEntity(thisEntity); } }
/// <summary> /// Action to remove the ring for the remove ring button /// </summary> /// <param name="button">Button that called this action</param> private void OnRemoveRing(MyGuiControlButton button) { MyPluginLog.Debug("Removing ring " + m_currentSelectedAsteroid.DisplayName); MyStarSystemGenerator.Static.RemoveObjectFromSystem(m_currentSelectedAsteroid.Id, delegate(bool success) { if (success) { m_parentScreen.ForceFetchStarSystem = true; m_parentScreen.ShouldRecreate = true; MyPluginLog.Debug("Refreshing admin menu"); } else { MyPluginGuiHelper.DisplayError(m_currentSelectedAsteroid.DisplayName + " could not be deleted", "Error"); } }); }
/// <summary> /// Registers all types with the EventOwnerAttribute. /// </summary> public void RegisterAll() { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { MyPluginLog.Debug("Registering: " + assembly.FullName); try { foreach (var type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(EventOwnerAttribute), true).Length > 0) { MyPluginLog.Log("Registering type " + type.Name + " in PluginEventHandler."); Register(type); } } }catch (ReflectionTypeLoadException) { MyPluginLog.Log("Couldnt register Types for assembly " + assembly.FullName, LogLevel.WARNING); } } }
/// <summary> /// Teleports the player to the selected ring /// </summary> /// <param name="button">Button to call</param> private void OnTeleportToSphere(MyGuiControlButton button) { MyPluginLog.Debug("Teleporting player to " + m_currentSelectedAsteroid.DisplayName); if (MySession.Static.CameraController != MySession.Static.LocalCharacter || true) { if (m_currentSelectedAsteroid != null) { IMyAsteroidObjectShape shape = MyAsteroidSphereProvider.Static.GetAsteroidObjectShape(m_currentSelectedAsteroid); if (shape == null) { MyPluginGuiHelper.DisplayError("Cant teleport to asteroid sphere. It does not exist", "Error"); return; } m_parentScreen.CloseScreenNow(); MyMultiplayer.TeleportControlledEntity(shape.GetPointInShape()); MyGuiScreenGamePlay.SetCameraController(); } } }
/// <summary> /// Gets the current star system as represented on the server /// </summary> /// <param name="callback">Callback to call, when star system was retreived</param> public void GetStarSystem(Action <MyObjectBuilder_SystemData> callback) { MyPluginLog.Debug("Get star system"); m_getSystemCallbacks.Add(++m_getSystemIndex, callback); PluginEventHandler.Static.RaiseStaticEvent(SendGetStarSystemServer, m_getSystemIndex, Sync.MyId); }
private static void SendGetStarSystemServer(ulong callbackId, ulong clientId) { MyPluginLog.Debug("Server: Get star system"); PluginEventHandler.Static.RaiseStaticEvent(SendGetStarSystemClient, Static.StarSystem, callbackId, clientId); }
/// <summary> /// Builds the edit menu /// </summary> private void BuildEditMenu() { MyPluginLog.Debug("Adding edit menu"); if (m_fetchedStarSytem == null || ForceFetchStarSystem) { MyPluginLog.Debug("Fetching system data"); MyGuiControlRotatingWheel m_loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero); m_loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER; Controls.Add(m_loadingWheel); MyStarSystemGenerator.Static.GetStarSystem(delegate(MyObjectBuilder_SystemData starSystem) { m_fetchedStarSytem = starSystem; m_selectedObject = null; ShouldRecreate = true; ForceFetchStarSystem = false; }); return; } var topCombo = GetCombo(); Vector2 start = topCombo.Position + new Vector2(0, MARGIN_VERT * 2 + GetCombo().Size.Y); Vector2 end = start + new Vector2(topCombo.Size.X, 0.8f - MARGIN_VERT); MyGuiControlLabel systemObjsLabel = new MyGuiControlLabel(null, null, "System Objects"); systemObjsLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP; systemObjsLabel.Position = start; Controls.Add(systemObjsLabel); m_systemObjectsBox = new MyGuiControlListbox(); m_systemObjectsBox.VisibleRowsCount = 8; m_systemObjectsBox.Size = new Vector2(m_usableWidth, m_systemObjectsBox.Size.Y); m_systemObjectsBox.Position = start; m_systemObjectsBox.PositionY += systemObjsLabel.Size.Y + MARGIN_VERT; m_systemObjectsBox.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP; foreach (var obj in m_fetchedStarSytem.GetAllObjects()) { if (obj.Type == MySystemObjectType.EMPTY) { continue; } m_systemObjectsBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder(obj.DisplayName), userData: obj)); } if (m_selectedObject != null) { m_systemObjectsBox.SelectByUserData(m_selectedObject); } m_systemObjectsBox.ItemsSelected += OnSystemObjectSelect; Controls.Add(m_systemObjectsBox); MyGuiControlSeparatorList sep = new MyGuiControlSeparatorList(); sep.AddHorizontal(new Vector2(m_systemObjectsBox.Position.X, m_systemObjectsBox.Position.Y + m_systemObjectsBox.Size.Y + MARGIN_VERT), m_usableWidth); BuildEditingSubMenu(); sep.AddHorizontal(new Vector2(m_scrollPane.Position.X - m_scrollPane.Size.X / 2, m_scrollPane.Position.Y + m_scrollPane.Size.Y), m_usableWidth); Controls.Add(sep); MyPluginLog.Debug("Added edit menu"); }