1
0
Fork 0

Fixed inverted battle stats

This commit is contained in:
Michaël Lemaire 2018-04-16 20:12:51 +02:00
parent d7a1c0d1b6
commit 9bd274ec45
3 changed files with 14 additions and 14 deletions

View file

@ -25,17 +25,17 @@ module TK.SpaceTac.Specs {
stats.processLog(battle.log, battle.fleets[0]); stats.processLog(battle.log, battle.fleets[0]);
check.equals(stats.stats, {}); check.equals(stats.stats, {});
battle.log.add(new ShipDamageDiff(attacker, 1, 3, 2)); battle.log.add(new ShipDamageDiff(defender, 1, 3, 2));
stats.processLog(battle.log, battle.fleets[0], true); stats.processLog(battle.log, battle.fleets[0], true);
check.equals(stats.stats, { "Damage to hull": [0, 1], "Damage shielded": [0, 3], "Damage evaded": [0, 2] }); check.equals(stats.stats, { "Damage taken": [0, 1], "Damage shielded": [0, 3], "Damage evaded": [0, 2] });
battle.log.add(new ShipDamageDiff(defender, 2, 1, 3)); battle.log.add(new ShipDamageDiff(attacker, 2, 1, 3));
stats.processLog(battle.log, battle.fleets[0], true); stats.processLog(battle.log, battle.fleets[0], true);
check.equals(stats.stats, { "Damage to hull": [2, 1], "Damage shielded": [1, 3], "Damage evaded": [3, 2] }); check.equals(stats.stats, { "Damage taken": [2, 1], "Damage shielded": [1, 3], "Damage evaded": [3, 2] });
battle.log.add(new ShipDamageDiff(attacker, 1, 1, 1)); battle.log.add(new ShipDamageDiff(defender, 1, 1, 1));
stats.processLog(battle.log, battle.fleets[0], true); stats.processLog(battle.log, battle.fleets[0], true);
check.equals(stats.stats, { "Damage to hull": [2, 2], "Damage shielded": [1, 4], "Damage evaded": [3, 3] }); check.equals(stats.stats, { "Damage taken": [2, 2], "Damage shielded": [1, 4], "Damage evaded": [3, 3] });
}) })
test.case("collects distance moved", check => { test.case("collects distance moved", check => {

View file

@ -37,7 +37,7 @@ module TK.SpaceTac {
/** /**
* Process a battle log * Process a battle log
*/ */
processLog(log: BattleLog, attacker: Fleet, clear = false) { processLog(log: BattleLog, attacker: Fleet, clear = true) {
if (clear) { if (clear) {
this.stats = {}; this.stats = {};
} }
@ -49,9 +49,9 @@ module TK.SpaceTac {
let diff_ship = diff.ship_id; let diff_ship = diff.ship_id;
let attacker_ship = any(attacker.ships, ship => ship.is(diff_ship)); let attacker_ship = any(attacker.ships, ship => ship.is(diff_ship));
if (diff instanceof ShipDamageDiff) { if (diff instanceof ShipDamageDiff) {
this.addStat("Damage evaded", diff.evaded, !attacker_ship); this.addStat("Damage evaded", diff.evaded, attacker_ship);
this.addStat("Damage shielded", diff.shield, !attacker_ship); this.addStat("Damage shielded", diff.shield, attacker_ship);
this.addStat("Damage to hull", diff.hull, !attacker_ship); this.addStat("Damage taken", diff.hull, attacker_ship);
} else if (diff instanceof ShipMoveDiff) { } else if (diff instanceof ShipMoveDiff) {
this.addStat("Move distance (km)", diff.getDistance(), attacker_ship); this.addStat("Move distance (km)", diff.getDistance(), attacker_ship);
} else if (diff instanceof DroneDeployedDiff) { } else if (diff instanceof DroneDeployedDiff) {

View file

@ -53,7 +53,7 @@ module TK.SpaceTac.UI.Specs {
battle.setPlayingShip(battle.play_order[0]); battle.setPlayingShip(battle.play_order[0]);
list.refresh(false); list.refresh(false);
check.in("started", check => { check.in("started", check => {
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-18, 962), "first ship position"); check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position"); check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
}); });
@ -61,7 +61,7 @@ module TK.SpaceTac.UI.Specs {
list.refresh(false); list.refresh(false);
check.in("end turn", check => { check.in("end turn", check => {
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(2, 843), "first ship position"); check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(2, 843), "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(-18, 962), "second ship position"); check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(-14, 962), "second ship position");
}); });
ship = battle.fleets[1].addShip(); ship = battle.fleets[1].addShip();
@ -71,7 +71,7 @@ module TK.SpaceTac.UI.Specs {
list.setShipsFromBattle(battle, false); list.setShipsFromBattle(battle, false);
check.in("third ship added", check => { check.in("third ship added", check => {
check.equals(list.items.length, 3, "item count"); check.equals(list.items.length, 3, "item count");
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-18, 962), "first ship position"); check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position"); check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
check.equals(nn(list.findItem(battle.play_order[2])).position, new Phaser.Point(2, 744), "third ship position"); check.equals(nn(list.findItem(battle.play_order[2])).position, new Phaser.Point(2, 744), "third ship position");
}); });
@ -81,7 +81,7 @@ module TK.SpaceTac.UI.Specs {
list.refresh(false); list.refresh(false);
check.in("ship dead", check => { check.in("ship dead", check => {
check.equals(list.items.length, 3, "item count"); check.equals(list.items.length, 3, "item count");
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-18, 962), "first ship position"); check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
check.equals(nn(list.findItem(dead)).position, new Phaser.Point(200, 843), "dead ship position"); check.equals(nn(list.findItem(dead)).position, new Phaser.Point(200, 843), "dead ship position");
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position"); check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
}); });