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,113 @@
|
||||
package clonetitle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
dnftitlebook "longheng.io/server/internal/modules/dnf/titlebook"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrOwnerUnavailable = errors.New("clone title owner unavailable")
|
||||
ErrCharacterRequired = errors.New("selected character id required")
|
||||
ErrCharacterNotFound = errors.New("character record not found")
|
||||
ErrAccountMismatch = errors.New("character account does not match session account")
|
||||
ErrTitleNotOwned = errors.New("clone title is not owned in the title book")
|
||||
)
|
||||
|
||||
const statKey = "clone_title_item_id"
|
||||
|
||||
type Command struct {
|
||||
AccountID string
|
||||
SelectedCharacterID uint16
|
||||
ItemID int32
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
CharacterID string
|
||||
ItemID int32
|
||||
}
|
||||
|
||||
// Owner owns clone-title selection. The bridge owns only the current EXE wire
|
||||
// format and response ordering.
|
||||
type Owner struct {
|
||||
characters dnfrepo.CharacterRepository
|
||||
inventory dnfrepo.InventoryRepository
|
||||
}
|
||||
|
||||
func NewOwner(repos dnfrepo.Group) (*Owner, error) {
|
||||
if repos.Character == nil || repos.Inventory == nil {
|
||||
return nil, ErrOwnerUnavailable
|
||||
}
|
||||
return &Owner{
|
||||
characters: repos.Character,
|
||||
inventory: repos.Inventory,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (o *Owner) Apply(ctx context.Context, cmd Command) (Result, error) {
|
||||
if o == nil || o.characters == nil || o.inventory == nil {
|
||||
return Result{}, ErrOwnerUnavailable
|
||||
}
|
||||
if cmd.SelectedCharacterID == 0 {
|
||||
return Result{}, ErrCharacterRequired
|
||||
}
|
||||
characterID := strconv.FormatUint(uint64(cmd.SelectedCharacterID), 10)
|
||||
character, found, err := o.characters.Load(ctx, characterID)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
if !found || strings.TrimSpace(character.CharacterID) != characterID {
|
||||
return Result{}, fmt.Errorf("%w: character=%s", ErrCharacterNotFound, characterID)
|
||||
}
|
||||
if accountID := strings.TrimSpace(cmd.AccountID); accountID != "" &&
|
||||
strings.TrimSpace(character.AccountID) != accountID {
|
||||
return Result{}, fmt.Errorf("%w: character=%s", ErrAccountMismatch, characterID)
|
||||
}
|
||||
if cmd.ItemID < 0 {
|
||||
return Result{}, fmt.Errorf("%w: character=%s item=%d", ErrTitleNotOwned, characterID, cmd.ItemID)
|
||||
}
|
||||
if cmd.ItemID != 0 {
|
||||
inventory, found, loadErr := o.inventory.Load(ctx, characterID)
|
||||
if loadErr != nil {
|
||||
return Result{}, loadErr
|
||||
}
|
||||
if !found || !ownsTitleBookItem(inventory, int64(cmd.ItemID)) {
|
||||
return Result{}, fmt.Errorf("%w: character=%s item=%d", ErrTitleNotOwned, characterID, cmd.ItemID)
|
||||
}
|
||||
}
|
||||
|
||||
character = dnfrepo.CloneCharacter(character)
|
||||
if character.Stats == nil {
|
||||
character.Stats = make(map[string]int64, 1)
|
||||
}
|
||||
character.Stats[statKey] = int64(cmd.ItemID)
|
||||
if cmd.UpdatedAt.IsZero() {
|
||||
character.UpdatedAt = time.Now().UTC()
|
||||
} else {
|
||||
character.UpdatedAt = cmd.UpdatedAt.UTC()
|
||||
}
|
||||
if err := dnfrepo.SaveCharacterFields(ctx, o.characters, character, dnfrepo.CharacterFieldStats); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
return Result{CharacterID: characterID, ItemID: cmd.ItemID}, nil
|
||||
}
|
||||
|
||||
func ownsTitleBookItem(inventory dnfrepo.InventoryRecord, itemID int64) bool {
|
||||
if itemID <= 0 {
|
||||
return false
|
||||
}
|
||||
prefix := strconv.Itoa(int(dnftitlebook.ListType)) + ":"
|
||||
for key, stack := range inventory.Slots {
|
||||
if strings.HasPrefix(key, prefix) && stack.ItemID == itemID && stack.Count != 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package clonetitle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
||||
dnfrepomemory "longheng.io/server/internal/modules/dnf/repository/memory"
|
||||
)
|
||||
|
||||
func TestOwnerApplyPersistsCloneTitle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repos := dnfrepomemory.NewMemoryGroup()
|
||||
if err := repos.Character.Save(ctx, dnfrepo.CharacterRecord{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Stats: map[string]int64{"emotion_index": 3},
|
||||
}); err != nil {
|
||||
t.Fatalf("save character: %v", err)
|
||||
}
|
||||
if err := repos.Inventory.Save(ctx, dnfrepo.InventoryRecord{
|
||||
CharacterID: "19",
|
||||
Slots: map[string]dnfrepo.ItemStack{
|
||||
"100:0": {ItemID: 123456, Count: 1},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save inventory: %v", err)
|
||||
}
|
||||
owner, err := NewOwner(repos)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOwner: %v", err)
|
||||
}
|
||||
result, err := owner.Apply(ctx, Command{
|
||||
AccountID: "account-1",
|
||||
SelectedCharacterID: 19,
|
||||
ItemID: 123456,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Apply: %v", err)
|
||||
}
|
||||
if result.CharacterID != "19" || result.ItemID != 123456 {
|
||||
t.Fatalf("result = %+v", result)
|
||||
}
|
||||
character, found, err := repos.Character.Load(ctx, "19")
|
||||
if err != nil || !found {
|
||||
t.Fatalf("load character found=%t err=%v", found, err)
|
||||
}
|
||||
if character.Stats["clone_title_item_id"] != 123456 ||
|
||||
character.Stats["emotion_index"] != 3 {
|
||||
t.Fatalf("stats = %+v", character.Stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyRejectsUnownedCloneTitle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repos := dnfrepomemory.NewMemoryGroup()
|
||||
if err := repos.Character.Save(ctx, dnfrepo.CharacterRecord{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
}); err != nil {
|
||||
t.Fatalf("save character: %v", err)
|
||||
}
|
||||
if err := repos.Inventory.Save(ctx, dnfrepo.InventoryRecord{
|
||||
CharacterID: "19",
|
||||
Slots: map[string]dnfrepo.ItemStack{
|
||||
"0:9": {ItemID: 123456, Count: 1},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save inventory: %v", err)
|
||||
}
|
||||
owner, err := NewOwner(repos)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOwner: %v", err)
|
||||
}
|
||||
_, err = owner.Apply(ctx, Command{
|
||||
AccountID: "account-1",
|
||||
SelectedCharacterID: 19,
|
||||
ItemID: 123456,
|
||||
})
|
||||
if !errors.Is(err, ErrTitleNotOwned) {
|
||||
t.Fatalf("Apply error = %v, want ErrTitleNotOwned", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyZeroClearsCloneTitleWithoutBookItem(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repos := dnfrepomemory.NewMemoryGroup()
|
||||
if err := repos.Character.Save(ctx, dnfrepo.CharacterRecord{
|
||||
CharacterID: "19",
|
||||
AccountID: "account-1",
|
||||
Stats: map[string]int64{statKey: 123456},
|
||||
}); err != nil {
|
||||
t.Fatalf("save character: %v", err)
|
||||
}
|
||||
if err := repos.Inventory.Save(ctx, dnfrepo.InventoryRecord{
|
||||
CharacterID: "19",
|
||||
Slots: map[string]dnfrepo.ItemStack{},
|
||||
}); err != nil {
|
||||
t.Fatalf("save inventory: %v", err)
|
||||
}
|
||||
owner, err := NewOwner(repos)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOwner: %v", err)
|
||||
}
|
||||
if _, err := owner.Apply(ctx, Command{
|
||||
AccountID: "account-1",
|
||||
SelectedCharacterID: 19,
|
||||
ItemID: 0,
|
||||
}); err != nil {
|
||||
t.Fatalf("Apply clear: %v", err)
|
||||
}
|
||||
character, found, err := repos.Character.Load(ctx, "19")
|
||||
if err != nil || !found {
|
||||
t.Fatalf("load character found=%t err=%v", found, err)
|
||||
}
|
||||
if got := character.Stats[statKey]; got != 0 {
|
||||
t.Fatalf("%s = %d, want 0", statKey, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerApplyRejectsMissingCharacter(t *testing.T) {
|
||||
repos := dnfrepomemory.NewMemoryGroup()
|
||||
owner, err := NewOwner(repos)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOwner: %v", err)
|
||||
}
|
||||
_, err = owner.Apply(context.Background(), Command{SelectedCharacterID: 19})
|
||||
if !errors.Is(err, ErrCharacterNotFound) {
|
||||
t.Fatalf("Apply error = %v, want ErrCharacterNotFound", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user