Fix buying energy with gems not giving the correct amount

This commit is contained in:
Melledy
2025-11-20 05:37:21 -08:00
parent 480d0d60b3
commit 6289e3f1b6
2 changed files with 16 additions and 5 deletions

View File

@@ -635,20 +635,27 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
return change.setSuccess(true); return change.setSuccess(true);
} }
public PlayerChangeInfo buyEnergy() { public PlayerChangeInfo buyEnergy(int count) {
// Validate count
if (count <= 0 || count > 6) {
return null;
}
// Create change info // Create change info
var change = new PlayerChangeInfo(); var change = new PlayerChangeInfo();
// Make sure we have the gems // Make sure we have the gems
if (!this.hasItem(GameConstants.ENERGY_BUY_ITEM_ID, 30)) { int cost = 30 * count;
if (!this.hasItem(GameConstants.ENERGY_BUY_ITEM_ID, cost)) {
return change; return change;
} }
// Remove gems // Remove gems
this.removeItem(GameConstants.ENERGY_BUY_ITEM_ID, 30, change); this.removeItem(GameConstants.ENERGY_BUY_ITEM_ID, cost, change);
// Add energy // Add energy
this.getPlayer().addEnergy(60, change); this.getPlayer().addEnergy(60 * count, change);
// Success // Success
return change; return change;

View File

@@ -3,6 +3,7 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler; import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId; import emu.nebula.net.NetMsgId;
import emu.nebula.proto.EnergyBuy.EnergyBuyResp; import emu.nebula.proto.EnergyBuy.EnergyBuyResp;
import emu.nebula.proto.Public.UI32;
import emu.nebula.net.HandlerId; import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession; import emu.nebula.net.GameSession;
@@ -11,8 +12,11 @@ public class HandlerEnergyBuyReq extends NetHandler {
@Override @Override
public byte[] handle(GameSession session, byte[] message) throws Exception { public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = UI32.parseFrom(message);
// Buy energy // Buy energy
var change = session.getPlayer().getInventory().buyEnergy(); var change = session.getPlayer().getInventory().buyEnergy(req.getValue());
if (change == null) { if (change == null) {
return session.encodeMsg(NetMsgId.energy_buy_failed_ack); return session.encodeMsg(NetMsgId.energy_buy_failed_ack);