public SpawnChunk GetOrCreateSpawnChunk(Point2 point) { SpawnChunk spawnChunk = GetSpawnChunk(point); if (spawnChunk == null) { spawnChunk = new SpawnChunk { Point = point }; m_chunks.Add(point, spawnChunk); } return(spawnChunk); }
public void SpawnChunks() { List <SpawnChunk> list = new List <SpawnChunk>(); foreach (GameWidget gameWidget in m_subsystemViews.GameWidgets) { Vector2 v = new Vector2(gameWidget.ActiveCamera.ViewPosition.X, gameWidget.ActiveCamera.ViewPosition.Z); Vector2 p = v - new Vector2(40f); Vector2 p2 = v + new Vector2(40f); Point2 point = Terrain.ToChunk(p); Point2 point2 = Terrain.ToChunk(p2); for (int i = point.X; i <= point2.X; i++) { for (int j = point.Y; j <= point2.Y; j++) { Vector2 v2 = new Vector2(((float)i + 0.5f) * 16f, ((float)j + 0.5f) * 16f); if (Vector2.DistanceSquared(v, v2) < 1600f) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(v2.X), Terrain.ToCell(v2.Y)); if (chunkAtCell != null && chunkAtCell.State > TerrainChunkState.InvalidPropagatedLight) { Point2 point3 = new Point2(i, j); SpawnChunk orCreateSpawnChunk = GetOrCreateSpawnChunk(point3); foreach (SpawnEntityData spawnsDatum in orCreateSpawnChunk.SpawnsData) { SpawnEntity(spawnsDatum); } orCreateSpawnChunk.SpawnsData.Clear(); this.SpawningChunk?.Invoke(orCreateSpawnChunk); orCreateSpawnChunk.IsSpawned = true; } } } } } foreach (SpawnChunk item in list) { foreach (SpawnEntityData spawnsDatum2 in item.SpawnsData) { SpawnEntity(spawnsDatum2); } item.SpawnsData.Clear(); } }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); m_subsystemViews = base.Project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("Chunks")) { ValuesDictionary valuesDictionary2 = (ValuesDictionary)item.Value; SpawnChunk spawnChunk = new SpawnChunk(); spawnChunk.Point = HumanReadableConverter.ConvertFromString <Point2>(item.Key); spawnChunk.IsSpawned = valuesDictionary2.GetValue <bool>("IsSpawned"); spawnChunk.LastVisitedTime = valuesDictionary2.GetValue <double>("LastVisitedTime"); string value = valuesDictionary2.GetValue("SpawnsData", string.Empty); if (!string.IsNullOrEmpty(value)) { LoadSpawnsData(value, spawnChunk.SpawnsData); } m_chunks[spawnChunk.Point] = spawnChunk; } }
public void UpdateLastVisitedTime() { foreach (ComponentPlayer componentPlayer in m_subsystemPlayers.ComponentPlayers) { Vector2 v = new Vector2(componentPlayer.ComponentBody.Position.X, componentPlayer.ComponentBody.Position.Z); Vector2 p = v - new Vector2(8f); Vector2 p2 = v + new Vector2(8f); Point2 point = Terrain.ToChunk(p); Point2 point2 = Terrain.ToChunk(p2); for (int i = point.X; i <= point2.X; i++) { for (int j = point.Y; j <= point2.Y; j++) { SpawnChunk spawnChunk = GetSpawnChunk(new Point2(i, j)); if (spawnChunk != null) { spawnChunk.LastVisitedTime = m_subsystemGameInfo.TotalElapsedGameTime; } } } } }