1
0
Fork 0
spacetac/src/core/effects/RepelEffect.ts
2019-11-21 23:14:27 +01:00

42 lines
1.4 KiB
TypeScript

import { any } from "../../common/Tools";
import { arenaAngle, ArenaLocation, ArenaLocationAngle } from "../ArenaLocation";
import { BaseBattleDiff } from "../diffs/BaseBattleDiff";
import { ShipMoveDiff } from "../diffs/ShipMoveDiff";
import { Drone } from "../Drone";
import { ExclusionAreas } from "../ExclusionAreas";
import { Ship } from "../Ship";
import { BaseEffect } from "./BaseEffect";
import { PinnedEffect } from "./PinnedEffect";
/**
* 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);
let exclusions = ExclusionAreas.fromShip(ship);
destination = exclusions.stopBefore(destination, ship.location);
// 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`;
}
}