1
0
Fork 0

Fixed cooldown not resetting the usage counter

This commit is contained in:
Michaël Lemaire 2017-12-20 22:21:12 +01:00
parent fddf7a3916
commit 58334da31a
4 changed files with 51 additions and 6 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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");
},
]);
});

View File

@ -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);