Merge ascension/instance/infinite arena/vampire survivor progress into one manager

This commit is contained in:
Melledy
2025-11-09 21:27:08 -08:00
parent 3f7b0d366d
commit db5209ff06
15 changed files with 172 additions and 187 deletions

View File

@@ -2,58 +2,24 @@ package emu.nebula.game.instance;
import java.util.ArrayList;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import emu.nebula.GameConstants;
import emu.nebula.Nebula;
import emu.nebula.data.GameData;
import emu.nebula.database.GameDatabaseObject;
import emu.nebula.game.inventory.ItemParamMap;
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 emu.nebula.game.quest.QuestCondType;
import emu.nebula.proto.PlayerData.PlayerInfo;
import emu.nebula.proto.Public.CharGemInstance;
import emu.nebula.proto.Public.DailyInstance;
import emu.nebula.proto.Public.RegionBossLevel;
import emu.nebula.proto.Public.SkillInstance;
import emu.nebula.proto.Public.WeekBossLevel;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import lombok.Getter;
@Getter
@Entity(value = "instances", useDiscriminator = false)
public class InstanceManager extends PlayerManager implements GameDatabaseObject {
@Id
private int uid;
private Int2IntMap dailyInstanceLog;
private Int2IntMap regionBossLog;
private Int2IntMap skillInstanceLog;
private Int2IntMap charGemLog;
private Int2IntMap weekBossLog;
private transient int curInstanceId;
private transient int rewardType;
@Deprecated // Morphia
public InstanceManager() {
}
public class InstanceManager extends PlayerManager {
private int curInstanceId;
private int rewardType;
public InstanceManager(Player player) {
super(player);
this.uid = player.getUid();
this.dailyInstanceLog = new Int2IntOpenHashMap();
this.regionBossLog = new Int2IntOpenHashMap();
this.skillInstanceLog = new Int2IntOpenHashMap();
this.charGemLog = new Int2IntOpenHashMap();
this.weekBossLog = new Int2IntOpenHashMap();
this.save();
}
public void setCurInstanceId(int id) {
@@ -65,18 +31,8 @@ public class InstanceManager extends PlayerManager implements GameDatabaseObject
this.rewardType = rewardType;
}
public void saveInstanceLog(Int2IntMap log, String logName, int id, int newStar) {
// Get current star
int star = log.get(id);
// Check star
if (newStar <= star || newStar > 7) {
return;
}
// Add to log and update database
log.put(id, newStar);
Nebula.getGameDatabase().update(this, this.getUid(), logName + "." + id, newStar);
private PlayerProgress getProgress() {
return this.getPlayer().getProgress();
}
public PlayerChangeInfo settleInstance(InstanceData data, QuestCondType questCondition, Int2IntMap log, String logName, int star) {
@@ -104,7 +60,7 @@ public class InstanceManager extends PlayerManager implements GameDatabaseObject
getPlayer().getInventory().addItems(settleData.getFirstRewards(), change);
// Log
this.saveInstanceLog(log, logName, data.getId(), star);
this.getProgress().saveInstanceLog(log, logName, data.getId(), star);
// Quest triggers
this.getPlayer().getQuestManager().triggerQuest(questCondition, 1);
@@ -182,68 +138,4 @@ public class InstanceManager extends PlayerManager implements GameDatabaseObject
return change.setSuccess(true);
}
// Proto
public void toProto(PlayerInfo proto) {
// Init
int minStars = 0;
// Simple hack to unlock all instances
if (Nebula.getConfig().getServerOptions().unlockInstances) {
minStars = 1;
}
// Daily instance
for (var data : GameData.getDailyInstanceDataTable()) {
int stars = Math.max(getDailyInstanceLog().get(data.getId()), minStars);
var p = DailyInstance.newInstance()
.setId(data.getId())
.setStar(stars);
proto.addDailyInstances(p);
}
// Regional boss
for (var data : GameData.getRegionBossLevelDataTable()) {
int stars = Math.max(getRegionBossLog().get(data.getId()), minStars);
var p = RegionBossLevel.newInstance()
.setId(data.getId())
.setStar(stars);
proto.addRegionBossLevels(p);
}
// Skill instance
for (var data : GameData.getSkillInstanceDataTable()) {
int stars = Math.max(getSkillInstanceLog().get(data.getId()), minStars);
var p = SkillInstance.newInstance()
.setId(data.getId())
.setStar(stars);
proto.addSkillInstances(p);
}
// Char gem instance
for (var data : GameData.getCharGemInstanceDataTable()) {
int stars = Math.max(getCharGemLog().get(data.getId()), minStars);
var p = CharGemInstance.newInstance()
.setId(data.getId())
.setStar(stars);
proto.addCharGemInstances(p);
}
// Weekly boss
for (var data : GameData.getWeekBossLevelDataTable()) {
var p = WeekBossLevel.newInstance()
.setId(data.getId())
.setFirst(this.getWeekBossLog().get(data.getId()) == 1);
proto.addWeekBossLevels(p);
}
}
}