2015-02-27 00:00:00 +00:00
|
|
|
/// <reference path="BaseEffect.ts"/>
|
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2017-01-24 00:14:04 +00:00
|
|
|
/**
|
|
|
|
* Wrapper around another effect, to make it stick to a ship.
|
|
|
|
*
|
|
|
|
* The "effect" is to stick the wrapped effect to the ship, that will be applied in time.
|
|
|
|
*/
|
2017-01-23 23:07:54 +00:00
|
|
|
export class StickyEffect extends BaseEffect {
|
2017-01-24 00:14:04 +00:00
|
|
|
// Wrapped effect
|
|
|
|
base: BaseEffect;
|
|
|
|
|
2015-02-27 00:00:00 +00:00
|
|
|
// Duration, in number of turns
|
|
|
|
duration: number;
|
|
|
|
|
2017-01-24 00:14:04 +00:00
|
|
|
// Apply the effect on stick (doesn't count against duration)
|
|
|
|
on_stick: boolean;
|
|
|
|
|
|
|
|
// Apply the effect on turn start instead of end
|
|
|
|
on_turn_end: boolean;
|
|
|
|
|
2015-02-27 00:00:00 +00:00
|
|
|
// Base constructor
|
2017-01-24 00:14:04 +00:00
|
|
|
constructor(base: BaseEffect, duration = 0, on_stick = false, on_turn_end = false) {
|
|
|
|
super(base.code);
|
2015-02-27 00:00:00 +00:00
|
|
|
|
2017-01-24 00:14:04 +00:00
|
|
|
this.base = base;
|
2015-02-27 00:00:00 +00:00
|
|
|
this.duration = duration;
|
2017-01-24 00:14:04 +00:00
|
|
|
this.on_stick = on_stick;
|
|
|
|
this.on_turn_end = on_turn_end;
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:00:00 +00:00
|
|
|
applyOnShip(ship: Ship): boolean {
|
2017-01-24 00:14:04 +00:00
|
|
|
ship.addStickyEffect(new StickyEffect(this.base, this.duration, this.on_stick, this.on_turn_end));
|
|
|
|
if (this.on_stick) {
|
|
|
|
this.base.applyOnShip(ship);
|
|
|
|
}
|
2015-02-27 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:14:04 +00:00
|
|
|
private applyOnce(ship: Ship) {
|
|
|
|
if (this.duration > 0) {
|
|
|
|
this.base.applyOnShip(ship);
|
|
|
|
this.duration--;
|
|
|
|
ship.addBattleEvent(new EffectDurationChangedEvent(ship, this, this.duration + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the effect at the beginning of the turn, for the ship this effect is sticked to.
|
|
|
|
*/
|
|
|
|
startTurn(ship: Ship) {
|
|
|
|
if (!this.on_turn_end) {
|
|
|
|
this.applyOnce(ship);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the effect at the end of the turn, for the ship this effect is sticked to.
|
|
|
|
*/
|
|
|
|
endTurn(ship: Ship) {
|
|
|
|
if (this.on_turn_end) {
|
|
|
|
this.applyOnce(ship);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isBeneficial(): boolean {
|
|
|
|
return this.base.isBeneficial();
|
2015-02-27 00:00:00 +00:00
|
|
|
}
|
2015-04-22 20:03:59 +00:00
|
|
|
|
|
|
|
getFullCode(): string {
|
2017-01-24 00:14:04 +00:00
|
|
|
return this.base.getFullCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
getDescription(): string {
|
|
|
|
return this.base.getDescription();
|
2015-04-22 20:03:59 +00:00
|
|
|
}
|
2015-02-27 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|