Implement Finale Echoing sweep

This commit is contained in:
Melledy
2026-03-16 21:35:43 -07:00
parent 4744618ce9
commit 574cbb34ba
2 changed files with 106 additions and 0 deletions
@@ -12,6 +12,7 @@ import emu.nebula.data.resources.ActivityDef;
import emu.nebula.data.resources.JointDrill2LevelDef; import emu.nebula.data.resources.JointDrill2LevelDef;
import emu.nebula.game.activity.ActivityManager; import emu.nebula.game.activity.ActivityManager;
import emu.nebula.game.activity.GameActivity; import emu.nebula.game.activity.GameActivity;
import emu.nebula.game.inventory.ItemParamMap;
import emu.nebula.game.jointdrill.JointDrillBuild; import emu.nebula.game.jointdrill.JointDrillBuild;
import emu.nebula.game.jointdrill.JointDrillRankEntry; import emu.nebula.game.jointdrill.JointDrillRankEntry;
import emu.nebula.game.jointdrill.JointDrillScore; import emu.nebula.game.jointdrill.JointDrillScore;
@@ -245,6 +246,55 @@ public class JointDrillActivity extends GameActivity {
return score; return score;
} }
public synchronized PlayerChangeInfo sweep(int levelId, int count) {
// Sanity check
if (count <= 0) {
return null;
}
// Check if the player has completed this level
if (!this.getPassedLevels().containsKey(levelId)) {
return null;
}
// Verify that we have enough tickets
if (!getPlayer().getInventory().hasItem(GameConstants.JOINT_DRILL_TICKET_ID, count)) {
return null;
}
// Get level data
var level = GameData.getJointDrill2LevelDataTable().get(levelId);
if (level == null) {
return null;
}
// Setup variables
var change = new PlayerChangeInfo();
var totalRewards = new ItemParamMap();
var list = new ArrayList<>();
// Consume tickets
getPlayer().getInventory().removeItem(GameConstants.JOINT_DRILL_TICKET_ID, count, change);
// Generate rewards from sweep
for (int i = 0; i < count; i++) {
var rewards = level.getRewards().generate();
totalRewards.add(rewards);
list.add(rewards);
}
// Add rewards to player
getPlayer().getInventory().addItems(totalRewards, change);
// Set reward list as extra data for change info
change.setExtraData(list);
// Complete
return change;
}
// Proto // Proto
@Override @Override
@@ -0,0 +1,56 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.JointDrillSweep.JointDrillSweepReq;
import emu.nebula.proto.JointDrillSweep.JointDrillSweepResp;
import emu.nebula.proto.Public.ItemTpls;
import emu.nebula.net.HandlerId;
import java.util.List;
import emu.nebula.game.activity.type.JointDrillActivity;
import emu.nebula.game.inventory.ItemParamMap;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.joint_drill_sweep_req)
public class HandlerJointDrillSweepReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Get joint drill activity
var activity = session.getPlayer().getActivityManager().getFirstActivity(JointDrillActivity.class);
if (activity == null) {
return session.encodeMsg(NetMsgId.joint_drill_sweep_failed_ack);
}
// Parse request
var req = JointDrillSweepReq.parseFrom(message);
// Apply for joint drill stage
var change = activity.sweep(req.getLevelId(), req.getCount());
if (change == null) {
return session.encodeMsg(NetMsgId.joint_drill_sweep_failed_ack);
}
// Create response packet
var rsp = JointDrillSweepResp.newInstance()
.setChange(change.toProto());
// Encode sweep rewards to proto
@SuppressWarnings("unchecked")
var list = (List<ItemParamMap>) change.getExtraData();
for (var rewards : list) {
var templates = ItemTpls.newInstance();
rewards.toItemTemplateStream().forEach(templates::addItems);
rsp.addRewards(templates);
}
// Encode and send
return session.encodeMsg(NetMsgId.joint_drill_sweep_succeed_ack, rsp);
}
}