public virtual void Tick(RealmTime time) { if (this is Projectile) { return; } if (interactive && Owner != null) { if (BehaviorBase.HasPlayerNearby(this) && !HasConditionEffect(ConditionEffects.Stasis)) { MovementBehavior.Tick(this, time); AttackBehavior.Tick(this, time); ReproduceBehavior.Tick(this, time); } foreach (var i in CondBehaviors) { if ((i.Condition & BehaviorCondition.Other) != 0 && i.ConditionMeet(this)) { i.Behave(BehaviorCondition.Other, this, time, null); } } posHistory[posIdx++] = new Position() { X = X, Y = Y }; ProcessConditionEffects(time); } }
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.Obstacles[pt.X, pt.Y] != 0 || BehaviorBase.HasPlayerNearby(world, 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; 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 void SpawnEvent(ISetPiece setpiece) { var pt = new IntPoint(); 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.Obstacles[pt.X, pt.Y] != 0 || BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y)); pt.X -= (setpiece.Size - 1) / 2; pt.Y -= (setpiece.Size - 1) / 2; setpiece.RenderSetPiece(world, pt); }