From 300d51aaf23f04622f53fb755090ab8328822f40 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:44:54 -0800 Subject: [PATCH] Implement vampire survivor reward chest --- .../game/vampire/VampireSurvivorGame.java | 55 +++++++++++++++---- .../HandlerVampireSurvivorRewardChestReq.java | 43 +++++++++++++++ 2 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 src/main/java/emu/nebula/server/handlers/HandlerVampireSurvivorRewardChestReq.java diff --git a/src/main/java/emu/nebula/game/vampire/VampireSurvivorGame.java b/src/main/java/emu/nebula/game/vampire/VampireSurvivorGame.java index 95babbd..3ba9dc9 100644 --- a/src/main/java/emu/nebula/game/vampire/VampireSurvivorGame.java +++ b/src/main/java/emu/nebula/game/vampire/VampireSurvivorGame.java @@ -18,6 +18,7 @@ public class VampireSurvivorGame { private IntSet cards; + // Reward selector private int rewardLevel; private IntList rewards; @@ -31,14 +32,9 @@ public class VampireSurvivorGame { this.calcRewards(); } - public void calcRewards() { - // Clear reward list first - this.rewards.clear(); - - // Increment level - this.rewardLevel++; - + private WeightedList getRandom() { var random = new WeightedList(); + for (var card : GameData.getFateCardDataTable()) { // Filter only vampire surv cards if (!card.isIsVampire()) { @@ -54,6 +50,19 @@ public class VampireSurvivorGame { random.add(100, card.getId()); } + return random; + } + + public void calcRewards() { + // Clear reward list first + this.rewards.clear(); + + // Increment level + this.rewardLevel++; + + // Get random selector + var random = this.getRandom(); + // Add 2 rewards this.getRewards().add(random.next().intValue()); this.getRewards().add(random.next().intValue()); @@ -66,16 +75,42 @@ public class VampireSurvivorGame { } // Get fate card id - int id = this.getRewards().getInt(index); + int cardId = this.getRewards().getInt(index); // Add to cards - this.getCards().add(id); + this.getCards().add(cardId); // Reroll rewards this.calcRewards(); // Success - return id; + return cardId; + } + + public IntList calcRewardChest(int event, int number) { + // Init variables + var chest = new IntArrayList(); + int count = 2; + + for (int i = 0; i < count; i++) { + // Get random selector + var random = this.getRandom(); + + // Sanity check + if (random.size() == 0) { + break; + } + + // Get + int cardId = random.next(); + + // Add to cards + this.getCards().add(cardId); + chest.add(cardId); + } + + // Success + return chest; } // Proto diff --git a/src/main/java/emu/nebula/server/handlers/HandlerVampireSurvivorRewardChestReq.java b/src/main/java/emu/nebula/server/handlers/HandlerVampireSurvivorRewardChestReq.java new file mode 100644 index 0000000..3315f72 --- /dev/null +++ b/src/main/java/emu/nebula/server/handlers/HandlerVampireSurvivorRewardChestReq.java @@ -0,0 +1,43 @@ +package emu.nebula.server.handlers; + +import emu.nebula.net.NetHandler; +import emu.nebula.net.NetMsgId; +import emu.nebula.proto.Public.CardInfo; +import emu.nebula.proto.VampireSurvivorRewardChest.VampireSurvivorRewardChestReq; +import emu.nebula.proto.VampireSurvivorRewardChest.VampireSurvivorRewardChestResp; +import emu.nebula.net.HandlerId; +import emu.nebula.net.GameSession; + +@HandlerId(NetMsgId.vampire_survivor_reward_chest_req) +public class HandlerVampireSurvivorRewardChestReq extends NetHandler { + + @Override + public byte[] handle(GameSession session, byte[] message) throws Exception { + // Parse req + var req = VampireSurvivorRewardChestReq.parseFrom(message); + + // Sanity check + var game = session.getPlayer().getVampireSurvivorManager().getGame(); + if (game == null) { + return session.encodeMsg(NetMsgId.vampire_survivor_reward_chest_failed_ack); + } + + // Calculate rewards from chest + var chest = game.calcRewardChest(req.getEventType(), req.getNumber()); + + // Build response + var rsp = VampireSurvivorRewardChestResp.newInstance(); + + for (int cardId : chest) { + var card = CardInfo.newInstance() + .setId(cardId) + .setNew(true); + + rsp.addChestCards(card); + } + + // Encode and send + return session.encodeMsg(NetMsgId.vampire_survivor_reward_chest_succeed_ack, rsp); + } + +}