2017-11-14 00:07:06 +00:00
|
|
|
module TK.SpaceTac.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("MoveAction", test => {
|
2018-07-10 14:43:05 +00:00
|
|
|
test.case("checks target is on the grid", check => {
|
|
|
|
let ship = new Ship();
|
|
|
|
let battle = new Battle(ship.fleet);
|
2018-07-09 10:28:18 +00:00
|
|
|
battle.grid = new PixelGrid();
|
2017-10-25 22:45:53 +00:00
|
|
|
TestTools.setShipPlaying(battle, ship);
|
2018-07-10 14:43:05 +00:00
|
|
|
TestTools.setShipModel(ship, 1, 0, 1);
|
|
|
|
let action = new MoveAction("Engine", { distance_per_power: 1 });
|
2018-02-08 15:16:03 +00:00
|
|
|
ship.actions.addCustom(action);
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2018-07-10 14:43:05 +00:00
|
|
|
let result = action.checkTarget(ship, Target.newFromLocation(0, 20));
|
2018-07-09 10:28:18 +00:00
|
|
|
check.equals(result, true);
|
2018-07-10 14:43:05 +00:00
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(0, 5.5));
|
|
|
|
check.equals(result, false);
|
|
|
|
result = action.checkTarget(ship, Target.newFromShip(ship));
|
2018-07-09 10:28:18 +00:00
|
|
|
check.equals(result, false);
|
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(0, 0));
|
|
|
|
check.equals(result, false);
|
2014-12-31 00:00:00 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("forbids targetting a ship", check => {
|
2014-12-31 00:00:00 +00:00
|
|
|
var ship1 = new Ship(null, "Test1");
|
|
|
|
var ship2 = new Ship(null, "Test2");
|
2018-02-08 15:16:03 +00:00
|
|
|
var action = new MoveAction();
|
|
|
|
ship1.actions.addCustom(action);
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
var result = action.checkTarget(ship1, Target.newFromShip(ship1));
|
2018-07-09 13:33:37 +00:00
|
|
|
check.equals(result, false);
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
result = action.checkTarget(ship1, Target.newFromShip(ship2));
|
2018-07-09 13:33:37 +00:00
|
|
|
check.equals(result, false);
|
2014-12-31 00:00:00 +00:00
|
|
|
});
|
2015-01-07 00:00:00 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
test.case("applies and reverts", check => {
|
|
|
|
let battle = TestTools.createBattle();
|
|
|
|
let ship = battle.play_order[0];
|
2018-07-09 10:28:18 +00:00
|
|
|
ship.setArenaPosition(500, 600);
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship, 100, 0, 20);
|
2017-11-14 00:07:06 +00:00
|
|
|
ship.setValue("power", 5);
|
|
|
|
|
2018-07-09 10:28:18 +00:00
|
|
|
let action = new MoveAction("Engine", { distance_per_power: 4 });
|
2018-02-08 15:16:03 +00:00
|
|
|
ship.actions.addCustom(action);
|
2017-11-14 00:07:06 +00:00
|
|
|
|
|
|
|
TestTools.actionChain(check, battle, [
|
2017-12-04 18:12:06 +00:00
|
|
|
[ship, action, Target.newFromLocation(510, 605)],
|
2017-11-14 00:07:06 +00:00
|
|
|
], [
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship.arena_x, 500, "ship X");
|
|
|
|
check.equals(ship.arena_y, 600, "ship Y");
|
2017-11-14 00:07:06 +00:00
|
|
|
check.equals(ship.getValue("power"), 5, "power");
|
|
|
|
},
|
|
|
|
check => {
|
2018-07-09 10:28:18 +00:00
|
|
|
check.equals(ship.arena_x, 510, "ship X");
|
|
|
|
check.equals(ship.arena_y, 605, "ship Y");
|
|
|
|
check.equals(ship.getValue("power"), 2, "power");
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
|
|
|
]);
|
2015-01-07 00:00:00 +00:00
|
|
|
});
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("can't move too much near another ship", check => {
|
2015-04-21 20:14:17 +00:00
|
|
|
var battle = TestTools.createBattle(1, 1);
|
|
|
|
var ship = battle.fleets[0].ships[0];
|
|
|
|
var enemy = battle.fleets[1].ships[0];
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship, 100, 0, 100);
|
2017-08-17 17:51:22 +00:00
|
|
|
ship.setArenaPosition(500, 500);
|
|
|
|
enemy.setArenaPosition(1000, 500);
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-10 14:23:32 +00:00
|
|
|
var action = new MoveAction("Engine", { distance_per_power: 1000 });
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-12 14:16:39 +00:00
|
|
|
var result = action.checkTarget(ship, Target.newFromLocation(700, 500));
|
2018-07-13 14:52:59 +00:00
|
|
|
check.equals(result, true, "700");
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-12 14:16:39 +00:00
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(800, 500));
|
2018-07-13 14:52:59 +00:00
|
|
|
check.equals(result, true, "800");
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-13 14:52:59 +00:00
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(950, 500));
|
|
|
|
check.equals(result, false, "950");
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-12 14:16:39 +00:00
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(1000, 500));
|
2018-07-13 14:52:59 +00:00
|
|
|
check.equals(result, false, "1000");
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2018-07-12 14:16:39 +00:00
|
|
|
result = action.checkTarget(ship, Target.newFromLocation(1200, 500));
|
2018-07-13 14:52:59 +00:00
|
|
|
check.equals(result, true, "1200");
|
2017-07-31 22:49:00 +00:00
|
|
|
});
|
2017-08-17 22:53:21 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("builds a textual description", check => {
|
2018-07-09 14:04:40 +00:00
|
|
|
let action = new MoveAction("Engine", { distance_per_power: 58 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(action.getEffectsDescription(), "Move: 58km per power point");
|
2017-08-17 22:53:21 +00:00
|
|
|
});
|
2018-04-04 16:17:10 +00:00
|
|
|
|
|
|
|
test.case("can't be used while in vigilance", check => {
|
|
|
|
let ship = new Ship();
|
|
|
|
TestTools.setShipModel(ship, 10, 10, 10);
|
|
|
|
let vigilance = ship.actions.addCustom(new VigilanceAction("Vigilance"));
|
|
|
|
let action = ship.actions.addCustom(new MoveAction("Engine"));
|
|
|
|
|
|
|
|
check.equals(action.checkCannotBeApplied(ship), null);
|
|
|
|
ship.actions.toggle(vigilance, true);
|
|
|
|
check.equals(action.checkCannotBeApplied(ship), ActionUnavailability.VIGILANCE);
|
|
|
|
});
|
2014-12-31 00:00:00 +00:00
|
|
|
});
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|