public override void Fire(GameState state, Queries queries) { // Splash damage var q = new Queries.NearestUnit { SearchFrom = Position, LaneKey = LaneKey, MaxDistance = SplashRadius }; var a = queries.GetNearestUnitTuples(q, s => s.Side != Side); var spawns = new List <SpawnEvent>(); F.Loop(value => { var dist = value.First; var unit = value.Second; var ratio = 1.0f - dist / SplashRadius; unit.Health -= ratio * Damage; }, a); // Explosion effect spawns.Add(new SpawnEvent(Position, ObjectType.DecalExplosion)); spawns.Add(new SpawnEvent(Position, ObjectType.LightExplosion)); spawns.Add(new SpawnEvent(Position, ObjectType.ParticleExplosionSmoke)); spawns.Add(new SpawnEvent(Position, ObjectType.ParticleExplosionFire)); // Spawn all the things F.Loop(spawn => { Factory.Spawn(spawn, state); }, spawns); }
private void _checkForCapturingSoldiers() { var laneWidth = Map.GetLaneWidth(); var q = new Queries.NearestUnit { SearchFrom = State.Position, MaxDistance = laneWidth, LaneKey = State.LaneKey, }; var capDist = BalanceConsts.ControlPointCaptureDistance; var ul = new Vector2(laneWidth * -0.5f, -capDist) + State.Position; var rect = new Rect(ul, new Vector2(laneWidth, capDist * 2f)); var tuples = Game.Queries.GetNearestUnitTuples(q, s => s.UnitType == UnitType.Soldier); var soldiers = F.Map(t => t.Second, tuples); var hasEnemy = soldiers.Any(s => s.Side == Side.Enemy && rect.Contains(s.Position)); var hasPlayer = soldiers.Any(s => s.Side == Side.Player && rect.Contains(s.Position)); if (hasPlayer ^ hasEnemy) { var newSide = hasEnemy ? Side.Enemy : Side.Player; if (State.Side != newSide) { var sound = newSide == Side.Player ? SoundType.Capture : SoundType.LoseCapture; Game.PushEvent(new Events.PlaySoundEvent(sound)); State.Side = newSide; ControlPointGlow.ChangeSide(newSide); } } }
public void LookupsTest() { var x = 50.0f; var r = PhysicsConsts.SoldierRadius * 2; var posA = new Vector2(x, 0); var posB = new Vector2(x, r); var posC = new Vector2(x, r * 2.0f); var unitA = new SoldierState { Side = Side.Player, Id = "0", LaneKey = "0", Position = posA }; var unitB = new SoldierState { Side = Side.Enemy, Id = "1", LaneKey = "0", Position = posB }; var unitC = new SoldierState { Side = Side.Enemy, Id = "2", LaneKey = "0", Position = posC }; var a = new GameState(Difficulty.Easy); a.Soldiers = new List <SoldierState>(new[] { unitA, unitB, unitC }); Game.LoadFromState(a); var lookups = Game.Queries; Func <BaseUnitState, bool> enemyFilter = v => v.Id != unitA.Id && v.Side != unitA.Side; Func <BaseUnitState, bool> anyFilter = v => true; var closestEnemyQuery = new Queries.NearestUnit { LaneKey = "0", MaxDistance = 200, PreferredId = null, SearchFrom = unitA.Position }; var preferredEnemyQuery = new Queries.NearestUnit { LaneKey = "0", MaxDistance = 200, PreferredId = "2", SearchFrom = unitA.Position }; var nonexistentEnemyQuery = new Queries.NearestUnit { LaneKey = "0", MaxDistance = 0, PreferredId = null, SearchFrom = unitA.Position }; var closesetEnemy = lookups.GetNearestUnit(closestEnemyQuery, enemyFilter); var preferredEnemy = lookups.GetNearestUnit(preferredEnemyQuery, enemyFilter); var nonexistentEnemy = lookups.GetNearestUnit(nonexistentEnemyQuery, enemyFilter); var self = lookups.GetNearestUnit(closestEnemyQuery, anyFilter); Assert.AreEqual(closesetEnemy.Id, "1"); Assert.AreEqual(preferredEnemy.Id, "2"); Assert.AreEqual(self.Id, "0"); Assert.AreEqual(nonexistentEnemy, null); }