2017-11-14 00:07:06 +00:00
|
|
|
/// <reference path="../diffs/BaseBattleDiff.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-05-28 22:16:50 +00:00
|
|
|
export type EffectAmount = number | { base: number, span: number };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for effects of actions that can be applied on ships
|
|
|
|
*
|
2017-11-14 00:07:06 +00:00
|
|
|
* Effects will generate diffs to modify the battle state
|
2017-05-28 22:16:50 +00:00
|
|
|
*/
|
2017-11-14 00:07:06 +00:00
|
|
|
export class BaseEffect extends RObject {
|
2015-01-22 00:00:00 +00:00
|
|
|
// Identifier code for the type of effect
|
2017-11-14 00:07:06 +00:00
|
|
|
code: string
|
2015-01-22 00:00:00 +00:00
|
|
|
|
|
|
|
constructor(code: string) {
|
2017-11-14 00:07:06 +00:00
|
|
|
super();
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
this.code = code;
|
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
/**
|
|
|
|
* Get the list of diffs needed to activate this effect on a ship
|
|
|
|
*/
|
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of diffs needed to remove this effect on a ship
|
|
|
|
*/
|
2017-11-29 22:03:58 +00:00
|
|
|
getOffDiffs(ship: Ship): BaseBattleDiff[] {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of diffs to apply when this effect is active on a ship beginning its turn
|
|
|
|
*/
|
|
|
|
getTurnStartDiffs(ship: Ship): BaseBattleDiff[] {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of diffs to apply when this effect is active on a ship ending its turn
|
|
|
|
*/
|
|
|
|
getTurnEndDiffs(ship: Ship): BaseBattleDiff[] {
|
2017-11-14 00:07:06 +00:00
|
|
|
return [];
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
2017-01-16 23:20:33 +00:00
|
|
|
|
|
|
|
// Return true if the effect is beneficial to the ship, false if it's a drawback
|
|
|
|
isBeneficial(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:14:04 +00:00
|
|
|
// Get a full code, that can be used to identify this effect (for example: "attrlimit-aprecovery")
|
|
|
|
getFullCode(): string {
|
|
|
|
return this.code;
|
|
|
|
}
|
|
|
|
|
2017-01-16 23:20:33 +00:00
|
|
|
// Return a human readable description
|
|
|
|
getDescription(): string {
|
|
|
|
return "unknown effect";
|
|
|
|
}
|
2017-05-28 22:16:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve an effect amount
|
|
|
|
*/
|
|
|
|
resolveAmount(val: EffectAmount, random = RandomGenerator.global): number {
|
|
|
|
if (typeof val == "number") {
|
|
|
|
return val;
|
|
|
|
} else if (val.span) {
|
|
|
|
return random.randInt(val.base, val.base + val.span);
|
|
|
|
} else {
|
|
|
|
return val.base;
|
|
|
|
}
|
|
|
|
}
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|