2017-05-25 23:09:29 +00:00
|
|
|
module TS.SpaceTac {
|
|
|
|
/**
|
|
|
|
* 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-05-29 23:15:32 +00:00
|
|
|
processLog(log: BattleLog, attacker: Fleet) {
|
|
|
|
this.stats = {};
|
|
|
|
|
|
|
|
log.events.forEach(event => {
|
2017-05-25 23:09:29 +00:00
|
|
|
if (event instanceof DamageEvent) {
|
|
|
|
this.addStat("Damage dealt", event.hull + event.shield, event.ship.fleet !== attacker);
|
|
|
|
} else if (event instanceof MoveEvent) {
|
2017-05-30 16:24:55 +00:00
|
|
|
this.addStat("Move distance (km)", event.getDistance(), event.ship.fleet === attacker);
|
2017-05-25 23:09:29 +00:00
|
|
|
} else if (event instanceof DroneDeployedEvent) {
|
|
|
|
this.addStat("Drones deployed", 1, event.ship.fleet === attacker);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|