DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
This commit is contained in:
commit
645b64fe21
4388 files changed
+1405457
No files matched your search
@@ -0,0 +1,237 @@
|
||||
// Package epicwish owns the character-scoped durable Epic wish list.
|
||||
// Packet layouts, PVF item validation, dungeon routing, and reward selection
|
||||
// remain outside this package.
|
||||
package epicwish
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaximumItems is the current client's fixed Epic wish slot count.
|
||||
MaximumItems = 5
|
||||
// CountStat stores the number of serialized wish slots, including zero
|
||||
// placeholders retained by the client.
|
||||
CountStat = "epic_wish_count"
|
||||
)
|
||||
|
||||
var itemStatKeys = [MaximumItems]string{
|
||||
"epic_wish_item_0",
|
||||
"epic_wish_item_1",
|
||||
"epic_wish_item_2",
|
||||
"epic_wish_item_3",
|
||||
"epic_wish_item_4",
|
||||
}
|
||||
|
||||
var (
|
||||
ErrOwnerUnavailable = errors.New("epic wish owner is unavailable")
|
||||
ErrCharacterRequired = errors.New("epic wish character id is required")
|
||||
ErrAccountRequired = errors.New("epic wish account id is required")
|
||||
ErrCharacterNotFound = errors.New("epic wish character is missing")
|
||||
ErrAccountMismatch = errors.New("epic wish character does not belong to account")
|
||||
ErrTooManyItems = errors.New("epic wish item count exceeds client limit")
|
||||
ErrDuplicateItem = errors.New("epic wish contains a duplicate nonzero item")
|
||||
ErrPersistedStateInvalid = errors.New("persisted epic wish state is invalid")
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
CharacterID string
|
||||
AccountID string
|
||||
Items []uint32
|
||||
}
|
||||
|
||||
// Result is detached from both the repository transaction and the command.
|
||||
// Callers may retain or mutate it without changing durable state.
|
||||
type Result struct {
|
||||
Character dnfrepo.CharacterRecord
|
||||
Items []uint32
|
||||
Changed bool
|
||||
}
|
||||
|
||||
// Owner owns only the atomic Character.Stats mutation.
|
||||
type Owner struct {
|
||||
assets dnfrepo.CharacterAssetUnitOfWork
|
||||
}
|
||||
|
||||
func NewOwner(repositories dnfrepo.Group) (*Owner, error) {
|
||||
if repositories.CharacterAssets == nil {
|
||||
return nil, ErrOwnerUnavailable
|
||||
}
|
||||
return &Owner{assets: repositories.CharacterAssets}, nil
|
||||
}
|
||||
|
||||
// Apply replaces the complete ordered wish list. Replaying the same canonical
|
||||
// list is idempotent and does not issue another repository save.
|
||||
func (o *Owner) Apply(ctx context.Context, command Command) (Result, error) {
|
||||
if o == nil || o.assets == nil {
|
||||
return Result{}, ErrOwnerUnavailable
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
characterID := strings.TrimSpace(command.CharacterID)
|
||||
if characterID == "" {
|
||||
return Result{}, ErrCharacterRequired
|
||||
}
|
||||
accountID := strings.TrimSpace(command.AccountID)
|
||||
if accountID == "" {
|
||||
return Result{}, ErrAccountRequired
|
||||
}
|
||||
items, err := cloneValidatedItems(command.Items)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
|
||||
var result Result
|
||||
err = o.assets.WithinCharacterAssets(ctx, characterID, func(
|
||||
characters dnfrepo.CharacterRepository,
|
||||
_ dnfrepo.InventoryRepository,
|
||||
_ dnfrepo.EquipmentRepository,
|
||||
) error {
|
||||
if characters == nil {
|
||||
return ErrOwnerUnavailable
|
||||
}
|
||||
character, found, loadErr := characters.Load(ctx, characterID)
|
||||
if loadErr != nil {
|
||||
return fmt.Errorf("load epic wish character: %w", loadErr)
|
||||
}
|
||||
if !found || strings.TrimSpace(character.CharacterID) != characterID {
|
||||
return fmt.Errorf("%w: character=%s", ErrCharacterNotFound, characterID)
|
||||
}
|
||||
if strings.TrimSpace(character.AccountID) != accountID {
|
||||
return fmt.Errorf(
|
||||
"%w: account=%q character=%s",
|
||||
ErrAccountMismatch,
|
||||
accountID,
|
||||
characterID,
|
||||
)
|
||||
}
|
||||
|
||||
changed := !hasCanonicalStats(character.Stats, items)
|
||||
character = dnfrepo.CloneCharacter(character)
|
||||
if changed {
|
||||
if character.Stats == nil {
|
||||
character.Stats = make(map[string]int64, MaximumItems+1)
|
||||
}
|
||||
character.Stats[CountStat] = int64(len(items))
|
||||
for index, key := range itemStatKeys {
|
||||
var value uint32
|
||||
if index < len(items) {
|
||||
value = items[index]
|
||||
}
|
||||
character.Stats[key] = int64(value)
|
||||
}
|
||||
if saveErr := dnfrepo.SaveCharacterFields(
|
||||
ctx,
|
||||
characters,
|
||||
character,
|
||||
dnfrepo.CharacterFieldStats,
|
||||
); saveErr != nil {
|
||||
return fmt.Errorf("save epic wish character stats: %w", saveErr)
|
||||
}
|
||||
}
|
||||
result = freezeResult(Result{Character: character, Items: items, Changed: changed})
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
return freezeResult(result), nil
|
||||
}
|
||||
|
||||
// ItemsFromCharacter decodes one canonical persisted wish list. Invalid
|
||||
// durable values fail closed instead of being truncated into a forged client
|
||||
// snapshot.
|
||||
func ItemsFromCharacter(character dnfrepo.CharacterRecord) ([]uint32, error) {
|
||||
if character.Stats == nil {
|
||||
return nil, nil
|
||||
}
|
||||
count := character.Stats[CountStat]
|
||||
if count < 0 || count > MaximumItems {
|
||||
return nil, fmt.Errorf("%w: count=%d", ErrPersistedStateInvalid, count)
|
||||
}
|
||||
items := make([]uint32, int(count))
|
||||
seen := make(map[uint32]struct{}, len(items))
|
||||
for index := range items {
|
||||
value := character.Stats[itemStatKeys[index]]
|
||||
if value < 0 || value > math.MaxUint32 {
|
||||
return nil, fmt.Errorf(
|
||||
"%w: slot=%d value=%d",
|
||||
ErrPersistedStateInvalid,
|
||||
index,
|
||||
value,
|
||||
)
|
||||
}
|
||||
items[index] = uint32(value)
|
||||
if items[index] == 0 {
|
||||
continue
|
||||
}
|
||||
if _, duplicate := seen[items[index]]; duplicate {
|
||||
return nil, fmt.Errorf(
|
||||
"%w: %w: item=%d",
|
||||
ErrPersistedStateInvalid,
|
||||
ErrDuplicateItem,
|
||||
items[index],
|
||||
)
|
||||
}
|
||||
seen[items[index]] = struct{}{}
|
||||
}
|
||||
return append([]uint32(nil), items...), nil
|
||||
}
|
||||
|
||||
func cloneValidatedItems(items []uint32) ([]uint32, error) {
|
||||
if len(items) > MaximumItems {
|
||||
return nil, fmt.Errorf("%w: count=%d", ErrTooManyItems, len(items))
|
||||
}
|
||||
cloned := append([]uint32(nil), items...)
|
||||
seen := make(map[uint32]struct{}, len(cloned))
|
||||
for _, itemID := range cloned {
|
||||
if itemID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, duplicate := seen[itemID]; duplicate {
|
||||
return nil, fmt.Errorf("%w: item=%d", ErrDuplicateItem, itemID)
|
||||
}
|
||||
seen[itemID] = struct{}{}
|
||||
}
|
||||
return cloned, nil
|
||||
}
|
||||
|
||||
func hasCanonicalStats(stats map[string]int64, items []uint32) bool {
|
||||
if stats == nil {
|
||||
return false
|
||||
}
|
||||
count, found := stats[CountStat]
|
||||
if !found || count != int64(len(items)) {
|
||||
return false
|
||||
}
|
||||
for index, key := range itemStatKeys {
|
||||
value, found := stats[key]
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
var want uint32
|
||||
if index < len(items) {
|
||||
want = items[index]
|
||||
}
|
||||
if value != int64(want) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func freezeResult(result Result) Result {
|
||||
result.Character = dnfrepo.CloneCharacter(result.Character)
|
||||
result.Items = append([]uint32(nil), result.Items...)
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
package epicwish
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
dnfrepomemory "longheng.io/server/internal/modules/dnf/repository/memory"
|
||||
"longheng.io/server/internal/platform/db"
|
||||
)
|
||||
|
||||
func TestOwnerApplyPersistsCanonicalStatsAndFreezesResult(t *testing.T) {
|
||||
repositories := seededEpicWishRepositories(t, map[string]int64{
|
||||
"gold": 99,
|
||||
CountStat: 1,
|
||||
itemStatKeys[0]: 900,
|
||||
itemStatKeys[1]: 901,
|
||||
itemStatKeys[2]: 902,
|
||||
itemStatKeys[3]: 903,
|
||||
itemStatKeys[4]: 904,
|
||||
"unrelated_marker": 77,
|
||||
})
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
requested := []uint32{100, 0, 200}
|
||||
result, err := owner.Apply(context.Background(), Command{
|
||||
CharacterID: " 19 ",
|
||||
AccountID: " account-1 ",
|
||||
Items: requested,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !result.Changed || !reflect.DeepEqual(result.Items, requested) {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
assertEpicWishCharacter(t, result.Character, requested)
|
||||
if result.Character.Stats["gold"] != 99 || result.Character.Stats["unrelated_marker"] != 77 {
|
||||
t.Fatalf("unrelated stats changed: %+v", result.Character.Stats)
|
||||
}
|
||||
|
||||
requested[0] = 999
|
||||
result.Items[0] = 998
|
||||
result.Character.Stats[itemStatKeys[0]] = 997
|
||||
stored := loadEpicWishCharacter(t, repositories)
|
||||
assertEpicWishCharacter(t, stored, []uint32{100, 0, 200})
|
||||
if stored.Stats["gold"] != 99 || stored.Stats["unrelated_marker"] != 77 {
|
||||
t.Fatalf("stored unrelated stats changed: %+v", stored.Stats)
|
||||
}
|
||||
items, err := ItemsFromCharacter(stored)
|
||||
if err != nil || !reflect.DeepEqual(items, []uint32{100, 0, 200}) {
|
||||
t.Fatalf("decoded items=%v err=%v", items, err)
|
||||
}
|
||||
items[0] = 996
|
||||
if again, _ := ItemsFromCharacter(stored); !reflect.DeepEqual(again, []uint32{100, 0, 200}) {
|
||||
t.Fatalf("decoded items were not frozen: %v", again)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyRepeatedRequestIsIdempotent(t *testing.T) {
|
||||
repositories := seededEpicWishRepositories(t, map[string]int64{"gold": 50})
|
||||
saves := 0
|
||||
repositories.CharacterAssets = countingEpicWishAssets{
|
||||
base: repositories.CharacterAssets,
|
||||
saves: &saves,
|
||||
}
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
command := Command{CharacterID: "19", AccountID: "account-1", Items: []uint32{100, 0, 200}}
|
||||
first, err := owner.Apply(context.Background(), command)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := owner.Apply(context.Background(), command)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !first.Changed || second.Changed || saves != 1 {
|
||||
t.Fatalf("first=%+v second=%+v saves=%d", first, second, saves)
|
||||
}
|
||||
first.Items[0] = 999
|
||||
first.Character.Stats[itemStatKeys[0]] = 998
|
||||
if !reflect.DeepEqual(second.Items, command.Items) || second.Character.Stats[itemStatKeys[0]] != 100 {
|
||||
t.Fatalf("idempotent results share mutable state: first=%+v second=%+v", first, second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyValidatesLimitAndNonzeroUniquenessBeforeMutation(t *testing.T) {
|
||||
repositories := seededEpicWishRepositories(t, canonicalEpicWishStats([]uint32{700}))
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
items []uint32
|
||||
want error
|
||||
}{
|
||||
{name: "too many", items: []uint32{1, 2, 3, 4, 5, 6}, want: ErrTooManyItems},
|
||||
{name: "duplicate nonzero", items: []uint32{1, 0, 1}, want: ErrDuplicateItem},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if _, err := owner.Apply(context.Background(), Command{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Items: test.items,
|
||||
}); !errors.Is(err, test.want) {
|
||||
t.Fatalf("err=%v want=%v", err, test.want)
|
||||
}
|
||||
assertEpicWishCharacter(t, loadEpicWishCharacter(t, repositories), []uint32{700})
|
||||
})
|
||||
}
|
||||
|
||||
result, err := owner.Apply(context.Background(), Command{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Items: []uint32{0, 0},
|
||||
})
|
||||
if err != nil || !result.Changed {
|
||||
t.Fatalf("zero placeholders result=%+v err=%v", result, err)
|
||||
}
|
||||
assertEpicWishCharacter(t, loadEpicWishCharacter(t, repositories), []uint32{0, 0})
|
||||
}
|
||||
|
||||
func TestOwnerApplyRejectsNilOwnerMissingIdentityAndAccountMismatch(t *testing.T) {
|
||||
if _, err := NewOwner(dnfrepo.Group{}); !errors.Is(err, ErrOwnerUnavailable) {
|
||||
t.Fatalf("NewOwner err=%v", err)
|
||||
}
|
||||
var nilOwner *Owner
|
||||
if _, err := nilOwner.Apply(context.Background(), Command{}); !errors.Is(err, ErrOwnerUnavailable) {
|
||||
t.Fatalf("nil owner err=%v", err)
|
||||
}
|
||||
|
||||
repositories := seededEpicWishRepositories(t, canonicalEpicWishStats([]uint32{700}))
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
command Command
|
||||
want error
|
||||
}{
|
||||
{name: "character", command: Command{AccountID: "account-1"}, want: ErrCharacterRequired},
|
||||
{name: "account", command: Command{CharacterID: "19"}, want: ErrAccountRequired},
|
||||
{name: "mismatch", command: Command{CharacterID: "19", AccountID: "account-2"}, want: ErrAccountMismatch},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if _, err := owner.Apply(context.Background(), test.command); !errors.Is(err, test.want) {
|
||||
t.Fatalf("err=%v want=%v", err, test.want)
|
||||
}
|
||||
assertEpicWishCharacter(t, loadEpicWishCharacter(t, repositories), []uint32{700})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyHandlesNilAndCanceledContext(t *testing.T) {
|
||||
repositories := seededEpicWishRepositories(t, canonicalEpicWishStats([]uint32{700}))
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := owner.Apply(nil, Command{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Items: []uint32{701},
|
||||
}); err != nil {
|
||||
t.Fatalf("nil context err=%v", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if _, err := owner.Apply(ctx, Command{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Items: []uint32{702},
|
||||
}); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("canceled context err=%v", err)
|
||||
}
|
||||
assertEpicWishCharacter(t, loadEpicWishCharacter(t, repositories), []uint32{701})
|
||||
}
|
||||
|
||||
func TestOwnerApplyRollsBackAndReturnsNoUncommittedResult(t *testing.T) {
|
||||
repositories := seededEpicWishRepositories(t, canonicalEpicWishStats([]uint32{700}))
|
||||
wantErr := errors.New("reject epic wish commit")
|
||||
repositories.CharacterAssets = rejectEpicWishAssetsAfterApply{
|
||||
base: repositories.CharacterAssets,
|
||||
err: wantErr,
|
||||
}
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := owner.Apply(context.Background(), Command{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Items: []uint32{800},
|
||||
})
|
||||
if !errors.Is(err, wantErr) || !reflect.DeepEqual(result, Result{}) {
|
||||
t.Fatalf("result=%+v err=%v", result, err)
|
||||
}
|
||||
assertEpicWishCharacter(t, loadEpicWishCharacter(t, repositories), []uint32{700})
|
||||
}
|
||||
|
||||
func TestItemsFromCharacterRejectsCorruptPersistedState(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
stats map[string]int64
|
||||
}{
|
||||
{name: "negative count", stats: map[string]int64{CountStat: -1}},
|
||||
{name: "oversized count", stats: map[string]int64{CountStat: MaximumItems + 1}},
|
||||
{name: "negative item", stats: map[string]int64{CountStat: 1, itemStatKeys[0]: -1}},
|
||||
{name: "oversized item", stats: map[string]int64{CountStat: 1, itemStatKeys[0]: int64(^uint32(0)) + 1}},
|
||||
{name: "duplicate item", stats: map[string]int64{CountStat: 2, itemStatKeys[0]: 9, itemStatKeys[1]: 9}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if _, err := ItemsFromCharacter(dnfrepo.CharacterRecord{Stats: test.stats}); !errors.Is(err, ErrPersistedStateInvalid) {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
items, err := ItemsFromCharacter(dnfrepo.CharacterRecord{})
|
||||
if err != nil || items != nil {
|
||||
t.Fatalf("empty character items=%v err=%v", items, err)
|
||||
}
|
||||
}
|
||||
|
||||
func seededEpicWishRepositories(t *testing.T, stats map[string]int64) dnfrepo.Group {
|
||||
t.Helper()
|
||||
repositories := dnfrepomemory.NewMemoryGroup()
|
||||
character := dnfrepo.CharacterRecord{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Stats: make(map[string]int64, len(stats)),
|
||||
}
|
||||
for key, value := range stats {
|
||||
character.Stats[key] = value
|
||||
}
|
||||
if err := repositories.Character.Save(context.Background(), character); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return repositories
|
||||
}
|
||||
|
||||
func canonicalEpicWishStats(items []uint32) map[string]int64 {
|
||||
stats := map[string]int64{CountStat: int64(len(items))}
|
||||
for index, key := range itemStatKeys {
|
||||
if index < len(items) {
|
||||
stats[key] = int64(items[index])
|
||||
} else {
|
||||
stats[key] = 0
|
||||
}
|
||||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
func assertEpicWishCharacter(t *testing.T, character dnfrepo.CharacterRecord, want []uint32) {
|
||||
t.Helper()
|
||||
items, err := ItemsFromCharacter(character)
|
||||
if err != nil || !reflect.DeepEqual(items, want) {
|
||||
t.Fatalf("character=%+v items=%v want=%v err=%v", character, items, want, err)
|
||||
}
|
||||
if !hasCanonicalStats(character.Stats, want) {
|
||||
t.Fatalf("character stats are not canonical: %+v", character.Stats)
|
||||
}
|
||||
}
|
||||
|
||||
func loadEpicWishCharacter(t *testing.T, repositories dnfrepo.Group) dnfrepo.CharacterRecord {
|
||||
t.Helper()
|
||||
character, found, err := repositories.Character.Load(context.Background(), "19")
|
||||
if err != nil || !found {
|
||||
t.Fatalf("load character found=%t err=%v", found, err)
|
||||
}
|
||||
return character
|
||||
}
|
||||
|
||||
type countingEpicWishAssets struct {
|
||||
base dnfrepo.CharacterAssetUnitOfWork
|
||||
saves *int
|
||||
}
|
||||
|
||||
func (u countingEpicWishAssets) WithinCharacterAssets(
|
||||
ctx context.Context,
|
||||
characterID string,
|
||||
apply func(dnfrepo.CharacterRepository, dnfrepo.InventoryRepository, dnfrepo.EquipmentRepository) error,
|
||||
) error {
|
||||
return u.base.WithinCharacterAssets(ctx, characterID, func(
|
||||
characters dnfrepo.CharacterRepository,
|
||||
inventory dnfrepo.InventoryRepository,
|
||||
equipment dnfrepo.EquipmentRepository,
|
||||
) error {
|
||||
return apply(countingEpicWishCharacters{CharacterRepository: characters, saves: u.saves}, inventory, equipment)
|
||||
})
|
||||
}
|
||||
|
||||
type countingEpicWishCharacters struct {
|
||||
dnfrepo.CharacterRepository
|
||||
saves *int
|
||||
}
|
||||
|
||||
func (r countingEpicWishCharacters) Save(ctx context.Context, character dnfrepo.CharacterRecord) error {
|
||||
*r.saves++
|
||||
return r.CharacterRepository.Save(ctx, character)
|
||||
}
|
||||
|
||||
func (r countingEpicWishCharacters) SaveFields(
|
||||
ctx context.Context,
|
||||
character dnfrepo.CharacterRecord,
|
||||
fields ...dnfrepo.CharacterField,
|
||||
) error {
|
||||
*r.saves++
|
||||
return dnfrepo.SaveCharacterFields(ctx, r.CharacterRepository, character, fields...)
|
||||
}
|
||||
|
||||
type rejectEpicWishAssetsAfterApply struct {
|
||||
base dnfrepo.CharacterAssetUnitOfWork
|
||||
err error
|
||||
}
|
||||
|
||||
func (u rejectEpicWishAssetsAfterApply) WithinCharacterAssets(
|
||||
ctx context.Context,
|
||||
characterID string,
|
||||
apply func(dnfrepo.CharacterRepository, dnfrepo.InventoryRepository, dnfrepo.EquipmentRepository) error,
|
||||
) error {
|
||||
return u.base.WithinCharacterAssets(ctx, characterID, func(
|
||||
characters dnfrepo.CharacterRepository,
|
||||
inventory dnfrepo.InventoryRepository,
|
||||
equipment dnfrepo.EquipmentRepository,
|
||||
) error {
|
||||
if err := apply(characters, inventory, equipment); err != nil {
|
||||
return err
|
||||
}
|
||||
return u.err
|
||||
})
|
||||
}
|
||||
|
||||
var _ db.FieldStore[dnfrepo.CharacterRecord, dnfrepo.CharacterField] = countingEpicWishCharacters{}
|
||||
Reference in new issue
Block a user