private static void Run(SpawnPointModel model) { for (int i = 0; i < model.SpawnPoints.Count; i++) { var spawnGroup = model.SpawnPoints[i]; if (ImGui.CollapsingHeader($"Spawn group #{i}")) { Run(spawnGroup, i); } } }
private void RealizeMapObject(MapObjectModel model) { GameObject result; switch (model.MapObjectType) { case MapObjectType.SpawnPoint: result = (GameObject)Instantiate(SpawnPointPrototype, model.Position, Quaternion.Euler(model.Rotation)); result.transform.SetParent(SpawnPointRoot.transform); SpawnPointActuator actuator = result.GetComponent <SpawnPointActuator>(); if (actuator == null) { throw new ApplicationException("Spawn Point Prototype does not have a Spawn Point Actuator behavior on it!"); } SpawnPointModel spawnPointModel = SpawnPointRepository.GetSpawnPointByName(model.ModelName); if (spawnPointModel == null) { throw new DataException("Spawn Point Model " + model.ModelName + " isn't defined in the SpawnPoint data file."); } actuator.RealizeModel(spawnPointModel); break; case MapObjectType.RevivableSpawnPoint: result = (GameObject)Instantiate(RevivableSpawnPointPrototype, model.Position, Quaternion.Euler(model.Rotation)); result.transform.SetParent(GameObjectRoot.transform); RevivableSpawnPointActuator revivableSpawnPointActuator = result.GetComponent <RevivableSpawnPointActuator>(); if (revivableSpawnPointActuator == null) { throw new ApplicationException("Revivable Spawn Point Prototype does not have a Revivable Spawn Point Actuator behavior on it!"); } SpawnPointModel revivableSpawnPointModel = RevivableSpawnPointRepository.GetSpawnPointByName(model.ModelName); if (revivableSpawnPointModel == null) { throw new DataException("Revivable Spawn Point Model " + model.ModelName + " isn't defined in the SpawnPoint data file."); } revivableSpawnPointActuator.RealizeModel(revivableSpawnPointModel); break; case MapObjectType.Waypoint: result = (GameObject)Instantiate(WaypointPrototype, model.Position, Quaternion.Euler(model.Rotation)); result.transform.SetParent(GameObjectRoot.transform); break; default: throw new ApplicationException("Unexpected Map Object type:" + model.MapObjectType); } }
public bool PlaceGameItemInSpawnPoint(GameItem item) { List <SpawnPointModel> spawnPointOptions = new List <SpawnPointModel>(); // find possible solutions to place the obstacle for (int i = 0; i < spawnPoints.Length - item.laneWeight + 1; i++) { if (spawnPoints[i].IsSlotTaken()) { continue; } // check if the obstacle can fit in the current slot bool canSpawn = true; for (int weight = 1; weight < item.laneWeight + 1; weight++) { if (spawnPoints[i + weight - 1].IsSlotTaken()) { canSpawn = false; } } if (canSpawn) { spawnPointOptions.Add(spawnPoints[i]); } } if (spawnPointOptions.Count > 0) { // place obstacle in a random slot SpawnPointModel randomOption = spawnPointOptions[Random.Range(0, spawnPointOptions.Count)]; // reserve spawnpoint slots if an object is bigger than one lane for (int i = 0; i < spawnPoints.Length; i++) { if (spawnPoints[i] == randomOption) { for (int weight = 1; weight < item.laneWeight + 1; weight++) { spawnPoints[i + weight - 1].reserveSlot(); } break; } } randomOption.SetItem(item); return(true); } else { return(false); } }
public static async void LoadSpawnPoints(LobbyModel lobby) { // Load the items for the selected track List <SpawnPointModel> spawnPoints = await DatabaseHandler.LoadTrackSpawns(lobby.Track).ConfigureAwait(false); // Initialize the random seems Random random = new Random(); foreach (Client player in lobby.Players) { // Get a random spawn point SpawnPointModel spawn = spawnPoints[random.Next(spawnPoints.Count)]; // Set the player into the spawn player.Position = spawn.Position; player.Rotation = spawn.Rotation; player.Dimension = (uint)lobby.Id; // Remove the spawn point spawnPoints.Remove(spawn); } }
public static async Task <List <SpawnPointModel> > LoadTrackSpawns(int trackId) { List <SpawnPointModel> spawns = new List <SpawnPointModel>(); using (MySqlConnection connection = new MySqlConnection(connectionHandle)) { await connection.OpenAsync().ConfigureAwait(false); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT `posX`, `posY`, `posZ`, `rotX`, `rotY`, `rotZ` FROM `spawns` WHERE `trackId` = @trackId"; command.Parameters.AddWithValue("@trackId", trackId); DbDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false); while (reader.HasRows) { // Get the position and rotation float positionX = reader.GetFloat(reader.GetOrdinal("posX")); float positionY = reader.GetFloat(reader.GetOrdinal("posY")); float positionZ = reader.GetFloat(reader.GetOrdinal("posZ")); float rotationX = reader.GetFloat(reader.GetOrdinal("rotX")); float rotationY = reader.GetFloat(reader.GetOrdinal("rotY")); float rotationZ = reader.GetFloat(reader.GetOrdinal("rotZ")); SpawnPointModel spawnPoint = new SpawnPointModel() { Position = new Vector3(positionX, positionY, positionZ), Rotation = new Vector3(rotationX, rotationY, rotationZ) }; spawns.Add(spawnPoint); } } return(spawns); }