2017-02-07 00:08:07 +00:00
|
|
|
/// <reference path="BaseAction.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-02-07 00:08:07 +00:00
|
|
|
/**
|
|
|
|
* Action to deploy a drone in space
|
|
|
|
*/
|
|
|
|
export class DeployDroneAction extends BaseAction {
|
2017-04-18 19:51:23 +00:00
|
|
|
// Power usage
|
|
|
|
power: number;
|
|
|
|
|
|
|
|
// Maximal distance the drone may be deployed
|
|
|
|
deploy_distance: number;
|
|
|
|
|
|
|
|
// Effect radius of the deployed drone
|
|
|
|
effect_radius: number;
|
|
|
|
|
|
|
|
// Duration of the drone in turns, before being destroyed
|
|
|
|
lifetime: number;
|
|
|
|
|
|
|
|
// Effects applied to ships in range of the drone
|
|
|
|
effects: BaseEffect[];
|
|
|
|
|
|
|
|
// Source equipment
|
2017-03-09 17:11:00 +00:00
|
|
|
equipment: Equipment;
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
constructor(equipment: Equipment, power = 1, deploy_distance = 0, lifetime = 0, effect_radius = 0, effects: BaseEffect[] = []) {
|
2017-09-19 15:09:06 +00:00
|
|
|
super("deploy-" + equipment.code, "Deploy", equipment);
|
2017-04-18 19:51:23 +00:00
|
|
|
|
|
|
|
this.power = power;
|
|
|
|
this.deploy_distance = deploy_distance;
|
|
|
|
this.lifetime = lifetime;
|
|
|
|
this.effect_radius = effect_radius;
|
|
|
|
this.effects = effects;
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:11:30 +00:00
|
|
|
getTargettingMode(ship: Ship): ActionTargettingMode {
|
|
|
|
return ActionTargettingMode.SPACE;
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
|
|
|
return this.power;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRangeRadius(ship: Ship): number {
|
|
|
|
return this.deploy_distance;
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:11:30 +00:00
|
|
|
filterImpactedShips(source: ArenaLocation, target: Target, ships: Ship[]): Ship[] {
|
|
|
|
return ships.filter(ship => arenaDistance(ship.location, target) <= this.effect_radius);
|
2017-02-07 00:08:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
checkLocationTarget(ship: Ship, target: Target): Target {
|
2017-02-07 00:08:07 +00:00
|
|
|
// TODO Not too close to other ships and drones
|
2017-04-18 19:51:23 +00:00
|
|
|
target = target.constraintInRange(ship.arena_x, ship.arena_y, this.deploy_distance);
|
2017-02-07 00:08:07 +00:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
protected customApply(ship: Ship, target: Target) {
|
2017-05-10 22:52:16 +00:00
|
|
|
let drone = new Drone(ship, this.equipment.code, this.lifetime);
|
2017-02-07 00:08:07 +00:00
|
|
|
drone.x = target.x;
|
|
|
|
drone.y = target.y;
|
2017-04-18 19:51:23 +00:00
|
|
|
drone.radius = this.effect_radius;
|
|
|
|
drone.effects = this.effects;
|
2017-03-07 19:27:46 +00:00
|
|
|
|
|
|
|
let battle = ship.getBattle();
|
|
|
|
if (battle) {
|
|
|
|
battle.addDrone(drone);
|
|
|
|
}
|
2017-02-07 00:08:07 +00:00
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
getEffectsDescription(): string {
|
2017-05-22 23:00:02 +00:00
|
|
|
let desc = `Deploy drone for ${this.lifetime} activation${this.lifetime > 1 ? "s" : ""} (power usage ${this.power}, max range ${this.deploy_distance}km)`;
|
2017-04-18 22:55:59 +00:00
|
|
|
let effects = this.effects.map(effect => {
|
|
|
|
let suffix = `for ships in ${this.effect_radius}km radius`;
|
2017-05-10 17:48:28 +00:00
|
|
|
return "• " + effect.getDescription() + " " + suffix;
|
2017-04-18 22:55:59 +00:00
|
|
|
});
|
|
|
|
return `${desc}:\n${effects.join("\n")}`;
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
2017-02-07 00:08:07 +00:00
|
|
|
}
|
|
|
|
}
|