Implement commissions

This commit is contained in:
Melledy
2025-11-12 03:25:23 -08:00
parent d4a7aa0320
commit be4a006c66
19 changed files with 526 additions and 40 deletions
@@ -2,6 +2,9 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.AgentApply.AgentApplyReq;
import emu.nebula.proto.AgentApply.AgentApplyResp;
import emu.nebula.proto.AgentApply.AgentRespInfo;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@@ -10,7 +13,36 @@ public class HandlerAgentApplyReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
return session.encodeMsg(NetMsgId.agent_apply_failed_ack);
// Parse request
var req = AgentApplyReq.parseFrom(message);
// Build response
var rsp = AgentApplyResp.newInstance();
// Apply for commissions
for (var apply : req.getApply()) {
// Apply
var agent = session.getPlayer().getAgentManager().apply(
apply.getId(),
apply.getProcessTime(),
apply.getCharIds()
);
// Serialize to proto
var info = AgentRespInfo.newInstance()
.setId(agent.getId())
.setBeginTime(agent.getStart());
rsp.addInfos(info);
}
// Save
if (rsp.getInfos().length() > 0) {
session.getPlayer().getAgentManager().save();
}
// Encode and send
return session.encodeMsg(NetMsgId.agent_apply_succeed_ack, rsp);
}
}