2014-12-31 00:00:00 +00:00
|
|
|
module SpaceTac.Game {
|
2015-01-07 00:00:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Action to move to a given location
|
|
|
|
export class MoveAction extends BaseAction {
|
2015-01-28 00:00:00 +00:00
|
|
|
constructor(equipment: Equipment) {
|
|
|
|
super("move", true, equipment);
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 00:00:00 +00:00
|
|
|
canBeUsed(battle: Battle, ship: Ship, remaining_ap: number = null): boolean {
|
|
|
|
if (battle && battle.playing_ship !== ship) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check AP usage
|
|
|
|
if (remaining_ap === null) {
|
|
|
|
remaining_ap = ship.ap_current.current;
|
|
|
|
}
|
|
|
|
return remaining_ap > 0.0001;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 00:00:00 +00:00
|
|
|
getActionPointsUsage(battle: Battle, ship: Ship, target: Target): number {
|
|
|
|
if (target === null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var distance = Target.newFromShip(ship).getDistanceTo(target);
|
|
|
|
return this.equipment.ap_usage * distance / this.equipment.distance;
|
|
|
|
}
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
|
|
|
|
// TODO Should forbid to move too much near another ship
|
2015-01-29 00:00:00 +00:00
|
|
|
var max_distance = this.equipment.distance * ship.ap_current.current / this.equipment.ap_usage;
|
|
|
|
return target.constraintInRange(ship.arena_x, ship.arena_y, max_distance);
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-02 00:00:00 +00:00
|
|
|
|
|
|
|
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
|
|
|
ship.moveTo(target.x, target.y);
|
|
|
|
return true;
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|