private int Spawn(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(_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++; } return(ret); } 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); }
public void SpawnEntity(string name, int x, int y) { Enemy entity = Entity.Resolve(_world.Manager, name) as Enemy; entity.Move(x, y); _world.EnterWorld(entity); }