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

41 lines
1.1 KiB
TypeScript

import { flatten } from "../../common/Tools";
import { VigilanceAction } from "../actions/VigilanceAction";
import { BaseBattleDiff } from "../diffs/BaseBattleDiff";
import { VigilanceAppliedDiff } from "../diffs/VigilanceAppliedDiff";
import { Drone } from "../Drone";
import { Ship } from "../Ship";
import { BaseEffect } from "./BaseEffect";
/**
* Apply vigilance effects on a ship that enters a vigilance area
*/
export class VigilanceEffect extends BaseEffect {
constructor(private action: VigilanceAction) {
super("vigilance");
}
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
if (source instanceof Ship) {
let result = flatten(this.action.intruder_effects.map(effect => effect.getOnDiffs(ship, source)));
if (result.length > 0) {
result.unshift(new VigilanceAppliedDiff(source, this.action, ship));
}
return result;
} else {
return [];
}
}
isInternal(): boolean {
return true;
}
isBeneficial(): boolean {
return false;
}
getDescription(): string {
return `Vigilance from ${this.action.name}`;
}
}