mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 04:45:02 +01:00
Implement vampire survivor reward chest
This commit is contained in:
@@ -18,6 +18,7 @@ public class VampireSurvivorGame {
|
|||||||
|
|
||||||
private IntSet cards;
|
private IntSet cards;
|
||||||
|
|
||||||
|
// Reward selector
|
||||||
private int rewardLevel;
|
private int rewardLevel;
|
||||||
private IntList rewards;
|
private IntList rewards;
|
||||||
|
|
||||||
@@ -31,14 +32,9 @@ public class VampireSurvivorGame {
|
|||||||
this.calcRewards();
|
this.calcRewards();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calcRewards() {
|
private WeightedList<Integer> getRandom() {
|
||||||
// Clear reward list first
|
|
||||||
this.rewards.clear();
|
|
||||||
|
|
||||||
// Increment level
|
|
||||||
this.rewardLevel++;
|
|
||||||
|
|
||||||
var random = new WeightedList<Integer>();
|
var random = new WeightedList<Integer>();
|
||||||
|
|
||||||
for (var card : GameData.getFateCardDataTable()) {
|
for (var card : GameData.getFateCardDataTable()) {
|
||||||
// Filter only vampire surv cards
|
// Filter only vampire surv cards
|
||||||
if (!card.isIsVampire()) {
|
if (!card.isIsVampire()) {
|
||||||
@@ -54,6 +50,19 @@ public class VampireSurvivorGame {
|
|||||||
random.add(100, card.getId());
|
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
|
// Add 2 rewards
|
||||||
this.getRewards().add(random.next().intValue());
|
this.getRewards().add(random.next().intValue());
|
||||||
this.getRewards().add(random.next().intValue());
|
this.getRewards().add(random.next().intValue());
|
||||||
@@ -66,16 +75,42 @@ public class VampireSurvivorGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get fate card id
|
// Get fate card id
|
||||||
int id = this.getRewards().getInt(index);
|
int cardId = this.getRewards().getInt(index);
|
||||||
|
|
||||||
// Add to cards
|
// Add to cards
|
||||||
this.getCards().add(id);
|
this.getCards().add(cardId);
|
||||||
|
|
||||||
// Reroll rewards
|
// Reroll rewards
|
||||||
this.calcRewards();
|
this.calcRewards();
|
||||||
|
|
||||||
// Success
|
// 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
|
// Proto
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user