Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
f18f06fd
Commit
f18f06fd
authored
Jun 21, 2022
by
Melledy
Browse files
Migrate battlepass to its own db collection
parent
b9bf33c2
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/database/DatabaseHelper.java
View file @
f18f06fd
...
@@ -11,6 +11,7 @@ import emu.grasscutter.GameConstants;
...
@@ -11,6 +11,7 @@ import emu.grasscutter.GameConstants;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.battlepass.BattlePassManager
;
import
emu.grasscutter.game.friends.Friendship
;
import
emu.grasscutter.game.friends.Friendship
;
import
emu.grasscutter.game.gacha.GachaRecord
;
import
emu.grasscutter.game.gacha.GachaRecord
;
import
emu.grasscutter.game.home.GameHome
;
import
emu.grasscutter.game.home.GameHome
;
...
@@ -296,10 +297,27 @@ public final class DatabaseHelper {
...
@@ -296,10 +297,27 @@ public final class DatabaseHelper {
public
static
boolean
deleteQuest
(
GameMainQuest
quest
)
{
public
static
boolean
deleteQuest
(
GameMainQuest
quest
)
{
return
DatabaseManager
.
getGameDatastore
().
delete
(
quest
).
wasAcknowledged
();
return
DatabaseManager
.
getGameDatastore
().
delete
(
quest
).
wasAcknowledged
();
}
}
public
static
GameHome
getHomeByUid
(
int
id
)
{
public
static
GameHome
getHomeByUid
(
int
id
)
{
return
DatabaseManager
.
getGameDatastore
().
find
(
GameHome
.
class
).
filter
(
Filters
.
eq
(
"ownerUid"
,
id
)).
first
();
return
DatabaseManager
.
getGameDatastore
().
find
(
GameHome
.
class
).
filter
(
Filters
.
eq
(
"ownerUid"
,
id
)).
first
();
}
}
public
static
void
saveHome
(
GameHome
gameHome
)
{
public
static
void
saveHome
(
GameHome
gameHome
)
{
DatabaseManager
.
getGameDatastore
().
save
(
gameHome
);
DatabaseManager
.
getGameDatastore
().
save
(
gameHome
);
}
}
public
static
BattlePassManager
loadBattlePass
(
Player
player
)
{
BattlePassManager
manager
=
DatabaseManager
.
getGameDatastore
().
find
(
BattlePassManager
.
class
).
filter
(
Filters
.
eq
(
"ownerUid"
,
player
.
getUid
())).
first
();
if
(
manager
==
null
)
{
manager
=
new
BattlePassManager
(
player
);
manager
.
save
();
}
else
{
manager
.
setPlayer
(
player
);
}
return
manager
;
}
public
static
void
saveBattlePass
(
BattlePassManager
manager
)
{
DatabaseManager
.
getGameDatastore
().
save
(
manager
);
}
}
}
src/main/java/emu/grasscutter/database/DatabaseManager.java
View file @
f18f06fd
...
@@ -14,6 +14,7 @@ import emu.grasscutter.Grasscutter;
...
@@ -14,6 +14,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.battlepass.BattlePassManager
;
import
emu.grasscutter.game.friends.Friendship
;
import
emu.grasscutter.game.friends.Friendship
;
import
emu.grasscutter.game.gacha.GachaRecord
;
import
emu.grasscutter.game.gacha.GachaRecord
;
import
emu.grasscutter.game.home.GameHome
;
import
emu.grasscutter.game.home.GameHome
;
...
@@ -31,7 +32,7 @@ public final class DatabaseManager {
...
@@ -31,7 +32,7 @@ public final class DatabaseManager {
private
static
final
Class
<?>[]
mappedClasses
=
new
Class
<?>[]
{
private
static
final
Class
<?>[]
mappedClasses
=
new
Class
<?>[]
{
DatabaseCounter
.
class
,
Account
.
class
,
Player
.
class
,
Avatar
.
class
,
GameItem
.
class
,
Friendship
.
class
,
DatabaseCounter
.
class
,
Account
.
class
,
Player
.
class
,
Avatar
.
class
,
GameItem
.
class
,
Friendship
.
class
,
GachaRecord
.
class
,
Mail
.
class
,
GameMainQuest
.
class
,
GameHome
.
class
GachaRecord
.
class
,
Mail
.
class
,
GameMainQuest
.
class
,
GameHome
.
class
,
BattlePassManager
.
class
};
};
public
static
Datastore
getGameDatastore
()
{
public
static
Datastore
getGameDatastore
()
{
...
...
src/main/java/emu/grasscutter/game/Account.java
View file @
f18f06fd
...
@@ -29,9 +29,6 @@ public class Account {
...
@@ -29,9 +29,6 @@ public class Account {
private
List
<
String
>
permissions
;
private
List
<
String
>
permissions
;
private
Locale
locale
;
private
Locale
locale
;
private
int
point
;
private
int
awardTakenLevel
;
private
String
banReason
;
private
String
banReason
;
private
int
banEndTime
;
private
int
banEndTime
;
private
int
banStartTime
;
private
int
banStartTime
;
...
@@ -212,22 +209,6 @@ public class Account {
...
@@ -212,22 +209,6 @@ public class Account {
return
this
.
permissions
.
remove
(
permission
);
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
// TODO make unique
public
String
generateLoginToken
()
{
public
String
generateLoginToken
()
{
this
.
token
=
Utils
.
bytesToHex
(
Crypto
.
createSessionKey
(
32
));
this
.
token
=
Utils
.
bytesToHex
(
Crypto
.
createSessionKey
(
32
));
...
...
src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java
View file @
f18f06fd
package
emu.grasscutter.game.battlepass
;
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.game.player.Player
;
import
emu.grasscutter.server.packet.send.PacketBattlePassCurScheduleUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketBattlePassCurScheduleUpdateNotify
;
@Entity
(
value
=
"battlepass"
,
useDiscriminator
=
false
)
public
class
BattlePassManager
{
public
class
BattlePassManager
{
@Id
private
ObjectId
id
;
private
final
Player
player
;
@Transient
private
Player
player
;
@Indexed
private
int
ownerUid
;
private
int
point
;
private
int
point
;
private
int
awardTakenLevel
;
private
int
awardTakenLevel
;
@Deprecated
// Morphia only
public
BattlePassManager
()
{}
public
BattlePassManager
(
Player
player
){
public
BattlePassManager
(
Player
player
)
{
this
.
player
=
player
;
this
.
setPlayer
(
player
);
point
=
player
.
getAccount
().
getPoint
();
}
awardTakenLevel
=
player
.
getAccount
().
getAwardTakenLevel
();
public
ObjectId
getId
()
{
return
id
;
}
public
Player
getPlayer
()
{
return
this
.
player
;
}
public
void
setPlayer
(
Player
player
)
{
this
.
player
=
player
;
this
.
ownerUid
=
player
.
getUid
();
}
public
int
getPoint
()
{
return
point
;
}
public
int
getAwardTakenLevel
()
{
return
awardTakenLevel
;
}
}
public
void
addPoint
(
int
point
){
public
void
addPoint
(
int
point
){
this
.
point
+=
point
;
this
.
point
+=
point
;
player
.
getAccount
().
setPoint
(
point
);
player
.
getSession
().
send
(
new
PacketBattlePassCurScheduleUpdateNotify
(
player
.
getSession
().
getPlayer
()));
player
.
getSession
().
send
(
new
PacketBattlePassCurScheduleUpdateNotify
(
player
.
getSession
().
getPlayer
()));
//save the point data
this
.
save
();
player
.
getAccount
().
save
();
}
}
public
void
updateAwardTakenLevel
(
int
level
){
public
void
updateAwardTakenLevel
(
int
level
){
this
.
awardTakenLevel
=
level
;
this
.
awardTakenLevel
=
level
;
player
.
getAccount
().
setAwardTakenLevel
(
awardTakenLevel
);
player
.
getSession
().
send
(
new
PacketBattlePassCurScheduleUpdateNotify
(
player
.
getSession
().
getPlayer
()));
player
.
getSession
().
send
(
new
PacketBattlePassCurScheduleUpdateNotify
(
player
.
getSession
().
getPlayer
()));
player
.
getAccount
()
.
save
();
this
.
save
();
}
}
public
int
getPoint
()
{
public
void
save
()
{
return
point
;
DatabaseHelper
.
saveBattlePass
(
this
);
}
public
int
getAwardTakenLevel
()
{
return
awardTakenLevel
;
}
}
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
f18f06fd
...
@@ -292,10 +292,6 @@ public class Player {
...
@@ -292,10 +292,6 @@ public class Player {
this
.
account
=
account
;
this
.
account
=
account
;
}
}
public
void
setBattlePassManager
(
Player
player
){
this
.
battlePassManager
=
new
BattlePassManager
(
player
);
}
public
GameSession
getSession
()
{
public
GameSession
getSession
()
{
return
session
;
return
session
;
}
}
...
@@ -1215,6 +1211,11 @@ public class Player {
...
@@ -1215,6 +1211,11 @@ public class Player {
public
BattlePassManager
getBattlePassManager
(){
public
BattlePassManager
getBattlePassManager
(){
return
battlePassManager
;
return
battlePassManager
;
}
}
public
void
loadBattlePassManager
()
{
if
(
this
.
battlePassManager
!=
null
)
return
;
this
.
battlePassManager
=
DatabaseHelper
.
loadBattlePass
(
this
);
}
public
AbilityManager
getAbilityManager
()
{
public
AbilityManager
getAbilityManager
()
{
return
abilityManager
;
return
abilityManager
;
...
@@ -1318,15 +1319,17 @@ public class Player {
...
@@ -1318,15 +1319,17 @@ public class Player {
}
}
//Make sure towerManager's player is online player
//Make sure towerManager's player is online player
this
.
getTowerManager
().
setPlayer
(
this
);
this
.
getTowerManager
().
setPlayer
(
this
);
// Load from db
// Load from db
this
.
getAvatars
().
loadFromDatabase
();
this
.
getAvatars
().
loadFromDatabase
();
this
.
getInventory
().
loadFromDatabase
();
this
.
getInventory
().
loadFromDatabase
();
this
.
getAvatars
().
postLoad
();
this
.
getAvatars
().
postLoad
();
// Needs to be called after inventory is handled
this
.
getFriendsList
().
loadFromDatabase
();
this
.
getFriendsList
().
loadFromDatabase
();
this
.
getMailHandler
().
loadFromDatabase
();
this
.
getMailHandler
().
loadFromDatabase
();
this
.
getQuestManager
().
loadFromDatabase
();
this
.
getQuestManager
().
loadFromDatabase
();
this
.
loadBattlePassManager
();
}
}
public
void
onLogin
()
{
public
void
onLogin
()
{
...
...
src/main/java/emu/grasscutter/server/game/GameSession.java
View file @
f18f06fd
...
@@ -76,7 +76,6 @@ public class GameSession implements GameSessionManager.KcpChannel {
...
@@ -76,7 +76,6 @@ public class GameSession implements GameSessionManager.KcpChannel {
this
.
player
=
player
;
this
.
player
=
player
;
this
.
player
.
setSession
(
this
);
this
.
player
.
setSession
(
this
);
this
.
player
.
setAccount
(
this
.
getAccount
());
this
.
player
.
setAccount
(
this
.
getAccount
());
this
.
player
.
setBattlePassManager
(
this
.
player
);;
}
}
public
SessionState
getState
()
{
public
SessionState
getState
()
{
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassAllDataNotify.java
View file @
f18f06fd
...
@@ -21,7 +21,7 @@ public class PacketBattlePassAllDataNotify extends BasePacket {
...
@@ -21,7 +21,7 @@ public class PacketBattlePassAllDataNotify extends BasePacket {
List
<
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
>
rewardTags
=
new
ArrayList
<>();
List
<
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
>
rewardTags
=
new
ArrayList
<>();
for
(
int
id
=
1
;
id
<=
player
.
get
Account
().
getAwardTakenLevel
();
id
++)
for
(
int
id
=
1
;
id
<=
player
.
get
BattlePassManager
().
getAwardTakenLevel
();
id
++)
rewardTags
.
add
(
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
.
newBuilder
()
rewardTags
.
add
(
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
.
newBuilder
()
.
setLevel
(
id
)
.
setLevel
(
id
)
.
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
)
.
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
)
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassCurScheduleUpdateNotify.java
View file @
f18f06fd
...
@@ -18,7 +18,7 @@ public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket {
...
@@ -18,7 +18,7 @@ public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket {
List
<
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
>
rewardTags
=
new
ArrayList
<>();
List
<
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
>
rewardTags
=
new
ArrayList
<>();
for
(
int
id
=
1
;
id
<=
player
.
get
Account
().
getAwardTakenLevel
();
id
++)
for
(
int
id
=
1
;
id
<=
player
.
get
BattlePassManager
().
getAwardTakenLevel
();
id
++)
rewardTags
.
add
(
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
.
newBuilder
()
rewardTags
.
add
(
BattlePassRewardTagOuterClass
.
BattlePassRewardTag
.
newBuilder
()
.
setLevel
(
id
)
.
setLevel
(
id
)
.
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
)
.
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
)
...
@@ -31,8 +31,7 @@ public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket {
...
@@ -31,8 +31,7 @@ public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket {
.
setIsViewed
(
true
).
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
).
setCurCyclePoints
(
0
)
.
setIsViewed
(
true
).
setUnlockStatus
(
BattlePassUnlockStatusOuterClass
.
BattlePassUnlockStatus
.
BATTLE_PASS_UNLOCK_STATUS_FREE
).
setCurCyclePoints
(
0
)
.
setCurCycle
(
BattlePassCycleOuterClass
.
BattlePassCycle
.
newBuilder
().
setBeginTime
(
1653940800
).
setEndTime
(
2059483200
).
setCycleIdx
(
3
).
build
());
.
setCurCycle
(
BattlePassCycleOuterClass
.
BattlePassCycle
.
newBuilder
().
setBeginTime
(
1653940800
).
setEndTime
(
2059483200
).
setCycleIdx
(
3
).
build
());
var
proto
var
proto
=
BattlePassCurScheduleUpdateNotifyOuterClass
.
BattlePassCurScheduleUpdateNotify
.
newBuilder
();
=
BattlePassCurScheduleUpdateNotifyOuterClass
.
BattlePassCurScheduleUpdateNotify
.
newBuilder
();
proto
.
setHaveCurSchedule
(
true
).
setCurSchedule
(
curSchedule
).
build
();
proto
.
setHaveCurSchedule
(
true
).
setCurSchedule
(
curSchedule
).
build
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment