Added action types (WIP)
This commit is contained in:
parent
37b7bd40d2
commit
1efa4a0595
|
@ -79,6 +79,14 @@ module SpaceTac.Game {
|
|||
return this.fleet.player;
|
||||
}
|
||||
|
||||
// Get the list of actions available
|
||||
// This list does not filter out actions unavailable due to insufficient AP, it justs filter out
|
||||
// actions that are not allowed/available at all on the ship
|
||||
getAvailableActions(): Actions.BaseAction[] {
|
||||
// TODO
|
||||
return [new Actions.MoveAction()];
|
||||
}
|
||||
|
||||
// Consumes action points
|
||||
useActionPoints(ap: number): void {
|
||||
this.ap_current -= ap;
|
||||
|
|
41
src/scripts/game/actions/BaseAction.ts
Normal file
41
src/scripts/game/actions/BaseAction.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
module SpaceTac.Game.Actions {
|
||||
// Base class for action definitions
|
||||
export class BaseAction {
|
||||
// Identifier code for the type of action
|
||||
code: string;
|
||||
|
||||
constructor(code: string) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
// Check basic conditions to know if the ship can use this action at all
|
||||
// Method to reimplement to set conditions
|
||||
canBeUsed(battle: Battle, ship: Ship): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Method to check if a target is applicable for this action
|
||||
// Will call checkLocationTarget or checkShipTarget by default
|
||||
checkTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
if (!this.canBeUsed(battle, ship)) {
|
||||
return null;
|
||||
} else if (target.ship) {
|
||||
return this.checkShipTarget(battle, ship, target);
|
||||
} else {
|
||||
return this.checkLocationTarget(battle, ship, target);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
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
|
||||
checkShipTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
18
src/scripts/game/actions/MoveAction.ts
Normal file
18
src/scripts/game/actions/MoveAction.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
module SpaceTac.Game.Actions {
|
||||
// Action to move to a given location
|
||||
export class MoveAction extends BaseAction {
|
||||
constructor() {
|
||||
super("move");
|
||||
}
|
||||
|
||||
canBeUsed(battle: Battle, ship: Ship): boolean {
|
||||
return ship.ap_current > 0;
|
||||
}
|
||||
|
||||
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
// TODO Should forbid to move too much near another ship
|
||||
var coords = ship.getLongestMove(target.x, target.y);
|
||||
return Target.newFromLocation(coords[0], coords[1]);
|
||||
}
|
||||
}
|
||||
}
|
34
src/scripts/game/specs/MoveAction.spec.ts
Normal file
34
src/scripts/game/specs/MoveAction.spec.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
module SpaceTac.Game.Specs {
|
||||
describe("MoveAction", function () {
|
||||
it("checks movement against remaining AP", function(){
|
||||
var ship = new Ship(null, "Test");
|
||||
ship.ap_current = 6;
|
||||
ship.movement_cost = 2;
|
||||
ship.arena_x = 0;
|
||||
ship.arena_y = 0;
|
||||
var action = new Actions.MoveAction();
|
||||
|
||||
var result = action.checkTarget(null, ship, Target.newFromLocation(0, 2));
|
||||
expect(result).toEqual(Target.newFromLocation(0, 2));
|
||||
|
||||
var result = action.checkTarget(null, ship, Target.newFromLocation(0, 8));
|
||||
expect(result).toEqual(Target.newFromLocation(0, 3));
|
||||
|
||||
ship.ap_current = 0;
|
||||
var result = action.checkTarget(null, ship, Target.newFromLocation(0, 8));
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("forbids targetting a ship", function(){
|
||||
var ship1 = new Ship(null, "Test1");
|
||||
var ship2 = new Ship(null, "Test2");
|
||||
var action = new Actions.MoveAction();
|
||||
|
||||
var result = action.checkTarget(null, ship1, Target.newFromShip(ship1));
|
||||
expect(result).toBeNull();
|
||||
|
||||
var result = action.checkTarget(null, ship1, Target.newFromShip(ship2));
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
module SpaceTac.View.Widgets {
|
||||
// Icon to activate a ship capability (move, fire...)
|
||||
export class CapabilityIcon extends Phaser.Button {
|
||||
export class ActionIcon extends Phaser.Button {
|
||||
constructor(battleview: BattleView, x: number, y:number, code: string) {
|
||||
super(battleview.game, x, y, 'capability-' + code);
|
||||
super(battleview.game, x, y, 'action-' + code);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue