1
0
Fork 0
spacetac/src/core/effects/RepelEffect.ts
2018-07-09 16:04:40 +02:00

38 lines
1.2 KiB
TypeScript

/// <reference path="BaseEffect.ts"/>
module TK.SpaceTac {
/**
* Repel ships from a central point
*/
export class RepelEffect extends BaseEffect {
value: number;
constructor(value = 0) {
super("repel");
this.value = value;
}
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
if (ship != source && !any(ship.getEffects(), effect => effect instanceof PinnedEffect && effect.hard)) {
let angle = arenaAngle(source.location, ship.location);
let destination = new ArenaLocation(
ship.arena_x + Math.cos(angle) * this.value,
ship.arena_y + Math.sin(angle) * this.value
);
// TODO Snap to grid (what if space is already occupied ?)
// TODO Apply area effect adding/removal
return [
new ShipMoveDiff(ship, ship.location, new ArenaLocationAngle(destination.x, destination.y, ship.arena_angle))
];
} else {
return [];
}
}
getDescription(): string {
return `repel ships ${this.value}km away`;
}
}
}