Implement monolith potential book

This commit is contained in:
Melledy committed 2026-10-18 23:35:41 -07:00
1 parent b7d6278b26
commit 465ccd769e
14 files changed
+403 -3

No files matched your search

@@ -0,0 +1,67 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.Public.UI32;
import emu.nebula.proto.PublicStarTower.StarTowerBookPotential;
import emu.nebula.proto.StarTowerBookCharPotentialGet.StarTowerBookPotentialGetResp;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import emu.nebula.net.HandlerId;
import emu.nebula.data.GameData;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.star_tower_book_char_potential_get_req)
public class HandlerStarTowerBookCharPotentialGetReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse character id
var req = UI32.parseFrom(message);
var character = session.getPlayer().getCharacters().getCharacterById(req.getValue());
if (character == null) {
return session.encodeMsg(NetMsgId.star_tower_book_char_potential_get_failed_ack);
}
// Get potentials
var potentialDef = GameData.getCharPotentialDataTable().get(character.getCharId());
if (potentialDef == null) {
return session.encodeMsg(NetMsgId.star_tower_book_char_potential_get_failed_ack);
}
// Build response
var rsp = StarTowerBookPotentialGetResp.newInstance();
// Get count
var potentials = new IntArrayList();
potentials.addElements(potentials.size(), potentialDef.getMasterSpecificPotentialIds());
potentials.addElements(potentials.size(), potentialDef.getAssistSpecificPotentialIds());
potentials.addElements(potentials.size(), potentialDef.getCommonPotentialIds());
potentials.addElements(potentials.size(), potentialDef.getMasterNormalPotentialIds());
potentials.addElements(potentials.size(), potentialDef.getAssistNormalPotentialIds());
// Serialize potentials
for (var potentialId : potentials) {
int level = character.getSeenPotentialLevel(potentialId);
if (level > 0) {
var info = StarTowerBookPotential.newInstance()
.setId(potentialId)
.setLevel(level);
rsp.addPotentials(info);
}
}
// Add received reward ids
for (int rewardId : character.getReceivedPotentialRewards()) {
rsp.addReceivedIds(rewardId);
}
// Encode and send
return session.encodeMsg(NetMsgId.star_tower_book_char_potential_get_succeed_ack, rsp);
}
}
@@ -0,0 +1,33 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.PublicStarTower.StarTowerBookCharPotentialBrief;
import emu.nebula.proto.StarTowerBookPotentialBriefListGet.StarTowerBookPotentialBriefListResp;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.star_tower_book_potential_brief_list_get_req)
public class HandlerStarTowerBookPotentialBriefListGetReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Build response
var rsp = StarTowerBookPotentialBriefListResp.newInstance();
// Get all characters
var characters = session.getPlayer().getCharacters().getCharacterCollection();
for (var character : characters) {
var info = StarTowerBookCharPotentialBrief.newInstance()
.setCharId(character.getCharId())
.setCount(character.getTotalSeenPotentials());
rsp.addInfos(info);
}
// Encode and send
return session.encodeMsg(NetMsgId.star_tower_book_potential_brief_list_get_succeed_ack, rsp);
}
}
@@ -0,0 +1,43 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.Public.UI32;
import emu.nebula.proto.StarTowerBookPotentialRewardReceive.StarTowerBookPotentialRewardReceiveResp;
import it.unimi.dsi.fastutil.ints.IntList;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.star_tower_book_potential_reward_receive_req)
public class HandlerStarTowerBookPotentialRewardReceiveReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse character id
var req = UI32.parseFrom(message);
var character = session.getPlayer().getCharacters().getCharacterById(req.getValue());
if (character == null) {
return session.encodeMsg(NetMsgId.star_tower_book_potential_reward_receive_failed_ack);
}
// Claim rewards
var change = character.claimPotentialBookRewards();
if (change == null) {
return session.encodeMsg(NetMsgId.star_tower_book_potential_reward_receive_failed_ack);
}
// Build response
var rsp = StarTowerBookPotentialRewardReceiveResp.newInstance()
.setChange(change.toProto());
// Add list of received reward ids to response
var received = (IntList) change.getExtraData();
received.forEach(rsp::addReceivedIds);
// Encode and send
return session.encodeMsg(NetMsgId.star_tower_book_potential_reward_receive_succeed_ack, rsp);
}
}