Implement vampire survivor talent unlocking

This commit is contained in:
Melledy
2025-11-14 20:16:25 -08:00
parent 139fe2cf27
commit b19667315d
6 changed files with 139 additions and 0 deletions

View File

@@ -103,6 +103,7 @@ public class GameData {
// Vampire survivor
@Getter private static DataTable<VampireSurvivorDef> VampireSurvivorDataTable = new DataTable<>();
@Getter private static DataTable<VampireTalentDef> VampireTalentDataTable = new DataTable<>();
// Score boss
@Getter private static DataTable<ScoreBossControlDef> ScoreBossControlDataTable = new DataTable<>();

View File

@@ -0,0 +1,18 @@
package emu.nebula.data.resources;
import emu.nebula.data.BaseDef;
import emu.nebula.data.ResourceType;
import lombok.Getter;
@Getter
@ResourceType(name = "VampireTalent.json")
public class VampireTalentDef extends BaseDef {
private int Id;
private int[] Prev;
private int Point;
@Override
public int getId() {
return Id;
}
}

View File

@@ -35,6 +35,74 @@ public class VampireSurvivorManager extends PlayerManager {
return this.getProgress().getFateCards().size() * 5;
}
public int getUsedTalentPoints() {
int amount = 0;
for (var talent : GameData.getVampireTalentDataTable()) {
if (this.getTalents().isSet(talent.getId())) {
amount += talent.getPoint();
}
}
return amount;
}
public boolean unlockTalent(int id) {
// Get talent data
var talent = GameData.getVampireTalentDataTable().get(id);
if (talent == null) {
return false;
}
// Check to make sure talent isnt already set
if (this.getTalents().isSet(talent.getId())) {
return false;
}
// Make sure any prerequisite talent is set
if (talent.getPrev() != null) {
boolean hasPrev = false;
for (int prevTalent : talent.getPrev()) {
if (this.getTalents().isSet(prevTalent)) {
hasPrev = true;
}
}
if (!hasPrev) {
return false;
}
}
// Calculate available points
int points = this.getTalentPoints() - this.getUsedTalentPoints();
// Make sure we have enough points to unlock this talent
if (talent.getPoint() > points) {
return false;
}
// Set & save in database
this.getTalents().setBit(talent.getId());
Nebula.getGameDatabase().update(this.getProgress(), this.getPlayerUid(), "vampireTalents", this.getTalents());
// Success
return true;
}
public void resetTalents() {
// Sanity check to prevent resetting empty talents
if (this.getTalents().isEmpty()) {
return;
}
// Clear talents
this.getTalents().clear();
// Save in database
Nebula.getGameDatabase().update(this.getProgress(), this.getPlayerUid(), "vampireTalents", this.getTalents());
}
public VampireSurvivorGame apply(int levelId, RepeatedLong builds) {
// Get data
var data = GameData.getVampireSurvivorDataTable().get(levelId);

View File

@@ -0,0 +1,20 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.vampire_talent_reset_req)
public class HandlerVampireTalentResetReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Reset talents
session.getPlayer().getVampireSurvivorManager().resetTalents();
// Encode and send
return session.encodeMsg(NetMsgId.vampire_talent_reset_succeed_ack);
}
}

View File

@@ -0,0 +1,24 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.Public.UI32;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.vampire_talent_unlock_req)
public class HandlerVampireTalentUnlockReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = UI32.parseFrom(message);
// Unlock talent
boolean success = session.getPlayer().getVampireSurvivorManager().unlockTalent(req.getValue());
// Encode and send
return session.encodeMsg(success ? NetMsgId.vampire_talent_unlock_succeed_ack : NetMsgId.vampire_talent_unlock_failed_ack);
}
}

View File

@@ -13,6 +13,14 @@ public class Bitset {
public Bitset(long[] longArray) {
this.data = longArray;
}
public boolean isEmpty() {
return this.data.length == 1 && this.data[0] == 0L;
}
public void clear() {
this.data = new long[1];
}
public boolean isSet(int index) {
int longArrayOffset = (int) Math.floor((index - 1) / 64D);