2017-06-12 22:28:54 +00:00
|
|
|
/// <reference path="BaseAction.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-06-12 22:28:54 +00:00
|
|
|
/**
|
|
|
|
* Action to toggle some effects on the ship or around it, until next turn start
|
2017-11-29 00:36:07 +00:00
|
|
|
*
|
|
|
|
* Toggle actions consume power when activated, and restore it when deactivated
|
2017-06-12 22:28:54 +00:00
|
|
|
*/
|
|
|
|
export class ToggleAction extends BaseAction {
|
2017-11-29 00:36:07 +00:00
|
|
|
// Power consumption (for activation)
|
2017-06-12 22:28:54 +00:00
|
|
|
power: number
|
|
|
|
|
|
|
|
// Effect radius
|
|
|
|
radius: number
|
|
|
|
|
|
|
|
// Effects applied
|
|
|
|
effects: BaseEffect[]
|
|
|
|
|
|
|
|
// Equipment cannot be null
|
|
|
|
equipment: Equipment
|
|
|
|
|
|
|
|
// Current activation status
|
|
|
|
activated = false
|
|
|
|
|
2017-11-29 22:03:58 +00:00
|
|
|
constructor(equipment: Equipment, power = 1, radius = 0, effects: BaseEffect[] = [], code = `toggle-${equipment.code}`) {
|
|
|
|
super(code, equipment);
|
2017-06-12 22:28:54 +00:00
|
|
|
|
|
|
|
this.power = power;
|
|
|
|
this.radius = radius;
|
|
|
|
this.effects = effects;
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:03:58 +00:00
|
|
|
getVerb(): string {
|
|
|
|
return this.activated ? "Deactivate" : "Activate";
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:33:48 +00:00
|
|
|
getTargettingMode(ship: Ship): ActionTargettingMode {
|
2017-10-03 16:11:30 +00:00
|
|
|
if (this.activated || !this.radius) {
|
|
|
|
return ActionTargettingMode.SELF_CONFIRM;
|
2017-10-01 16:33:48 +00:00
|
|
|
} else {
|
2017-10-03 16:11:30 +00:00
|
|
|
return ActionTargettingMode.SURROUNDINGS;
|
2017-10-01 16:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:28:54 +00:00
|
|
|
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
2017-11-29 00:36:07 +00:00
|
|
|
return this.activated ? -this.power : this.power;
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getRangeRadius(ship: Ship): number {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:11:30 +00:00
|
|
|
filterImpactedShips(source: ArenaLocation, target: Target, ships: Ship[]): Ship[] {
|
|
|
|
return ships.filter(ship => arenaDistance(ship.location, source) <= this.radius);
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
|
2017-11-29 00:36:07 +00:00
|
|
|
let result: BaseBattleDiff[] = [
|
2017-11-14 00:07:06 +00:00
|
|
|
new ShipActionToggleDiff(ship, this, !this.activated)
|
2017-11-29 00:36:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
let ships = this.getImpactedShips(ship, target, ship.location);
|
|
|
|
ships.forEach(iship => {
|
|
|
|
this.effects.forEach(effect => {
|
|
|
|
if (this.activated) {
|
|
|
|
result.push(new ShipEffectRemovedDiff(iship, effect));
|
2017-11-29 22:03:58 +00:00
|
|
|
result = result.concat(effect.getOffDiffs(iship));
|
2017-11-29 00:36:07 +00:00
|
|
|
} else {
|
|
|
|
result.push(new ShipEffectAddedDiff(iship, effect));
|
|
|
|
result = result.concat(effect.getOnDiffs(iship, ship));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getEffectsDescription(): string {
|
|
|
|
if (this.effects.length == 0) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
let desc = `When active (power usage ${this.power})`;
|
|
|
|
let effects = this.effects.map(effect => {
|
|
|
|
let suffix = this.radius ? `in ${this.radius}km radius` : "on owner ship";
|
|
|
|
return "• " + effect.getDescription() + " " + suffix;
|
|
|
|
});
|
|
|
|
return `${desc}:\n${effects.join("\n")}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|