服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package adventuregroup
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
|
)
|
|
|
|
const SelectorSlotMetadataKey = "selector_adventure_info_slot"
|
|
|
|
var (
|
|
ErrOwnerUnavailable = errors.New("adventure-group owner is unavailable")
|
|
ErrAccountRequired = errors.New("adventure-group account id is required")
|
|
ErrAccountNotFound = errors.New("adventure-group account is missing")
|
|
ErrSelectorSlotRange = errors.New("adventure-group selector slot is outside the verified range")
|
|
)
|
|
|
|
type RememberSelectorSlotCommand struct {
|
|
AccountID string
|
|
Slot int
|
|
SlotLimit int
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type RememberSelectorSlotResult struct {
|
|
AccountID string
|
|
Slot int
|
|
Changed bool
|
|
}
|
|
|
|
type Owner struct {
|
|
accounts dnfrepo.AccountRepository
|
|
}
|
|
|
|
func NewOwner(repositories dnfrepo.Group) (*Owner, error) {
|
|
if repositories.Account == nil {
|
|
return nil, ErrOwnerUnavailable
|
|
}
|
|
return &Owner{accounts: repositories.Account}, nil
|
|
}
|
|
|
|
// RememberSelectorSlot persists only a slot already verified against the
|
|
// account roster by the bridge. The metadata write is key-scoped so unrelated
|
|
// account fields and metadata cannot be replaced.
|
|
func (o *Owner) RememberSelectorSlot(
|
|
ctx context.Context,
|
|
command RememberSelectorSlotCommand,
|
|
) (RememberSelectorSlotResult, error) {
|
|
if o == nil || o.accounts == nil {
|
|
return RememberSelectorSlotResult{}, ErrOwnerUnavailable
|
|
}
|
|
accountID := strings.TrimSpace(command.AccountID)
|
|
if accountID == "" {
|
|
return RememberSelectorSlotResult{}, ErrAccountRequired
|
|
}
|
|
if command.SlotLimit <= 0 || command.Slot < 0 || command.Slot >= command.SlotLimit {
|
|
return RememberSelectorSlotResult{}, fmt.Errorf(
|
|
"%w: slot=%d limit=%d",
|
|
ErrSelectorSlotRange,
|
|
command.Slot,
|
|
command.SlotLimit,
|
|
)
|
|
}
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return RememberSelectorSlotResult{}, err
|
|
}
|
|
account, found, err := o.accounts.Load(ctx, accountID)
|
|
if err != nil {
|
|
return RememberSelectorSlotResult{}, fmt.Errorf("load adventure-group account: %w", err)
|
|
}
|
|
if !found || strings.TrimSpace(account.AccountID) != accountID {
|
|
return RememberSelectorSlotResult{}, fmt.Errorf("%w: account=%s", ErrAccountNotFound, accountID)
|
|
}
|
|
result := RememberSelectorSlotResult{AccountID: accountID, Slot: command.Slot}
|
|
value := strconv.Itoa(command.Slot)
|
|
if strings.TrimSpace(account.Metadata[SelectorSlotMetadataKey]) == value {
|
|
return result, nil
|
|
}
|
|
if err := dnfrepo.SaveAccountMetadataEntry(
|
|
ctx,
|
|
o.accounts,
|
|
account,
|
|
SelectorSlotMetadataKey,
|
|
value,
|
|
command.UpdatedAt,
|
|
); err != nil {
|
|
return RememberSelectorSlotResult{}, fmt.Errorf("save adventure-group selector slot: %w", err)
|
|
}
|
|
result.Changed = true
|
|
return result, nil
|
|
}
|