mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 04:45:02 +01:00
Fix buying energy with gems not giving the correct amount
This commit is contained in:
@@ -635,20 +635,27 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
return change.setSuccess(true);
|
||||
}
|
||||
|
||||
public PlayerChangeInfo buyEnergy() {
|
||||
public PlayerChangeInfo buyEnergy(int count) {
|
||||
// Validate count
|
||||
if (count <= 0 || count > 6) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create change info
|
||||
var change = new PlayerChangeInfo();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Remove gems
|
||||
this.removeItem(GameConstants.ENERGY_BUY_ITEM_ID, 30, change);
|
||||
this.removeItem(GameConstants.ENERGY_BUY_ITEM_ID, cost, change);
|
||||
|
||||
// Add energy
|
||||
this.getPlayer().addEnergy(60, change);
|
||||
this.getPlayer().addEnergy(60 * count, change);
|
||||
|
||||
// Success
|
||||
return change;
|
||||
|
||||
@@ -3,6 +3,7 @@ package emu.nebula.server.handlers;
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.EnergyBuy.EnergyBuyResp;
|
||||
import emu.nebula.proto.Public.UI32;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@@ -11,8 +12,11 @@ public class HandlerEnergyBuyReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = UI32.parseFrom(message);
|
||||
|
||||
// Buy energy
|
||||
var change = session.getPlayer().getInventory().buyEnergy();
|
||||
var change = session.getPlayer().getInventory().buyEnergy(req.getValue());
|
||||
|
||||
if (change == null) {
|
||||
return session.encodeMsg(NetMsgId.energy_buy_failed_ack);
|
||||
|
||||
Reference in New Issue
Block a user