mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Migrate battlepass to its own db collection
This commit is contained in:
@@ -29,9 +29,6 @@ public class Account {
|
||||
private List<String> permissions;
|
||||
private Locale locale;
|
||||
|
||||
private int point;
|
||||
private int awardTakenLevel;
|
||||
|
||||
private String banReason;
|
||||
private int banEndTime;
|
||||
private int banStartTime;
|
||||
@@ -212,22 +209,6 @@ public class Account {
|
||||
return this.permissions.remove(permission);
|
||||
}
|
||||
|
||||
public void setPoint(int point) {
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
public int getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setAwardTakenLevel(int level) {
|
||||
this.awardTakenLevel = level;
|
||||
}
|
||||
|
||||
public int getAwardTakenLevel() {
|
||||
return awardTakenLevel;
|
||||
}
|
||||
|
||||
// TODO make unique
|
||||
public String generateLoginToken() {
|
||||
this.token = Utils.bytesToHex(Crypto.createSessionKey(32));
|
||||
|
||||
@@ -1,35 +1,44 @@
|
||||
package emu.grasscutter.game.battlepass;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import dev.morphia.annotations.Transient;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.server.packet.send.PacketBattlePassCurScheduleUpdateNotify;
|
||||
|
||||
@Entity(value = "battlepass", useDiscriminator = false)
|
||||
public class BattlePassManager {
|
||||
|
||||
private final Player player;
|
||||
@Id private ObjectId id;
|
||||
@Transient private Player player;
|
||||
|
||||
@Indexed private int ownerUid;
|
||||
private int point;
|
||||
private int awardTakenLevel;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public BattlePassManager() {}
|
||||
|
||||
public BattlePassManager(Player player){
|
||||
this.player = player;
|
||||
point = player.getAccount().getPoint();
|
||||
awardTakenLevel = player.getAccount().getAwardTakenLevel();
|
||||
public BattlePassManager(Player player) {
|
||||
this.setPlayer(player);
|
||||
}
|
||||
|
||||
public ObjectId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void addPoint(int point){
|
||||
this.point += point;
|
||||
player.getAccount().setPoint(point);
|
||||
player.getSession().send(new PacketBattlePassCurScheduleUpdateNotify(player.getSession().getPlayer()));
|
||||
//save the point data
|
||||
player.getAccount().save();
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public void updateAwardTakenLevel(int level){
|
||||
this.awardTakenLevel = level;
|
||||
player.getAccount().setAwardTakenLevel(awardTakenLevel);
|
||||
player.getSession().send(new PacketBattlePassCurScheduleUpdateNotify(player.getSession().getPlayer()));
|
||||
player.getAccount().save();
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
this.ownerUid = player.getUid();
|
||||
}
|
||||
|
||||
|
||||
public int getPoint() {
|
||||
return point;
|
||||
}
|
||||
@@ -37,4 +46,20 @@ public class BattlePassManager {
|
||||
public int getAwardTakenLevel() {
|
||||
return awardTakenLevel;
|
||||
}
|
||||
|
||||
public void addPoint(int point){
|
||||
this.point += point;
|
||||
player.getSession().send(new PacketBattlePassCurScheduleUpdateNotify(player.getSession().getPlayer()));
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void updateAwardTakenLevel(int level){
|
||||
this.awardTakenLevel = level;
|
||||
player.getSession().send(new PacketBattlePassCurScheduleUpdateNotify(player.getSession().getPlayer()));
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
DatabaseHelper.saveBattlePass(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,10 +292,6 @@ public class Player {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public void setBattlePassManager(Player player){
|
||||
this.battlePassManager = new BattlePassManager(player);
|
||||
}
|
||||
|
||||
public GameSession getSession() {
|
||||
return session;
|
||||
}
|
||||
@@ -1215,6 +1211,11 @@ public class Player {
|
||||
public BattlePassManager getBattlePassManager(){
|
||||
return battlePassManager;
|
||||
}
|
||||
|
||||
public void loadBattlePassManager() {
|
||||
if (this.battlePassManager != null) return;
|
||||
this.battlePassManager = DatabaseHelper.loadBattlePass(this);
|
||||
}
|
||||
|
||||
public AbilityManager getAbilityManager() {
|
||||
return abilityManager;
|
||||
@@ -1318,15 +1319,17 @@ public class Player {
|
||||
}
|
||||
//Make sure towerManager's player is online player
|
||||
this.getTowerManager().setPlayer(this);
|
||||
|
||||
// Load from db
|
||||
this.getAvatars().loadFromDatabase();
|
||||
this.getInventory().loadFromDatabase();
|
||||
this.getAvatars().postLoad();
|
||||
this.getAvatars().postLoad(); // Needs to be called after inventory is handled
|
||||
|
||||
this.getFriendsList().loadFromDatabase();
|
||||
this.getMailHandler().loadFromDatabase();
|
||||
this.getQuestManager().loadFromDatabase();
|
||||
|
||||
|
||||
this.loadBattlePassManager();
|
||||
}
|
||||
|
||||
public void onLogin() {
|
||||
|
||||
Reference in New Issue
Block a user