mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-14 13:24:43 +01:00
Merge ascension/instance/infinite arena/vampire survivor progress into one manager
This commit is contained in:
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