Fixed sticky effects not being removed at end of battle
This commit is contained in:
parent
22c9112b80
commit
3fb2cf8e31
1
TODO
1
TODO
|
@ -1,3 +1,4 @@
|
|||
* Drones of dead ships are never destroyed
|
||||
* UI: Use a common component class, and a layer abstraction
|
||||
* Character sheet: add initial character creation
|
||||
* Character sheet: disable interaction during battle (except for loot screen)
|
||||
|
|
|
@ -138,17 +138,13 @@ module TS.SpaceTac {
|
|||
// Apply experience
|
||||
this.outcome.grantExperience(this.fleets);
|
||||
|
||||
// Wear down equipment
|
||||
iforeach(this.iships(), ship => {
|
||||
ship.listEquipment().forEach(equipment => {
|
||||
equipment.addWear(this.turn);
|
||||
});
|
||||
});
|
||||
|
||||
// Broadcast
|
||||
if (log && this.log) {
|
||||
this.log.add(new EndBattleEvent(this.outcome));
|
||||
}
|
||||
|
||||
// Apply to all ships
|
||||
iforeach(this.iships(), ship => ship.endBattle(this.turn));
|
||||
}
|
||||
|
||||
// Checks end battle conditions, returns true if the battle ended
|
||||
|
|
|
@ -460,5 +460,29 @@ module TS.SpaceTac.Specs {
|
|||
expect(ship.getAttribute("skill_energy")).toBe(1);
|
||||
expect(ship.getAttribute("skill_gravity")).toBe(14);
|
||||
});
|
||||
|
||||
it("restores as new at the end of battle", function () {
|
||||
let ship = new Ship();
|
||||
TestTools.setShipHP(ship, 10, 20);
|
||||
TestTools.setShipAP(ship, 5, 0);
|
||||
ship.addDamage(5, 5);
|
||||
ship.addStickyEffect(new StickyEffect(new DamageEffect(10), 8));
|
||||
ship.addStickyEffect(new StickyEffect(new AttributeLimitEffect("power_capacity", 3), 12));
|
||||
ship.updateAttributes();
|
||||
|
||||
expect(ship.getValue("hull")).toEqual(5);
|
||||
expect(ship.getValue("shield")).toEqual(15);
|
||||
expect(ship.getValue("power")).toEqual(3);
|
||||
expect(ship.sticky_effects.length).toEqual(2);
|
||||
expect(ship.getAttribute("power_capacity")).toEqual(3);
|
||||
|
||||
ship.endBattle(1);
|
||||
|
||||
expect(ship.getValue("hull")).toEqual(10);
|
||||
expect(ship.getValue("shield")).toEqual(20);
|
||||
expect(ship.getValue("power")).toEqual(5);
|
||||
expect(ship.sticky_effects.length).toEqual(0);
|
||||
expect(ship.getAttribute("power_capacity")).toEqual(5);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -321,14 +321,30 @@ module TS.SpaceTac {
|
|||
}
|
||||
}
|
||||
|
||||
// Method called at the start of battle
|
||||
/**
|
||||
* Method called at the start of battle
|
||||
*/
|
||||
startBattle() {
|
||||
this.alive = true;
|
||||
this.sticky_effects = [];
|
||||
this.updateAttributes();
|
||||
this.restoreHealth();
|
||||
this.initializeActionPoints();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called at the end of battle
|
||||
*/
|
||||
endBattle(turncount: number) {
|
||||
// Restore as pristine
|
||||
this.startBattle();
|
||||
|
||||
// Wear down equipment
|
||||
this.listEquipment().forEach(equipment => {
|
||||
equipment.addWear(turncount);
|
||||
});
|
||||
}
|
||||
|
||||
// Method called at the start of this ship turn
|
||||
startTurn(): void {
|
||||
if (this.playing) {
|
||||
|
|
|
@ -72,6 +72,10 @@ module TS.SpaceTac.UI {
|
|||
* Process a single event
|
||||
*/
|
||||
processBattleEvent(event: BaseLogEvent) {
|
||||
if (!this.subscription) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.delayed) {
|
||||
this.queue.push(event);
|
||||
return;
|
||||
|
@ -111,6 +115,7 @@ module TS.SpaceTac.UI {
|
|||
if (this.subscription) {
|
||||
this.log.unsubscribe(this.subscription);
|
||||
this.subscription = null;
|
||||
this.queue = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,6 +200,7 @@ module TS.SpaceTac.UI {
|
|||
// Battle ended (victory or defeat)
|
||||
private processEndBattleEvent(event: EndBattleEvent): void {
|
||||
this.view.endBattle();
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
// Sticky effect on ship added, changed or removed
|
||||
|
|
Loading…
Reference in a new issue