mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Refactor tutorial progress update logic to prevent overwriting existing progress unless the new phase is greater.
This commit is contained in:
@@ -29,11 +29,14 @@ func (s *TutorialServiceServer) SetTutorialProgress(ctx context.Context, req *pb
|
|||||||
nowMillis := gametime.NowMillis()
|
nowMillis := gametime.NowMillis()
|
||||||
var grants []questflow.RewardGrant
|
var grants []questflow.RewardGrant
|
||||||
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
|
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
|
||||||
|
existing, exists := user.Tutorials[req.TutorialType]
|
||||||
|
if !exists || req.ProgressPhase >= existing.ProgressPhase {
|
||||||
user.Tutorials[req.TutorialType] = store.TutorialProgressState{
|
user.Tutorials[req.TutorialType] = store.TutorialProgressState{
|
||||||
TutorialType: req.TutorialType,
|
TutorialType: req.TutorialType,
|
||||||
ProgressPhase: req.ProgressPhase,
|
ProgressPhase: req.ProgressPhase,
|
||||||
ChoiceId: req.ChoiceId,
|
ChoiceId: req.ChoiceId,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if req.TutorialType == int32(model.TutorialTypeMenuFirst) ||
|
if req.TutorialType == int32(model.TutorialTypeMenuFirst) ||
|
||||||
req.TutorialType == int32(model.TutorialTypeMenuSecond) {
|
req.TutorialType == int32(model.TutorialTypeMenuSecond) {
|
||||||
store.EnsureDefaultDeck(user, nowMillis)
|
store.EnsureDefaultDeck(user, nowMillis)
|
||||||
@@ -74,10 +77,13 @@ func (s *TutorialServiceServer) SetTutorialProgressAndReplaceDeck(ctx context.Co
|
|||||||
log.Printf("[TutorialService] SetTutorialProgressAndReplaceDeck: type=%d phase=%d deckType=%d deckNumber=%d", req.TutorialType, req.ProgressPhase, req.DeckType, req.UserDeckNumber)
|
log.Printf("[TutorialService] SetTutorialProgressAndReplaceDeck: type=%d phase=%d deckType=%d deckNumber=%d", req.TutorialType, req.ProgressPhase, req.DeckType, req.UserDeckNumber)
|
||||||
userId := currentUserId(ctx, s.users, s.sessions)
|
userId := currentUserId(ctx, s.users, s.sessions)
|
||||||
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
|
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
|
||||||
|
existing, exists := user.Tutorials[req.TutorialType]
|
||||||
|
if !exists || req.ProgressPhase >= existing.ProgressPhase {
|
||||||
user.Tutorials[req.TutorialType] = store.TutorialProgressState{
|
user.Tutorials[req.TutorialType] = store.TutorialProgressState{
|
||||||
TutorialType: req.TutorialType,
|
TutorialType: req.TutorialType,
|
||||||
ProgressPhase: req.ProgressPhase,
|
ProgressPhase: req.ProgressPhase,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if req.Deck != nil {
|
if req.Deck != nil {
|
||||||
store.ApplyDeckReplacement(user, model.DeckType(req.DeckType), req.UserDeckNumber, deckSlotsFromProto(req.Deck), gametime.NowMillis())
|
store.ApplyDeckReplacement(user, model.DeckType(req.DeckType), req.UserDeckNumber, deckSlotsFromProto(req.Deck), gametime.NowMillis())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user