2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("EndTurnAction", test => {
|
|
|
|
test.case("can't be applied to non-playing ship", check => {
|
2017-11-14 00:07:06 +00:00
|
|
|
let battle = new Battle();
|
|
|
|
battle.fleets[0].addShip();
|
|
|
|
battle.fleets[0].addShip();
|
|
|
|
battle.throwInitiative();
|
|
|
|
battle.setPlayingShip(battle.play_order[0]);
|
2017-03-07 19:27:46 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
let action = new EndTurnAction();
|
2018-04-04 16:17:10 +00:00
|
|
|
check.equals(action.checkCannotBeApplied(battle.play_order[0]), ActionUnavailability.NO_SUCH_ACTION);
|
2018-02-08 15:16:03 +00:00
|
|
|
|
|
|
|
action = EndTurnAction.SINGLETON;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(action.checkCannotBeApplied(battle.play_order[0]), null);
|
2018-04-04 16:17:10 +00:00
|
|
|
check.equals(action.checkCannotBeApplied(battle.play_order[1]), ActionUnavailability.NOT_PLAYING);
|
2015-01-07 00:00:00 +00:00
|
|
|
});
|
|
|
|
|
2017-11-28 18:01:56 +00:00
|
|
|
test.case("changes active ship", check => {
|
2017-11-14 00:07:06 +00:00
|
|
|
let battle = TestTools.createBattle(2, 0);
|
|
|
|
|
|
|
|
TestTools.actionChain(check, battle, [
|
|
|
|
[battle.play_order[0], EndTurnAction.SINGLETON, undefined],
|
|
|
|
], [
|
|
|
|
check => {
|
|
|
|
check.equals(battle.play_index, 0, "play_index is 0");
|
|
|
|
check.same(battle.playing_ship, battle.play_order[0], "first ship is playing");
|
|
|
|
check.equals(battle.play_order[0].playing, true, "first ship is playing");
|
|
|
|
check.equals(battle.play_order[1].playing, false, "second ship is not playing");
|
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(battle.play_index, 1, "play_index is 1");
|
|
|
|
check.same(battle.playing_ship, battle.play_order[1], "second ship is playing");
|
|
|
|
check.equals(battle.play_order[0].playing, false, "first ship is not playing");
|
|
|
|
check.equals(battle.play_order[1].playing, true, "second ship is playing");
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.case("generates power for previous ship", check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
let battle = TestTools.createBattle(1, 1);
|
|
|
|
let [ship1, ship2] = battle.play_order;
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship1, 100, 0, 10);
|
|
|
|
let toggle = new ToggleAction("toggle", { power: 2 });
|
|
|
|
ship1.actions.addCustom(toggle);
|
2017-12-04 18:12:06 +00:00
|
|
|
ship1.setValue("power", 6);
|
2015-01-07 00:00:00 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
TestTools.actionChain(check, battle, [
|
2018-02-08 15:16:03 +00:00
|
|
|
[ship1, toggle, undefined],
|
|
|
|
[ship1, toggle, undefined],
|
|
|
|
[ship1, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship2, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship1, toggle, undefined],
|
|
|
|
[ship1, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship2, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship1, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship2, EndTurnAction.SINGLETON, undefined],
|
|
|
|
[ship1, toggle, undefined],
|
|
|
|
[ship1, EndTurnAction.SINGLETON, undefined],
|
2017-11-14 00:07:06 +00:00
|
|
|
], [
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship1.getValue("power"), 6, "power value");
|
|
|
|
check.same(battle.playing_ship, ship1);
|
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(ship1.getValue("power"), 4, "power value");
|
|
|
|
check.same(battle.playing_ship, ship1);
|
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(ship1.getValue("power"), 6, "power value");
|
|
|
|
check.same(battle.playing_ship, ship1);
|
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(ship1.getValue("power"), 10, "power value");
|
2017-12-04 18:12:06 +00:00
|
|
|
check.same(battle.playing_ship, ship2);
|
2017-11-14 00:07:06 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(ship1.getValue("power"), 10, "power value");
|
2017-12-04 18:12:06 +00:00
|
|
|
check.same(battle.playing_ship, ship1);
|
2017-11-14 00:07:06 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(ship1.getValue("power"), 8, "power value");
|
2017-12-04 18:12:06 +00:00
|
|
|
check.same(battle.playing_ship, ship1);
|
2017-11-14 00:07:06 +00:00
|
|
|
},
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship1.getValue("power"), 8, "power value");
|
|
|
|
check.same(battle.playing_ship, ship2);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship1.getValue("power"), 8, "power value");
|
|
|
|
check.same(battle.playing_ship, ship1);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(ship1.getValue("power"), 8, "power value");
|
2017-12-04 18:12:06 +00:00
|
|
|
check.same(battle.playing_ship, ship2);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(ship1.getValue("power"), 8, "power value");
|
2017-12-04 18:12:06 +00:00
|
|
|
check.same(battle.playing_ship, ship1);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship1.getValue("power"), 10, "power value");
|
|
|
|
check.same(battle.playing_ship, ship1);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
|
|
|
check => {
|
2017-12-04 18:12:06 +00:00
|
|
|
check.equals(ship1.getValue("power"), 10, "power value");
|
|
|
|
check.same(battle.playing_ship, ship2);
|
2017-11-29 00:36:07 +00:00
|
|
|
},
|
2017-11-14 00:07:06 +00:00
|
|
|
]);
|
2015-01-07 00:00:00 +00:00
|
|
|
});
|
2017-11-14 21:16:42 +00:00
|
|
|
|
|
|
|
test.case("cools down equipment for previous ship", check => {
|
|
|
|
let battle = TestTools.createBattle(1, 0);
|
|
|
|
let ship = battle.play_order[0];
|
|
|
|
|
|
|
|
let equ1 = TestTools.addWeapon(ship);
|
2018-02-08 15:16:03 +00:00
|
|
|
equ1.configureCooldown(1, 3);
|
|
|
|
let cd1 = ship.actions.getCooldown(equ1);
|
|
|
|
cd1.use();
|
|
|
|
|
2017-11-14 21:16:42 +00:00
|
|
|
let equ2 = TestTools.addWeapon(ship);
|
2018-02-08 15:16:03 +00:00
|
|
|
equ2.configureCooldown(1, 2);
|
|
|
|
let cd2 = ship.actions.getCooldown(equ2);
|
|
|
|
cd2.use();
|
|
|
|
|
2017-11-14 21:16:42 +00:00
|
|
|
let equ3 = TestTools.addWeapon(ship);
|
2018-02-08 15:16:03 +00:00
|
|
|
let cd3 = ship.actions.getCooldown(equ3);
|
|
|
|
cd3.use();
|
2017-11-14 21:16:42 +00:00
|
|
|
|
|
|
|
TestTools.actionChain(check, battle, [
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
], [
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(cd1.heat, 3, "equ1 heat");
|
|
|
|
check.equals(cd2.heat, 2, "equ2 heat");
|
|
|
|
check.equals(cd3.heat, 0, "equ3 heat");
|
2017-11-14 21:16:42 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(cd1.heat, 2, "equ1 heat");
|
|
|
|
check.equals(cd2.heat, 1, "equ2 heat");
|
|
|
|
check.equals(cd3.heat, 0, "equ3 heat");
|
2017-11-14 21:16:42 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(cd1.heat, 1, "equ1 heat");
|
|
|
|
check.equals(cd2.heat, 0, "equ2 heat");
|
|
|
|
check.equals(cd3.heat, 0, "equ3 heat");
|
2017-11-14 21:16:42 +00:00
|
|
|
},
|
|
|
|
check => {
|
2018-02-08 15:16:03 +00:00
|
|
|
check.equals(cd1.heat, 0, "equ1 heat");
|
|
|
|
check.equals(cd2.heat, 0, "equ2 heat");
|
|
|
|
check.equals(cd3.heat, 0, "equ3 heat");
|
2017-11-14 21:16:42 +00:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
2017-11-28 18:01:56 +00:00
|
|
|
|
|
|
|
test.case("fades sticky effects for previous ship", check => {
|
|
|
|
let battle = TestTools.createBattle(1, 0);
|
|
|
|
let ship = battle.play_order[0];
|
|
|
|
|
|
|
|
let effect1 = new BaseEffect("e1");
|
2018-03-26 15:30:43 +00:00
|
|
|
let effect2 = new StickyEffect(new AttributeLimitEffect("evasion", 7), 2);
|
2017-11-28 18:01:56 +00:00
|
|
|
|
|
|
|
ship.active_effects.add(effect1);
|
|
|
|
ship.active_effects.add(effect2);
|
|
|
|
effect2.base.getOnDiffs(ship, ship).forEach(effect => effect.apply(battle));
|
2018-03-29 22:57:53 +00:00
|
|
|
check.patch(battle, "getAreaEffects", (): [Ship, BaseEffect][] => [[ship, effect1]]);
|
2017-11-28 18:01:56 +00:00
|
|
|
|
|
|
|
TestTools.actionChain(check, battle, [
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
[ship, EndTurnAction.SINGLETON, Target.newFromShip(ship)],
|
|
|
|
], [
|
|
|
|
check => {
|
|
|
|
check.equals(ship.active_effects.count(), 2, "effect count");
|
|
|
|
check.contains(ship.active_effects.ids(), effect2.id, "sticky effect active");
|
|
|
|
check.equals((<StickyEffect>nn(ship.active_effects.get(effect2.id))).duration, 2, "duration sticky effect");
|
2018-03-26 15:30:43 +00:00
|
|
|
check.equals(ship.attributes.evasion.getMaximal(), 7, "max evasion");
|
2017-11-28 18:01:56 +00:00
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(ship.active_effects.count(), 2, "effect count");
|
|
|
|
check.contains(ship.active_effects.ids(), effect2.id, "sticky effect active");
|
|
|
|
check.equals((<StickyEffect>nn(ship.active_effects.get(effect2.id))).duration, 1, "duration sticky effect");
|
2018-03-26 15:30:43 +00:00
|
|
|
check.equals(ship.attributes.evasion.getMaximal(), 7, "max evasion");
|
2017-11-28 18:01:56 +00:00
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(ship.active_effects.count(), 1, "effect count");
|
|
|
|
check.notcontains(ship.active_effects.ids(), effect2.id, "sticky effect removed");
|
2018-03-26 15:30:43 +00:00
|
|
|
check.equals(ship.attributes.evasion.getMaximal(), Infinity, "max evasion");
|
2017-11-28 18:01:56 +00:00
|
|
|
},
|
|
|
|
check => {
|
|
|
|
check.equals(ship.active_effects.count(), 1, "effect count");
|
|
|
|
check.notcontains(ship.active_effects.ids(), effect2.id, "sticky effect removed");
|
2018-03-26 15:30:43 +00:00
|
|
|
check.equals(ship.attributes.evasion.getMaximal(), Infinity, "max evasion");
|
2017-11-28 18:01:56 +00:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
2015-01-07 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|