2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-02-06 21:46:55 +00:00
|
|
|
/**
|
|
|
|
* Drones are static objects that apply effects in a circular zone around themselves.
|
|
|
|
*/
|
2017-11-14 00:07:06 +00:00
|
|
|
export class Drone extends RObject {
|
|
|
|
// ID of the owning ship
|
|
|
|
owner: RObjectId
|
2017-02-06 21:46:55 +00:00
|
|
|
|
2017-05-10 22:52:16 +00:00
|
|
|
// Code of the drone
|
2017-11-14 00:07:06 +00:00
|
|
|
code: string
|
2017-05-10 22:52:16 +00:00
|
|
|
|
2017-02-06 21:46:55 +00:00
|
|
|
// Location in arena
|
2018-01-31 18:19:50 +00:00
|
|
|
x = 0
|
|
|
|
y = 0
|
2018-07-10 14:23:32 +00:00
|
|
|
|
|
|
|
// Radius and ship filter
|
2018-01-31 18:19:50 +00:00
|
|
|
radius = 0
|
2018-07-10 14:23:32 +00:00
|
|
|
filter = ActionTargettingFilter.ALL
|
2017-02-06 21:46:55 +00:00
|
|
|
|
|
|
|
// Effects to apply
|
2017-11-14 00:07:06 +00:00
|
|
|
effects: BaseEffect[] = []
|
2017-02-06 21:46:55 +00:00
|
|
|
|
2017-11-29 22:03:58 +00:00
|
|
|
// Action that triggered that drone
|
2018-07-10 14:23:32 +00:00
|
|
|
parent: DeployDroneAction | null = null
|
2017-11-29 22:03:58 +00:00
|
|
|
|
|
|
|
constructor(owner: Ship, code = "drone") {
|
2017-11-14 00:07:06 +00:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.owner = owner.id;
|
2017-02-08 18:54:02 +00:00
|
|
|
this.code = code;
|
2017-02-06 21:46:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 17:51:22 +00:00
|
|
|
/**
|
|
|
|
* Return the current location of the drone
|
|
|
|
*/
|
|
|
|
get location(): ArenaLocation {
|
|
|
|
return new ArenaLocation(this.x, this.y);
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:48:28 +00:00
|
|
|
/**
|
|
|
|
* 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";
|
|
|
|
}
|
2017-11-29 22:03:58 +00:00
|
|
|
return `While deployed:\n${effects}`;
|
2017-05-10 17:48:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 21:46:55 +00:00
|
|
|
/**
|
2017-05-10 22:52:16 +00:00
|
|
|
* Get the list of affected ships.
|
2017-02-06 21:46:55 +00:00
|
|
|
*/
|
2017-11-14 00:07:06 +00:00
|
|
|
getAffectedShips(battle: Battle): Ship[] {
|
2018-07-10 14:23:32 +00:00
|
|
|
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;
|
2017-02-06 21:46:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|