Implement infinite arena

This commit is contained in:
Melledy
2025-11-09 07:22:21 -08:00
parent 7d5fef1020
commit 3f7b0d366d
7 changed files with 259 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.InfinityTowerApply.InfinityTowerApplyReq;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.infinity_tower_apply_req)
public class HandlerInfinityTowerApplyReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Template hanlder
var req = InfinityTowerApplyReq.parseFrom(message);
// Apply
boolean success = session.getPlayer().getInfinityTowerManager().apply(req.getLevelId(), req.getBuildId());
if (!success) {
return session.encodeMsg(NetMsgId.infinity_tower_apply_failed_ack);
}
// Encode and send
return session.encodeMsg(NetMsgId.infinity_tower_apply_succeed_ack);
}
}

View File

@@ -0,0 +1,22 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.InfinityTowerInfo.InfinityTowerInfoResp;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.infinity_tower_info_req)
public class HandlerInfinityTowerInfoReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Build response
var rsp = InfinityTowerInfoResp.newInstance()
.setBountyLevel(0);
// Encode and send
return session.encodeMsg(NetMsgId.infinity_tower_info_succeed_ack, rsp);
}
}

View File

@@ -0,0 +1,49 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.InfinityTowerSettle.InfinityTowerSettleReq;
import emu.nebula.proto.InfinityTowerSettle.InfinityTowerSettleResp;
import emu.nebula.net.HandlerId;
import emu.nebula.game.inventory.ItemParamMap;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.infinity_tower_settle_req)
public class HandlerInfinityTowerSettleReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = InfinityTowerSettleReq.parseFrom(message);
// Settle
var manager = session.getPlayer().getInfinityTowerManager();
var change = manager.settle(req.getValue());
if (change == null) {
return session.encodeMsg(NetMsgId.infinity_tower_settle_failed_ack);
}
// Get next level
int nextLevel = manager.getLevelId() + 1;
// Try to apply for next level
if (!manager.apply(nextLevel, -1)) {
nextLevel = 0;
}
// Build response
var rsp = InfinityTowerSettleResp.newInstance()
.setNextLevelId(nextLevel)
.setBountyLevel(manager.getBountyLevel())
.setChange(change.toProto());
if (change.getExtraData() != null && change.getExtraData() instanceof ItemParamMap rewards) {
rewards.toItemTemplateStream().forEach(rsp::addShow);
}
// Encode and send
return session.encodeMsg(NetMsgId.infinity_tower_settle_succeed_ack, rsp);
}
}