1
0
Fork 0

Added battle stat "Power used"

This commit is contained in:
Michaël Lemaire 2017-09-14 23:56:28 +02:00
parent 44426745d6
commit a8032eea8b
7 changed files with 32 additions and 9 deletions

View file

@ -71,5 +71,22 @@ module TS.SpaceTac.Specs {
stats.processLog(battle.log, battle.fleets[0]);
expect(stats.stats).toEqual({ "Drones deployed": [1, 1] });
})
it("collects power usage", function () {
let stats = new BattleStats();
let battle = new Battle();
let attacker = battle.fleets[0].addShip();
let defender = battle.fleets[1].addShip();
stats.processLog(battle.log, battle.fleets[0]);
expect(stats.stats).toEqual({});
battle.log.add(new ActionAppliedEvent(attacker, new BaseAction("nop", "nop", false), null, 4));
stats.processLog(battle.log, battle.fleets[0]);
expect(stats.stats).toEqual({ "Power used": [4, 0] });
battle.log.add(new ActionAppliedEvent(defender, new BaseAction("nop", "nop", false), null, 2));
stats.processLog(battle.log, battle.fleets[0]);
expect(stats.stats).toEqual({ "Power used": [4, 2] });
})
})
}

View file

@ -41,7 +41,9 @@ module TS.SpaceTac {
this.stats = {};
log.events.forEach(event => {
if (event instanceof DamageEvent) {
if (event instanceof ActionAppliedEvent) {
this.addStat("Power used", event.power, event.ship.fleet === attacker);
} else if (event instanceof DamageEvent) {
this.addStat("Damage dealt", event.hull + event.shield, event.ship.fleet !== attacker);
} else if (event instanceof MoveEvent) {
this.addStat("Move distance (km)", event.getDistance(), event.ship.fleet === attacker);

View file

@ -248,11 +248,11 @@ module TS.SpaceTac.Specs {
expect(action.activated).toBe(false);
expect(battle.log.events).toEqual([
new ActionAppliedEvent(ship, action, null),
new ActionAppliedEvent(ship, action, null, 0),
new ToggleEvent(ship, action, true),
new ActiveEffectsEvent(ship, [], [], [new AttributeEffect("power_capacity", 1)]),
new ValueChangeEvent(ship, new ShipAttribute("power capacity", 1), 1),
new ActionAppliedEvent(ship, action, null),
new ActionAppliedEvent(ship, action, null, 0),
new ToggleEvent(ship, action, false),
new ActiveEffectsEvent(ship, [], [], []),
new ValueChangeEvent(ship, new ShipAttribute("power capacity", 0), -1),

View file

@ -146,7 +146,7 @@ module TS.SpaceTac {
let battle = ship.getBattle();
if (battle) {
battle.log.add(new ActionAppliedEvent(ship, this, checked_target));
battle.log.add(new ActionAppliedEvent(ship, this, checked_target, cost));
}
this.customApply(ship, checked_target);

View file

@ -50,7 +50,7 @@ module TS.SpaceTac {
expect(drone.radius).toEqual(4);
expect(drone.effects).toEqual([new DamageEffect(50)]);
expect(battle.log.events).toEqual([
new ActionAppliedEvent(ship, action, Target.newFromLocation(5, 0)),
new ActionAppliedEvent(ship, action, Target.newFromLocation(5, 0), 2),
new DroneDeployedEvent(drone)
]);

View file

@ -61,7 +61,7 @@ module TS.SpaceTac.Equipments {
equipment.action.apply(ship, target);
checkHP(50, 10, 50, 10, 50, 10);
expect(battle.log.events.length).toBe(5);
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, Target.newFromLocation(1, 0)));
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, Target.newFromLocation(1, 0), 4));
expect(battle.log.events[1]).toEqual(new FireEvent(ship, equipment, Target.newFromLocation(1, 0)));
expect(battle.log.events[2]).toEqual(new DamageEvent(ship, 0, 20));
expect(battle.log.events[3]).toEqual(new DamageEvent(enemy1, 0, 20));
@ -76,7 +76,7 @@ module TS.SpaceTac.Equipments {
equipment.action.apply(ship, target);
checkHP(50, 10, 40, 0, 40, 0);
expect(battle.log.events.length).toBe(4);
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, target));
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, target, 4));
expect(battle.log.events[1]).toEqual(new FireEvent(ship, equipment, target));
expect(battle.log.events[2]).toEqual(new DamageEvent(enemy1, 10, 10));
expect(battle.log.events[3]).toEqual(new DamageEvent(enemy2, 10, 10));
@ -90,7 +90,7 @@ module TS.SpaceTac.Equipments {
equipment.action.apply(ship, target);
checkHP(50, 10, 40, 0, 40, 0);
expect(battle.log.events.length).toBe(2);
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, target));
expect(battle.log.events[0]).toEqual(new ActionAppliedEvent(ship, equipment.action, target, 4));
expect(battle.log.events[1]).toEqual(new FireEvent(ship, equipment, target));
});
});

View file

@ -8,10 +8,14 @@ module TS.SpaceTac {
// Action applied
action: BaseAction
constructor(ship: Ship, action: BaseAction, target: Target | null) {
// Power usage
power: number
constructor(ship: Ship, action: BaseAction, target: Target | null, power: number) {
super("action", ship, target);
this.action = action;
this.power = power;
}
}
}