public override void Use(Entity entity, Item item) { base.Use(entity, item); var room = entity.GetComponent <RoomComponent>().Room; if (room == null) { return; } // Copy to array, because we are going to change the list in the loop var mobs = room.Tagged[Tags.Mob].ToArray(); foreach (var mob in mobs) { try { var m = (Mob)Activator.CreateInstance(mob.GetType()); entity.Area.Add(m); m.Center = mob.Center; if (!(MobRegistry.FindFor(m.GetType())?.NearWall ?? false)) { m.Center += Rnd.Vector(-8, 8); } } catch (Exception e) { Log.Error(e); } } }
private void SpawnWave(Entity entity) { var filter = CheckDistance(entity); MobRegistry.SetupForBiome(Run.Level.Biome.Id); var c = Rnd.Int(5, 11); for (var i = 0; i < c; i++) { Timer.Add(() => { var mob = MobRegistry.Generate(); entity.Area.Add(mob); var v = MobRegistry.FindFor(mob.GetType()); if (v?.NearWall ?? false) { mob.Center = Room.GetRandomFreeTileNearWall(filter) * 16; } else if (v?.AwayFromWall ?? false) { mob.Center = Room.GetRandomWallFreeTile(filter) * 16; } else { mob.Center = Room.GetRandomFreeTile(filter) * 16; } if (mob.TryGetComponent <ZAnimationComponent>(out var z)) { z.Animate(); } else if (mob.TryGetComponent <MobAnimationComponent>(out var m)) { m.Animate(); } var where = mob.Center; for (var j = 0; j < 8; j++) { var part = new ParticleEntity(Particles.Dust()); part.Position = where + Rnd.Vector(-8, 8); part.Particle.Scale = Rnd.Float(1f, 1.3f); part.Particle.Velocity = MathUtils.CreateVector(Rnd.AnglePI(), 40); Run.Level.Area.Add(part); part.Depth = 1; } Audio.PlaySfx("scroll"); }, (i) * 0.2f); } wave++; }
public override void Use(Entity entity, Item item) { if (!entity.TryGetComponent <RoomComponent>(out var r) || r.Room == null) { return; } var filter = CheckDistance(entity); MobRegistry.SetupForBiome(Run.Level.Biome.Id); for (var i = 0; i < Count; i++) { Timer.Add(() => { var mob = MobRegistry.Generate(); entity.Area.Add(mob); if (MobRegistry.FindFor(mob.GetType())?.NearWall ?? false) { mob.Center = r.Room.GetRandomFreeTileNearWall(filter) * 16; } else { mob.Center = r.Room.GetRandomFreeTile(filter) * 16; } var where = mob.Center; for (var j = 0; j < 8; j++) { var part = new ParticleEntity(Particles.Dust()); part.Position = where + Rnd.Vector(-8, 8); part.Particle.Scale = Rnd.Float(1f, 1.3f); part.Particle.Velocity = MathUtils.CreateVector(Rnd.AnglePI(), 40); Run.Level.Area.Add(part); part.Depth = 1; } Audio.PlaySfx("scroll"); }, (i - 1) * 0.2f); } }