1
0
Fork 0
spacetac/src/scripts/game/actions/MoveAction.ts

29 lines
1.1 KiB
TypeScript
Raw Normal View History

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