1
0
Fork 0

Fixed displaying of negative power cost (power recovery)

This commit is contained in:
Michaël Lemaire 2017-11-29 23:50:40 +01:00
parent 05a0607445
commit bc99d6aa6b
5 changed files with 25 additions and 17 deletions

View file

@ -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;
}

View file

@ -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));

View file

@ -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());

View file

@ -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) {

View file

@ -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`;
}
}
}