mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 18:05:05 +01:00
Migrate battlepass to its own db collection
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user