Fixed events being broadcast after a battle end
This commit is contained in:
parent
c646b8722c
commit
9f170969ba
1
TODO.md
1
TODO.md
|
@ -36,7 +36,6 @@ Character sheet
|
||||||
Battle
|
Battle
|
||||||
------
|
------
|
||||||
|
|
||||||
* Fix numerous effects being displayed on ships at the end, behind outcome dialog
|
|
||||||
* Add a voluntary retreat option
|
* Add a voluntary retreat option
|
||||||
* Display effects description instead of attribute changes
|
* Display effects description instead of attribute changes
|
||||||
* Display radius for area effects (both on action hover, and while action is active)
|
* Display radius for area effects (both on action hover, and while action is active)
|
||||||
|
|
|
@ -86,5 +86,17 @@ module TS.SpaceTac {
|
||||||
}
|
}
|
||||||
checkEvent(result[16], playing, "ship_change", playing);
|
checkEvent(result[16], playing, "ship_change", playing);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stop accepting events once the battle is ended", function () {
|
||||||
|
let log = new BattleLog();
|
||||||
|
|
||||||
|
log.add(new ValueChangeEvent(new Ship(), new ShipValue("test"), 1));
|
||||||
|
log.add(new EndBattleEvent(new BattleOutcome(null)));
|
||||||
|
log.add(new ShipChangeEvent(new Ship(), new Ship()));
|
||||||
|
|
||||||
|
expect(log.events.length).toBe(2);
|
||||||
|
expect(log.events[0] instanceof ValueChangeEvent).toBe(true);
|
||||||
|
expect(log.events[1] instanceof EndBattleEvent).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,16 @@ module TS.SpaceTac {
|
||||||
// It also allows to register a callback to receive these events
|
// It also allows to register a callback to receive these events
|
||||||
export class BattleLog {
|
export class BattleLog {
|
||||||
// Full list of battle events
|
// Full list of battle events
|
||||||
events: BaseBattleEvent[];
|
events: BaseBattleEvent[]
|
||||||
|
|
||||||
// List of subscribers
|
// List of subscribers
|
||||||
private subscribers: LogSubscriber[];
|
private subscribers: LogSubscriber[]
|
||||||
|
|
||||||
// List of event codes to ignore
|
// List of event codes to ignore
|
||||||
private filters: string[];
|
private filters: string[]
|
||||||
|
|
||||||
|
// Indicator that the battle has ended
|
||||||
|
private ended = false
|
||||||
|
|
||||||
// Create an initially empty log
|
// Create an initially empty log
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -30,6 +33,7 @@ module TS.SpaceTac {
|
||||||
|
|
||||||
// Clear the stored events
|
// Clear the stored events
|
||||||
clear(): void {
|
clear(): void {
|
||||||
|
this.ended = false;
|
||||||
this.events = [];
|
this.events = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +41,12 @@ module TS.SpaceTac {
|
||||||
add(event: BaseBattleEvent): void {
|
add(event: BaseBattleEvent): void {
|
||||||
// Apply filters
|
// Apply filters
|
||||||
var filtered = false;
|
var filtered = false;
|
||||||
this.filters.forEach((code: string) => {
|
this.filters.forEach(code => {
|
||||||
if (event.code === code) {
|
if (event.code === code) {
|
||||||
filtered = true;
|
filtered = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (filtered) {
|
if (filtered || this.ended) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +55,10 @@ module TS.SpaceTac {
|
||||||
this.subscribers.forEach(subscriber => {
|
this.subscribers.forEach(subscriber => {
|
||||||
subscriber(event);
|
subscriber(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (event instanceof EndBattleEvent) {
|
||||||
|
this.ended = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out a type of event
|
// Filter out a type of event
|
||||||
|
|
|
@ -3,6 +3,7 @@ module TS.SpaceTac.Specs {
|
||||||
it("removes generated encounters that lose", function () {
|
it("removes generated encounters that lose", function () {
|
||||||
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
||||||
var fleet = new Fleet();
|
var fleet = new Fleet();
|
||||||
|
fleet.addShip();
|
||||||
location.encounter_random = new SkewedRandomGenerator([0]);
|
location.encounter_random = new SkewedRandomGenerator([0]);
|
||||||
var battle = location.enterLocation(fleet);
|
var battle = location.enterLocation(fleet);
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ module TS.SpaceTac.Specs {
|
||||||
it("leaves generated encounters that win", function () {
|
it("leaves generated encounters that win", function () {
|
||||||
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
||||||
var fleet = new Fleet();
|
var fleet = new Fleet();
|
||||||
|
fleet.addShip();
|
||||||
location.encounter_random = new SkewedRandomGenerator([0]);
|
location.encounter_random = new SkewedRandomGenerator([0]);
|
||||||
var battle = location.enterLocation(fleet);
|
var battle = location.enterLocation(fleet);
|
||||||
|
|
||||||
|
|
|
@ -86,10 +86,9 @@ module TS.SpaceTac {
|
||||||
var encounter = this.tryGenerateEncounter();
|
var encounter = this.tryGenerateEncounter();
|
||||||
if (encounter) {
|
if (encounter) {
|
||||||
var battle = new Battle(fleet, encounter);
|
var battle = new Battle(fleet, encounter);
|
||||||
battle.log.subscribe((event: BaseBattleEvent) => {
|
battle.log.subscribe(event => {
|
||||||
if (event.code === "endbattle") {
|
if (event instanceof EndBattleEvent) {
|
||||||
var endbattle = <EndBattleEvent>event;
|
if (!event.outcome.draw && event.outcome.winner !== encounter) {
|
||||||
if (!endbattle.outcome.draw && endbattle.outcome.winner !== encounter) {
|
|
||||||
// The encounter fleet lost, remove it
|
// The encounter fleet lost, remove it
|
||||||
this.encounter = null;
|
this.encounter = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,13 +150,6 @@ module TS.SpaceTac.UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leaving the view, we unbind the battle
|
|
||||||
shutdown() {
|
|
||||||
this.log_processor.destroy();
|
|
||||||
|
|
||||||
super.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display an animated "BATTLE" text in the center of the view
|
// Display an animated "BATTLE" text in the center of the view
|
||||||
displayFightMessage(): void {
|
displayFightMessage(): void {
|
||||||
var text = this.game.add.text(this.getMidWidth(), this.getMidHeight(), "BATTLE !",
|
var text = this.game.add.text(this.getMidWidth(), this.getMidHeight(), "BATTLE !",
|
||||||
|
|
|
@ -229,11 +229,6 @@ module TS.SpaceTac.UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the log processor
|
|
||||||
destroy() {
|
|
||||||
// TODO interrupt current processing or delay
|
|
||||||
}
|
|
||||||
|
|
||||||
// Playing ship changed
|
// Playing ship changed
|
||||||
private processShipChangeEvent(event: ShipChangeEvent): number {
|
private processShipChangeEvent(event: ShipChangeEvent): number {
|
||||||
this.view.arena.setShipPlaying(event.new_ship);
|
this.view.arena.setShipPlaying(event.new_ship);
|
||||||
|
@ -275,7 +270,6 @@ module TS.SpaceTac.UI {
|
||||||
// Battle ended (victory or defeat)
|
// Battle ended (victory or defeat)
|
||||||
private processEndBattleEvent(event: EndBattleEvent): number {
|
private processEndBattleEvent(event: EndBattleEvent): number {
|
||||||
this.view.endBattle();
|
this.view.endBattle();
|
||||||
this.destroy();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue