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
|
|
|
}
|
|
|
|
|
|
|
|
canBeUsed(battle: Battle, ship: Ship): boolean {
|
2015-01-19 00:00:00 +00:00
|
|
|
return ship.ap_current.current > 0;
|
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 {
|
2015-01-29 00:00:00 +00:00
|
|
|
var distance = Target.newFromShip(ship).getDistanceTo(target);
|
2015-01-02 00:00:00 +00:00
|
|
|
ship.moveTo(target.x, target.y);
|
2015-01-29 00:00:00 +00:00
|
|
|
var cost = this.equipment.ap_usage * distance / this.equipment.distance;
|
|
|
|
ship.useActionPoints(cost);
|
2015-01-02 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|