mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 04:45:02 +01:00
Implement buying energy
This commit is contained in:
@@ -9,8 +9,9 @@ public class GameConstants {
|
||||
public static final int INTRO_GUIDE_ID = 1;
|
||||
|
||||
public static final int GOLD_ITEM_ID = 1;
|
||||
public static final int ENERGY_BUY_ITEM_ID = 2;
|
||||
public static final int EXP_ITEM_ID = 21;
|
||||
|
||||
|
||||
public static final int MAX_ENERGY = 240;
|
||||
public static final int ENERGY_REGEN_TIME = 360; // Seconds
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package emu.nebula.game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import emu.nebula.GameConstants;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
@@ -337,6 +338,25 @@ public class Inventory extends PlayerManager {
|
||||
return change.setSuccess(true);
|
||||
}
|
||||
|
||||
public PlayerChangeInfo buyEnergy() {
|
||||
// Create change info
|
||||
var change = new PlayerChangeInfo();
|
||||
|
||||
// Make sure we have the gems
|
||||
if (!this.verifyItem(GameConstants.ENERGY_BUY_ITEM_ID, 30)) {
|
||||
return change;
|
||||
}
|
||||
|
||||
// Remove gems
|
||||
this.removeItem(GameConstants.ENERGY_BUY_ITEM_ID, 30, change);
|
||||
|
||||
// Add energy
|
||||
this.getPlayer().addEnergy(60, change);
|
||||
|
||||
// Success
|
||||
return change;
|
||||
}
|
||||
|
||||
public PlayerChangeInfo useItem(int id, int count, PlayerChangeInfo change) {
|
||||
// Changes
|
||||
if (change == null) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.EnergyBuy.EnergyBuyResp;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.energy_buy_req)
|
||||
public class HandlerEnergyBuyReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Buy energy
|
||||
var change = session.getPlayer().getInventory().buyEnergy();
|
||||
|
||||
if (change == null) {
|
||||
return session.encodeMsg(NetMsgId.energy_buy_failed_ack);
|
||||
}
|
||||
|
||||
// Build response
|
||||
var rsp = EnergyBuyResp.newInstance()
|
||||
.setChange(change.toProto())
|
||||
.setCount(0); // TODO max energy buy count per day
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.energy_buy_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user