mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-15 13:54:51 +01:00
Merge ascension/instance/infinite arena/vampire survivor progress into one manager
This commit is contained in:
@@ -72,6 +72,8 @@ public class Player implements GameDatabaseObject {
|
||||
// Managers
|
||||
private final transient CharacterStorage characters;
|
||||
private final transient GachaManager gachaManager;
|
||||
private final transient StarTowerManager starTowerManager;
|
||||
private final transient InstanceManager instanceManager;
|
||||
private final transient InfinityTowerManager infinityTowerManager;
|
||||
private final transient VampireSurvivorManager vampireSurvivorManager;
|
||||
private final transient ScoreBossManager scoreBossManager;
|
||||
@@ -80,8 +82,7 @@ public class Player implements GameDatabaseObject {
|
||||
private transient Inventory inventory;
|
||||
private transient FormationManager formations;
|
||||
private transient Mailbox mailbox;
|
||||
private transient StarTowerManager starTowerManager;
|
||||
private transient InstanceManager instanceManager;
|
||||
private transient PlayerProgress progress;
|
||||
private transient StoryManager storyManager;
|
||||
private transient QuestManager questManager;
|
||||
|
||||
@@ -93,6 +94,8 @@ public class Player implements GameDatabaseObject {
|
||||
// Init player managers
|
||||
this.characters = new CharacterStorage(this);
|
||||
this.gachaManager = new GachaManager(this);
|
||||
this.starTowerManager = new StarTowerManager(this);
|
||||
this.instanceManager = new InstanceManager(this);
|
||||
this.infinityTowerManager = new InfinityTowerManager(this);
|
||||
this.vampireSurvivorManager = new VampireSurvivorManager(this);
|
||||
this.scoreBossManager = new ScoreBossManager(this);
|
||||
@@ -482,18 +485,18 @@ public class Player implements GameDatabaseObject {
|
||||
public void onLoad() {
|
||||
// Load from database
|
||||
this.getCharacters().loadFromDatabase();
|
||||
this.getStarTowerManager().loadFromDatabase();
|
||||
|
||||
// Load inventory first
|
||||
// Load inventory before referenced classes
|
||||
if (this.inventory == null) {
|
||||
this.inventory = this.loadManagerFromDatabase(Inventory.class);
|
||||
}
|
||||
this.getInventory().loadFromDatabase();
|
||||
|
||||
// Load referenced classes
|
||||
// Load referenced classes from the database
|
||||
this.formations = this.loadManagerFromDatabase(FormationManager.class);
|
||||
this.mailbox = this.loadManagerFromDatabase(Mailbox.class);
|
||||
this.starTowerManager = this.loadManagerFromDatabase(StarTowerManager.class);
|
||||
this.instanceManager = this.loadManagerFromDatabase(InstanceManager.class);
|
||||
this.progress = this.loadManagerFromDatabase(PlayerProgress.class);
|
||||
this.storyManager = this.loadManagerFromDatabase(StoryManager.class);
|
||||
this.questManager = this.loadManagerFromDatabase(QuestManager.class);
|
||||
}
|
||||
@@ -646,8 +649,8 @@ public class Player implements GameDatabaseObject {
|
||||
proto.addDictionaries(dictionaryProto);
|
||||
}
|
||||
|
||||
// Add instances
|
||||
this.getInstanceManager().toProto(proto);
|
||||
// Add progress
|
||||
this.getProgress().toProto(proto);
|
||||
|
||||
// Handbook
|
||||
proto.addHandbook(this.getCharacters().getCharacterHandbook());
|
||||
|
||||
134
src/main/java/emu/nebula/game/player/PlayerProgress.java
Normal file
134
src/main/java/emu/nebula/game/player/PlayerProgress.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package emu.nebula.game.player;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
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 = "progress", useDiscriminator = false)
|
||||
public class PlayerProgress extends PlayerManager implements GameDatabaseObject {
|
||||
@Id
|
||||
private int uid;
|
||||
|
||||
private Int2IntMap dailyInstanceLog;
|
||||
private Int2IntMap regionBossLog;
|
||||
private Int2IntMap skillInstanceLog;
|
||||
private Int2IntMap charGemLog;
|
||||
private Int2IntMap weekBossLog;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public PlayerProgress() {
|
||||
|
||||
}
|
||||
|
||||
public PlayerProgress(Player player) {
|
||||
super(player);
|
||||
this.uid = player.getUid();
|
||||
|
||||
// Star Tower
|
||||
|
||||
// Instances
|
||||
this.dailyInstanceLog = new Int2IntOpenHashMap();
|
||||
this.regionBossLog = new Int2IntOpenHashMap();
|
||||
this.skillInstanceLog = new Int2IntOpenHashMap();
|
||||
this.charGemLog = new Int2IntOpenHashMap();
|
||||
this.weekBossLog = new Int2IntOpenHashMap();
|
||||
|
||||
// Infinity Arena
|
||||
|
||||
// Vampire Survivor
|
||||
|
||||
// Save to database
|
||||
this.save();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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(this.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(this.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(this.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(this.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user