1
0
Fork 0

Fixed dead ship leaving its drones behind

This commit is contained in:
Michaël Lemaire 2017-11-30 00:56:22 +01:00
parent bc99d6aa6b
commit a2ad1ecab0
6 changed files with 61 additions and 7 deletions

View file

@ -37,6 +37,7 @@ Character sheet
Battle
------
* Fix the suicide case when the playing ship dies (it is removed from play_order but no ShipChangeDiff is emitted)
* Fix arena's ship hovering happening even when the character sheet (or a dialog) is open on top
* Add a voluntary retreat option
* Add scroll buttons when there are too many actions

View file

@ -112,14 +112,26 @@ module TK.SpaceTac {
let result: BaseBattleDiff[] = [];
iforeach(this.battle.iships(true), ship => {
if (ship.getValue("hull") == 0) {
result.push(new ShipDeathDiff(this.battle, ship));
if (ship.getValue("hull") <= 0) {
result = result.concat(ship.getDeathDiffs(this.battle));
}
});
return result;
}
/**
* Check that the playing ship is not playing
*/
checkDeadShipPlaying(): BaseBattleDiff[] {
if (this.battle.playing_ship && !this.battle.playing_ship.alive) {
let ship = this.battle.playing_ship;
return EndTurnAction.SINGLETON.getDiffs(ship, this.battle);
} else {
return [];
}
}
/**
* Check area effects (remove obsolete ones, and add missing ones)
*/

View file

@ -365,5 +365,33 @@ module TK.SpaceTac.Specs {
ship.active_effects.add(new StickyEffect(new AttributeLimitEffect("skill_photons", 3)));
check.equals(ship.getAttributeDescription("skill_photons"), "Forces of light, and electromagnetic radiation\n\nLevelled up: +2\nPhotonic engine Mk1: +4\n???: limit to 3");
});
test.case("produces death diffs", check => {
let battle = TestTools.createBattle(1);
let ship = nn(battle.playing_ship);
check.equals(ship.getDeathDiffs(battle), [
new ShipValueDiff(ship, "hull", -1),
new ShipDeathDiff(battle, ship),
]);
let effect1 = ship.active_effects.add(new AttributeEffect("skill_quantum", 2));
let effect2 = ship.active_effects.add(new StickyEffect(new AttributeEffect("skill_materials", 4)));
let weapon1 = TestTools.addWeapon(ship);
weapon1.action = new ToggleAction(weapon1, 3);
let weapon2 = TestTools.addWeapon(ship);
let action = weapon2.action = new ToggleAction(weapon2, 3);
action.activated = true;
check.equals(ship.getDeathDiffs(battle), [
new ShipEffectRemovedDiff(ship, effect1),
new ShipAttributeDiff(ship, "skill_quantum", {}, { cumulative: 2 }),
new ShipEffectRemovedDiff(ship, effect2),
new ShipAttributeDiff(ship, "skill_materials", {}, { cumulative: 4 }),
new ShipActionToggleDiff(ship, action, false),
new ShipValueDiff(ship, "hull", -1),
new ShipDeathDiff(battle, ship),
]);
});
});
}

View file

@ -303,12 +303,25 @@ module TK.SpaceTac {
getDeathDiffs(battle: Battle): BaseBattleDiff[] {
let result: BaseBattleDiff[] = [];
// Remove active effects
this.active_effects.list().forEach(effect => {
if (!(effect instanceof StickyEffect)) {
result.push(new ShipEffectRemovedDiff(this, effect));
}
result = result.concat(effect.getOffDiffs(this));
});
// Deactivate toggle actions
iforeach(this.iToggleActions(true), action => {
result = result.concat(action.getSpecificDiffs(this, battle, Target.newFromShip(this)));
});
// Put all values to 0
keys(SHIP_VALUES).forEach(value => {
result = result.concat(this.getValueDiffs(value, 0));
});
// TODO Remove sticky effects
// Mark as dead
result.push(new ShipDeathDiff(battle, this));
return result;

View file

@ -54,11 +54,11 @@ module TK.SpaceTac {
return target;
}
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
let result = super.getSpecificDiffs(ship, battle, target);
if (this.activated) {
let drone = first(battle.drones.list(), drone => drone.parent == this);
let drone = first(battle.drones.list(), idrone => this.is(idrone.parent));
if (drone) {
result.push(new DroneRecalledDiff(drone));
} else {

View file

@ -58,7 +58,7 @@ module TK.SpaceTac {
return ship.is(target.ship_id) ? target : null;
}
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
let result: BaseBattleDiff[] = [
new ShipActionToggleDiff(ship, this, !this.activated)
];