Added dynamic fading on move actions
This commit is contained in:
parent
675a7f80c9
commit
9814f08883
BIN
src/assets/images/battle/action-fading.png
Normal file
BIN
src/assets/images/battle/action-fading.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 720 B |
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue