2017-02-09 00:00:35 +00:00
|
|
|
module TS.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
|
|
|
|
*
|
|
|
|
* Effects are typically one shot, but sticky effects can be used to apply effects over a period
|
|
|
|
*/
|
2017-02-07 18:54:53 +00:00
|
|
|
export class BaseEffect {
|
2015-01-22 00:00:00 +00:00
|
|
|
// Identifier code for the type of effect
|
|
|
|
code: string;
|
|
|
|
|
|
|
|
// Base constructor
|
|
|
|
constructor(code: string) {
|
|
|
|
this.code = code;
|
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Apply ponctually the effect on a given ship
|
|
|
|
// Return true if the effect could be applied
|
2017-05-28 22:16:50 +00:00
|
|
|
applyOnShip(ship: Ship, source: Ship | Drone): boolean {
|
2015-01-28 00:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|