1
0
Fork 0

Fixed sticky effects, when applied twice

This commit is contained in:
Michaël Lemaire 2017-11-28 19:15:22 +01:00
parent 3f268a3bff
commit e34033c976
3 changed files with 27 additions and 9 deletions

View file

@ -52,7 +52,6 @@ Battle
* Add a "loot all" button (on the character sheet or outcome dialog?)
* Mark targetting in error when target is refused by the action (there is already an arrow for this)
* Repair drone has its activation effect sometimes displayed as permanent effect on ships in the radius
* Merge identical sticky effects
* Allow to undo last moves
* Add a battle log display
* Allow to move targetting indicator with arrow keys

View file

@ -13,6 +13,21 @@ module TK.SpaceTac.Specs {
battle.applyDiffs(effect.getOnDiffs(ship, ship));
check.in("after", check => {
check.equals(ship.active_effects.count(), 1, "one sticky effect");
let sticked = ship.active_effects.list()[0];
if (sticked instanceof StickyEffect) {
check.equals(sticked.base, effect.base, "sticked effect");
check.equals(sticked.duration, 2, "sticked duration");
check.equals(ship.getAttribute("precision"), 1, "precision");
sticked.duration = 1;
} else {
check.fail("Not a sticky effect");
}
})
battle.applyDiffs(effect.getOnDiffs(ship, ship));
check.in("after second apply", check => {
check.equals(ship.active_effects.count(), 1, "one sticky effect");
let sticked = ship.active_effects.list()[0];
if (sticked instanceof StickyEffect) {

View file

@ -22,22 +22,26 @@ module TK.SpaceTac {
}
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
// TODO if already there, remove the previous one to replace it
let result: BaseBattleDiff[] = [
new ShipEffectAddedDiff(ship, this),
]
let result: BaseBattleDiff[] = [];
let previous = ship.active_effects.get(this.id);
if (previous) {
result = result.concat(previous.getOffDiffs(ship, source));
}
result.push(new ShipEffectAddedDiff(ship, this));
result = result.concat(this.base.getOnDiffs(ship, source));
return result;
}
getOffDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
let result: BaseBattleDiff[] = [
new ShipEffectRemovedDiff(ship, this),
]
let result: BaseBattleDiff[] = [];
result = result.concat(this.base.getOffDiffs(ship, source));
if (ship.active_effects.get(this.id)) {
result.push(new ShipEffectRemovedDiff(ship, this));
result = result.concat(this.base.getOffDiffs(ship, source));
}
return result;
}