Save Monolith and Menace Arena progress to the database

This commit is contained in:
Melledy
2025-11-11 04:42:41 -08:00
parent d9bd61c50d
commit b106541f44
6 changed files with 121 additions and 29 deletions

View File

@@ -15,6 +15,7 @@ import lombok.Getter;
@ResourceType(name = "InfinityTowerLevel.json") @ResourceType(name = "InfinityTowerLevel.json")
public class InfinityTowerLevelDef extends BaseDef { public class InfinityTowerLevelDef extends BaseDef {
private int Id; private int Id;
private int DifficultyId;
private String BaseAwardPreview; private String BaseAwardPreview;
private transient List<InstanceRewardParam> rewards; private transient List<InstanceRewardParam> rewards;

View File

@@ -1,6 +1,7 @@
package emu.nebula.game.infinitytower; package emu.nebula.game.infinitytower;
import emu.nebula.data.GameData; import emu.nebula.data.GameData;
import emu.nebula.data.resources.InfinityTowerLevelDef;
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;
@@ -9,7 +10,9 @@ import lombok.Getter;
@Getter @Getter
public class InfinityTowerManager extends PlayerManager { public class InfinityTowerManager extends PlayerManager {
private InfinityTowerLevelDef levelData;
private int levelId; private int levelId;
private long buildId; private long buildId;
public InfinityTowerManager(Player player) { public InfinityTowerManager(Player player) {
@@ -28,6 +31,7 @@ public class InfinityTowerManager extends PlayerManager {
} }
// Set level id // Set level id
this.levelData = data;
this.levelId = levelId; this.levelId = levelId;
// Set build id // Set build id
@@ -41,21 +45,21 @@ public class InfinityTowerManager extends PlayerManager {
public PlayerChangeInfo settle(int value) { public PlayerChangeInfo settle(int value) {
// Verify level data // Verify level data
var data = GameData.getInfinityTowerLevelDataTable().get(this.getLevelId()); if (this.getLevelData() == null) {
if (data == null) {
return null; return null;
} }
// Init change info // Init change info
var change = new PlayerChangeInfo(); var change = new PlayerChangeInfo();
// TODO // Check if the player has won or not TODO
if (value != 1) { if (value != 1) {
// Player lost, so we return nothing
return change; return change;
} }
// Calculate rewards // Calculate rewards
var rewards = data.generateRewards(); var rewards = this.getLevelData().generateRewards();
// Add items // Add items
this.getPlayer().getInventory().addItems(rewards, change); this.getPlayer().getInventory().addItems(rewards, change);
@@ -63,6 +67,9 @@ public class InfinityTowerManager extends PlayerManager {
// Set in change info // Set in change info
change.setExtraData(rewards); change.setExtraData(rewards);
// Log in player progress
this.getPlayer().getProgress().addInfinityArenaLog(this.getLevelId());
// Success // Success
return change.setSuccess(true); return change.setSuccess(true);
} }

View File

@@ -37,7 +37,7 @@ import emu.nebula.proto.Public.Story;
import emu.nebula.proto.Public.WorldClass; import emu.nebula.proto.Public.WorldClass;
import emu.nebula.proto.Public.WorldClassRewardState; import emu.nebula.proto.Public.WorldClassRewardState;
import emu.nebula.proto.Public.Title; import emu.nebula.proto.Public.Title;
import emu.nebula.proto.Public.VampireSurvivorLevel;
import lombok.Getter; import lombok.Getter;
import us.hebi.quickbuf.ProtoMessage; import us.hebi.quickbuf.ProtoMessage;
import us.hebi.quickbuf.RepeatedInt; import us.hebi.quickbuf.RepeatedInt;
@@ -656,25 +656,6 @@ public class Player implements GameDatabaseObject {
proto.addHandbook(this.getCharacters().getCharacterHandbook()); proto.addHandbook(this.getCharacters().getCharacterHandbook());
proto.addHandbook(this.getCharacters().getDiscHandbook()); proto.addHandbook(this.getCharacters().getDiscHandbook());
// Force unlock all monoliths
for (var towerData : GameData.getStarTowerDataTable()) {
proto.addRglPassedIds(towerData.getId());
}
// Force unlock all vampire survivor records
var vsProto = proto.getMutableVampireSurvivorRecord();
vsProto.getMutableSeason();
for (var vsData : GameData.getVampireSurvivorDataTable()) {
var level = VampireSurvivorLevel.newInstance()
.setId(vsData.getId())
.setScore(0)
.setPassed(true);
vsProto.addRecords(level);
}
// Extra // Extra
proto.getMutableAgent(); proto.getMutableAgent();
proto.getMutablePhone(); proto.getMutablePhone();

View File

@@ -10,9 +10,12 @@ import emu.nebula.proto.Public.CharGemInstance;
import emu.nebula.proto.Public.DailyInstance; import emu.nebula.proto.Public.DailyInstance;
import emu.nebula.proto.Public.RegionBossLevel; import emu.nebula.proto.Public.RegionBossLevel;
import emu.nebula.proto.Public.SkillInstance; import emu.nebula.proto.Public.SkillInstance;
import emu.nebula.proto.Public.VampireSurvivorLevel;
import emu.nebula.proto.Public.WeekBossLevel; import emu.nebula.proto.Public.WeekBossLevel;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
@@ -21,11 +24,20 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
@Id @Id
private int uid; private int uid;
// Star Tower
private IntSet starTowerLog;
// Instances
private Int2IntMap dailyInstanceLog; private Int2IntMap dailyInstanceLog;
private Int2IntMap regionBossLog; private Int2IntMap regionBossLog;
private Int2IntMap skillInstanceLog; private Int2IntMap skillInstanceLog;
private Int2IntMap charGemLog; private Int2IntMap charGemLog;
private Int2IntMap weekBossLog; private Int2IntMap weekBossLog;
// Infinite Arena
private Int2IntMap infinityArenaLog;
// Vampire Survivors TODO
@Deprecated // Morphia only @Deprecated // Morphia only
public PlayerProgress() { public PlayerProgress() {
@@ -37,6 +49,7 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
this.uid = player.getUid(); this.uid = player.getUid();
// Star Tower // Star Tower
this.starTowerLog = new IntOpenHashSet();
// Instances // Instances
this.dailyInstanceLog = new Int2IntOpenHashMap(); this.dailyInstanceLog = new Int2IntOpenHashMap();
@@ -46,6 +59,7 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
this.weekBossLog = new Int2IntOpenHashMap(); this.weekBossLog = new Int2IntOpenHashMap();
// Infinity Arena // Infinity Arena
this.infinityArenaLog = new Int2IntOpenHashMap();
// Vampire Survivor // Vampire Survivor
@@ -53,6 +67,31 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
this.save(); this.save();
} }
public void addStarTowerLog(int id) {
// Sanity check
if (this.getStarTowerLog().contains(id)) {
return;
}
// Add & Save to database
this.getStarTowerLog().add(id);
Nebula.getGameDatabase().addToList(this, this.getUid(), "starTowerLog", id);
}
public void addInfinityArenaLog(int levelId) {
// Calculate arena id
int id = (int) Math.floor(levelId / 10000D);
// Check highest clear
int highestClearId = this.getInfinityArenaLog().get(id);
// Add & Save to database
if (levelId > highestClearId) {
this.getInfinityArenaLog().put(id, levelId);
Nebula.getGameDatabase().update(this, this.getUid(), "infinityArenaLog." + id, levelId);
}
}
public void saveInstanceLog(Int2IntMap log, String logName, int id, int newStar) { public void saveInstanceLog(Int2IntMap log, String logName, int id, int newStar) {
// Get current star // Get current star
int star = log.get(id); int star = log.get(id);
@@ -70,13 +109,23 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
// Proto // Proto
public void toProto(PlayerInfo proto) { public void toProto(PlayerInfo proto) {
// Init // Check if we want to unlock all instances
int minStars = 0; boolean unlockAll = Nebula.getConfig().getServerOptions().unlockInstances;
// Star tower
if (unlockAll) {
// Force unlock all monoliths
for (var towerData : GameData.getStarTowerDataTable()) {
proto.addRglPassedIds(towerData.getId());
}
} else {
for (var towerId : this.getStarTowerLog()) {
proto.addRglPassedIds(towerId);
}
}
// Simple hack to unlock all instances // Simple hack to unlock all instances
if (Nebula.getConfig().getServerOptions().unlockInstances) { int minStars = unlockAll ? 1 : 0;
minStars = 1;
}
// Daily instance // Daily instance
for (var data : GameData.getDailyInstanceDataTable()) { for (var data : GameData.getDailyInstanceDataTable()) {
@@ -130,5 +179,19 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
proto.addWeekBossLevels(p); proto.addWeekBossLevels(p);
} }
// Force unlock all vampire survivor records
var vsProto = proto.getMutableVampireSurvivorRecord();
vsProto.getMutableSeason();
for (var vsData : GameData.getVampireSurvivorDataTable()) {
var level = VampireSurvivorLevel.newInstance()
.setId(vsData.getId())
.setScore(0)
.setPassed(true);
vsProto.addRecords(level);
}
} }
} }

View File

@@ -630,6 +630,9 @@ public class StarTowerGame {
// Mark change info // Mark change info
settle.getMutableChange(); settle.getMutableChange();
// Log victory
this.getManager().getPlayer().getProgress().addStarTowerLog(this.getId());
// Complete // Complete
return rsp; return rsp;
} }

View File

@@ -3,9 +3,14 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler; import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId; import emu.nebula.net.NetMsgId;
import emu.nebula.proto.InfinityTowerInfo.InfinityTowerInfoResp; import emu.nebula.proto.InfinityTowerInfo.InfinityTowerInfoResp;
import emu.nebula.proto.Public.InfinityTowerLevelInfo;
import emu.nebula.net.HandlerId; import emu.nebula.net.HandlerId;
import emu.nebula.Nebula;
import emu.nebula.data.GameData;
import emu.nebula.net.GameSession; import emu.nebula.net.GameSession;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
@HandlerId(NetMsgId.infinity_tower_info_req) @HandlerId(NetMsgId.infinity_tower_info_req)
public class HandlerInfinityTowerInfoReq extends NetHandler { public class HandlerInfinityTowerInfoReq extends NetHandler {
@@ -15,6 +20,38 @@ public class HandlerInfinityTowerInfoReq extends NetHandler {
var rsp = InfinityTowerInfoResp.newInstance() var rsp = InfinityTowerInfoResp.newInstance()
.setBountyLevel(0); .setBountyLevel(0);
// Add unlocked levels
if (Nebula.getConfig().getServerOptions().unlockInstances) {
// Force unlock every level
var levels = new Int2ObjectOpenHashMap<InfinityTowerLevelInfo>();
for (var data : GameData.getInfinityTowerLevelDataTable()) {
int id = (int) Math.floor(data.getId() / 10000D);
var info = levels.computeIfAbsent(
id,
diff -> InfinityTowerLevelInfo.newInstance().setId(id)
);
if (data.getId() > info.getLevelId()) {
info.setLevelId(data.getId());
}
}
for (var info : levels.values()) {
rsp.addInfos(info);
}
} else {
// Get infinite arena log from player progress
for (var entry : session.getPlayer().getProgress().getInfinityArenaLog().int2IntEntrySet()) {
var info = InfinityTowerLevelInfo.newInstance()
.setId(entry.getIntKey())
.setLevelId(entry.getIntValue());
rsp.addInfos(info);
}
}
// Encode and send // Encode and send
return session.encodeMsg(NetMsgId.infinity_tower_info_succeed_ack, rsp); return session.encodeMsg(NetMsgId.infinity_tower_info_succeed_ack, rsp);
} }