Align SCUM operations with reference tools

This commit is contained in:
npc0-hue
2026-08-13 18:21:08 +08:00
parent 8b236d7c15
commit da01d39866
24 changed files with 375 additions and 105 deletions
+31 -22
View File
@@ -1,6 +1,10 @@
package domain
import "time"
import (
"encoding/json"
"strings"
"time"
)
const SCUMRewardDeliverCommandType = "reward.deliver"
const SCUMGiftNotificationCommandType = "player.notify"
@@ -15,7 +19,32 @@ type SCUMGiftItemCatalog struct {
Items []SCUMGiftItemDefinition
}
var SCUMGiftItemCatalogs = []SCUMGiftItemCatalog{{GameVersion: "0.9.700.90357", Items: []SCUMGiftItemDefinition{{Key: "bandage", Label: "绷带", MaximumQuantity: 20}, {Key: "water-bottle", Label: "饮用水", MaximumQuantity: 10}, {Key: "improvised-spear", Label: "简易长矛", MaximumQuantity: 2}}}}
func ParseSCUMGiftItemCatalog(content string) (SCUMGiftItemCatalog, bool) {
var catalog struct {
GameVersion string `json:"gameVersion"`
Items []struct {
Key string `json:"key"`
Label string `json:"label"`
MaximumQuantity int `json:"maximumQuantity"`
} `json:"items"`
}
if json.Unmarshal([]byte(content), &catalog) != nil || strings.TrimSpace(catalog.GameVersion) == "" || len(catalog.Items) == 0 {
return SCUMGiftItemCatalog{}, false
}
result := SCUMGiftItemCatalog{GameVersion: catalog.GameVersion, Items: make([]SCUMGiftItemDefinition, 0, len(catalog.Items))}
seen := map[string]struct{}{}
for _, item := range catalog.Items {
if strings.TrimSpace(item.Key) == "" || strings.TrimSpace(item.Label) == "" || item.MaximumQuantity < 1 {
return SCUMGiftItemCatalog{}, false
}
if _, ok := seen[item.Key]; ok {
return SCUMGiftItemCatalog{}, false
}
seen[item.Key] = struct{}{}
result.Items = append(result.Items, SCUMGiftItemDefinition{Key: item.Key, Label: item.Label, MaximumQuantity: item.MaximumQuantity})
}
return result, true
}
type GameGiftItem struct {
CatalogItemKey string
@@ -122,23 +151,3 @@ func CopyGameGiftGrant(value GameGiftGrant) GameGiftGrant {
value.Items = CopyGameGiftItems(value.Items)
return value
}
func SCUMGiftCatalogForVersion(version string) (SCUMGiftItemCatalog, bool) {
for _, catalog := range SCUMGiftItemCatalogs {
if catalog.GameVersion == version {
return catalog, true
}
}
return SCUMGiftItemCatalog{}, false
}
func SCUMGiftItemForVersion(version, key string) (SCUMGiftItemDefinition, bool) {
catalog, ok := SCUMGiftCatalogForVersion(version)
if !ok {
return SCUMGiftItemDefinition{}, false
}
for _, item := range catalog.Items {
if item.Key == key {
return item, true
}
}
return SCUMGiftItemDefinition{}, false
}
+10 -8
View File
@@ -88,14 +88,16 @@ type SCUMObservationResult struct {
type SCUMDataSet string
const (
SCUMDataSetUsers SCUMDataSet = "scum_users"
SCUMDataSetSquads SCUMDataSet = "scum_squads"
SCUMDataSetMembers SCUMDataSet = "scum_squad_members"
SCUMDataSetVehicles SCUMDataSet = "scum_vehicles"
SCUMDataSetFlags SCUMDataSet = "scum_flags"
SCUMDataSetActivity SCUMDataSet = "scum_activity_events"
SCUMDataSetGifts SCUMDataSet = "scum_gift_catalogs"
SCUMDataSetMapPoints SCUMDataSet = "scum_map_points"
SCUMDataSetUsers SCUMDataSet = "scum_users"
SCUMDataSetSquads SCUMDataSet = "scum_squads"
SCUMDataSetMembers SCUMDataSet = "scum_squad_members"
SCUMDataSetVehicles SCUMDataSet = "scum_vehicles"
SCUMDataSetFlags SCUMDataSet = "scum_flags"
SCUMDataSetActivity SCUMDataSet = "scum_activity_events"
// Gift events are facts observed in SCUM's finished_timed_gift_spawner table.
// Platform-owned gift catalogs, revisions, and grants use their own repositories.
SCUMDataSetGiftEvents SCUMDataSet = "scum_gift_events"
SCUMDataSetMapPoints SCUMDataSet = "scum_map_points"
)
type SCUMDataRow struct {