2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2014-12-31 00:00:00 +00:00
|
|
|
// Base class for action definitions
|
2017-02-07 18:54:53 +00:00
|
|
|
export class BaseAction {
|
2014-12-31 00:00:00 +00:00
|
|
|
// Identifier code for the type of action
|
|
|
|
code: string;
|
|
|
|
|
2017-01-08 22:42:53 +00:00
|
|
|
// Human-readable name
|
|
|
|
name: string;
|
|
|
|
|
2015-01-06 00:00:00 +00:00
|
|
|
// Boolean at true if the action needs a target
|
|
|
|
needs_target: boolean;
|
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Equipment that triggers this action
|
2017-03-09 17:11:00 +00:00
|
|
|
equipment: Equipment | null;
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2015-01-06 00:00:00 +00:00
|
|
|
// Create the action
|
2017-03-09 17:11:00 +00:00
|
|
|
constructor(code: string, name: string, needs_target: boolean, equipment: Equipment | null = null) {
|
2014-12-31 00:00:00 +00:00
|
|
|
this.code = code;
|
2017-01-08 22:42:53 +00:00
|
|
|
this.name = name;
|
2015-01-06 00:00:00 +00:00
|
|
|
this.needs_target = needs_target;
|
2015-01-28 00:00:00 +00:00
|
|
|
this.equipment = equipment;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
/**
|
|
|
|
* Check basic conditions to know if the ship can use this action at all
|
|
|
|
*
|
|
|
|
* Method to extend to set conditions
|
|
|
|
*
|
|
|
|
* Returns an informative message indicating why the action cannot be used, null otherwise
|
|
|
|
*/
|
2017-03-09 17:11:00 +00:00
|
|
|
checkCannotBeApplied(ship: Ship, remaining_ap: number | null = null): string | null {
|
2017-03-07 19:27:46 +00:00
|
|
|
let battle = ship.getBattle();
|
2015-02-26 00:00:00 +00:00
|
|
|
if (battle && battle.playing_ship !== ship) {
|
|
|
|
// Ship is not playing
|
2017-03-07 19:27:46 +00:00
|
|
|
return "ship not playing";
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check AP usage
|
|
|
|
if (remaining_ap === null) {
|
2017-02-07 19:15:21 +00:00
|
|
|
remaining_ap = ship.values.power.get();
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
var ap_usage = this.getActionPointsUsage(ship, null);
|
2017-03-07 19:27:46 +00:00
|
|
|
if (remaining_ap >= ap_usage) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return "not enough power";
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 00:00:00 +00:00
|
|
|
// Get the number of action points the action applied to a target would use
|
2017-03-09 17:11:00 +00:00
|
|
|
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
2017-04-18 19:51:23 +00:00
|
|
|
return 0;
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:00:00 +00:00
|
|
|
// Get the range of this action
|
|
|
|
getRangeRadius(ship: Ship): number {
|
2017-04-18 19:51:23 +00:00
|
|
|
return 0;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 00:00:00 +00:00
|
|
|
// Get the effect area radius of this action
|
|
|
|
getBlastRadius(ship: Ship): number {
|
2017-04-18 19:51:23 +00:00
|
|
|
return 0;
|
2015-03-06 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Method to check if a target is applicable for this action
|
|
|
|
// Will call checkLocationTarget or checkShipTarget by default
|
2017-03-09 17:11:00 +00:00
|
|
|
checkTarget(ship: Ship, target: Target | null): Target | null {
|
2017-03-07 19:27:46 +00:00
|
|
|
if (this.checkCannotBeApplied(ship)) {
|
2014-12-31 00:00:00 +00:00
|
|
|
return null;
|
2015-01-06 00:00:00 +00:00
|
|
|
} else if (target) {
|
|
|
|
if (target.ship) {
|
2017-03-07 19:27:46 +00:00
|
|
|
return this.checkShipTarget(ship, target);
|
2015-01-06 00:00:00 +00:00
|
|
|
} else {
|
2017-03-07 19:27:46 +00:00
|
|
|
return this.checkLocationTarget(ship, target);
|
2015-01-06 00:00:00 +00:00
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
} else {
|
2015-01-06 00:00:00 +00:00
|
|
|
return null;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method to reimplement to check if a space target is applicable
|
|
|
|
// Must return null if the target can't be applied, an altered target, or the original target
|
2017-03-09 17:11:00 +00:00
|
|
|
checkLocationTarget(ship: Ship, target: Target): Target | null {
|
2014-12-31 00:00:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method to reimplement to check if a ship target is applicable
|
|
|
|
// Must return null if the target can't be applied, an altered target, or the original target
|
2017-03-09 17:11:00 +00:00
|
|
|
checkShipTarget(ship: Ship, target: Target): Target | null {
|
2014-12-31 00:00:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2015-01-02 00:00:00 +00:00
|
|
|
|
|
|
|
// Apply an action, returning true if it was successful
|
2017-03-09 17:11:00 +00:00
|
|
|
apply(ship: Ship, target: Target | null): boolean {
|
2017-03-07 19:27:46 +00:00
|
|
|
let reject = this.checkCannotBeApplied(ship);
|
|
|
|
if (reject == null) {
|
2017-03-08 23:18:40 +00:00
|
|
|
let checked_target = this.checkTarget(ship, target);
|
|
|
|
if (!checked_target && this.needs_target) {
|
|
|
|
console.warn("Action rejected - invalid target", ship, this, target);
|
2015-01-06 00:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-03-08 23:18:40 +00:00
|
|
|
let cost = this.getActionPointsUsage(ship, checked_target);
|
2017-02-19 21:52:11 +00:00
|
|
|
if (!ship.useActionPoints(cost)) {
|
2017-03-08 23:18:40 +00:00
|
|
|
console.warn("Action rejected - not enough power", ship, this, checked_target);
|
2015-02-26 00:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-02-19 21:52:11 +00:00
|
|
|
|
2017-03-08 23:18:40 +00:00
|
|
|
this.customApply(ship, checked_target);
|
2017-02-19 21:52:11 +00:00
|
|
|
return true;
|
2015-01-06 00:00:00 +00:00
|
|
|
} else {
|
2017-03-07 19:27:46 +00:00
|
|
|
console.warn(`Action rejected - ${reject}`, ship, this, target);
|
2015-01-02 00:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method to reimplement to apply a action
|
2017-03-09 17:11:00 +00:00
|
|
|
protected customApply(ship: Ship, target: Target | null) {
|
2015-01-02 00:00:00 +00:00
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-18 22:55:59 +00:00
|
|
|
* Get textual description of effects
|
2017-04-18 19:51:23 +00:00
|
|
|
*/
|
2017-04-18 22:55:59 +00:00
|
|
|
getEffectsDescription(): string {
|
|
|
|
return "";
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|