private void SpawnEvent(string name, ISetPiece setpiece, WmapTerrain terrain) { var pt = new IntPoint(); if (terrain == WmapTerrain.None) { do { pt.X = _rand.Next(0, _world.Map.Width); pt.Y = _rand.Next(0, _world.Map.Height); } while ((_world.Map[pt.X, pt.Y].Terrain <WmapTerrain.Mountains || _world.Map[pt.X, pt.Y].Terrain> WmapTerrain.MidForest) || !_world.IsPassable(pt.X, pt.Y, true) || _world.AnyPlayerNearby(pt.X, pt.Y)); } else { do { pt.X = _rand.Next(0, _world.Map.Width); pt.Y = _rand.Next(0, _world.Map.Height); } while (_world.Map[pt.X, pt.Y].Terrain == terrain || !_world.IsPassable(pt.X, pt.Y, true) || _world.AnyPlayerNearby(pt.X, pt.Y)); } pt.X -= (setpiece.Size - 1) / 2; pt.Y -= (setpiece.Size - 1) / 2; setpiece.RenderSetPiece(_world, pt); Log.InfoFormat("Oryx spawned {0} at ({1}, {2}).", name, pt.X, pt.Y); }
private int HandleSpawn(ObjectDesc desc, WmapTerrain terrain, int w, int h) { Entity entity; var ret = 0; var pt = new IntPoint(); if (desc.Spawn != null) { var num = (int)GetNormal(rand, desc.Spawn.Mean, desc.Spawn.StdDev); if (num > desc.Spawn.Max) { num = desc.Spawn.Max; } else if (num < desc.Spawn.Min) { num = desc.Spawn.Min; } do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || !world.IsPassable(pt.X, pt.Y) || world.AnyPlayerNearby(pt.X, pt.Y)); for (var k = 0; k < num; k++) { entity = Entity.Resolve(desc.ObjectType); entity.Move( pt.X + (float)(rand.NextDouble() * 2 - 1) * 5, pt.Y + (float)(rand.NextDouble() * 2 - 1) * 5); (entity as Enemy).Terrain = terrain; if (entity.GetNearestEntity(10, true) == null) { world.EnterWorld(entity); } ret++; } } else { do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || !world.IsPassable(pt.X, pt.Y) || world.AnyPlayerNearby(pt.X, pt.Y)); entity = Entity.Resolve(desc.ObjectType); entity.Move(pt.X, pt.Y); (entity as Enemy).Terrain = terrain; world.EnterWorld(entity); ret++; } return(ret); }
public Spawn( WmapTerrain WmapTerrain, int Density, List <KeyValuePair <string, double> > Entities ) { this.WmapTerrain = WmapTerrain; this.Density = Density; this.Entities = Entities; }
private int Spawn(ObjectDesc desc, WmapTerrain terrain, int w, int h) { Entity entity; int ret = 0; var pt = new IntPoint(); if (desc.Spawn != null) { var num = (int)GetNormal(rand, desc.Spawn.Mean, desc.Spawn.StdDev); if (num > desc.Spawn.Max) { num = desc.Spawn.Max; } else if (num < desc.Spawn.Min) { num = desc.Spawn.Min; } do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || world.Obstacles[pt.X, pt.Y] != 0 || BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y)); for (int k = 0; k < num; k++) { entity = Entity.Resolve(desc.ObjectType); entity.Move( pt.X + (float)(rand.NextDouble() * 2 - 1) * 5, pt.Y + (float)(rand.NextDouble() * 2 - 1) * 5); (entity as Enemy).Terrain = terrain; world.EnterWorld(entity); ret++; } } else { do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || world.Obstacles[pt.X, pt.Y] != 0 || BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y)); entity = Entity.Resolve(desc.ObjectType); entity.Move(pt.X, pt.Y); (entity as Enemy).Terrain = terrain; world.EnterWorld(entity); ret++; } return(ret); }
private ushort GetRandomObjType(WmapTerrain wmapTerrain) { foreach (Spawn i in RealmSpawnCache) { if (i.WmapTerrain == wmapTerrain) // assuming only one { GetRandomObjType(i.Entities); break; } } return(0); }
public void Init() { log.InfoFormat("Oryx is controlling world {0}({1})...", world.Id, world.Name); int w = world.Map.Width; int h = world.Map.Height; var stats = new int[40]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { WmapTile tile = world.Map[x, y]; if (tile.Terrain != WmapTerrain.None) { stats[(int)tile.Terrain - 1]++; } } } log.Info("Spawning minions..."); foreach (var i in spawn) { WmapTerrain terrain = i.Key; int idx = (int)terrain - 1; int enemyCount = stats[idx] / i.Value.Item1; enemyMaxCounts[idx] = enemyCount; enemyCounts[idx] = 0; for (int j = 0; j < enemyCount; j++) { ushort objType = GetRandomObjType(i.Value.Item2); if (objType == 0) { continue; } enemyCounts[idx] += Spawn(world.Manager.GameData.ObjectDescs[objType], terrain, w, h); if (enemyCounts[idx] >= enemyCount) { break; } } } log.Info("Oryx is done."); }
public void Reset(Wmap map = null, int x = 0, int y = 0) { TileId = _originalDesc.TileId; TileDesc = _originalDesc.TileDesc; ObjType = _originalDesc.ObjType; ObjDesc = _originalDesc.ObjDesc; ObjCfg = _originalDesc.ObjCfg; Terrain = _originalDesc.Terrain; Region = _originalDesc.Region; Elevation = _originalDesc.Elevation; if (map != null) { InitConnection(map, x, y); } UpdateCount++; }
public void Init() { int w = world.Map.Width; int h = world.Map.Height; var stats = new int[13]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { WmapTile tile = world.Map[x, y]; if (tile.Terrain != WmapTerrain.None) { stats[(int)tile.Terrain - 1]++; } } } foreach (var i in spawn) { WmapTerrain terrain = i.Key; int idx = (int)terrain - 1; int enemyCount = stats[idx] / i.Value.Item1; enemyMaxCounts[idx] = enemyCount; enemyCounts[idx] = 0; for (int j = 0; j < enemyCount; j++) { short objType = GetRandomObjType(i.Value.Item2); if (objType == 0) { continue; } enemyCounts[idx] += Spawn(XmlDatas.ObjectDescs[objType], terrain, w, h); if (enemyCounts[idx] >= enemyCount) { break; } } } }
private void EnsurePopulation() { RecalculateEnemyCount(); int[] state = new int[12]; int[] diff = new int[12]; int c = 0; for (var i = 0; i < state.Length; i++) { if (enemyCounts[i] > enemyMaxCounts[i] * 1.5) //Kill some { state[i] = 1; diff[i] = enemyCounts[i] - enemyMaxCounts[i]; c++; } else if (enemyCounts[i] < enemyMaxCounts[i] * 0.75) //Add some { state[i] = 2; diff[i] = enemyMaxCounts[i] - enemyCounts[i]; } else { state[i] = 0; } } foreach (var i in world.Enemies) //Kill { int idx = (int)i.Value.Terrain - 1; if (idx == -1 || state[idx] == 0 || i.Value.GetNearestEntity(10, true) != null || diff[idx] == 0) { continue; } if (state[idx] == 1) { world.LeaveWorld(i.Value); diff[idx]--; if (diff[idx] == 0) { c--; } } if (c == 0) { break; } } int w = world.Map.Width, h = world.Map.Height; for (int i = 0; i < state.Length; i++) //Add { if (state[i] != 2) { continue; } int x = diff[i]; WmapTerrain t = (WmapTerrain)(i + 1); for (int j = 0; j < x;) { ushort objType = GetRandomObjType(t); if (objType == 0) { continue; } j += HandleSpawn(GameServer.Manager.GameData.ObjectDescs[objType], t, w, h); } } RecalculateEnemyCount(); GC.Collect(); }
private int Spawn(ObjectDesc desc, WmapTerrain terrain, int w, int h) { Entity entity; int ret = 0; var pt = new IntPoint(); if (desc.Spawn != null) { var num = (int) GetNormal(rand, desc.Spawn.Mean, desc.Spawn.StdDev); if (num > desc.Spawn.Max) num = desc.Spawn.Max; else if (num < desc.Spawn.Min) num = desc.Spawn.Min; do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || !world.IsPassable(pt.X, pt.Y) || world.AnyPlayerNearby(pt.X, pt.Y)); for (int k = 0; k < num; k++) { entity = Entity.Resolve(world.Manager, desc.ObjectType); entity.Move( pt.X + (float) (rand.NextDouble()*2 - 1)*5, pt.Y + (float) (rand.NextDouble()*2 - 1)*5); (entity as Enemy).Terrain = terrain; world.EnterWorld(entity); ret++; } } else { do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); } while (world.Map[pt.X, pt.Y].Terrain != terrain || !world.IsPassable(pt.X, pt.Y) || world.AnyPlayerNearby(pt.X, pt.Y)); entity = Entity.Resolve(world.Manager, desc.ObjectType); entity.Move(pt.X, pt.Y); (entity as Enemy).Terrain = terrain; world.EnterWorld(entity); ret++; } return ret; }
void EnsurePopulation() { RecalculateEnemyCount(); int[] state = new int[12]; int[] diff = new int[12]; int c = 0; for (int i = 0; i < state.Length; i++) { if (enemyCounts[i] > enemyMaxCounts[i] * 0.9) //Kill some { state[i] = 1; diff[i] = enemyCounts[i] - enemyMaxCounts[i]; c++; } else if (enemyCounts[i] < enemyMaxCounts[i] * 0.25) //Add some { state[i] = 2; diff[i] = enemyMaxCounts[i] - enemyCounts[i]; } else { state[i] = 0; } } foreach (var i in world.Enemies) //Kill { int idx = (int)i.Value.Terrain - 1; float dist = 500; //Distance that enemies are removed if (idx == -1 || state[idx] == 0 || Behavior.GetNearestEntity(i.Value, ref dist, true) != null || diff[idx] == 0) { continue; } if (state[idx] == 1) { world.LeaveWorld(i.Value); diff[idx]--; if (diff[idx] == 0) { c--; } } if (c == 0) { break; } } int w = world.Map.Width, h = world.Map.Height; for (int i = 0; i < state.Length; i++) //Add { if (state[i] != 2) { continue; } int x = diff[i]; WmapTerrain t = (WmapTerrain)(i + 1); for (int j = 0; j < x;) { short objType = GetRandomObjType(spawn[t].Item2); if (objType == 0) { continue; } j += Spawn(XmlDatas.ObjectDescs[objType], t, w, h); } } RecalculateEnemyCount(); GC.Collect(); //We're actually using this shit? LOL! }