1
0
Fork 0
spacetac/src/core/Drone.ts
2018-07-10 16:23:32 +02:00

67 lines
1.8 KiB
TypeScript

module TK.SpaceTac {
/**
* Drones are static objects that apply effects in a circular zone around themselves.
*/
export class Drone extends RObject {
// ID of the owning ship
owner: RObjectId
// Code of the drone
code: string
// Location in arena
x = 0
y = 0
// Radius and ship filter
radius = 0
filter = ActionTargettingFilter.ALL
// Effects to apply
effects: BaseEffect[] = []
// Action that triggered that drone
parent: DeployDroneAction | null = null
constructor(owner: Ship, code = "drone") {
super();
this.owner = owner.id;
this.code = code;
}
/**
* Return the current location of the drone
*/
get location(): ArenaLocation {
return new ArenaLocation(this.x, this.y);
}
/**
* Get a textual description of this drone
*/
getDescription(): string {
let effects = this.effects.map(effect => "• " + effect.getDescription()).join("\n");
if (effects.length == 0) {
effects = "• do nothing";
}
return `While deployed:\n${effects}`;
}
/**
* Get the list of affected ships.
*/
getAffectedShips(battle: Battle): Ship[] {
let ships = battle.ships.list();
ships = ships.filter(ship => ship.alive);
ships = ships.filter(ship => battle.grid.inRange(this, ship.location, this.radius));
let owner = battle.getShip(this.owner);
if (owner) {
ships = BaseAction.filterTargets(owner, ships, this.filter);
} else {
ships = [];
}
return ships;
}
}
}