Added battle log events for temporary effects
This commit is contained in:
parent
b89c443f13
commit
df9da97b8f
|
@ -224,12 +224,27 @@ module SpaceTac.Game {
|
|||
// Method called at the end of this ship turn
|
||||
endTurn(): void {
|
||||
// Decrement sticky effects duration
|
||||
this.temporary_effects = this.temporary_effects.filter((effect: TemporaryEffect): boolean => {
|
||||
if (effect.duration <= 1) {
|
||||
this.addBattleEvent(new EffectRemovedEvent(this, effect));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
this.temporary_effects.forEach((effect: TemporaryEffect) => {
|
||||
effect.duration -= 1;
|
||||
this.addBattleEvent(new EffectDurationChangedEvent(this, effect, effect.duration + 1));
|
||||
});
|
||||
this.temporary_effects = this.temporary_effects.filter((effect: TemporaryEffect): boolean => {
|
||||
return effect.duration > 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Add a temporary effect
|
||||
// A copy of the effect will be used
|
||||
addTemporaryEffect(effect: TemporaryEffect, log: boolean = true): void {
|
||||
this.temporary_effects.push(Tools.copyObject(effect));
|
||||
if (log) {
|
||||
this.addBattleEvent(new EffectAddedEvent(this, effect));
|
||||
}
|
||||
}
|
||||
|
||||
// Move toward a location
|
||||
|
|
|
@ -16,7 +16,7 @@ module SpaceTac.Game {
|
|||
}
|
||||
|
||||
applyOnShip(ship: Ship): boolean {
|
||||
ship.temporary_effects.push(Tools.copyObject(this));
|
||||
ship.addTemporaryEffect(this);
|
||||
this.singleApply(ship, true);
|
||||
return true;
|
||||
}
|
||||
|
|
17
src/scripts/game/events/EffectAddedEvent.ts
Normal file
17
src/scripts/game/events/EffectAddedEvent.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path="BaseLogEvent.ts"/>
|
||||
|
||||
module SpaceTac.Game {
|
||||
"use strict";
|
||||
|
||||
// Event logged when a TemporaryEffect is added to a ship
|
||||
export class EffectAddedEvent extends BaseLogEvent {
|
||||
// Pointer to the effect
|
||||
effect: TemporaryEffect;
|
||||
|
||||
constructor(ship: Ship, effect: TemporaryEffect) {
|
||||
super("effectadd", ship);
|
||||
|
||||
this.effect = effect;
|
||||
}
|
||||
}
|
||||
}
|
21
src/scripts/game/events/EffectDurationChangedEvent.ts
Normal file
21
src/scripts/game/events/EffectDurationChangedEvent.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/// <reference path="BaseLogEvent.ts"/>
|
||||
|
||||
module SpaceTac.Game {
|
||||
"use strict";
|
||||
|
||||
// Event logged when a TemporaryEffect is added to a ship
|
||||
export class EffectDurationChangedEvent extends BaseLogEvent {
|
||||
// Pointer to the effect
|
||||
effect: TemporaryEffect;
|
||||
|
||||
// Previous duration
|
||||
previous: number;
|
||||
|
||||
constructor(ship: Ship, effect: TemporaryEffect, previous: number) {
|
||||
super("effectadd", ship);
|
||||
|
||||
this.effect = effect;
|
||||
this.previous = previous;
|
||||
}
|
||||
}
|
||||
}
|
17
src/scripts/game/events/EffectRemovedEvent.ts
Normal file
17
src/scripts/game/events/EffectRemovedEvent.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path="BaseLogEvent.ts"/>
|
||||
|
||||
module SpaceTac.Game {
|
||||
"use strict";
|
||||
|
||||
// Event logged when a TemporaryEffect is removed from a ship
|
||||
export class EffectRemovedEvent extends BaseLogEvent {
|
||||
// Pointer to the effect
|
||||
effect: TemporaryEffect;
|
||||
|
||||
constructor(ship: Ship, effect: TemporaryEffect) {
|
||||
super("effectdel", ship);
|
||||
|
||||
this.effect = effect;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -123,6 +123,42 @@ module SpaceTac.Game {
|
|||
expect(battle.log.events.length).toBe(0);
|
||||
});
|
||||
|
||||
it("sets and logs temporary effects", function () {
|
||||
var ship = new Ship();
|
||||
var battle = new Battle(ship.fleet);
|
||||
|
||||
var effect = new TemporaryEffect("test", 2);
|
||||
|
||||
ship.addTemporaryEffect(effect);
|
||||
|
||||
expect(ship.temporary_effects).toEqual([effect]);
|
||||
expect(battle.log.events).toEqual([
|
||||
new EffectAddedEvent(ship, effect)
|
||||
]);
|
||||
|
||||
battle.log.clear();
|
||||
ship.endTurn();
|
||||
|
||||
expect(ship.temporary_effects).toEqual([new TemporaryEffect("test", 1)]);
|
||||
expect(battle.log.events).toEqual([
|
||||
new EffectDurationChangedEvent(ship, new TemporaryEffect("test", 1), 2)
|
||||
]);
|
||||
|
||||
battle.log.clear();
|
||||
ship.endTurn();
|
||||
|
||||
expect(ship.temporary_effects).toEqual([]);
|
||||
expect(battle.log.events).toEqual([
|
||||
new EffectRemovedEvent(ship, new TemporaryEffect("test", 1))
|
||||
]);
|
||||
|
||||
battle.log.clear();
|
||||
ship.endTurn();
|
||||
|
||||
expect(ship.temporary_effects).toEqual([]);
|
||||
expect(battle.log.events).toEqual([]);
|
||||
});
|
||||
|
||||
it("sets and logs death state", function () {
|
||||
var fleet = new Fleet();
|
||||
var battle = new Battle(fleet);
|
||||
|
|
Loading…
Reference in a new issue