1
0
Fork 0
spacetac/src/core/diffs/ShipMoveDiff.ts

42 lines
1.1 KiB
TypeScript

/// <reference path="BaseBattleDiff.ts"/>
module TK.SpaceTac {
/**
* A ship moves in the arena
*/
export class ShipMoveDiff extends BaseBattleShipDiff {
// Previous location
start: ArenaLocationAngle
// New location
end: ArenaLocationAngle
// Engine used
engine: MoveAction | null
constructor(ship: Ship | RObjectId, start: ArenaLocationAngle, end: ArenaLocationAngle, engine: MoveAction | null = null) {
super(ship);
this.start = start;
this.end = end;
this.engine = engine;
}
/**
* Get the distance travelled
*/
getDistance(): number {
return arenaDistance(this.start, this.end);
}
applyOnShip(ship: Ship, battle: Battle) {
ship.setArenaPosition(this.end.x, this.end.y);
ship.setArenaFacingAngle(this.end.angle);
}
getReverse(): ShipMoveDiff {
return new ShipMoveDiff(this.ship_id, this.end, this.start, this.engine);
}
}
}