Implement item quick growth

This commit is contained in:
Melledy
2025-11-08 22:00:06 -08:00
parent 2c18963b08
commit 66ce7cf698
4 changed files with 55 additions and 9 deletions

View File

@@ -0,0 +1,40 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.ItemQuickGrowth.ItemGrowthReq;
import emu.nebula.net.HandlerId;
import emu.nebula.game.player.PlayerChangeInfo;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.item_quick_growth_req)
public class HandlerItemQuickGrowthReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = ItemGrowthReq.parseFrom(message);
// Init change
var change = new PlayerChangeInfo();
// Create items
for (var item : req.getList()) {
if (item.hasProduct()) {
session.getPlayer().getInventory().produce(
item.getProduct().getId(),
item.getProduct().getNum(),
change
);
}
}
if (change.isEmpty()) {
return session.encodeMsg(NetMsgId.item_quick_growth_failed_ack);
}
// Send response
return session.encodeMsg(NetMsgId.item_quick_growth_succeed_ack, change.toProto());
}
}