2017-02-06 21:46:55 +00:00
|
|
|
/// <reference path="effects/BaseEffect.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-02-06 21:46:55 +00:00
|
|
|
/**
|
|
|
|
* Fake effect to capture apply requests
|
|
|
|
*/
|
|
|
|
class FakeEffect extends BaseEffect {
|
|
|
|
applied: Ship[] = []
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super("fake");
|
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
2017-02-06 21:46:55 +00:00
|
|
|
this.applied.push(ship);
|
2017-11-14 00:07:06 +00:00
|
|
|
return [];
|
2017-02-06 21:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getApplyCalls() {
|
|
|
|
let result = acopy(this.applied);
|
|
|
|
this.applied = [];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function newTestDrone(x: number, y: number, radius: number, owner: Ship): [Drone, FakeEffect] {
|
|
|
|
let drone = new Drone(owner);
|
|
|
|
drone.x = x;
|
|
|
|
drone.y = y;
|
|
|
|
drone.radius = radius;
|
|
|
|
let effect = new FakeEffect();
|
|
|
|
drone.effects.push(effect);
|
2017-11-14 00:07:06 +00:00
|
|
|
let battle = owner.getBattle();
|
|
|
|
if (battle) {
|
|
|
|
battle.addDrone(drone);
|
|
|
|
}
|
2017-02-06 21:46:55 +00:00
|
|
|
return [drone, effect];
|
|
|
|
}
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("Drone", test => {
|
|
|
|
test.case("applies effects on all ships inside the radius", check => {
|
2017-05-10 22:52:16 +00:00
|
|
|
let battle = new Battle();
|
|
|
|
let ship1 = new Ship(battle.fleets[0], "ship1");
|
2017-02-06 21:46:55 +00:00
|
|
|
ship1.setArenaPosition(0, 0);
|
2017-05-10 22:52:16 +00:00
|
|
|
let ship2 = new Ship(battle.fleets[0], "ship2");
|
2017-02-06 21:46:55 +00:00
|
|
|
ship2.setArenaPosition(5, 5);
|
2017-05-10 22:52:16 +00:00
|
|
|
let ship3 = new Ship(battle.fleets[0], "ship3");
|
2017-02-06 21:46:55 +00:00
|
|
|
ship3.setArenaPosition(10, 10);
|
2017-05-10 22:52:16 +00:00
|
|
|
let ship4 = new Ship(battle.fleets[0], "ship4");
|
|
|
|
ship4.setArenaPosition(0, 0);
|
|
|
|
ship4.setDead();
|
2017-02-06 21:46:55 +00:00
|
|
|
let [drone, effect] = newTestDrone(2, 2, 8, ship1);
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(effect.getApplyCalls(), []);
|
2017-02-06 21:46:55 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
drone.activate(battle);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(effect.getApplyCalls(), [ship1, ship2]);
|
2017-02-06 21:46:55 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("signals the need for destruction after its lifetime", check => {
|
2017-05-10 22:52:16 +00:00
|
|
|
let battle = new Battle();
|
|
|
|
let owner = new Ship(battle.fleets[0]);
|
2017-02-06 21:46:55 +00:00
|
|
|
let [drone, effect] = newTestDrone(0, 0, 5, owner);
|
2017-05-10 22:52:16 +00:00
|
|
|
drone.duration = 3;
|
2017-02-06 21:46:55 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let removeDrone = check.patch(battle, "removeDrone", null);
|
2017-02-08 18:54:02 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
drone.activate(battle);
|
|
|
|
check.equals(drone.duration, 2);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(removeDrone, 0);
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
drone.activate(battle);
|
|
|
|
check.equals(drone.duration, 1);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(removeDrone, 0);
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
drone.activate(battle);
|
|
|
|
check.equals(drone.duration, 0);
|
|
|
|
check.called(removeDrone, [[drone]]);
|
2017-02-06 21:46:55 +00:00
|
|
|
});
|
2017-02-15 21:15:31 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
test.case("builds diffs on activation", check => {
|
2017-02-15 21:15:31 +00:00
|
|
|
let battle = new Battle();
|
|
|
|
let ship = new Ship();
|
|
|
|
ship.fleet.setBattle(battle);
|
|
|
|
let other = new Ship();
|
|
|
|
let drone = new Drone(ship);
|
2017-11-14 00:07:06 +00:00
|
|
|
|
|
|
|
drone.duration = 2;
|
|
|
|
check.in("duration=2", check => {
|
|
|
|
check.equals(drone.getDiffs(battle, [ship, other]), [
|
|
|
|
new DroneAppliedDiff(drone, [ship, other]),
|
|
|
|
], "two ships in range");
|
|
|
|
check.equals(drone.getDiffs(battle, []), [
|
|
|
|
], "no ship in range");
|
|
|
|
});
|
|
|
|
|
|
|
|
drone.duration = 1;
|
|
|
|
check.in("duration=1", check => {
|
|
|
|
check.equals(drone.getDiffs(battle, [ship, other]), [
|
|
|
|
new DroneAppliedDiff(drone, [ship, other]),
|
|
|
|
new DroneDestroyedDiff(drone),
|
|
|
|
], "two ships in range");
|
|
|
|
check.equals(drone.getDiffs(battle, []), [
|
|
|
|
new DroneDestroyedDiff(drone),
|
|
|
|
], "no ship in range");
|
|
|
|
});
|
|
|
|
|
|
|
|
drone.duration = 0;
|
|
|
|
check.in("duration=0", check => {
|
|
|
|
check.equals(drone.getDiffs(battle, [ship, other]), [
|
|
|
|
new DroneDestroyedDiff(drone),
|
|
|
|
], "two ships in range");
|
|
|
|
check.equals(drone.getDiffs(battle, []), [
|
|
|
|
new DroneDestroyedDiff(drone),
|
|
|
|
], "no ship in range");
|
|
|
|
});
|
2017-02-15 21:15:31 +00:00
|
|
|
});
|
2017-05-10 17:48:28 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("builds a textual description", check => {
|
2017-05-10 17:48:28 +00:00
|
|
|
let drone = new Drone(new Ship());
|
|
|
|
drone.duration = 1;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(drone.getDescription(), "For 1 activation:\n• do nothing");
|
2017-05-10 17:48:28 +00:00
|
|
|
|
|
|
|
drone.duration = 3;
|
|
|
|
drone.effects = [
|
|
|
|
new DamageEffect(5),
|
2017-06-11 20:44:12 +00:00
|
|
|
new AttributeEffect("skill_quantum", 1)
|
2017-05-10 17:48:28 +00:00
|
|
|
]
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(drone.getDescription(), "For 3 activations:\n• do 5 damage\n• quantum skill +1");
|
2017-05-10 17:48:28 +00:00
|
|
|
});
|
2017-02-06 21:46:55 +00:00
|
|
|
});
|
|
|
|
}
|