2017-06-12 22:28:54 +00:00
|
|
|
/// <reference path="BaseAction.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2018-02-08 15:16:03 +00:00
|
|
|
/**
|
|
|
|
* Configuration of a toggle action
|
|
|
|
*/
|
|
|
|
export interface ToggleActionConfig {
|
|
|
|
// Power consumption (while active)
|
|
|
|
power: number
|
|
|
|
// Effect radius
|
|
|
|
radius: number
|
|
|
|
// Effects applied
|
|
|
|
effects: BaseEffect[]
|
2018-03-29 22:57:53 +00:00
|
|
|
// Filtering ships that will receive the effects
|
|
|
|
filter: ActionTargettingFilter
|
2018-02-08 15:16:03 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2018-02-08 15:16:03 +00:00
|
|
|
power = 1
|
|
|
|
radius = 0
|
|
|
|
effects: BaseEffect[] = []
|
2018-03-29 22:57:53 +00:00
|
|
|
filter = ActionTargettingFilter.ALL
|
2018-02-08 15:16:03 +00:00
|
|
|
|
|
|
|
constructor(name: string, config?: Partial<ToggleActionConfig>, code?: string) {
|
|
|
|
super(name, code);
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
this.configureToggle(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure the toggling
|
|
|
|
*/
|
|
|
|
configureToggle(config: Partial<ToggleActionConfig>): void {
|
|
|
|
copyfields(config, this);
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
getVerb(ship: Ship): string {
|
|
|
|
return ship.actions.isToggled(this) ? "Deactivate" : "Activate";
|
2017-11-29 22:03:58 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 16:33:48 +00:00
|
|
|
getTargettingMode(ship: Ship): ActionTargettingMode {
|
2018-02-08 15:16:03 +00:00
|
|
|
if (ship.actions.isToggled(this) || !this.radius) {
|
2017-10-03 16:11:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 21:28:06 +00:00
|
|
|
getPowerUsage(ship: Ship, target: Target | null): number {
|
2018-02-08 15:16:03 +00:00
|
|
|
return ship.actions.isToggled(this) ? -this.power : this.power;
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getRangeRadius(ship: Ship): number {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-29 22:57:53 +00:00
|
|
|
filterImpactedShips(ship: Ship, source: ArenaLocation, target: Target, ships: Ship[]): Ship[] {
|
|
|
|
let result = ships.filter(iship => arenaDistance(iship.location, source) <= this.radius);
|
|
|
|
result = BaseAction.filterTargets(ship, result, this.filter);
|
|
|
|
return result;
|
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
|
|
|
}
|
|
|
|
|
2018-03-29 22:57:53 +00:00
|
|
|
getSpecificDiffs(ship: Ship, battle: Battle, target: Target, apply_effects = true): BaseBattleDiff[] {
|
2018-02-08 15:16:03 +00:00
|
|
|
let activated = ship.actions.isToggled(this);
|
|
|
|
|
2017-11-29 00:36:07 +00:00
|
|
|
let result: BaseBattleDiff[] = [
|
2018-02-08 15:16:03 +00:00
|
|
|
new ShipActionToggleDiff(ship, 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 => {
|
2018-02-08 15:16:03 +00:00
|
|
|
if (activated) {
|
2017-11-29 00:36:07 +00:00
|
|
|
result.push(new ShipEffectRemovedDiff(iship, effect));
|
2018-03-29 22:57:53 +00:00
|
|
|
if (apply_effects) {
|
|
|
|
result = result.concat(effect.getOffDiffs(iship));
|
|
|
|
}
|
2017-11-29 00:36:07 +00:00
|
|
|
} else {
|
|
|
|
result.push(new ShipEffectAddedDiff(iship, effect));
|
2018-03-29 22:57:53 +00:00
|
|
|
if (apply_effects) {
|
|
|
|
result = result.concat(effect.getOnDiffs(iship, ship));
|
|
|
|
}
|
2017-11-29 00:36:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
2017-06-12 22:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getEffectsDescription(): string {
|
|
|
|
if (this.effects.length == 0) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-03-29 22:57:53 +00:00
|
|
|
// TODO filter
|
2017-06-12 22:28:54 +00:00
|
|
|
let desc = `When active (power usage ${this.power})`;
|
|
|
|
let effects = this.effects.map(effect => {
|
2018-03-29 22:57:53 +00:00
|
|
|
let suffix = this.radius ? `on ${BaseAction.getFilterDesc(this.filter)} in ${this.radius}km radius` : "on owner ship";
|
2017-06-12 22:28:54 +00:00
|
|
|
return "• " + effect.getDescription() + " " + suffix;
|
|
|
|
});
|
|
|
|
return `${desc}:\n${effects.join("\n")}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|