1
0
Fork 0

Added dynamic fading on move actions

This commit is contained in:
Michaël Lemaire 2015-02-26 01:00:00 +01:00
parent 675a7f80c9
commit 9814f08883
5 changed files with 38 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

View file

@ -35,6 +35,15 @@ module SpaceTac.Game {
return remaining_ap >= ap_usage; 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 // Method to check if a target is applicable for this action
// Will call checkLocationTarget or checkShipTarget by default // Will call checkLocationTarget or checkShipTarget by default
checkTarget(battle: Battle, ship: Ship, target: Target): Target { checkTarget(battle: Battle, ship: Ship, target: Target): Target {

View file

@ -19,6 +19,15 @@ module SpaceTac.Game {
return remaining_ap > 0.0001; 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 { checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
// TODO Should forbid to move too much near another ship // TODO Should forbid to move too much near another ship
var max_distance = this.equipment.distance * ship.ap_current.current / this.equipment.ap_usage; 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 { 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); ship.moveTo(target.x, target.y);
var cost = this.equipment.ap_usage * distance / this.equipment.distance;
ship.useActionPoints(cost); ship.useActionPoints(cost);
return true; return true;
} }

View file

@ -80,7 +80,7 @@ module SpaceTac.View {
this.bar.actionEnded(); this.bar.actionEnded();
// Update fading statuses // 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 // Set the lighting color to highlight
if (this.game.renderType !== Phaser.HEADLESS) { if (this.game.renderType !== Phaser.HEADLESS) {
@ -105,6 +105,7 @@ module SpaceTac.View {
processHover(target: Game.Target): void { processHover(target: Game.Target): void {
target = this.action.checkTarget(this.battleview.battle, this.ship, target); target = this.action.checkTarget(this.battleview.battle, this.ship, target);
this.targetting.setTarget(target, false); this.targetting.setTarget(target, false);
this.bar.updateFadings(this.action.getActionPointsUsage(this.battleview.battle, this.ship, target));
} }
// Called when a target is selected // Called when a target is selected
@ -123,6 +124,7 @@ module SpaceTac.View {
} }
this.layer_active.tint = 0xFFFFFF; this.layer_active.tint = 0xFFFFFF;
this.updateActiveStatus(); this.updateActiveStatus();
this.updateFadingStatus(this.ship.ap_current.current);
} }
// Update the active status, from the action canBeUsed result // 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 // Update the fading status, given an hypothetical remaining AP
updateFadingStatus(remaining_ap: number): void { updateFadingStatus(remaining_ap: number): void {
this.fading = !this.action.canBeUsed(this.battleview.battle, this.ship, remaining_ap); 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);
} }
} }
} }

View file

@ -35,6 +35,8 @@ module SpaceTac.View.Specs {
inbattleview_it("mark actions that would become unavailable after use", (battleview: BattleView) => { inbattleview_it("mark actions that would become unavailable after use", (battleview: BattleView) => {
var bar = battleview.action_bar; var bar = battleview.action_bar;
var ship = new Game.Ship(); var ship = new Game.Ship();
ship.arena_x = 1;
ship.arena_y = 8;
var engine = (new Game.Equipments.ConventionalEngine()).generate(); var engine = (new Game.Equipments.ConventionalEngine()).generate();
engine.ap_usage = 8; engine.ap_usage = 8;
engine.distance = 4; engine.distance = 4;
@ -82,6 +84,19 @@ module SpaceTac.View.Specs {
ship.ap_current.set(3); ship.ap_current.set(3);
bar.actions[1].processClick(); bar.actions[1].processClick();
checkFading([0, 1, 2], [3]); 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]);
}); });
}); });
} }