Fix Menace Arena not saving properly

This commit is contained in:
Melledy
2025-12-13 01:20:06 -08:00
parent 9599877005
commit 4d14099f11
6 changed files with 88 additions and 15 deletions

View File

@@ -132,6 +132,7 @@ public class GameData {
// ===== Infinity Tower ===== // ===== Infinity Tower =====
@Getter private static DataTable<InfinityTowerLevelDef> InfinityTowerLevelDataTable = new DataTable<>(); @Getter private static DataTable<InfinityTowerLevelDef> InfinityTowerLevelDataTable = new DataTable<>();
@Getter private static DataTable<InfinityTowerDifficultyDef> InfinityTowerDifficultyDataTable = new DataTable<>();
// ===== Vampire Survivor ===== // ===== Vampire Survivor =====
@Getter private static DataTable<VampireSurvivorDef> VampireSurvivorDataTable = new DataTable<>(); @Getter private static DataTable<VampireSurvivorDef> VampireSurvivorDataTable = new DataTable<>();

View File

@@ -0,0 +1,19 @@
package emu.nebula.data.resources;
import emu.nebula.data.BaseDef;
import emu.nebula.data.ResourceType;
import lombok.Getter;
@Getter
@ResourceType(name = "InfinityTowerDifficulty.json")
public class InfinityTowerDifficultyDef extends BaseDef {
private int Id;
private int TowerId;
@Override
public int getId() {
return Id;
}
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import emu.nebula.data.BaseDef; import emu.nebula.data.BaseDef;
import emu.nebula.data.GameData;
import emu.nebula.data.ResourceType; import emu.nebula.data.ResourceType;
import emu.nebula.game.inventory.ItemParamMap; import emu.nebula.game.inventory.ItemParamMap;
import emu.nebula.game.inventory.ItemRewardParam; import emu.nebula.game.inventory.ItemRewardParam;
@@ -25,8 +26,13 @@ public class InfinityTowerLevelDef extends BaseDef {
return Id; return Id;
} }
public int getEnergyConsume() { public int getTowerId() {
return 0; var diff = GameData.getInfinityTowerDifficultyDataTable().get(this.DifficultyId);
if (diff == null) {
return 0;
}
return diff.getTowerId();
} }
public ItemParamMap generateRewards() { public ItemParamMap generateRewards() {

View File

@@ -6,7 +6,7 @@ import emu.nebula.game.achievement.AchievementCondition;
import emu.nebula.game.player.Player; import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerChangeInfo; import emu.nebula.game.player.PlayerChangeInfo;
import emu.nebula.game.player.PlayerManager; import emu.nebula.game.player.PlayerManager;
import emu.nebula.game.player.PlayerProgress;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
@@ -19,6 +19,10 @@ public class InfinityTowerManager extends PlayerManager {
super(player); super(player);
} }
private PlayerProgress getProgress() {
return this.getPlayer().getProgress();
}
public int getBountyLevel() { public int getBountyLevel() {
return 0; return 0;
} }
@@ -59,7 +63,8 @@ public class InfinityTowerManager extends PlayerManager {
} }
// Check logs if the player has completed the level already // Check logs if the player has completed the level already
if (this.getPlayer().getProgress().getInfinityArenaLog().containsKey(this.getLevelId())) { int highestLevel = this.getProgress().getInfinityTowerLog().get(this.getLevelData().getTowerId());
if (highestLevel >= this.getLevelId()) {
return change; return change;
} }
@@ -73,7 +78,7 @@ public class InfinityTowerManager extends PlayerManager {
change.setExtraData(rewards); change.setExtraData(rewards);
// Log in player progress // Log in player progress
this.getPlayer().getProgress().addInfinityArenaLog(this.getLevelId()); this.getPlayer().getProgress().addInfinityTowerLog(this.getLevelData());
// Trigger achievement // Trigger achievement
this.getPlayer().trigger(AchievementCondition.InfinityTowerClearSpecificFloor, 10, this.getLevelId(), 0); this.getPlayer().trigger(AchievementCondition.InfinityTowerClearSpecificFloor, 10, this.getLevelId(), 0);

View File

@@ -8,6 +8,7 @@ import dev.morphia.annotations.Id;
import dev.morphia.annotations.PostLoad; import dev.morphia.annotations.PostLoad;
import emu.nebula.Nebula; import emu.nebula.Nebula;
import emu.nebula.data.GameData; import emu.nebula.data.GameData;
import emu.nebula.data.resources.InfinityTowerLevelDef;
import emu.nebula.database.GameDatabaseObject; import emu.nebula.database.GameDatabaseObject;
import emu.nebula.game.tutorial.TutorialLevelLog; import emu.nebula.game.tutorial.TutorialLevelLog;
import emu.nebula.game.vampire.VampireSurvivorLog; import emu.nebula.game.vampire.VampireSurvivorLog;
@@ -44,7 +45,8 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
private Int2IntMap weekBossLog; private Int2IntMap weekBossLog;
// Infinite Arena // Infinite Arena
private Int2IntMap infinityArenaLog; private Int2IntMap infinityTowerLog;
@Deprecated private Int2IntMap infinityArenaLog;
// Vampire Survivors // Vampire Survivors
private Map<Integer, VampireSurvivorLog> vampireLog; private Map<Integer, VampireSurvivorLog> vampireLog;
@@ -76,8 +78,8 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
this.charGemLog = new Int2IntOpenHashMap(); this.charGemLog = new Int2IntOpenHashMap();
this.weekBossLog = new Int2IntOpenHashMap(); this.weekBossLog = new Int2IntOpenHashMap();
// Infinity Arena // Infinity Tower
this.infinityArenaLog = new Int2IntOpenHashMap(); this.infinityTowerLog = new Int2IntOpenHashMap();
// Vampire Survivor // Vampire Survivor
this.vampireLog = new HashMap<>(); this.vampireLog = new HashMap<>();
@@ -156,17 +158,22 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
Nebula.getGameDatabase().update(this, this.getUid(), "towerTickets", this.towerTickets); Nebula.getGameDatabase().update(this, this.getUid(), "towerTickets", this.towerTickets);
} }
public void addInfinityArenaLog(int levelId) { public void addInfinityTowerLog(InfinityTowerLevelDef level) {
// Calculate arena id // Calculate tower id
int id = (int) Math.floor(levelId / 10000D); int towerId = level.getTowerId();
int levelId = level.getId();
if (towerId <= 0) {
return;
}
// Check highest clear // Check highest clear
int highestClearId = this.getInfinityArenaLog().get(id); int highestClearId = this.getInfinityTowerLog().get(towerId);
// Add & Save to database // Add & Save to database
if (levelId > highestClearId) { if (levelId > highestClearId) {
this.getInfinityArenaLog().put(id, levelId); this.getInfinityTowerLog().put(towerId, levelId);
Nebula.getGameDatabase().update(this, this.getUid(), "infinityArenaLog." + id, levelId); Nebula.getGameDatabase().update(this, this.getUid(), "infinityArenaLog." + towerId, levelId);
} }
} }
@@ -295,8 +302,43 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
@PostLoad @PostLoad
public void postLoad() { public void postLoad() {
boolean shouldSave = false;
// Fix missing star tower growth
if (this.starTowerGrowth == null) { if (this.starTowerGrowth == null) {
this.starTowerGrowth = new int[1]; this.starTowerGrowth = new int[1];
shouldSave = true;
}
// Fix missing infinity tower log
if (this.infinityTowerLog == null) {
this.infinityTowerLog = new Int2IntOpenHashMap();
shouldSave = true;
}
// Carry over infinity tower progress
if (this.infinityArenaLog != null) {
for (int levelId : this.infinityArenaLog.values()) {
var data = GameData.getInfinityTowerLevelDataTable().get(levelId);
if (data == null) {
continue;
}
int towerId = data.getTowerId();
if (towerId > 0) {
this.infinityTowerLog.put(data.getTowerId(), levelId);
}
}
// Clear old infinity tower logs when done
this.infinityArenaLog = null;
shouldSave = true;
}
// Update in database if anything changed
if (shouldSave) {
this.save();
} }
} }
} }

View File

@@ -17,7 +17,7 @@ public class HandlerInfinityTowerInfoReq extends NetHandler {
.setBountyLevel(session.getPlayer().getInfinityTowerManager().getBountyLevel()); .setBountyLevel(session.getPlayer().getInfinityTowerManager().getBountyLevel());
// Get infinite arena log from player progress // Get infinite arena log from player progress
for (var entry : session.getPlayer().getProgress().getInfinityArenaLog().int2IntEntrySet()) { for (var entry : session.getPlayer().getProgress().getInfinityTowerLog().int2IntEntrySet()) {
var info = InfinityTowerLevelInfo.newInstance() var info = InfinityTowerLevelInfo.newInstance()
.setId(entry.getIntKey()) .setId(entry.getIntKey())
.setLevelId(entry.getIntValue()); .setLevelId(entry.getIntValue());