From 58334da31a4bfcc29bcba936f12772b358cbdc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 20 Dec 2017 22:21:12 +0100 Subject: [PATCH] Fixed cooldown not resetting the usage counter --- TODO.md | 2 +- src/core/actions/BaseAction.spec.ts | 40 +++++++++++++++++++++++-- src/core/diffs/ShipCooldownDiff.spec.ts | 9 ++++-- src/core/diffs/ShipCooldownDiff.ts | 6 ++++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index c7e590d..876d7ad 100644 --- a/TODO.md +++ b/TODO.md @@ -41,7 +41,6 @@ Character sheet Battle ------ -* Investigate cooldown not resetting properly the usage count * Add a voluntary retreat option * Add scroll buttons when there are too many actions * Toggle bar/text display in power section of action bar @@ -65,6 +64,7 @@ Battle Ships models and equipments --------------------------- +* Smooth the price depreciation in battles, it's too high when first using equipments * Add permanent effects and actions to ship models * Add critical hit/miss (or indicate lucky/unlucky throws) * Add damage over time effect (tricky to make intuitive) diff --git a/src/core/actions/BaseAction.spec.ts b/src/core/actions/BaseAction.spec.ts index 2af336b..9574f0a 100644 --- a/src/core/actions/BaseAction.spec.ts +++ b/src/core/actions/BaseAction.spec.ts @@ -1,6 +1,42 @@ module TK.SpaceTac.Specs { testing("BaseAction", test => { - test.case("check if equipment can be used with remaining AP", check => { + test.case("may be applied and reverted", check => { + let battle = TestTools.createBattle(); + let ship = nn(battle.playing_ship); + TestTools.setShipAP(ship, 10, 4); + let equipment = TestTools.addWeapon(ship, 0, 3, 100, 50); + let action = nn(equipment.action); + action.cooldown.configure(2, 1); + + TestTools.actionChain(check, battle, [ + [ship, action, Target.newFromLocation(0, 0)], + [ship, action, Target.newFromLocation(0, 0)], + [ship, EndTurnAction.SINGLETON, undefined], + ], [ + check => { + check.equals(ship.getValue("power"), 10, "power"); + check.equals(action.cooldown.uses, 0, "uses"); + check.equals(action.cooldown.heat, 0, "heat"); + }, + check => { + check.equals(ship.getValue("power"), 7, "power"); + check.equals(action.cooldown.uses, 1, "uses"); + check.equals(action.cooldown.heat, 0, "heat"); + }, + check => { + check.equals(ship.getValue("power"), 4, "power"); + check.equals(action.cooldown.uses, 2, "uses"); + check.equals(action.cooldown.heat, 1, "heat"); + }, + check => { + check.equals(ship.getValue("power"), 8, "power"); + check.equals(action.cooldown.uses, 0, "uses"); + check.equals(action.cooldown.heat, 0, "heat"); + }, + ]); + }) + + test.case("checks if equipment can be used with remaining AP", check => { var equipment = new Equipment(SlotType.Hull); var action = new BaseAction("test", equipment); check.patch(action, "getActionPointsUsage", () => 3); @@ -25,7 +61,7 @@ module TK.SpaceTac.Specs { check.equals(action.checkCannotBeApplied(ship), "not enough power"); }) - test.case("check if equipment can be used with overheat", check => { + test.case("checks if equipment can be used with overheat", check => { let equipment = new Equipment(); let action = new BaseAction("test", equipment); let ship = new Ship(); diff --git a/src/core/diffs/ShipCooldownDiff.spec.ts b/src/core/diffs/ShipCooldownDiff.spec.ts index 36ee6ec..9f3213f 100644 --- a/src/core/diffs/ShipCooldownDiff.spec.ts +++ b/src/core/diffs/ShipCooldownDiff.spec.ts @@ -12,13 +12,16 @@ module TK.SpaceTac.Specs { new ShipCooldownDiff(ship, weapon, 2), ], [ check => { - check.equals(weapon.cooldown.heat, 3, "in cooldown for 3 turns"); + check.equals(weapon.cooldown.heat, 3, "heat"); + check.equals(weapon.cooldown.uses, 1, "uses"); }, check => { - check.equals(weapon.cooldown.heat, 2, "in cooldown for 2 turns"); + check.equals(weapon.cooldown.heat, 2, "heat"); + check.equals(weapon.cooldown.uses, 1, "uses"); }, check => { - check.equals(weapon.cooldown.heat, 0, "not in cooldown"); + check.equals(weapon.cooldown.heat, 0, "heat"); + check.equals(weapon.cooldown.uses, 0, "uses"); }, ]); }); diff --git a/src/core/diffs/ShipCooldownDiff.ts b/src/core/diffs/ShipCooldownDiff.ts index 2ab8573..4268130 100644 --- a/src/core/diffs/ShipCooldownDiff.ts +++ b/src/core/diffs/ShipCooldownDiff.ts @@ -22,6 +22,9 @@ module TK.SpaceTac { let equipment = ship.getEquipment(this.equipment); if (equipment) { equipment.cooldown.heat -= this.heat; + if (equipment.cooldown.heat == 0) { + equipment.cooldown.uses = 0; + } } else { console.error("Cannot apply diff, equipment not found", this); } @@ -30,6 +33,9 @@ module TK.SpaceTac { revertOnShip(ship: Ship, battle: Battle) { let equipment = ship.getEquipment(this.equipment); if (equipment) { + if (equipment.cooldown.heat == 0) { + equipment.cooldown.uses = equipment.cooldown.overheat; + } equipment.cooldown.heat += this.heat; } else { console.error("Cannot revert diff, equipment not found", this);