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,402 @@
|
||||
package avatarfitting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
PartCount = 8
|
||||
settingsScopeSuffix = ":avatar_fitting_room"
|
||||
settingsUsedParts = "used_parts_total"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrOwnerUnavailable = errors.New("dnf avatar fitting room owner is unavailable")
|
||||
ErrCharacterRequired = errors.New("dnf avatar fitting room character is required")
|
||||
ErrCharacterNotFound = errors.New("dnf avatar fitting room character was not found")
|
||||
ErrAccountMismatch = errors.New("dnf avatar fitting room account does not match")
|
||||
ErrTownRequired = errors.New("dnf avatar fitting room requires town state")
|
||||
ErrRequestInvalid = errors.New("dnf avatar fitting room request is invalid")
|
||||
ErrEquipmentMismatch = errors.New("dnf avatar fitting room equipped avatar does not match")
|
||||
ErrTicketMissing = errors.New("dnf avatar fitting room ticket is missing")
|
||||
ErrRewardSpace = errors.New("dnf avatar fitting room reward inventory space is unavailable")
|
||||
)
|
||||
|
||||
// Change is one of the eight current-client avatar fitting-room rows. The
|
||||
// durable equipment slot is server-owned; ObjectIndex is echoed only after a
|
||||
// successful commit so the client can rebind the already refreshed object.
|
||||
type Change struct {
|
||||
EquipmentSlot int16
|
||||
ObjectIndex int32
|
||||
CurrentItemID int64
|
||||
OutputItemID int64
|
||||
PVFPath string
|
||||
EquipmentType string
|
||||
}
|
||||
|
||||
type Reward struct {
|
||||
ItemID int64
|
||||
CountPerCrossing int64
|
||||
SlotStart int16
|
||||
SlotEnd int16
|
||||
StackLimit int64
|
||||
BuildStack func(slot int16, count int64) (dnfrepo.ItemStack, error)
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
AccountID string
|
||||
CharacterID string
|
||||
InDungeon bool
|
||||
TicketItemID int64
|
||||
Changes [PartCount]Change
|
||||
GaugeThreshold int64
|
||||
Reward *Reward
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Changes [PartCount]Change
|
||||
TicketSlots []int16
|
||||
EquipmentSlots []int16
|
||||
RewardSlots []int16
|
||||
TicketConsumed int64
|
||||
RewardGranted int64
|
||||
GaugeBefore int64
|
||||
GaugeAfter int64
|
||||
}
|
||||
|
||||
type Owner struct {
|
||||
settlements dnfrepo.CharacterSettlementUnitOfWork
|
||||
}
|
||||
|
||||
func NewOwner(repositories dnfrepo.Group) (*Owner, error) {
|
||||
if repositories.CharacterSettlement == nil {
|
||||
return nil, ErrOwnerUnavailable
|
||||
}
|
||||
return &Owner{settlements: repositories.CharacterSettlement}, nil
|
||||
}
|
||||
|
||||
// Commit atomically replaces all eligible worn avatar rows, consumes one
|
||||
// fitting-room ticket per replaced row and advances the character-local VIP
|
||||
// gauge. Equipment, inventory and gauge are never allowed to diverge.
|
||||
func (o *Owner) Commit(ctx context.Context, command Command) (Result, error) {
|
||||
if o == nil || o.settlements == nil {
|
||||
return Result{}, ErrOwnerUnavailable
|
||||
}
|
||||
command.AccountID = strings.TrimSpace(command.AccountID)
|
||||
command.CharacterID = strings.TrimSpace(command.CharacterID)
|
||||
if command.AccountID == "" || command.CharacterID == "" || command.TicketItemID <= 0 {
|
||||
return Result{}, ErrCharacterRequired
|
||||
}
|
||||
if command.InDungeon {
|
||||
return Result{}, ErrTownRequired
|
||||
}
|
||||
var result Result
|
||||
err := o.settlements.WithinCharacterSettlement(ctx, command.CharacterID, func(tx dnfrepo.Group) error {
|
||||
if tx.Character == nil || tx.Inventory == nil || tx.Equipment == nil || tx.Settings == nil {
|
||||
return ErrOwnerUnavailable
|
||||
}
|
||||
character, found, err := tx.Character.Load(ctx, command.CharacterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return ErrCharacterNotFound
|
||||
}
|
||||
if strings.TrimSpace(character.AccountID) != command.AccountID {
|
||||
return ErrAccountMismatch
|
||||
}
|
||||
inventory, found, err := tx.Inventory.Load(ctx, command.CharacterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return ErrTicketMissing
|
||||
}
|
||||
equipment, found, err := tx.Equipment.Load(ctx, command.CharacterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return ErrEquipmentMismatch
|
||||
}
|
||||
inventory = dnfrepo.CloneInventory(inventory)
|
||||
equipment = dnfrepo.CloneEquipment(equipment)
|
||||
|
||||
changed := make(map[int16]struct{}, PartCount)
|
||||
for index, change := range command.Changes {
|
||||
if change.EquipmentSlot < 0 {
|
||||
if change.ObjectIndex != -1 || change.CurrentItemID != -1 || change.OutputItemID != 0 {
|
||||
return fmt.Errorf("%w: absent part=%d", ErrRequestInvalid, index)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if change.ObjectIndex < 0 || change.CurrentItemID <= 0 || change.OutputItemID <= 0 ||
|
||||
change.OutputItemID > math.MaxUint32 || strings.TrimSpace(change.PVFPath) == "" ||
|
||||
strings.TrimSpace(change.EquipmentType) == "" {
|
||||
return fmt.Errorf("%w: part=%d", ErrRequestInvalid, index)
|
||||
}
|
||||
if _, duplicate := changed[change.EquipmentSlot]; duplicate {
|
||||
return fmt.Errorf("%w: duplicate equipment slot=%d", ErrRequestInvalid, change.EquipmentSlot)
|
||||
}
|
||||
key, entry, ok := equipmentEntryForSlot(equipment, change.EquipmentSlot)
|
||||
if !ok || entry.ItemID != change.CurrentItemID {
|
||||
return fmt.Errorf("%w: part=%d slot=%d expected=%d", ErrEquipmentMismatch, index, change.EquipmentSlot, change.CurrentItemID)
|
||||
}
|
||||
entry.ItemID = change.OutputItemID
|
||||
if len(entry.RawEntry) < 6 {
|
||||
return fmt.Errorf("%w: part=%d slot=%d raw=%d", ErrEquipmentMismatch, index, change.EquipmentSlot, len(entry.RawEntry))
|
||||
}
|
||||
entry.RawEntry = append([]byte(nil), entry.RawEntry...)
|
||||
binary.LittleEndian.PutUint32(entry.RawEntry[2:6], uint32(change.OutputItemID))
|
||||
entry.Extra = cloneStringMap(entry.Extra)
|
||||
entry.Extra["pvf_path"] = strings.TrimSpace(change.PVFPath)
|
||||
entry.Extra["equipment_type"] = strings.TrimSpace(change.EquipmentType)
|
||||
delete(entry.Extra, dnfrepo.CloneAvatarAppearanceExtraKey)
|
||||
equipment.Entries[key] = entry
|
||||
changed[change.EquipmentSlot] = struct{}{}
|
||||
result.Changes[index] = change
|
||||
result.EquipmentSlots = append(result.EquipmentSlots, change.EquipmentSlot)
|
||||
}
|
||||
if len(changed) == 0 {
|
||||
return ErrRequestInvalid
|
||||
}
|
||||
|
||||
result.TicketConsumed = int64(len(changed))
|
||||
ticketSlots, err := consumeTickets(&inventory, command.TicketItemID, result.TicketConsumed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result.TicketSlots = ticketSlots
|
||||
|
||||
scope := "character:" + command.CharacterID + settingsScopeSuffix
|
||||
settings, settingsFound, err := tx.Settings.Load(ctx, scope)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !settingsFound {
|
||||
settings = dnfrepo.SettingsRecord{Scope: scope, Values: make(map[string]string)}
|
||||
} else {
|
||||
settings = dnfrepo.CloneSettings(settings)
|
||||
if settings.Values == nil {
|
||||
settings.Values = make(map[string]string)
|
||||
}
|
||||
}
|
||||
result.GaugeBefore, err = parseNonNegative(settings.Values[settingsUsedParts])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result.GaugeAfter = result.GaugeBefore + result.TicketConsumed
|
||||
if result.GaugeAfter < result.GaugeBefore {
|
||||
return ErrRequestInvalid
|
||||
}
|
||||
if command.GaugeThreshold > 0 && command.Reward != nil {
|
||||
beforeCrossings := result.GaugeBefore / command.GaugeThreshold
|
||||
afterCrossings := result.GaugeAfter / command.GaugeThreshold
|
||||
if command.Reward.CountPerCrossing <= 0 {
|
||||
return ErrRequestInvalid
|
||||
}
|
||||
result.RewardGranted = (afterCrossings - beforeCrossings) * command.Reward.CountPerCrossing
|
||||
if result.RewardGranted > 0 {
|
||||
result.RewardSlots, err = grantReward(&inventory, *command.Reward, result.RewardGranted)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
settings.Values[settingsUsedParts] = strconv.FormatInt(result.GaugeAfter, 10)
|
||||
|
||||
now := time.Now().UTC()
|
||||
inventory.UpdatedAt = now
|
||||
equipment.UpdatedAt = now
|
||||
settings.UpdatedAt = now
|
||||
if err := dnfrepo.SaveInventoryFields(ctx, tx.Inventory, inventory, dnfrepo.InventoryFieldSlots); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dnfrepo.SaveEquipmentFields(ctx, tx.Equipment, equipment, dnfrepo.EquipmentFieldEntries); err != nil {
|
||||
return err
|
||||
}
|
||||
return dnfrepo.SaveSettingsFields(ctx, tx.Settings, settings, dnfrepo.SettingsFieldValues)
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
func equipmentEntryForSlot(record dnfrepo.EquipmentRecord, slot int16) (string, dnfrepo.EquipmentEntry, bool) {
|
||||
for key, entry := range record.Entries {
|
||||
if entry.SlotIndex == slot {
|
||||
return key, entry, true
|
||||
}
|
||||
}
|
||||
return "", dnfrepo.EquipmentEntry{}, false
|
||||
}
|
||||
|
||||
func consumeTickets(record *dnfrepo.InventoryRecord, itemID, count int64) ([]int16, error) {
|
||||
if record == nil || count <= 0 {
|
||||
return nil, ErrTicketMissing
|
||||
}
|
||||
type candidate struct {
|
||||
key string
|
||||
slot int16
|
||||
}
|
||||
var candidates []candidate
|
||||
for key, stack := range record.Slots {
|
||||
listType, slot, ok := parseSlotKey(key)
|
||||
if ok && listType == dnfrepo.MainInventoryListType && stack.ItemID == itemID && stack.Count > 0 {
|
||||
candidates = append(candidates, candidate{key: key, slot: slot})
|
||||
}
|
||||
}
|
||||
sort.Slice(candidates, func(i, j int) bool { return candidates[i].slot < candidates[j].slot })
|
||||
remaining := count
|
||||
changed := make([]int16, 0, len(candidates))
|
||||
for _, candidate := range candidates {
|
||||
if remaining == 0 {
|
||||
break
|
||||
}
|
||||
stack := record.Slots[candidate.key]
|
||||
used := stack.Count
|
||||
if used > remaining {
|
||||
used = remaining
|
||||
}
|
||||
stack.Count -= used
|
||||
remaining -= used
|
||||
changed = append(changed, candidate.slot)
|
||||
if stack.Count == 0 {
|
||||
delete(record.Slots, candidate.key)
|
||||
continue
|
||||
}
|
||||
if stack.Count > math.MaxUint32 || len(stack.RawEntry) < 10 {
|
||||
return nil, ErrTicketMissing
|
||||
}
|
||||
stack.RawEntry = append([]byte(nil), stack.RawEntry...)
|
||||
binary.LittleEndian.PutUint32(stack.RawEntry[6:10], uint32(stack.Count))
|
||||
stack.Extra = cloneStringMap(stack.Extra)
|
||||
stack.Extra["count"] = strconv.FormatInt(stack.Count, 10)
|
||||
record.Slots[candidate.key] = stack
|
||||
}
|
||||
if remaining != 0 {
|
||||
return nil, ErrTicketMissing
|
||||
}
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
func grantReward(record *dnfrepo.InventoryRecord, reward Reward, count int64) ([]int16, error) {
|
||||
if record == nil || reward.ItemID <= 0 || count <= 0 || reward.BuildStack == nil ||
|
||||
reward.SlotStart < 0 || reward.SlotEnd < reward.SlotStart {
|
||||
return nil, ErrRewardSpace
|
||||
}
|
||||
// declaredLimit 是 PVF 声明值:<=0 表示没写 [stack limit](不受总量规则约束)。
|
||||
declaredLimit := reward.StackLimit
|
||||
if reward.StackLimit <= 0 {
|
||||
reward.StackLimit = math.MaxUint32
|
||||
}
|
||||
// PVF [stack limit] 是这个容器里该道具的总量上限:额度按容器里同 id 总量算,
|
||||
// 容器里已经有该道具的行时不能再开第二行。
|
||||
space := dnfrepo.ContainerItemSpace(
|
||||
record.Slots,
|
||||
dnfrepo.MainInventoryListType,
|
||||
reward.ItemID,
|
||||
declaredLimit,
|
||||
)
|
||||
remaining := count
|
||||
changed := make([]int16, 0, 1)
|
||||
for slot := reward.SlotStart; slot <= reward.SlotEnd && remaining > 0; slot++ {
|
||||
key := fmt.Sprintf("%d:%d", dnfrepo.MainInventoryListType, slot)
|
||||
stack, occupied := record.Slots[key]
|
||||
if !occupied || stack.ItemID != reward.ItemID || stack.Count <= 0 || stack.Count >= reward.StackLimit ||
|
||||
len(stack.RawEntry) < 10 || (!stack.ExpireAt.IsZero() && !time.Now().UTC().Before(stack.ExpireAt)) {
|
||||
continue
|
||||
}
|
||||
available := reward.StackLimit - stack.Count
|
||||
if available > space {
|
||||
available = space
|
||||
}
|
||||
if available <= 0 {
|
||||
continue
|
||||
}
|
||||
added := remaining
|
||||
if added > available {
|
||||
added = available
|
||||
}
|
||||
stack.Count += added
|
||||
remaining -= added
|
||||
space -= added
|
||||
stack.RawEntry = append([]byte(nil), stack.RawEntry...)
|
||||
binary.LittleEndian.PutUint32(stack.RawEntry[6:10], uint32(stack.Count))
|
||||
stack.Extra = cloneStringMap(stack.Extra)
|
||||
stack.Extra["count"] = strconv.FormatInt(stack.Count, 10)
|
||||
record.Slots[key] = stack
|
||||
changed = append(changed, slot)
|
||||
}
|
||||
for slot := reward.SlotStart; slot <= reward.SlotEnd && remaining > 0; slot++ {
|
||||
key := fmt.Sprintf("%d:%d", dnfrepo.MainInventoryListType, slot)
|
||||
if _, occupied := record.Slots[key]; occupied {
|
||||
continue
|
||||
}
|
||||
if !dnfrepo.CanOpenContainerItemRow(record.Slots, dnfrepo.MainInventoryListType, reward.ItemID, declaredLimit) {
|
||||
break
|
||||
}
|
||||
chunk := remaining
|
||||
if chunk > reward.StackLimit {
|
||||
chunk = reward.StackLimit
|
||||
}
|
||||
if chunk > space {
|
||||
chunk = space
|
||||
}
|
||||
if chunk <= 0 {
|
||||
break
|
||||
}
|
||||
stack, err := reward.BuildStack(slot, chunk)
|
||||
if err != nil || stack.ItemID != reward.ItemID || stack.Count != chunk {
|
||||
return nil, errors.Join(ErrRewardSpace, err)
|
||||
}
|
||||
record.Slots[key] = stack
|
||||
changed = append(changed, slot)
|
||||
remaining -= chunk
|
||||
space -= chunk
|
||||
}
|
||||
if remaining != 0 {
|
||||
return nil, ErrRewardSpace
|
||||
}
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
func parseSlotKey(key string) (byte, int16, bool) {
|
||||
parts := strings.Split(strings.TrimSpace(key), ":")
|
||||
if len(parts) != 2 {
|
||||
return 0, 0, false
|
||||
}
|
||||
list, err1 := strconv.ParseUint(parts[0], 10, 8)
|
||||
slot, err2 := strconv.ParseInt(parts[1], 10, 16)
|
||||
return byte(list), int16(slot), err1 == nil && err2 == nil
|
||||
}
|
||||
|
||||
func parseNonNegative(value string) (int64, error) {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return 0, nil
|
||||
}
|
||||
parsed, err := strconv.ParseInt(strings.TrimSpace(value), 10, 64)
|
||||
if err != nil || parsed < 0 {
|
||||
return 0, ErrRequestInvalid
|
||||
}
|
||||
return parsed, nil
|
||||
}
|
||||
|
||||
func cloneStringMap(source map[string]string) map[string]string {
|
||||
if len(source) == 0 {
|
||||
return make(map[string]string)
|
||||
}
|
||||
out := make(map[string]string, len(source)+2)
|
||||
for key, value := range source {
|
||||
out[key] = value
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package avatarfitting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
dnfrepomemory "longheng.io/server/internal/modules/dnf/repository/memory"
|
||||
)
|
||||
|
||||
func TestCommitAtomicallyConsumesTicketsReplacesAvatarsAndGrantsGaugeReward(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repositories := dnfrepomemory.NewMemoryGroup()
|
||||
seedAvatarFittingOwner(t, ctx, repositories, 2)
|
||||
owner, err := NewOwner(repositories)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
command := testAvatarFittingCommand()
|
||||
result, err := owner.Commit(ctx, command)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.TicketConsumed != 2 || result.RewardGranted != 1 || result.GaugeBefore != 19 || result.GaugeAfter != 21 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
inventory, _, _ := repositories.Inventory.Load(ctx, "7")
|
||||
if _, found := inventory.Slots["0:10"]; found {
|
||||
t.Fatal("ticket row remained after exact two-ticket consume")
|
||||
}
|
||||
if reward, found := inventory.Slots["0:20"]; !found || reward.ItemID != 9000 || reward.Count != 1 {
|
||||
t.Fatalf("reward=%+v found=%t", reward, found)
|
||||
}
|
||||
equipment, _, _ := repositories.Equipment.Load(ctx, "7")
|
||||
for key, want := range map[string]int64{"0": 2000, "1": 2001} {
|
||||
entry := equipment.Entries[key]
|
||||
if entry.ItemID != want || int64(binary.LittleEndian.Uint32(entry.RawEntry[2:6])) != want {
|
||||
t.Fatalf("equipment[%s]=%+v want=%d", key, entry, want)
|
||||
}
|
||||
}
|
||||
settings, _, _ := repositories.Settings.Load(ctx, "character:7:avatar_fitting_room")
|
||||
if settings.Values[settingsUsedParts] != "21" {
|
||||
t.Fatalf("settings=%+v", settings.Values)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitRollsBackEveryAggregateWhenTicketsAreInsufficient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repositories := dnfrepomemory.NewMemoryGroup()
|
||||
seedAvatarFittingOwner(t, ctx, repositories, 1)
|
||||
owner, _ := NewOwner(repositories)
|
||||
_, err := owner.Commit(ctx, testAvatarFittingCommand())
|
||||
if !errors.Is(err, ErrTicketMissing) {
|
||||
t.Fatalf("error=%v want=%v", err, ErrTicketMissing)
|
||||
}
|
||||
inventory, _, _ := repositories.Inventory.Load(ctx, "7")
|
||||
if stack := inventory.Slots["0:10"]; stack.ItemID != 490702492 || stack.Count != 1 {
|
||||
t.Fatalf("ticket changed on rollback: %+v", stack)
|
||||
}
|
||||
equipment, _, _ := repositories.Equipment.Load(ctx, "7")
|
||||
if equipment.Entries["0"].ItemID != 1000 || equipment.Entries["1"].ItemID != 1001 {
|
||||
t.Fatalf("equipment changed on rollback: %+v", equipment.Entries)
|
||||
}
|
||||
settings, _, _ := repositories.Settings.Load(ctx, "character:7:avatar_fitting_room")
|
||||
if settings.Values[settingsUsedParts] != "19" {
|
||||
t.Fatalf("gauge changed on rollback: %+v", settings.Values)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitRollsBackWhenGaugeRewardHasNoInventorySpace(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repositories := dnfrepomemory.NewMemoryGroup()
|
||||
seedAvatarFittingOwner(t, ctx, repositories, 2)
|
||||
inventory, _, _ := repositories.Inventory.Load(ctx, "7")
|
||||
inventory.Slots["0:20"] = dnfrepo.ItemStack{ItemID: 1234, Count: 1, RawEntry: make([]byte, 119)}
|
||||
if err := repositories.Inventory.Save(ctx, inventory); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
owner, _ := NewOwner(repositories)
|
||||
_, err := owner.Commit(ctx, testAvatarFittingCommand())
|
||||
if !errors.Is(err, ErrRewardSpace) {
|
||||
t.Fatalf("error=%v want=%v", err, ErrRewardSpace)
|
||||
}
|
||||
inventory, _, _ = repositories.Inventory.Load(ctx, "7")
|
||||
if stack := inventory.Slots["0:10"]; stack.ItemID != 490702492 || stack.Count != 2 {
|
||||
t.Fatalf("tickets changed on reward rollback: %+v", stack)
|
||||
}
|
||||
equipment, _, _ := repositories.Equipment.Load(ctx, "7")
|
||||
if equipment.Entries["0"].ItemID != 1000 || equipment.Entries["1"].ItemID != 1001 {
|
||||
t.Fatalf("equipment changed on reward rollback: %+v", equipment.Entries)
|
||||
}
|
||||
settings, _, _ := repositories.Settings.Load(ctx, "character:7:avatar_fitting_room")
|
||||
if settings.Values[settingsUsedParts] != "19" {
|
||||
t.Fatalf("gauge changed on reward rollback: %+v", settings.Values)
|
||||
}
|
||||
}
|
||||
|
||||
func testAvatarFittingCommand() Command {
|
||||
command := Command{
|
||||
AccountID: "dnf:1",
|
||||
CharacterID: "7",
|
||||
TicketItemID: 490702492,
|
||||
GaugeThreshold: 20,
|
||||
Reward: &Reward{
|
||||
ItemID: 9000, CountPerCrossing: 1, SlotStart: 20, SlotEnd: 20, StackLimit: 1000,
|
||||
BuildStack: func(slot int16, count int64) (dnfrepo.ItemStack, error) {
|
||||
return dnfrepo.ItemStack{ItemID: 9000, Count: count, RawEntry: make([]byte, 119)}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
for index := range command.Changes {
|
||||
command.Changes[index] = Change{EquipmentSlot: -1, ObjectIndex: -1, CurrentItemID: -1}
|
||||
}
|
||||
command.Changes[0] = Change{EquipmentSlot: 0, ObjectIndex: 100, CurrentItemID: 1000, OutputItemID: 2000, PVFPath: "equipment/a.equ", EquipmentType: "[hat avatar]"}
|
||||
command.Changes[1] = Change{EquipmentSlot: 1, ObjectIndex: 101, CurrentItemID: 1001, OutputItemID: 2001, PVFPath: "equipment/b.equ", EquipmentType: "[hair avatar]"}
|
||||
return command
|
||||
}
|
||||
|
||||
func seedAvatarFittingOwner(t *testing.T, ctx context.Context, repositories dnfrepo.Group, tickets int64) {
|
||||
t.Helper()
|
||||
if err := repositories.Character.Save(ctx, dnfrepo.CharacterRecord{CharacterID: "7", AccountID: "dnf:1", Job: "0"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ticketRaw := make([]byte, 119)
|
||||
binary.LittleEndian.PutUint32(ticketRaw[6:10], uint32(tickets))
|
||||
if err := repositories.Inventory.Save(ctx, dnfrepo.InventoryRecord{CharacterID: "7", Slots: map[string]dnfrepo.ItemStack{
|
||||
"0:10": {ItemID: 490702492, Count: tickets, RawEntry: ticketRaw},
|
||||
}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw0, raw1 := make([]byte, 119), make([]byte, 119)
|
||||
binary.LittleEndian.PutUint32(raw0[2:6], 1000)
|
||||
binary.LittleEndian.PutUint32(raw1[2:6], 1001)
|
||||
if err := repositories.Equipment.Save(ctx, dnfrepo.EquipmentRecord{CharacterID: "7", Entries: map[string]dnfrepo.EquipmentEntry{
|
||||
"0": {SlotIndex: 0, ItemID: 1000, RawEntry: raw0},
|
||||
"1": {SlotIndex: 1, ItemID: 1001, RawEntry: raw1},
|
||||
}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := repositories.Settings.Save(ctx, dnfrepo.SettingsRecord{Scope: "character:7:avatar_fitting_room", Values: map[string]string{settingsUsedParts: "19"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user