feat(scum): add versioned gift grants
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
const SCUMRewardDeliverCommandType = "reward.deliver"
|
||||
const SCUMGiftNotificationCommandType = "player.notify"
|
||||
|
||||
type SCUMGiftItemDefinition struct {
|
||||
Key string
|
||||
Label string
|
||||
MaximumQuantity int
|
||||
}
|
||||
type SCUMGiftItemCatalog struct {
|
||||
GameVersion string
|
||||
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}}}}
|
||||
|
||||
type GameGiftItem struct {
|
||||
CatalogItemKey string
|
||||
Label string
|
||||
Quantity int
|
||||
}
|
||||
type GameGiftCatalog struct {
|
||||
ID string
|
||||
ServerInstanceID string
|
||||
Name string
|
||||
GameVersion string
|
||||
DraftItems []GameGiftItem
|
||||
LatestRevisionID string
|
||||
CreatedBy string
|
||||
UpdatedAt time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
type GameGiftRevision struct {
|
||||
ID string
|
||||
CatalogID string
|
||||
ServerInstanceID string
|
||||
Revision int
|
||||
GameVersion string
|
||||
Items []GameGiftItem
|
||||
PublishedBy string
|
||||
PublishedAt time.Time
|
||||
}
|
||||
type GameGiftGrantStatus string
|
||||
|
||||
const (
|
||||
GameGiftGrantPendingApproval GameGiftGrantStatus = "pending-approval"
|
||||
GameGiftGrantQueued GameGiftGrantStatus = "queued"
|
||||
GameGiftGrantDelivered GameGiftGrantStatus = "delivered"
|
||||
GameGiftGrantNotificationFailed GameGiftGrantStatus = "notification_failed"
|
||||
GameGiftGrantFailed GameGiftGrantStatus = "failed"
|
||||
GameGiftGrantUnknown GameGiftGrantStatus = "unknown"
|
||||
)
|
||||
|
||||
type GameGiftGrant struct {
|
||||
ID string
|
||||
ServerInstanceID string
|
||||
CatalogID string
|
||||
RevisionID string
|
||||
RevisionNumber int
|
||||
GameVersion string
|
||||
Items []GameGiftItem
|
||||
GamePlayerRecordID string
|
||||
GamePlayerID string
|
||||
PlayerDisplayName string
|
||||
Notice string
|
||||
IdempotencyKey string
|
||||
RequesterID string
|
||||
ApproverID string
|
||||
Status GameGiftGrantStatus
|
||||
DeliveryCommandID string
|
||||
NotificationCommandID string
|
||||
DeliverySummary string
|
||||
NotificationSummary string
|
||||
CreatedAt time.Time
|
||||
ApprovedAt time.Time
|
||||
CompletedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
type GameGiftCatalogFilter struct {
|
||||
ServerInstanceID string
|
||||
Limit int
|
||||
}
|
||||
type GameGiftRevisionFilter struct {
|
||||
CatalogID string
|
||||
ServerInstanceID string
|
||||
Limit int
|
||||
}
|
||||
type GameGiftGrantFilter struct {
|
||||
ServerInstanceID string
|
||||
GamePlayerRecordID string
|
||||
IdempotencyKey string
|
||||
Limit int
|
||||
}
|
||||
type GameGiftCatalogRequest struct {
|
||||
ID string
|
||||
Name string
|
||||
GameVersion string
|
||||
Items []GameGiftItem
|
||||
}
|
||||
type GameGiftGrantRequest struct {
|
||||
RevisionID string
|
||||
GamePlayerRecordID string
|
||||
Notice string
|
||||
IdempotencyKey string
|
||||
}
|
||||
|
||||
func CopyGameGiftItems(items []GameGiftItem) []GameGiftItem {
|
||||
return append([]GameGiftItem(nil), items...)
|
||||
}
|
||||
func CopyGameGiftCatalog(value GameGiftCatalog) GameGiftCatalog {
|
||||
value.DraftItems = CopyGameGiftItems(value.DraftItems)
|
||||
return value
|
||||
}
|
||||
func CopyGameGiftRevision(value GameGiftRevision) GameGiftRevision {
|
||||
value.Items = CopyGameGiftItems(value.Items)
|
||||
return value
|
||||
}
|
||||
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