2017-11-14 00:07:06 +00:00
|
|
|
/// <reference path="BaseAction.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-11-14 00:07:06 +00:00
|
|
|
/**
|
|
|
|
* Action to end the ship's turn
|
|
|
|
*
|
|
|
|
* This action is not provided by an equipment and is always available
|
|
|
|
*/
|
2015-01-06 00:00:00 +00:00
|
|
|
export class EndTurnAction extends BaseAction {
|
2017-11-14 00:07:06 +00:00
|
|
|
// Singleton that may be used for all ships
|
|
|
|
static SINGLETON = new EndTurnAction();
|
|
|
|
|
2015-01-06 00:00:00 +00:00
|
|
|
constructor() {
|
2017-11-29 22:03:58 +00:00
|
|
|
super("endturn");
|
|
|
|
}
|
|
|
|
|
|
|
|
getVerb(): string {
|
|
|
|
return "End ship's turn";
|
2015-01-06 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 22:50:40 +00:00
|
|
|
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
|
|
|
let toggled_cost = isum(imap(ship.iToggleActions(true), action => action.power));
|
|
|
|
let power_diff = ship.getAttribute("power_generation") - toggled_cost;
|
2017-12-04 19:01:50 +00:00
|
|
|
let power_excess = ship.getValue("power") + power_diff - ship.getAttribute("power_capacity");
|
|
|
|
if (power_excess > 0) {
|
|
|
|
power_diff -= power_excess;
|
|
|
|
}
|
2017-11-29 22:50:40 +00:00
|
|
|
return -power_diff;
|
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
|
|
|
|
if (ship.is(battle.playing_ship)) {
|
|
|
|
let result: BaseBattleDiff[] = [];
|
|
|
|
let new_ship = battle.getNextShip();
|
|
|
|
|
2017-11-14 21:16:42 +00:00
|
|
|
// Cool down equipment
|
|
|
|
ship.listEquipment().filter(equ => equ.cooldown.heat > 0).forEach(equ => {
|
|
|
|
result.push(new ShipCooldownDiff(ship, equ, 1));
|
|
|
|
});
|
2017-03-07 19:27:46 +00:00
|
|
|
|
2017-11-29 22:03:58 +00:00
|
|
|
// "On turn end" effects
|
2017-11-28 18:01:56 +00:00
|
|
|
iforeach(ship.active_effects.iterator(), effect => {
|
2017-11-29 22:03:58 +00:00
|
|
|
result = result.concat(effect.getTurnEndDiffs(ship));
|
2017-11-28 18:01:56 +00:00
|
|
|
});
|
2017-11-14 00:07:06 +00:00
|
|
|
|
2017-11-28 18:01:56 +00:00
|
|
|
// Change the active ship
|
2017-11-14 00:07:06 +00:00
|
|
|
let cycle_diff = (battle.play_order.indexOf(new_ship) == 0) ? 1 : 0;
|
|
|
|
result.push(new ShipChangeDiff(ship, new_ship, cycle_diff));
|
|
|
|
|
2017-11-29 22:03:58 +00:00
|
|
|
// "On turn start" effects
|
|
|
|
iforeach(new_ship.active_effects.iterator(), effect => {
|
|
|
|
result = result.concat(effect.getTurnStartDiffs(ship));
|
|
|
|
});
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return [];
|
2017-03-07 19:27:46 +00:00
|
|
|
}
|
2015-01-06 00:00:00 +00:00
|
|
|
}
|
2017-05-22 16:29:04 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
protected checkShipTarget(ship: Ship, target: Target): Target | null {
|
2017-11-14 00:07:06 +00:00
|
|
|
return ship.is(target.ship_id) ? target : null;
|
2017-09-19 15:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getTargettingMode(ship: Ship): ActionTargettingMode {
|
|
|
|
return ship.getValue("power") ? ActionTargettingMode.SELF_CONFIRM : ActionTargettingMode.SELF;
|
|
|
|
}
|
2017-11-14 00:07:06 +00:00
|
|
|
|
2017-05-22 16:29:04 +00:00
|
|
|
getEffectsDescription(): string {
|
|
|
|
return "End the current ship's turn.\nWill also generate power and cool down equipments.";
|
|
|
|
}
|
2015-01-06 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|