Added end turn action
This commit is contained in:
parent
16b67b94a7
commit
709c43ade4
|
@ -88,7 +88,7 @@ module SpaceTac.Game {
|
|||
// actions that are not allowed/available at all on the ship
|
||||
getAvailableActions(): BaseAction[] {
|
||||
// TODO
|
||||
return [new MoveAction()];
|
||||
return [new MoveAction(), new EndTurnAction()];
|
||||
}
|
||||
|
||||
// Consumes action points
|
||||
|
|
|
@ -4,8 +4,13 @@ module SpaceTac.Game {
|
|||
// Identifier code for the type of action
|
||||
code: string;
|
||||
|
||||
constructor(code: string) {
|
||||
// Boolean at true if the action needs a target
|
||||
needs_target: boolean;
|
||||
|
||||
// Create the action
|
||||
constructor(code: string, needs_target: boolean) {
|
||||
this.code = code;
|
||||
this.needs_target = needs_target;
|
||||
}
|
||||
|
||||
// Check basic conditions to know if the ship can use this action at all
|
||||
|
@ -19,10 +24,14 @@ module SpaceTac.Game {
|
|||
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 if (target) {
|
||||
if (target.ship) {
|
||||
return this.checkShipTarget(battle, ship, target);
|
||||
} else {
|
||||
return this.checkLocationTarget(battle, ship, target);
|
||||
}
|
||||
} else {
|
||||
return this.checkLocationTarget(battle, ship, target);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,11 +49,15 @@ module SpaceTac.Game {
|
|||
|
||||
// Apply an action, returning true if it was successful
|
||||
apply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
target = this.checkTarget(battle, ship, target);
|
||||
if (!target) {
|
||||
if (this.canBeUsed(battle, ship)) {
|
||||
target = this.checkTarget(battle, ship, target);
|
||||
if (!target && this.needs_target) {
|
||||
return false;
|
||||
}
|
||||
return this.customApply(battle, ship, target);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return this.customApply(battle, ship, target);
|
||||
}
|
||||
|
||||
// Method to reimplement to apply a action
|
||||
|
|
17
src/scripts/game/actions/EndTurnAction.ts
Normal file
17
src/scripts/game/actions/EndTurnAction.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
module SpaceTac.Game {
|
||||
// Action to end the ship's turn
|
||||
export class EndTurnAction extends BaseAction {
|
||||
constructor() {
|
||||
super("endturn", false);
|
||||
}
|
||||
|
||||
canBeUsed(battle: Battle, ship: Ship): boolean {
|
||||
return battle.playing_ship === ship;
|
||||
}
|
||||
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
battle.advanceToNextShip();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ module SpaceTac.Game {
|
|||
// Action to move to a given location
|
||||
export class MoveAction extends BaseAction {
|
||||
constructor() {
|
||||
super("move");
|
||||
super("move", true);
|
||||
}
|
||||
|
||||
canBeUsed(battle: Battle, ship: Ship): boolean {
|
||||
|
|
|
@ -15,7 +15,7 @@ module SpaceTac.View {
|
|||
private targetting: Targetting;
|
||||
|
||||
// Create an icon for a single ship action
|
||||
constructor(bar: ActionBar, x: number, y:number, ship: Game.Ship, action: Game.BaseAction) {
|
||||
constructor(bar: ActionBar, x: number, y: number, ship: Game.Ship, action: Game.BaseAction) {
|
||||
this.battleview = bar.battleview;
|
||||
this.ship = ship;
|
||||
this.action = action;
|
||||
|
@ -23,6 +23,8 @@ module SpaceTac.View {
|
|||
super(bar.game, x, y, 'action-' + action.code);
|
||||
bar.add(this);
|
||||
|
||||
// TODO Handle action.canBeUsed() result to enable/disable the button
|
||||
|
||||
this.onInputUp.add(() => {
|
||||
this.processClick();
|
||||
}, this);
|
||||
|
@ -30,12 +32,20 @@ module SpaceTac.View {
|
|||
|
||||
// Process a click event on the action icon
|
||||
processClick() {
|
||||
if (!this.action.canBeUsed(this.battleview.battle, this.ship)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Action started", this.action);
|
||||
|
||||
this.targetting = this.battleview.enterTargettingMode();
|
||||
this.targetting.setSource(this.battleview.arena.findShipSprite(this.ship));
|
||||
this.targetting.targetSelected.add(this.processSelection, this);
|
||||
this.targetting.targetHovered.add(this.processHover, this);
|
||||
if (this.action.needs_target) {
|
||||
this.targetting = this.battleview.enterTargettingMode();
|
||||
this.targetting.setSource(this.battleview.arena.findShipSprite(this.ship));
|
||||
this.targetting.targetSelected.add(this.processSelection, this);
|
||||
this.targetting.targetHovered.add(this.processHover, this);
|
||||
} else {
|
||||
this.processSelection(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Called when a target is hovered
|
||||
|
@ -49,8 +59,9 @@ module SpaceTac.View {
|
|||
processSelection(target: Game.Target) {
|
||||
console.log("Action target", this.action, target);
|
||||
|
||||
this.action.apply(this.battleview.battle, this.ship, target);
|
||||
this.battleview.exitTargettingMode();
|
||||
if (this.action.apply(this.battleview.battle, this.ship, target)) {
|
||||
this.battleview.exitTargettingMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ module SpaceTac.View {
|
|||
// Update visual effects for current targetting
|
||||
update(): void {
|
||||
if (this.battleview) {
|
||||
if (this.source) {
|
||||
if (this.source && this.target) {
|
||||
this.line.clear();
|
||||
this.line.lineStyle(3, 0xFFFFFF);
|
||||
this.line.moveTo(this.source.x, this.source.y);
|
||||
|
|
Loading…
Reference in a new issue