1
0
Fork 0
spacetac/src/core/actions/DeployDroneAction.ts

129 lines
4.5 KiB
TypeScript
Raw Normal View History

2017-11-29 22:03:58 +00:00
/// <reference path="ToggleAction.ts"/>
2017-02-07 00:08:07 +00:00
2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
/**
2018-03-29 22:57:53 +00:00
* Configuration of a drone deployment action
2017-02-07 00:08:07 +00:00
*/
export interface DeployDroneActionConfig {
// Maximal distance the drone may be deployed
2017-11-29 22:03:58 +00:00
deploy_distance: number
// Effect radius of the deployed drone
2017-11-29 22:03:58 +00:00
drone_radius: number
// Effects applied to ships in range of the drone
2017-11-29 22:03:58 +00:00
drone_effects: BaseEffect[]
}
/**
* Action to deploy a drone in space
*
* This is a toggled action, meaning that deploying a drone requires a permanent power supply from the ship
*/
export class DeployDroneAction extends ToggleAction implements DeployDroneActionConfig {
deploy_distance = 0
drone_radius = 0
drone_effects: BaseEffect[] = []
2017-03-09 17:11:00 +00:00
constructor(name: string, toggle_config?: Partial<ToggleActionConfig>, drone_config?: Partial<DeployDroneActionConfig>, code?: string) {
super(name, toggle_config, code);
if (drone_config) {
this.configureDrone(drone_config);
}
}
/**
* Configure the deployed drone
*/
configureDrone(config: Partial<DeployDroneActionConfig>): void {
copyfields(config, this);
}
getVerb(ship: Ship): string {
return ship.actions.isToggled(this) ? "Recall" : "Deploy";
2017-10-03 16:11:30 +00:00
}
2017-11-29 22:03:58 +00:00
getTargettingMode(ship: Ship): ActionTargettingMode {
return ship.actions.isToggled(this) ? ActionTargettingMode.SELF : ActionTargettingMode.SPACE;
}
getDefaultTarget(ship: Ship): Target {
2018-07-09 13:33:37 +00:00
if (ship.actions.isToggled(this)) {
return Target.newFromShip(ship);
} else {
let harmful = any(this.effects, effect => !effect.isBeneficial());
let distance = this.drone_radius * (harmful ? 1.1 : 0.9);
return Target.newFromLocation(
ship.arena_x + Math.cos(ship.arena_angle) * distance,
ship.arena_y + Math.sin(ship.arena_angle) * distance
);
}
}
getRangeRadius(ship: Ship): number {
2018-07-10 14:23:32 +00:00
if (ship.actions.isToggled(this)) {
return 0;
} else {
return this.deploy_distance * ship.grid.getUnit();
}
}
2018-03-29 22:57:53 +00:00
filterImpactedShips(ship: Ship, source: ArenaLocation, target: Target, ships: Ship[]): Ship[] {
2018-07-10 14:23:32 +00:00
let result = ships.filter(iship => ship.grid.inRange(target, iship.location, this.drone_radius));
2018-03-29 22:57:53 +00:00
result = BaseAction.filterTargets(ship, result, this.filter);
return result;
2017-02-07 00:08:07 +00:00
}
2018-07-12 14:16:39 +00:00
checkShipTarget(ship: Ship, target: Target, from: IArenaLocation): boolean {
2018-07-09 13:33:37 +00:00
if (ship.actions.isToggled(this)) {
return target.isShip(ship);
} else {
return false;
}
2018-07-09 10:28:18 +00:00
}
2018-07-12 14:16:39 +00:00
checkLocationTarget(ship: Ship, target: Target, from: IArenaLocation): boolean {
2018-07-09 13:33:37 +00:00
if (ship.actions.isToggled(this)) {
return false;
} else {
2018-07-12 14:16:39 +00:00
return ship.grid.inRange(from, target, this.deploy_distance);
2018-07-09 13:33:37 +00:00
}
2017-02-07 00:08:07 +00:00
}
getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
2017-11-29 22:03:58 +00:00
let result = super.getSpecificDiffs(ship, battle, target);
if (ship.actions.isToggled(this)) {
let drone = first(battle.drones.list(), idrone => this.is(idrone.parent));
2017-11-29 22:03:58 +00:00
if (drone) {
result.push(new DroneRecalledDiff(drone));
} else {
return [];
}
} else {
let drone = new Drone(ship, this.code);
2017-11-29 22:03:58 +00:00
drone.parent = this;
drone.x = target.x;
drone.y = target.y;
drone.radius = this.drone_radius;
2018-07-10 14:23:32 +00:00
drone.filter = this.filter;
2017-11-29 22:03:58 +00:00
drone.effects = this.drone_effects;
result.push(new DroneDeployedDiff(drone));
}
return result;
2017-02-07 00:08:07 +00:00
}
getEffectsDescription(): string {
2017-11-29 22:03:58 +00:00
let desc = `Deploy drone (power usage ${this.power}, max range ${this.deploy_distance}km)`;
2018-03-29 22:57:53 +00:00
let suffix = `on ${BaseAction.getFilterDesc(this.filter)} in ${this.drone_radius}km radius`;
2017-11-29 22:03:58 +00:00
let effects = this.drone_effects.map(effect => {
2017-05-10 17:48:28 +00:00
return "• " + effect.getDescription() + " " + suffix;
});
return `${desc}:\n${effects.join("\n")}`;
}
2017-02-07 00:08:07 +00:00
}
}