Align SCUM operations with reference tools
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user