1
0
Fork 0

Fixed setting capacity attribute not broadcasting value change

This commit is contained in:
Michaël Lemaire 2017-06-23 01:04:54 +02:00
parent 20377b49e7
commit b6f80caf70
3 changed files with 47 additions and 4 deletions

2
TODO
View file

@ -20,7 +20,6 @@
* Arena: any displayed info should be based on a ship copy stored in ArenaShip, and in sync with current log index (not the game state ship)
* Arena: add engine trail
* Log processor: Cancel previous animations, and allow no animation mode
* Fix capacity limit effect not refreshing associated value (for example, on "limit power capacity to 3", potential "power" value change is not broadcast)
* Actions: fix targetting not resetting on current cursor location when using keyboard shortcuts
* Add actions with cost dependent of distance (like current move actions)
* Find incentives to move from starting position
@ -31,6 +30,7 @@
* Controls: fix hover being stuck when the cursor exits the window, or the item moves or is hidden
* Drones: add hull points and take area damage
* Drones: find a way to avoid arena cluttering
* Drones: repair drone has its activation effect displayed as permanent effect on ships in the radius
* Add a battle log display
* Allow to undo last moves
* Merge identical sticky effects

View file

@ -244,6 +244,16 @@ module TS.SpaceTac {
return diff != 0;
}
/**
* Set a value's maximal capacity
*/
setValueCapacity(name: keyof ShipValues, maximal: number, log = true): void {
if (this.getValue(name) > maximal) {
this.setValue(name, maximal, false, log);
}
this.values[name].setMaximal(maximal);
}
/**
* Get a ship attribute's current value
*/
@ -268,11 +278,11 @@ module TS.SpaceTac {
// TODO more generic
if (name == "power_capacity") {
this.values.power.setMaximal(attr.get());
this.setValueCapacity("power", attr.get());
} else if (name == "shield_capacity") {
this.values.shield.setMaximal(attr.get());
this.setValueCapacity("shield", attr.get());
} else if (name == "hull_capacity") {
this.values.hull.setMaximal(attr.get());
this.setValueCapacity("hull", attr.get());
}
if (log && diff != 0) {

View file

@ -0,0 +1,33 @@
module TS.SpaceTac {
describe("AttributeLimitEffect", function () {
it("limits an attribute", function () {
let battle = new Battle();
let ship = battle.fleets[0].addShip();
expect(ship.getAttribute("shield_capacity")).toBe(0);
expect(ship.getValue("shield")).toBe(0);
TestTools.setShipHP(ship, 100, 50);
ship.setValue("shield", 40);
expect(ship.getAttribute("shield_capacity")).toBe(50);
expect(ship.getValue("shield")).toBe(40);
battle.log.clear();
let effect = new StickyEffect(new AttributeLimitEffect("shield_capacity", 30));
ship.addStickyEffect(effect);
expect(ship.getAttribute("shield_capacity")).toBe(30);
expect(ship.getValue("shield")).toBe(30);
console.log(battle.log.events);
expect(battle.log.events).toEqual([
new ActiveEffectsEvent(ship, [new AttributeEffect("hull_capacity", 100), new AttributeEffect("shield_capacity", 50)], [effect]),
new ValueChangeEvent(ship, new ShipValue("shield", 30, 50), -10),
new ValueChangeEvent(ship, new ShipAttribute("shield capacity", 30), -20),
]);
ship.cleanStickyEffects();
expect(ship.getAttribute("shield_capacity")).toBe(50);
expect(ship.getValue("shield")).toBe(30);
});
});
}