diff --git a/src/assets/images/battle/action-fading.png b/src/assets/images/battle/action-fading.png new file mode 100644 index 0000000..a26a3aa Binary files /dev/null and b/src/assets/images/battle/action-fading.png differ diff --git a/src/scripts/game/actions/BaseAction.ts b/src/scripts/game/actions/BaseAction.ts index dbd2352..c886b98 100644 --- a/src/scripts/game/actions/BaseAction.ts +++ b/src/scripts/game/actions/BaseAction.ts @@ -35,6 +35,15 @@ module SpaceTac.Game { return remaining_ap >= ap_usage; } + // Get the number of action points the action applied to a target would use + getActionPointsUsage(battle: Battle, ship: Ship, target: Target): number { + if (this.equipment) { + return this.equipment.ap_usage; + } else { + return 0; + } + } + // 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 { diff --git a/src/scripts/game/actions/MoveAction.ts b/src/scripts/game/actions/MoveAction.ts index 8a6c294..639fe59 100644 --- a/src/scripts/game/actions/MoveAction.ts +++ b/src/scripts/game/actions/MoveAction.ts @@ -19,6 +19,15 @@ module SpaceTac.Game { return remaining_ap > 0.0001; } + getActionPointsUsage(battle: Battle, ship: Ship, target: Target): number { + if (target === null) { + return 0; + } + + var distance = Target.newFromShip(ship).getDistanceTo(target); + return this.equipment.ap_usage * distance / this.equipment.distance; + } + 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; @@ -26,9 +35,8 @@ module SpaceTac.Game { } protected customApply(battle: Battle, ship: Ship, target: Target): boolean { - var distance = Target.newFromShip(ship).getDistanceTo(target); + var cost = this.getActionPointsUsage(battle, ship, target); ship.moveTo(target.x, target.y); - var cost = this.equipment.ap_usage * distance / this.equipment.distance; ship.useActionPoints(cost); return true; } diff --git a/src/scripts/view/battle/ActionIcon.ts b/src/scripts/view/battle/ActionIcon.ts index 49f7d33..3c2a34e 100644 --- a/src/scripts/view/battle/ActionIcon.ts +++ b/src/scripts/view/battle/ActionIcon.ts @@ -80,7 +80,7 @@ module SpaceTac.View { this.bar.actionEnded(); // Update fading statuses - this.bar.updateFadings(this.action.equipment.ap_usage); + this.bar.updateFadings(this.action.getActionPointsUsage(this.battleview.battle, this.ship, null)); // Set the lighting color to highlight if (this.game.renderType !== Phaser.HEADLESS) { @@ -105,6 +105,7 @@ module SpaceTac.View { processHover(target: Game.Target): void { target = this.action.checkTarget(this.battleview.battle, this.ship, target); this.targetting.setTarget(target, false); + this.bar.updateFadings(this.action.getActionPointsUsage(this.battleview.battle, this.ship, target)); } // Called when a target is selected @@ -123,6 +124,7 @@ module SpaceTac.View { } this.layer_active.tint = 0xFFFFFF; this.updateActiveStatus(); + this.updateFadingStatus(this.ship.ap_current.current); } // Update the active status, from the action canBeUsed result @@ -136,7 +138,7 @@ module SpaceTac.View { // Update the fading status, given an hypothetical remaining AP updateFadingStatus(remaining_ap: number): void { this.fading = !this.action.canBeUsed(this.battleview.battle, this.ship, remaining_ap); - Animation.setVisibility(this.game, this.layer_fading, this.fading, 200); + Animation.setVisibility(this.game, this.layer_fading, this.fading && this.active, 200); } } } diff --git a/src/scripts/view/specs/ActionBar.spec.ts b/src/scripts/view/specs/ActionBar.spec.ts index e5a4634..cd8d99c 100644 --- a/src/scripts/view/specs/ActionBar.spec.ts +++ b/src/scripts/view/specs/ActionBar.spec.ts @@ -35,6 +35,8 @@ module SpaceTac.View.Specs { inbattleview_it("mark actions that would become unavailable after use", (battleview: BattleView) => { var bar = battleview.action_bar; var ship = new Game.Ship(); + ship.arena_x = 1; + ship.arena_y = 8; var engine = (new Game.Equipments.ConventionalEngine()).generate(); engine.ap_usage = 8; engine.distance = 4; @@ -82,6 +84,19 @@ module SpaceTac.View.Specs { ship.ap_current.set(3); bar.actions[1].processClick(); checkFading([0, 1, 2], [3]); + + // Dynamic AP usage for move actions + ship.ap_current.set(6); + bar.actions[0].processClick(); + checkFading([], [0, 1, 2, 3]); + bar.actions[0].processHover(Game.Target.newFromLocation(2, 8)); + checkFading([2], [0, 1, 3]); + bar.actions[0].processHover(Game.Target.newFromLocation(3, 8)); + checkFading([1, 2], [0, 3]); + bar.actions[0].processHover(Game.Target.newFromLocation(4, 8)); + checkFading([0, 1, 2], [3]); + bar.actions[0].processHover(Game.Target.newFromLocation(5, 8)); + checkFading([0, 1, 2], [3]); }); }); }