2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("WeaponEffect", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupBattleview(test);
|
2017-10-26 21:47:13 +00:00
|
|
|
let clock = test.clock();
|
2017-02-21 22:38:31 +00:00
|
|
|
|
2017-07-23 17:31:46 +00:00
|
|
|
function checkEmitters(step: string, expected: number) {
|
2017-10-26 21:47:13 +00:00
|
|
|
test.check.same(testgame.view.arena.layer_weapon_effects.children.length, expected, `${step} - layer children`);
|
|
|
|
test.check.same(keys(testgame.view.game.particles.emitters).length, expected, `${step} - registered emitters`);
|
2017-07-23 17:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fastForward(milliseconds: number) {
|
2017-10-26 21:47:13 +00:00
|
|
|
clock.forward(milliseconds);
|
2017-07-23 17:31:46 +00:00
|
|
|
testgame.ui.updateLogic(milliseconds);
|
|
|
|
}
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("displays shield hit effect", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-07-23 17:31:46 +00:00
|
|
|
battleview.timer = new Timer();
|
|
|
|
|
2017-06-22 22:37:38 +00:00
|
|
|
let effect = new WeaponEffect(battleview.arena, new Ship(), new Target(0, 0), new Equipment());
|
2017-05-09 20:41:35 +00:00
|
|
|
effect.shieldImpactEffect({ x: 10, y: 10 }, { x: 20, y: 15 }, 1000, 3000, true);
|
2017-02-13 19:31:45 +00:00
|
|
|
|
|
|
|
let layer = battleview.arena.layer_weapon_effects;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(layer.children.length, 2);
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(layer.children[0] instanceof Phaser.Image, true);
|
|
|
|
check.nears(layer.children[0].rotation, -2.677945044588987, 10);
|
|
|
|
check.containing(layer.children[0].position, { x: 20, y: 15 });
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(layer.children[1] instanceof Phaser.Particles.Arcade.Emitter, true);
|
2017-02-13 19:31:45 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("displays gatling gun effect", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-07-23 17:31:46 +00:00
|
|
|
battleview.timer = new Timer();
|
|
|
|
|
2017-10-03 20:56:25 +00:00
|
|
|
let ship = nn(battleview.battle.playing_ship);
|
|
|
|
let effect = new WeaponEffect(battleview.arena, new Ship(), Target.newFromShip(ship), new Equipment());
|
|
|
|
effect.gunEffect();
|
|
|
|
|
|
|
|
let layer = battleview.arena.layer_weapon_effects;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(layer.children.length, 1);
|
|
|
|
check.equals(layer.children[0] instanceof Phaser.Particles.Arcade.Emitter, true);
|
2017-10-03 20:56:25 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("displays shield and hull effect on impacted ships", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-10-03 20:56:25 +00:00
|
|
|
battleview.timer = new Timer();
|
|
|
|
|
2017-06-22 22:37:38 +00:00
|
|
|
let ship = nn(battleview.battle.playing_ship);
|
2017-02-13 19:31:45 +00:00
|
|
|
ship.setArenaPosition(50, 30);
|
|
|
|
|
2017-10-03 20:56:25 +00:00
|
|
|
let weapon = new Equipment();
|
|
|
|
weapon.action = new TriggerAction(weapon, [new DamageEffect()], 1, 500);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.patch(weapon.action, "getImpactedShips", () => [ship]);
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let dest = new Ship();
|
|
|
|
let effect = new WeaponEffect(battleview.arena, dest, Target.newFromShip(dest), weapon);
|
|
|
|
check.patch(effect, "getEffectForWeapon", () => (() => 100));
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let mock_shield_impact = check.patch(effect, "shieldImpactEffect", null);
|
|
|
|
let mock_hull_impact = check.patch(effect, "hullImpactEffect", null);
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
ship.setValue("shield", 0);
|
2017-10-03 20:56:25 +00:00
|
|
|
effect.start();
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(mock_shield_impact, 0);
|
|
|
|
check.called(mock_hull_impact, [
|
2017-11-14 00:07:06 +00:00
|
|
|
[Target.newFromShip(dest), ship.location, 40, 400]
|
2017-10-29 21:08:55 +00:00
|
|
|
]);
|
2017-02-13 19:31:45 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
ship.setValue("shield", 10);
|
2017-10-03 20:56:25 +00:00
|
|
|
effect.start();
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(mock_shield_impact, [
|
2017-11-14 00:07:06 +00:00
|
|
|
[Target.newFromShip(dest), ship.location, 40, 800, false]
|
2017-10-29 21:08:55 +00:00
|
|
|
]);
|
|
|
|
check.called(mock_hull_impact, 0);
|
2017-02-13 19:31:45 +00:00
|
|
|
});
|
2017-07-23 17:31:46 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("removes particle emitters when done", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-07-23 17:31:46 +00:00
|
|
|
battleview.timer = new Timer();
|
|
|
|
|
|
|
|
let effect = new WeaponEffect(battleview.arena, new Ship(), Target.newFromLocation(50, 50), new Equipment());
|
|
|
|
|
|
|
|
effect.gunEffect();
|
2017-10-03 20:56:25 +00:00
|
|
|
checkEmitters("gun effect started", 1);
|
2017-07-23 17:31:46 +00:00
|
|
|
fastForward(6000);
|
|
|
|
checkEmitters("gun effect ended", 0);
|
|
|
|
|
|
|
|
effect.hullImpactEffect({ x: 0, y: 0 }, { x: 50, y: 50 }, 1000, 2000);
|
|
|
|
checkEmitters("hull effect started", 1);
|
|
|
|
fastForward(8500);
|
|
|
|
checkEmitters("hull effect ended", 0);
|
|
|
|
});
|
2017-10-03 20:56:25 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("adds a laser effect", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-10-03 20:56:25 +00:00
|
|
|
battleview.timer = new Timer();
|
|
|
|
|
|
|
|
let effect = new WeaponEffect(battleview.arena, new Ship(), Target.newFromLocation(31, 49), new Equipment());
|
|
|
|
|
|
|
|
let result = effect.angularLaser({ x: 20, y: 30 }, 300, Math.PI / 4, -Math.PI / 2, 5);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, 200);
|
2017-10-03 20:56:25 +00:00
|
|
|
|
|
|
|
let layer = battleview.arena.layer_weapon_effects;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(layer.children.length, 1);
|
|
|
|
check.same(layer.children[0] instanceof Phaser.Image, true, "is image");
|
2017-10-03 20:56:25 +00:00
|
|
|
let image = <Phaser.Image>layer.children[0];
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(image.name, "battle-effects-laser");
|
|
|
|
//check.equals(image.width, 300);
|
|
|
|
check.equals(image.x, 20);
|
|
|
|
check.equals(image.y, 30);
|
|
|
|
check.nears(image.rotation, Math.PI / 4);
|
2017-10-03 20:56:25 +00:00
|
|
|
|
|
|
|
let values = battleview.animations.simulate(image, "rotation", 4, result);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.nears(values[0], Math.PI / 4);
|
|
|
|
check.nears(values[1], 0);
|
|
|
|
check.nears(values[2], -Math.PI / 4);
|
|
|
|
check.nears(values[3], -Math.PI / 2);
|
2017-10-03 20:56:25 +00:00
|
|
|
});
|
2017-02-13 19:31:45 +00:00
|
|
|
});
|
|
|
|
}
|