82 lines
3.6 KiB
TypeScript
82 lines
3.6 KiB
TypeScript
module TK.SpaceTac.Specs {
|
|
testing("DeployDroneAction", test => {
|
|
test.case("stores useful information", check => {
|
|
let ship = new Ship();
|
|
let action = new DeployDroneAction("testdrone");
|
|
ship.actions.addCustom(action);
|
|
|
|
check.equals(action.code, "testdrone");
|
|
check.equals(action.getVerb(ship), "Deploy");
|
|
|
|
ship.actions.toggle(action, true);
|
|
check.equals(action.getVerb(ship), "Recall");
|
|
});
|
|
|
|
test.case("provides a default target", check => {
|
|
let ship = new Ship();
|
|
let action = new DeployDroneAction("testdrone", undefined, { drone_radius: 50 });
|
|
ship.actions.addCustom(action);
|
|
|
|
check.equals(action.getDefaultTarget(ship), Target.newFromLocation(45, 0));
|
|
|
|
ship.actions.toggle(action, true);
|
|
|
|
check.equals(action.getDefaultTarget(ship), Target.newFromShip(ship));
|
|
});
|
|
|
|
test.case("allows to deploy in range", check => {
|
|
let ship = new Ship();
|
|
ship.setArenaPosition(0, 0);
|
|
let action = new DeployDroneAction("testdrone", { power: 0 }, { deploy_distance: 8 });
|
|
ship.actions.addCustom(action);
|
|
|
|
check.equals(action.checkTarget(ship, new Target(8, 0, null)), true, "deploy");
|
|
check.equals(action.checkTarget(ship, new Target(12, 0, null)), false, "too far");
|
|
check.equals(action.checkTarget(ship, Target.newFromShip(ship)), false, "activate on self");
|
|
|
|
let other = new Ship();
|
|
other.setArenaPosition(8, 0);
|
|
check.equals(action.checkTarget(ship, Target.newFromShip(other)), false, "activate on other");
|
|
|
|
ship.actions.toggle(action, true);
|
|
|
|
check.equals(action.checkTarget(ship, new Target(8, 0, null)), false, "already activated");
|
|
check.equals(action.checkTarget(ship, Target.newFromShip(ship)), true, "recall");
|
|
check.equals(action.checkTarget(ship, Target.newFromShip(other)), false, "recall other");
|
|
});
|
|
|
|
test.case("deploys a new drone", check => {
|
|
let battle = TestTools.createBattle();
|
|
let ship = battle.play_order[0];
|
|
ship.setArenaPosition(0, 0);
|
|
TestTools.setShipModel(ship, 100, 0, 3);
|
|
|
|
let action = new DeployDroneAction("testdrone", { power: 2, filter: ActionTargettingFilter.ALLIES_BUT_SELF },
|
|
{ deploy_distance: 8, drone_radius: 4, drone_effects: [new DamageEffect(50)] });
|
|
ship.actions.addCustom(action);
|
|
|
|
TestTools.actionChain(check, battle, [
|
|
[ship, action, new Target(5, 0)],
|
|
], [
|
|
check => {
|
|
check.equals(ship.getValue("power"), 3, "power=3");
|
|
check.equals(battle.drones.count(), 0, "drones=0");
|
|
},
|
|
check => {
|
|
check.equals(ship.getValue("power"), 1, "power=1");
|
|
check.equals(battle.drones.count(), 1, "drones=1");
|
|
|
|
let drone = battle.drones.list()[0];
|
|
check.equals(drone.code, "testdrone");
|
|
check.same(drone.owner, ship.id);
|
|
check.equals(drone.x, 5);
|
|
check.equals(drone.y, 0);
|
|
check.equals(drone.radius, 4);
|
|
check.equals(drone.filter, ActionTargettingFilter.ALLIES_BUT_SELF);
|
|
compare_effects(check, drone.effects, [new DamageEffect(50)]);
|
|
}
|
|
])
|
|
});
|
|
});
|
|
}
|