Implement vampire survivor reward chest

This commit is contained in:
Melledy
2025-11-14 16:44:54 -08:00
parent 6cb191eff9
commit 300d51aaf2
2 changed files with 88 additions and 10 deletions

View File

@@ -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<Integer> getRandom() {
var random = new WeightedList<Integer>();
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

View File

@@ -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);
}
}