mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 12:54:36 +01:00
Fix Menace Arena not saving properly
This commit is contained in:
@@ -132,6 +132,7 @@ public class GameData {
|
||||
|
||||
// ===== Infinity Tower =====
|
||||
@Getter private static DataTable<InfinityTowerLevelDef> InfinityTowerLevelDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<InfinityTowerDifficultyDef> InfinityTowerDifficultyDataTable = new DataTable<>();
|
||||
|
||||
// ===== Vampire Survivor =====
|
||||
@Getter private static DataTable<VampireSurvivorDef> VampireSurvivorDataTable = new DataTable<>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import emu.nebula.game.inventory.ItemParamMap;
|
||||
import emu.nebula.game.inventory.ItemRewardParam;
|
||||
@@ -25,8 +26,13 @@ public class InfinityTowerLevelDef extends BaseDef {
|
||||
return Id;
|
||||
}
|
||||
|
||||
public int getEnergyConsume() {
|
||||
return 0;
|
||||
public int getTowerId() {
|
||||
var diff = GameData.getInfinityTowerDifficultyDataTable().get(this.DifficultyId);
|
||||
if (diff == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return diff.getTowerId();
|
||||
}
|
||||
|
||||
public ItemParamMap generateRewards() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import emu.nebula.game.achievement.AchievementCondition;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
|
||||
import emu.nebula.game.player.PlayerProgress;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -18,6 +18,10 @@ public class InfinityTowerManager extends PlayerManager {
|
||||
public InfinityTowerManager(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
private PlayerProgress getProgress() {
|
||||
return this.getPlayer().getProgress();
|
||||
}
|
||||
|
||||
public int getBountyLevel() {
|
||||
return 0;
|
||||
@@ -59,7 +63,8 @@ public class InfinityTowerManager extends PlayerManager {
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -73,7 +78,7 @@ public class InfinityTowerManager extends PlayerManager {
|
||||
change.setExtraData(rewards);
|
||||
|
||||
// Log in player progress
|
||||
this.getPlayer().getProgress().addInfinityArenaLog(this.getLevelId());
|
||||
this.getPlayer().getProgress().addInfinityTowerLog(this.getLevelData());
|
||||
|
||||
// Trigger achievement
|
||||
this.getPlayer().trigger(AchievementCondition.InfinityTowerClearSpecificFloor, 10, this.getLevelId(), 0);
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.PostLoad;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.data.resources.InfinityTowerLevelDef;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
import emu.nebula.game.tutorial.TutorialLevelLog;
|
||||
import emu.nebula.game.vampire.VampireSurvivorLog;
|
||||
@@ -44,7 +45,8 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
||||
private Int2IntMap weekBossLog;
|
||||
|
||||
// Infinite Arena
|
||||
private Int2IntMap infinityArenaLog;
|
||||
private Int2IntMap infinityTowerLog;
|
||||
@Deprecated private Int2IntMap infinityArenaLog;
|
||||
|
||||
// Vampire Survivors
|
||||
private Map<Integer, VampireSurvivorLog> vampireLog;
|
||||
@@ -76,8 +78,8 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
||||
this.charGemLog = new Int2IntOpenHashMap();
|
||||
this.weekBossLog = new Int2IntOpenHashMap();
|
||||
|
||||
// Infinity Arena
|
||||
this.infinityArenaLog = new Int2IntOpenHashMap();
|
||||
// Infinity Tower
|
||||
this.infinityTowerLog = new Int2IntOpenHashMap();
|
||||
|
||||
// Vampire Survivor
|
||||
this.vampireLog = new HashMap<>();
|
||||
@@ -156,17 +158,22 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "towerTickets", this.towerTickets);
|
||||
}
|
||||
|
||||
public void addInfinityArenaLog(int levelId) {
|
||||
// Calculate arena id
|
||||
int id = (int) Math.floor(levelId / 10000D);
|
||||
public void addInfinityTowerLog(InfinityTowerLevelDef level) {
|
||||
// Calculate tower id
|
||||
int towerId = level.getTowerId();
|
||||
int levelId = level.getId();
|
||||
|
||||
if (towerId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check highest clear
|
||||
int highestClearId = this.getInfinityArenaLog().get(id);
|
||||
int highestClearId = this.getInfinityTowerLog().get(towerId);
|
||||
|
||||
// Add & Save to database
|
||||
if (levelId > highestClearId) {
|
||||
this.getInfinityArenaLog().put(id, levelId);
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "infinityArenaLog." + id, levelId);
|
||||
this.getInfinityTowerLog().put(towerId, levelId);
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "infinityArenaLog." + towerId, levelId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,8 +302,43 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
||||
|
||||
@PostLoad
|
||||
public void postLoad() {
|
||||
boolean shouldSave = false;
|
||||
|
||||
// Fix missing star tower growth
|
||||
if (this.starTowerGrowth == null) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class HandlerInfinityTowerInfoReq extends NetHandler {
|
||||
.setBountyLevel(session.getPlayer().getInfinityTowerManager().getBountyLevel());
|
||||
|
||||
// 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()
|
||||
.setId(entry.getIntKey())
|
||||
.setLevelId(entry.getIntValue());
|
||||
|
||||
Reference in New Issue
Block a user