Fix stale story-unlock and post-evolve weapon state

This commit is contained in:
Ilya Groshev
2026-05-01 16:22:24 +03:00
parent 3fe564cb1d
commit 20d8e4d3df
4 changed files with 145 additions and 11 deletions
+29
View File
@@ -3,6 +3,7 @@ package userdata
import (
"encoding/json"
"fmt"
"reflect"
"strings"
pb "lunar-tear/server/gen/proto"
@@ -120,6 +121,34 @@ func ComputeDeleteKeys(oldRecords, newRecords []map[string]any, keyFields []stri
return string(b)
}
func ComputeUpdateRecords(oldRecords, newRecords []map[string]any, keyFields []string) string {
if len(newRecords) == 0 {
return "[]"
}
oldByKey := make(map[string]map[string]any, len(oldRecords))
for _, r := range oldRecords {
oldByKey[compositeKey(r, keyFields)] = r
}
var changed []map[string]any
for _, r := range newRecords {
prev, exists := oldByKey[compositeKey(r, keyFields)]
if !exists || !reflect.DeepEqual(prev, r) {
changed = append(changed, r)
}
}
if len(changed) == 0 {
return "[]"
}
b, err := json.Marshal(changed)
if err != nil {
return "[]"
}
return string(b)
}
func compositeKey(record map[string]any, fields []string) string {
var sb strings.Builder
for i, f := range fields {