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

121 lines
5.2 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
2017-10-26 21:47:13 +00:00
testing("TriggerAction", test => {
test.case("constructs correctly", check => {
2017-02-15 22:34:27 +00:00
let equipment = new Equipment(SlotType.Weapon, "testweapon");
2017-10-03 16:11:30 +00:00
let action = new TriggerAction(equipment, [], 4, 30, 10);
2017-02-15 22:34:27 +00:00
2017-10-26 21:47:13 +00:00
check.equals(action.code, "fire-testweapon");
check.equals(action.name, "Fire");
check.same(action.equipment, equipment);
2017-10-03 16:11:30 +00:00
})
2017-02-15 22:34:27 +00:00
2017-10-26 21:47:13 +00:00
test.case("applies effects to alive ships in blast radius", check => {
2017-02-15 22:34:27 +00:00
let fleet = new Fleet();
let ship = new Ship(fleet, "ship");
2017-02-15 22:34:27 +00:00
let equipment = new Equipment(SlotType.Weapon, "testweapon");
let effect = new BaseEffect("testeffect");
let mock_apply = spyOn(effect, "applyOnShip").and.stub();
2017-10-03 16:11:30 +00:00
let action = new TriggerAction(equipment, [effect], 5, 100, 10);
2017-02-15 22:34:27 +00:00
TestTools.setShipAP(ship, 10);
let ship1 = new Ship(fleet, "ship1");
2017-02-15 22:34:27 +00:00
ship1.setArenaPosition(65, 72);
let ship2 = new Ship(fleet, "ship2");
2017-02-15 22:34:27 +00:00
ship2.setArenaPosition(45, 48);
let ship3 = new Ship(fleet, "ship3");
2017-02-15 22:34:27 +00:00
ship3.setArenaPosition(45, 48);
ship3.alive = false;
let battle = new Battle(fleet);
battle.play_order = [ship, ship1, ship2, ship3];
2017-10-25 22:45:53 +00:00
TestTools.setShipPlaying(battle, ship);
2017-02-15 22:34:27 +00:00
fleet.setBattle(battle);
action.apply(ship, Target.newFromLocation(50, 50));
2017-02-15 22:34:27 +00:00
expect(mock_apply).toHaveBeenCalledTimes(1);
expect(mock_apply).toHaveBeenCalledWith(ship2, ship);
2017-10-03 16:11:30 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("transforms ship target in location target, when the weapon has blast radius", check => {
let ship1 = new Ship();
ship1.setArenaPosition(50, 10);
let ship2 = new Ship();
ship2.setArenaPosition(150, 10);
let weapon = TestTools.addWeapon(ship1, 1, 0, 100, 30);
2017-09-19 15:09:06 +00:00
let action = nn(weapon.action);
2017-09-19 15:09:06 +00:00
let target = action.checkTarget(ship1, new Target(150, 10));
2017-10-26 21:47:13 +00:00
check.equals(target, new Target(150, 10));
2017-09-19 15:09:06 +00:00
target = action.checkTarget(ship1, Target.newFromShip(ship2));
2017-10-26 21:47:13 +00:00
check.equals(target, new Target(150, 10));
ship1.setArenaPosition(30, 10);
2017-09-19 15:09:06 +00:00
target = action.checkTarget(ship1, Target.newFromShip(ship2));
2017-10-26 21:47:13 +00:00
check.equals(target, new Target(130, 10));
ship1.setArenaPosition(0, 10);
2017-09-19 15:09:06 +00:00
target = action.checkTarget(ship1, Target.newFromShip(ship2));
2017-10-26 21:47:13 +00:00
check.equals(target, new Target(100, 10));
2017-10-03 16:11:30 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("lists impacted ships", check => {
2017-10-03 16:11:30 +00:00
let ship1 = new Ship(null, "S1");
ship1.setArenaPosition(10, 50);
let ship2 = new Ship(null, "S2");
ship2.setArenaPosition(40, 60);
let ship3 = new Ship(null, "S3");
ship3.setArenaPosition(0, 30);
let ships = [ship1, ship2, ship3];
let action = new TriggerAction(new Equipment(), [], 1, 50);
2017-10-26 21:47:13 +00:00
check.equals(action.filterImpactedShips({ x: 0, y: 0 }, Target.newFromShip(ship2), ships), [ship2]);
check.equals(action.filterImpactedShips({ x: 0, y: 0 }, Target.newFromLocation(10, 50), ships), []);
2017-10-03 16:11:30 +00:00
action = new TriggerAction(new Equipment(), [], 1, 50, 40);
2017-10-26 21:47:13 +00:00
check.equals(action.filterImpactedShips({ x: 0, y: 0 }, Target.newFromLocation(20, 20), ships), [ship1, ship3]);
2017-10-03 16:11:30 +00:00
action = new TriggerAction(new Equipment(), [], 1, 100, 0, 30);
2017-10-26 21:47:13 +00:00
check.equals(action.filterImpactedShips({ x: 0, y: 51 }, Target.newFromLocation(30, 50), ships), [ship1, ship2]);
2017-10-03 16:11:30 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("guesses targetting mode", check => {
2017-10-03 16:11:30 +00:00
let ship = new Ship();
let equ = new Equipment();
let action = new TriggerAction(equ, []);
2017-10-26 21:47:13 +00:00
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SELF_CONFIRM, "self");
2017-10-03 16:11:30 +00:00
action = new TriggerAction(equ, [], 1, 50);
2017-10-26 21:47:13 +00:00
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SHIP, "ship");
2017-10-03 16:11:30 +00:00
action = new TriggerAction(equ, [], 1, 50, 20);
2017-10-26 21:47:13 +00:00
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SPACE, "blast");
2017-10-03 16:11:30 +00:00
action = new TriggerAction(equ, [], 1, 0, 20);
2017-10-26 21:47:13 +00:00
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SURROUNDINGS, "surroundings");
2017-10-03 16:11:30 +00:00
action = new TriggerAction(equ, [], 1, 50, 0, 15);
2017-10-26 21:47:13 +00:00
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SPACE, "angle");
2017-10-03 16:11:30 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("rotates toward the target", check => {
let ship = new Ship();
let weapon = TestTools.addWeapon(ship, 1, 0, 100, 30);
2017-09-19 15:09:06 +00:00
let action = nn(weapon.action);
spyOn(action, "checkTarget").and.callFake((ship: Ship, target: Target) => target);
2017-10-26 21:47:13 +00:00
check.equals(ship.arena_angle, 0);
2017-09-19 15:09:06 +00:00
let result = action.apply(ship, Target.newFromLocation(10, 20));
2017-10-26 21:47:13 +00:00
check.equals(result, true);
check.nears(ship.arena_angle, 1.107, 3);
2017-09-19 15:09:06 +00:00
result = action.apply(ship, Target.newFromShip(ship));
2017-10-26 21:47:13 +00:00
check.equals(result, true);
check.nears(ship.arena_angle, 1.107, 3);
2017-10-03 16:11:30 +00:00
})
2017-02-15 22:34:27 +00:00
});
}