Fixed displaying of negative power cost (power recovery)
This commit is contained in:
parent
05a0607445
commit
bc99d6aa6b
|
@ -32,6 +32,15 @@ module TK.SpaceTac {
|
|||
return this.activated ? ActionTargettingMode.SELF : ActionTargettingMode.SPACE;
|
||||
}
|
||||
|
||||
getDefaultTarget(ship: Ship): Target {
|
||||
let harmful = any(this.effects, effect => !effect.isBeneficial());
|
||||
let distance = this.drone_radius * (harmful ? 1.1 : 0.9);
|
||||
return Target.newFromLocation(
|
||||
ship.arena_x + Math.cos(ship.arena_angle) * distance,
|
||||
ship.arena_y + Math.sin(ship.arena_angle) * distance
|
||||
);
|
||||
}
|
||||
|
||||
getRangeRadius(ship: Ship): number {
|
||||
return this.activated ? 0 : this.deploy_distance;
|
||||
}
|
||||
|
|
|
@ -18,16 +18,17 @@ module TK.SpaceTac {
|
|||
return "End ship's turn";
|
||||
}
|
||||
|
||||
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
||||
let toggled_cost = isum(imap(ship.iToggleActions(true), action => action.power));
|
||||
let power_diff = ship.getAttribute("power_generation") - toggled_cost;
|
||||
return -power_diff;
|
||||
}
|
||||
|
||||
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
|
||||
if (ship.is(battle.playing_ship)) {
|
||||
let result: BaseBattleDiff[] = [];
|
||||
let new_ship = battle.getNextShip();
|
||||
|
||||
// Generate power
|
||||
let toggled_cost = isum(imap(ship.iToggleActions(true), action => action.power));
|
||||
let power_diff = ship.getAttribute("power_generation") - toggled_cost;
|
||||
result = result.concat(ship.getValueDiffs("power", power_diff, true));
|
||||
|
||||
// Cool down equipment
|
||||
ship.listEquipment().filter(equ => equ.cooldown.heat > 0).forEach(equ => {
|
||||
result.push(new ShipCooldownDiff(ship, equ, 1));
|
||||
|
|
|
@ -74,13 +74,8 @@ module TK.SpaceTac.UI {
|
|||
if (event.code == "power_capacity") {
|
||||
this.updatePower();
|
||||
}
|
||||
} else if (event instanceof ShipActionUsedDiff) {
|
||||
} else if (event instanceof ShipActionUsedDiff || event instanceof ShipActionToggleDiff) {
|
||||
this.action_icons.forEach(action => action.refresh());
|
||||
} else if (event instanceof ShipActionToggleDiff) {
|
||||
let action_icon = first(this.action_icons, icon => icon.action.is(event.action));
|
||||
if (action_icon) {
|
||||
action_icon.refresh();
|
||||
}
|
||||
} else if (event instanceof ShipCooldownDiff) {
|
||||
let icons = this.action_icons.filter(icon => icon.action.equipment && icon.action.equipment.is(event.equipment));
|
||||
icons.forEach(icon => icon.refresh());
|
||||
|
|
|
@ -206,11 +206,12 @@ module TK.SpaceTac.UI {
|
|||
}
|
||||
|
||||
// left
|
||||
let power = this.action.getActionPointsUsage(this.ship, null);
|
||||
this.img_power.visible = bool(power);
|
||||
this.text_power.text = `${Math.abs(power)}`;
|
||||
this.text_power.fill = (power > 0) ? "#ffdd4b" : "#dbe748";
|
||||
this.text_power.alpha = disabled ? 0.2 : 1;
|
||||
if (disabled != this.disabled || selected != this.selected || toggled != this.toggled) {
|
||||
let power = this.action.getActionPointsUsage(this.ship, null);
|
||||
this.img_power.visible = toggled || (power > 0);
|
||||
this.text_power.text = `${power}`;
|
||||
this.text_power.alpha = disabled ? 0.2 : 1;
|
||||
if (disabled) {
|
||||
this.view.changeImage(this.img_power, "battle-actionbar-consumption-disabled");
|
||||
} else if (toggled) {
|
||||
|
|
|
@ -21,13 +21,15 @@ module TK.SpaceTac.UI {
|
|||
} else {
|
||||
cost = `Cost: 1 power per ${action.getDistanceByActionPoint(ship)}km`;
|
||||
}
|
||||
} else if (action.equipment) {
|
||||
} else {
|
||||
let power_usage = action.getActionPointsUsage(ship, null);
|
||||
if (power_usage) {
|
||||
if (ship.getValue("power") < power_usage) {
|
||||
cost = "Not enough power";
|
||||
} else {
|
||||
} else if (power_usage > 0) {
|
||||
cost = `Cost: ${power_usage} power`;
|
||||
} else {
|
||||
cost = `Recover: ${-power_usage} power`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue