2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-05-25 23:09:29 +00:00
|
|
|
/**
|
|
|
|
* Statistics collection over a battle
|
|
|
|
*/
|
|
|
|
export class BattleStats {
|
|
|
|
stats: { [name: string]: [number, number] } = {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a value to the collector
|
|
|
|
*/
|
|
|
|
addStat(name: string, value: number, attacker: boolean) {
|
|
|
|
if (!this.stats[name]) {
|
|
|
|
this.stats[name] = [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attacker) {
|
|
|
|
this.stats[name] = [this.stats[name][0] + value, this.stats[name][1]];
|
|
|
|
} else {
|
|
|
|
this.stats[name] = [this.stats[name][0], this.stats[name][1] + value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get important stats
|
|
|
|
*/
|
|
|
|
getImportant(maxcount: number): { name: string, attacker: number, defender: number }[] {
|
|
|
|
// TODO Sort by importance
|
|
|
|
let result: { name: string, attacker: number, defender: number }[] = [];
|
|
|
|
iteritems(this.stats, (name, [attacker, defender]) => {
|
|
|
|
if (result.length < maxcount) {
|
|
|
|
result.push({ name: name, attacker: Math.round(attacker), defender: Math.round(defender) });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-29 23:15:32 +00:00
|
|
|
* Process a battle log
|
2017-05-25 23:09:29 +00:00
|
|
|
*/
|
2017-09-14 22:24:53 +00:00
|
|
|
processLog(log: BattleLog, attacker: Fleet, clear = false) {
|
|
|
|
if (clear) {
|
|
|
|
this.stats = {};
|
|
|
|
}
|
2017-05-29 23:15:32 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
let n = log.count();
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
let diff = log.get(i);
|
|
|
|
if (diff instanceof BaseBattleShipDiff) {
|
|
|
|
let diff_ship = diff.ship_id;
|
|
|
|
let attacker_ship = any(attacker.ships, ship => ship.is(diff_ship));
|
|
|
|
if (diff instanceof ShipDamageDiff) {
|
|
|
|
this.addStat("Damage dealt", diff.hull + diff.shield, !attacker_ship);
|
|
|
|
} else if (diff instanceof ShipMoveDiff) {
|
|
|
|
this.addStat("Move distance (km)", diff.getDistance(), attacker_ship);
|
|
|
|
} else if (diff instanceof DroneDeployedDiff) {
|
|
|
|
this.addStat("Drones deployed", 1, attacker_ship);
|
|
|
|
}
|
2017-05-25 23:09:29 +00:00
|
|
|
}
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
2017-05-25 23:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|