1
0
Fork 0
spacetac/src/core/actions/MoveAction.spec.ts

156 lines
6.8 KiB
TypeScript
Raw Normal View History

module TK.SpaceTac.Specs {
2017-10-26 21:47:13 +00:00
testing("MoveAction", test => {
test.case("checks movement against remaining AP", check => {
var ship = new Ship();
var battle = new Battle(ship.fleet);
2017-10-25 22:45:53 +00:00
TestTools.setShipPlaying(battle, ship);
ship.setValue("power", 6);
2014-12-31 00:00:00 +00:00
ship.arena_x = 0;
ship.arena_y = 0;
var engine = new Equipment();
var action = new MoveAction(engine, 10);
2014-12-31 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
check.equals(action.getDistanceByActionPoint(ship), 10);
var result = action.checkTarget(ship, Target.newFromLocation(0, 20));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(0, 20));
2014-12-31 00:00:00 +00:00
result = action.checkTarget(ship, Target.newFromLocation(0, 80));
2017-10-26 21:47:13 +00:00
check.nears(nn(result).y, 59.9);
2014-12-31 00:00:00 +00:00
ship.setValue("power", 0);
result = action.checkTarget(ship, Target.newFromLocation(0, 80));
2017-10-26 21:47:13 +00:00
check.equals(result, null);
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");
2017-03-09 17:11:00 +00:00
var action = new MoveAction(new Equipment());
2014-12-31 00:00:00 +00:00
var result = action.checkTarget(ship1, Target.newFromShip(ship1));
2017-10-26 21:47:13 +00:00
check.equals(result, null);
2014-12-31 00:00:00 +00:00
result = action.checkTarget(ship1, Target.newFromShip(ship2));
2017-10-26 21:47:13 +00:00
check.equals(result, null);
2014-12-31 00:00:00 +00:00
});
2015-01-07 00:00:00 +00:00
test.case("applies and reverts", check => {
let battle = TestTools.createBattle();
let ship = battle.play_order[0];
ship.setArenaPosition(500, 600)
TestTools.setShipAP(ship, 20);
ship.setValue("power", 5);
let engine = new Equipment(SlotType.Engine);
let action = new MoveAction(engine, 1);
engine.action = action;
ship.addSlot(SlotType.Engine).attach(engine);
TestTools.actionChain(check, battle, [
[ship, action, Target.newFromLocation(510, 605)],
], [
check => {
check.equals(ship.arena_x, 500, "ship X");
check.equals(ship.arena_y, 600, "ship Y");
check.equals(ship.getValue("power"), 5, "power");
},
check => {
check.nears(ship.arena_x, 504.382693, 5, "ship X");
check.nears(ship.arena_y, 602.191346, 5, "ship Y");
check.equals(ship.getValue("power"), 0, "power");
}
]);
2015-01-07 00:00:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("can't move too much near another ship", check => {
var battle = TestTools.createBattle(1, 1);
var ship = battle.fleets[0].ships[0];
var enemy = battle.fleets[1].ships[0];
TestTools.setShipAP(ship, 100);
ship.setArenaPosition(500, 500);
enemy.setArenaPosition(1000, 500);
2018-01-31 18:19:50 +00:00
var action = new MoveAction(new Equipment(), 1000, 200);
var result = action.checkLocationTarget(ship, Target.newFromLocation(700, 500));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(700, 500));
result = action.checkLocationTarget(ship, Target.newFromLocation(800, 500));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(800, 500));
result = action.checkLocationTarget(ship, Target.newFromLocation(900, 500));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(800, 500));
result = action.checkLocationTarget(ship, Target.newFromLocation(1000, 500));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(800, 500));
result = action.checkLocationTarget(ship, Target.newFromLocation(1200, 500));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(1200, 500));
});
2017-05-29 18:12:57 +00:00
2017-10-26 21:47:13 +00:00
test.case("exclusion radius is applied correctly over two ships", check => {
2017-05-29 18:12:57 +00:00
var battle = TestTools.createBattle(1, 2);
var ship = battle.fleets[0].ships[0];
var enemy1 = battle.fleets[1].ships[0];
var enemy2 = battle.fleets[1].ships[1];
TestTools.setShipAP(ship, 100);
enemy1.setArenaPosition(0, 800);
enemy2.setArenaPosition(0, 1000);
2017-05-29 18:12:57 +00:00
2018-01-31 18:19:50 +00:00
var action = new MoveAction(new Equipment(), 1000, 150);
2017-05-29 18:12:57 +00:00
var result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1100));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(0, 650));
2017-05-29 18:12:57 +00:00
});
2017-07-31 22:49:00 +00:00
2017-10-26 21:47:13 +00:00
test.case("exclusion radius does not make the ship go back", check => {
2017-07-31 22:49:00 +00:00
var battle = TestTools.createBattle(1, 2);
var ship = battle.fleets[0].ships[0];
var enemy1 = battle.fleets[1].ships[0];
var enemy2 = battle.fleets[1].ships[1];
TestTools.setShipAP(ship, 100);
enemy1.setArenaPosition(0, 500);
enemy2.setArenaPosition(0, 800);
2017-07-31 22:49:00 +00:00
2018-01-31 18:19:50 +00:00
var action = new MoveAction(new Equipment(), 1000, 600);
2017-07-31 22:49:00 +00:00
let result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1000));
2017-10-26 21:47:13 +00:00
check.equals(result, null);
result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1400));
2017-10-26 21:47:13 +00:00
check.equals(result, Target.newFromLocation(0, 1400));
2017-07-31 22:49:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("applies ship maneuvrability to determine distance per power point", check => {
let ship = new Ship();
let action = new MoveAction(new Equipment(), 100, undefined, 60);
TestTools.setAttribute(ship, "maneuvrability", 0);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 40);
TestTools.setAttribute(ship, "maneuvrability", 1);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 60);
TestTools.setAttribute(ship, "maneuvrability", 2);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 70);
TestTools.setAttribute(ship, "maneuvrability", 10);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 90);
action = new MoveAction(new Equipment(), 100, undefined, 0);
TestTools.setAttribute(ship, "maneuvrability", 0);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 100);
TestTools.setAttribute(ship, "maneuvrability", 10);
2017-10-26 21:47:13 +00:00
check.nears(action.getDistanceByActionPoint(ship), 100);
});
2017-10-26 21:47:13 +00:00
test.case("builds a textual description", check => {
let action = new MoveAction(new Equipment(), 58, 0, 0);
2017-10-26 21:47:13 +00:00
check.equals(action.getEffectsDescription(), "Move: 58km per power point");
action = new MoveAction(new Equipment(), 58, 12, 0);
2017-10-26 21:47:13 +00:00
check.equals(action.getEffectsDescription(), "Move: 58km per power point (safety: 12km)");
action = new MoveAction(new Equipment(), 58, 12, 80);
2017-10-26 21:47:13 +00:00
check.equals(action.getEffectsDescription(), "Move: 12-58km per power point (safety: 12km)");
});
2014-12-31 00:00:00 +00:00
});
2015-01-07 00:00:00 +00:00
}