Implement cataclysm survivor (basic)

This commit is contained in:
Melledy
2025-11-08 05:57:44 -08:00
parent 2ecc0f28c5
commit c32df9e8aa
10 changed files with 356 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import emu.nebula.game.quest.QuestManager;
import emu.nebula.game.scoreboss.ScoreBossManager;
import emu.nebula.game.story.StoryManager;
import emu.nebula.game.tower.StarTowerManager;
import emu.nebula.game.vampire.VampireSurvivorManager;
import emu.nebula.net.GameSession;
import emu.nebula.net.NetMsgId;
import emu.nebula.net.NetMsgPacket;
@@ -70,6 +71,7 @@ public class Player implements GameDatabaseObject {
// Managers
private final transient CharacterStorage characters;
private final transient GachaManager gachaManager;
private final transient VampireSurvivorManager vampireSurvivorManager;
private final transient ScoreBossManager scoreBossManager;
// Referenced data
@@ -89,6 +91,7 @@ public class Player implements GameDatabaseObject {
// Init player managers
this.characters = new CharacterStorage(this);
this.gachaManager = new GachaManager(this);
this.vampireSurvivorManager = new VampireSurvivorManager(this);
this.scoreBossManager = new ScoreBossManager(this);
// Init next packages stack

View File

@@ -0,0 +1,99 @@
package emu.nebula.game.vampire;
import emu.nebula.data.GameData;
import emu.nebula.data.resources.VampireSurvivorDef;
import emu.nebula.proto.Public.CardInfo;
import emu.nebula.proto.Public.VampireSurvivorLevelReward;
import emu.nebula.util.WeightedList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import lombok.Getter;
@Getter
public class VampireSurvivorGame {
private final VampireSurvivorManager manager;
private final VampireSurvivorDef data;
private IntSet cards;
private int rewardLevel;
private IntList rewards;
public VampireSurvivorGame(VampireSurvivorManager manager, VampireSurvivorDef data) {
this.manager = manager;
this.data = data;
this.cards = new IntOpenHashSet();
this.rewards = new IntArrayList();
this.calcRewards();
}
public void calcRewards() {
// Clear reward list first
this.rewards.clear();
// Increment level
this.rewardLevel++;
var random = new WeightedList<Integer>();
for (var card : GameData.getFateCardDataTable()) {
// Filter only vampire surv cards
if (!card.isIsVampire()) {
continue;
}
// Skip cards we already have
if (this.getCards().contains(card.getId())) {
continue;
}
// Add
random.add(100, card.getId());
}
// Add 2 rewards
this.getRewards().add(random.next().intValue());
this.getRewards().add(random.next().intValue());
}
public int selectReward(int index, boolean reRoll) {
// Sanity check
if (index < 0 || index >= this.getRewards().size()) {
return -1;
}
// Get fate card id
int id = this.getRewards().getInt(index);
// Add to cards
this.getCards().add(id);
// Reroll rewards
this.calcRewards();
// Success
return id;
}
// Proto
public VampireSurvivorLevelReward getRewardProto() {
var proto = VampireSurvivorLevelReward.newInstance()
.setLevel(this.getRewardLevel());
var pkg = proto.getMutablePkg();
for (int id : this.getRewards()) {
var card = CardInfo.newInstance()
.setId(id);
pkg.addCards(card);
}
return proto;
}
}

View File

@@ -0,0 +1,54 @@
package emu.nebula.game.vampire;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import emu.nebula.data.GameData;
import emu.nebula.database.GameDatabaseObject;
import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerManager;
import lombok.Getter;
@Getter
@Entity(value = "vampire", useDiscriminator = false)
public class VampireSurvivorManager extends PlayerManager implements GameDatabaseObject {
@Id
private int uid;
// Game
private transient VampireSurvivorGame game;
// TODO talents
@Deprecated // Morphia only
public VampireSurvivorManager() {
}
public VampireSurvivorManager(Player player) {
super(player);
this.uid = player.getUid();
//this.save();
}
public VampireSurvivorGame apply(int levelId) {
// Get data
var data = GameData.getVampireSurvivorDataTable().get(levelId);
if (data == null) {
return null;
}
// Create game
this.game = new VampireSurvivorGame(this, data);
// Success
return this.game;
}
public void settle(boolean isWin, int score) {
// Clear game
this.game = null;
}
}