Migrate battlepass to its own db collection

This commit is contained in:
Melledy
2022-06-21 07:59:10 -07:00
parent d8f2421832
commit 23d7ef8378
8 changed files with 76 additions and 50 deletions

View File

@@ -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);
}
}