From 9814f0888374661daeb0b55f8728ee67f4da0d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 26 Feb 2015 01:00:00 +0100 Subject: [PATCH] Added dynamic fading on move actions --- src/assets/images/battle/action-fading.png | Bin 0 -> 720 bytes src/scripts/game/actions/BaseAction.ts | 9 +++++++++ src/scripts/game/actions/MoveAction.ts | 12 ++++++++++-- src/scripts/view/battle/ActionIcon.ts | 6 ++++-- src/scripts/view/specs/ActionBar.spec.ts | 15 +++++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/assets/images/battle/action-fading.png diff --git a/src/assets/images/battle/action-fading.png b/src/assets/images/battle/action-fading.png new file mode 100644 index 0000000000000000000000000000000000000000..a26a3aa1baeb41359f9f06a9dded8f8dec8d2a02 GIT binary patch literal 720 zcmV;>0x$iEP)Dlzx^#fmP!EBy!#0RfH>gz>>&F1U>;E20u{gnbkt#8Z``DR z00jc*_BNRr%#4bwD5IzpKzEUVqLKhfK~ZUdB%r87Ko3FP^uWg-FYT{xv48-8hyW0X zd;2Cy0Nt5HAgoRowx5%lx;;doD-bb&r+#8U>P>2v*RKFv0(c&CpD}<`n-l>EDS*^M zYU=h7%wMMfq;lMZ29XqyI+LaxF_n;{fB{%nTSzG-4dBh{WU(FcdV(c`b|t+X`kKg$L5!mzM=VQ|QdY4s z0cB%SZXJ}JNy!F{3}|+fayMvplQbAKt4X_0uAe~kdhQ3sEFozbvDwB=(}>Mtl176j zHA$;MlbNKgq$h`D0nn(BGous{kMmNdIh>ZrxBA`JbSp_s0Bugbd3MA`*l2y;{XFvy5<*%pH(;;>+GpIPCZ+CCR8`#65&FId@3E>eGr;x$?N!|C zdV`KS5Yg_hPmcpi*(a_35#adj02NnH+GHJ2)N9FOMwI|a^zQcUeTxu+*^*9vcLQ)c zdOf4-xd=eweEIOJsQVRtnS2p$+!T+;TD&d*0000= 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]); }); }); }