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,164 @@
|
||||
// 本文件把 DNF 静态数据装配接入框架组件生命周期。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
type Component struct {
|
||||
source dnfpvf.Source
|
||||
options Options
|
||||
now func() time.Time
|
||||
|
||||
mu sync.RWMutex
|
||||
store *Store
|
||||
started bool
|
||||
loadedAt time.Time
|
||||
lastError string
|
||||
}
|
||||
|
||||
type ComponentSnapshot struct {
|
||||
Started bool `json:"started"`
|
||||
LoadedAt time.Time `json:"loaded_at,omitempty"`
|
||||
Store Snapshot `json:"store"`
|
||||
LastError string `json:"last_error,omitempty"`
|
||||
}
|
||||
|
||||
// NewComponent 创建 DNF 静态数据生命周期组件。
|
||||
// 组件只在 Start 阶段从已加载内存的 PVF source 构建只读表,不访问磁盘、不写玩家状态。
|
||||
func NewComponent(source dnfpvf.Source, options Options) *Component {
|
||||
return &Component{
|
||||
source: source,
|
||||
options: cloneOptions(options),
|
||||
now: time.Now,
|
||||
}
|
||||
}
|
||||
|
||||
// Name 返回框架生命周期里展示的组件名。
|
||||
func (c *Component) Name() string {
|
||||
return "dnf-staticdata"
|
||||
}
|
||||
|
||||
// Preflight 检查 DNF 静态数据启动依赖是否齐全。
|
||||
// 这里只校验内存 PVF source 和 ctx 状态,不解析 PVF,也不产生经济或持久化副作用。
|
||||
func (c *Component) Preflight(ctx context.Context) error {
|
||||
if err := ctxErr(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if c == nil || c.source == nil {
|
||||
return ErrSourceRequired
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start 构建 DNF 静态数据内存表并发布给后续业务 owner 查询。
|
||||
// 这里复用 Load 的只读装配流程,不发奖、不扣资产、不写 Profile/MySQL/Redis/EventLog/Outbox。
|
||||
func (c *Component) Start(ctx context.Context) error {
|
||||
if err := c.Preflight(ctx); err != nil {
|
||||
c.recordError(err)
|
||||
return err
|
||||
}
|
||||
store, err := Load(ctx, c.source, c.options)
|
||||
if err != nil {
|
||||
c.recordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
c.store = store
|
||||
c.started = true
|
||||
c.loadedAt = c.clock().UTC()
|
||||
c.lastError = ""
|
||||
c.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop 清理 DNF 静态数据组件持有的 Store 引用。
|
||||
// Store 本身没有后台 goroutine 或外部连接,因此停止只收敛内存可见状态。
|
||||
func (c *Component) Stop(context.Context) error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.store = nil
|
||||
c.started = false
|
||||
c.loadedAt = time.Time{}
|
||||
c.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Store 返回启动后构建完成的 DNF 静态数据只读表。
|
||||
// 返回的 Store 只能用于查询,调用方不得把它当作玩家状态或结算 owner。
|
||||
func (c *Component) Store() (*Store, bool) {
|
||||
if c == nil {
|
||||
return nil, false
|
||||
}
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
if !c.started || c.store == nil {
|
||||
return nil, false
|
||||
}
|
||||
return c.store, true
|
||||
}
|
||||
|
||||
// Snapshot 返回 DNF 静态数据组件的启动状态和表规模。
|
||||
// 该快照用于 debug 面板、启动日志和接入验收,不暴露 PVF 原文内容。
|
||||
func (c *Component) Snapshot() ComponentSnapshot {
|
||||
if c == nil {
|
||||
return ComponentSnapshot{}
|
||||
}
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
snapshot := ComponentSnapshot{
|
||||
Started: c.started,
|
||||
LoadedAt: c.loadedAt,
|
||||
LastError: c.lastError,
|
||||
}
|
||||
if c.store != nil {
|
||||
snapshot.Store = c.store.Snapshot()
|
||||
}
|
||||
return snapshot
|
||||
}
|
||||
|
||||
func (c *Component) recordError(err error) {
|
||||
if c == nil || err == nil {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.store = nil
|
||||
c.started = false
|
||||
c.loadedAt = time.Time{}
|
||||
c.lastError = err.Error()
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Component) clock() time.Time {
|
||||
if c == nil || c.now == nil {
|
||||
return time.Now()
|
||||
}
|
||||
return c.now()
|
||||
}
|
||||
|
||||
func cloneOptions(options Options) Options {
|
||||
options.Build.Paths = append([]string(nil), options.Build.Paths...)
|
||||
options.Build.Lists = append([]string(nil), options.Build.Lists...)
|
||||
options.Build.Prefixes = append([]string(nil), options.Build.Prefixes...)
|
||||
return options
|
||||
}
|
||||
|
||||
func ctxErr(ctx context.Context) error {
|
||||
if ctx == nil {
|
||||
return nil
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// 本文件验证 DNF 静态数据组件只做生命周期装配。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
func TestComponentStartLoadsStore(t *testing.T) {
|
||||
component := NewComponent(componentSource(), Options{})
|
||||
if component.Name() != "dnf-staticdata" {
|
||||
t.Fatalf("unexpected component name: %s", component.Name())
|
||||
}
|
||||
if err := component.Preflight(context.Background()); err != nil {
|
||||
t.Fatalf("preflight: %v", err)
|
||||
}
|
||||
if _, ok := component.Store(); ok {
|
||||
t.Fatalf("store should not be visible before start")
|
||||
}
|
||||
|
||||
if err := component.Start(context.Background()); err != nil {
|
||||
t.Fatalf("start component: %v", err)
|
||||
}
|
||||
store, ok := component.Store()
|
||||
if !ok {
|
||||
t.Fatalf("expected loaded store")
|
||||
}
|
||||
item, ok := store.Equip.Find(1001)
|
||||
if !ok || item.Name != "component sword" {
|
||||
t.Fatalf("unexpected equip item: %+v ok=%v", item, ok)
|
||||
}
|
||||
snapshot := component.Snapshot()
|
||||
if !snapshot.Started || snapshot.Store.Index.Documents != 13 || snapshot.Store.Equip.Items != 1 {
|
||||
t.Fatalf("unexpected component snapshot: %+v", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComponentRejectsMissingSource(t *testing.T) {
|
||||
component := NewComponent(nil, Options{})
|
||||
if err := component.Preflight(context.Background()); !errors.Is(err, ErrSourceRequired) {
|
||||
t.Fatalf("expected ErrSourceRequired, got %v", err)
|
||||
}
|
||||
if err := component.Start(context.Background()); !errors.Is(err, ErrSourceRequired) {
|
||||
t.Fatalf("expected start source error, got %v", err)
|
||||
}
|
||||
if snapshot := component.Snapshot(); snapshot.Started || snapshot.LastError == "" {
|
||||
t.Fatalf("expected failed snapshot, got %+v", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComponentHonorsCanceledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
component := NewComponent(componentSource(), Options{})
|
||||
if err := component.Start(ctx); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("expected context canceled, got %v", err)
|
||||
}
|
||||
if _, ok := component.Store(); ok {
|
||||
t.Fatalf("store should not be visible after canceled start")
|
||||
}
|
||||
}
|
||||
|
||||
func TestComponentStopClearsStore(t *testing.T) {
|
||||
component := NewComponent(componentSource(), Options{})
|
||||
if err := component.Start(context.Background()); err != nil {
|
||||
t.Fatalf("start component: %v", err)
|
||||
}
|
||||
if err := component.Stop(context.Background()); err != nil {
|
||||
t.Fatalf("stop component: %v", err)
|
||||
}
|
||||
if _, ok := component.Store(); ok {
|
||||
t.Fatalf("store should be cleared after stop")
|
||||
}
|
||||
if snapshot := component.Snapshot(); snapshot.Started || snapshot.Store.Index.Documents != 0 {
|
||||
t.Fatalf("unexpected stopped snapshot: %+v", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComponentClonesOptions(t *testing.T) {
|
||||
lists := []string{"equipment/equipment.lst"}
|
||||
component := NewComponent(componentSource(), Options{
|
||||
Build: dnfpvf.BuildOptions{Lists: lists},
|
||||
})
|
||||
lists[0] = "missing.lst"
|
||||
if err := component.Start(context.Background()); err != nil {
|
||||
t.Fatalf("start with cloned options: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func componentSource() testSource {
|
||||
return testSource{
|
||||
texts: map[string]string{
|
||||
"equipment/equipment.lst": "1001 `equipment/component_sword.equ`\n",
|
||||
"equipment/component_sword.equ": `
|
||||
[name]
|
||||
` + "`component sword`" + `
|
||||
[equipment type]
|
||||
` + "`weapon`" + `
|
||||
[minimum level]
|
||||
1
|
||||
`,
|
||||
"skill/skilllist.lst": "0 `SwordmanSkill.lst`\n",
|
||||
"skill/SwordmanSkill.lst": "2001 `Swordman/component_slash.skl`\n",
|
||||
"skill/Swordman/component_slash.skl": `
|
||||
[name]
|
||||
` + "`component slash`" + `
|
||||
[required level]
|
||||
1
|
||||
`,
|
||||
"monster/monster.lst": "3001 `monster/component_dummy.mob`\n",
|
||||
"monster/component_dummy.mob": `
|
||||
[name]
|
||||
` + "`component dummy`" + `
|
||||
[level]
|
||||
1
|
||||
`,
|
||||
"dungeon/dungeon.lst": "4001 `dungeon/component_room.dgn`\n",
|
||||
"dungeon/component_room.dgn": `
|
||||
[name]
|
||||
` + "`component room`" + `
|
||||
[minimum level]
|
||||
1
|
||||
`,
|
||||
"drop/drop.lst": "5001 `drop/component.drop`\n",
|
||||
"drop/component.drop": `
|
||||
[name]
|
||||
` + "`component drop`" + `
|
||||
[gold]
|
||||
10
|
||||
`,
|
||||
"reward/reward.lst": "6001 `reward/component.rwd`\n",
|
||||
"reward/component.rwd": `
|
||||
[name]
|
||||
` + "`component reward`" + `
|
||||
[gold]
|
||||
20
|
||||
`,
|
||||
},
|
||||
reads: make(map[string]int),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Package staticdata 负责 DNF PVF 静态数据的一次性内存装配。
|
||||
//
|
||||
// 本包只组合项目层 PVF 索引和强类型表,不直接访问磁盘、不写 Profile、
|
||||
// 不发奖励,也不修改任何玩家状态。
|
||||
package staticdata
|
||||
@@ -0,0 +1,64 @@
|
||||
// 本文件负责从内存 PVF source 构建 DNF 静态数据总表。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"longheng.io/server/internal/modules/dnf/drop"
|
||||
"longheng.io/server/internal/modules/dnf/dungeon"
|
||||
"longheng.io/server/internal/modules/dnf/equip"
|
||||
"longheng.io/server/internal/modules/dnf/monster"
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
"longheng.io/server/internal/modules/dnf/reward"
|
||||
"longheng.io/server/internal/modules/dnf/skill"
|
||||
)
|
||||
|
||||
// Load 从已加载进内存的 PVF source 构建 DNF 静态数据 Store。
|
||||
// 这里只装配只读索引和强类型表,不发奖、不扣资产、不写 Profile/MySQL/Redis/EventLog/Outbox。
|
||||
func Load(ctx context.Context, source dnfpvf.Source, options Options) (*Store, error) {
|
||||
if source == nil {
|
||||
return nil, ErrSourceRequired
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
options = normalizeOptions(options)
|
||||
index, err := dnfpvf.Build(ctx, source, options.Build)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("build dnf staticdata index: %w", err)
|
||||
}
|
||||
equipTable, err := equip.Load(ctx, index, options.Equip)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata equip: %w", err)
|
||||
}
|
||||
skillTable, err := skill.Load(ctx, index, options.Skill)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata skill: %w", err)
|
||||
}
|
||||
monsterTable, err := monster.Load(ctx, index, options.Monster)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata monster: %w", err)
|
||||
}
|
||||
dungeonTable, err := dungeon.Load(ctx, index, options.Dungeon)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata dungeon: %w", err)
|
||||
}
|
||||
dropTable, err := drop.Load(ctx, index, options.Drop)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata drop: %w", err)
|
||||
}
|
||||
rewardTable, err := reward.Load(ctx, index, options.Reward)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnf staticdata reward: %w", err)
|
||||
}
|
||||
return &Store{
|
||||
Index: index,
|
||||
Equip: equipTable,
|
||||
Skill: skillTable,
|
||||
Monster: monsterTable,
|
||||
Dungeon: dungeonTable,
|
||||
Drop: dropTable,
|
||||
Reward: rewardTable,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
// 本文件验证 DNF 静态数据总装配只读取内存 PVF source。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
platformpvf "longheng.io/server/internal/platform/pvf"
|
||||
)
|
||||
|
||||
func TestLoadBuildsStaticStore(t *testing.T) {
|
||||
source := testSource{
|
||||
texts: map[string]string{
|
||||
"equipment/equipment.lst": "1001 `equipment/training_sword.equ`\n",
|
||||
"equipment/training_sword.equ": `
|
||||
[name]
|
||||
` + "`training sword`" + `
|
||||
[equipment type]
|
||||
` + "`weapon`" + `
|
||||
[minimum level]
|
||||
1
|
||||
[physical attack]
|
||||
12
|
||||
`,
|
||||
"skill/skilllist.lst": "0 `SwordmanSkill.lst`\n",
|
||||
"skill/SwordmanSkill.lst": "2001 `Swordman/training_slash.skl`\n",
|
||||
"skill/Swordman/training_slash.skl": `
|
||||
[name]
|
||||
` + "`training slash`" + `
|
||||
[skill type]
|
||||
` + "`active`" + `
|
||||
[required level]
|
||||
1
|
||||
[cool time]
|
||||
1.5
|
||||
`,
|
||||
"monster/monster.lst": "3001 `monster/training_dummy.mob`\n",
|
||||
"monster/training_dummy.mob": `
|
||||
[name]
|
||||
` + "`training dummy`" + `
|
||||
[monster type]
|
||||
` + "`normal`" + `
|
||||
[level]
|
||||
1
|
||||
[hp]
|
||||
100
|
||||
`,
|
||||
"dungeon/dungeon.lst": "4001 `dungeon/training_room.dgn`\n",
|
||||
"dungeon/training_room.dgn": `
|
||||
[name]
|
||||
` + "`training room`" + `
|
||||
[minimum level]
|
||||
1
|
||||
[maps]
|
||||
` + "`map/training.map`" + `
|
||||
[monsters]
|
||||
3001
|
||||
[reward]
|
||||
` + "`reward/training.rwd`" + `
|
||||
`,
|
||||
"drop/drop.lst": "5001 `drop/training.drop`\n",
|
||||
"drop/training.drop": `
|
||||
[name]
|
||||
` + "`training drop`" + `
|
||||
[items]
|
||||
1001
|
||||
[drop rate]
|
||||
1001 1.0
|
||||
[gold]
|
||||
10
|
||||
`,
|
||||
"reward/reward.lst": "6001 `reward/training.rwd`\n",
|
||||
"reward/training.rwd": `
|
||||
[name]
|
||||
` + "`training reward`" + `
|
||||
[drops]
|
||||
5001
|
||||
[gold]
|
||||
20
|
||||
[exp]
|
||||
30
|
||||
`,
|
||||
},
|
||||
reads: make(map[string]int),
|
||||
}
|
||||
store, err := Load(context.Background(), source, Options{})
|
||||
if err != nil {
|
||||
t.Fatalf("load staticdata: %v", err)
|
||||
}
|
||||
snapshot := store.Snapshot()
|
||||
if snapshot.Index.Documents != 13 || snapshot.Index.Lists != 7 || snapshot.Index.Refs != 7 {
|
||||
t.Fatalf("unexpected index snapshot: %+v", snapshot.Index)
|
||||
}
|
||||
if snapshot.Equip.Items != 1 || snapshot.Skill.Skills != 1 || snapshot.Monster.Monsters != 1 ||
|
||||
snapshot.Dungeon.Dungeons != 1 || snapshot.Drop.Entries != 1 || snapshot.Reward.Rewards != 1 {
|
||||
t.Fatalf("unexpected store snapshot: %+v", snapshot)
|
||||
}
|
||||
equipItem, ok := store.Equip.Find(1001)
|
||||
if !ok || equipItem.Name != "training sword" || equipItem.Stats["physical_attack"] != 12 {
|
||||
t.Fatalf("unexpected equip item: %+v ok=%v", equipItem, ok)
|
||||
}
|
||||
reward, ok := store.Reward.FindPath("./REWARD/training.rwd")
|
||||
if !ok || reward.Gold != 20 || reward.Exp != 30 {
|
||||
t.Fatalf("unexpected reward: %+v ok=%v", reward, ok)
|
||||
}
|
||||
before := source.reads["reward/training.rwd"]
|
||||
if _, ok := store.Index.Document("reward/training.rwd"); !ok {
|
||||
t.Fatalf("expected indexed reward document")
|
||||
}
|
||||
if source.reads["reward/training.rwd"] != before {
|
||||
t.Fatalf("document lookup should not read source again")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRequiresSource(t *testing.T) {
|
||||
_, err := Load(context.Background(), nil, Options{})
|
||||
if !errors.Is(err, ErrSourceRequired) {
|
||||
t.Fatalf("expected ErrSourceRequired, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadHonorsCanceledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
_, err := Load(ctx, testSource{texts: map[string]string{}, reads: make(map[string]int)}, Options{})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("expected context canceled, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultListsReturnsCopy(t *testing.T) {
|
||||
lists := DefaultLists()
|
||||
lists[0] = "changed.lst"
|
||||
again := DefaultLists()
|
||||
if again[0] == "changed.lst" {
|
||||
t.Fatalf("default lists returned mutable storage: %+v", again)
|
||||
}
|
||||
}
|
||||
|
||||
type testSource struct {
|
||||
texts map[string]string
|
||||
reads map[string]int
|
||||
}
|
||||
|
||||
func (s testSource) ReadText(relativePath string) (string, error) {
|
||||
key := listKey(relativePath)
|
||||
for path, text := range s.texts {
|
||||
if listKey(path) == key {
|
||||
s.reads[cleanList(path)]++
|
||||
return text, nil
|
||||
}
|
||||
}
|
||||
return "", platformpvf.ErrFileNotFound
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// 本文件负责 DNF 静态数据装配选项的默认值和列表去重。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"longheng.io/server/internal/modules/dnf/drop"
|
||||
"longheng.io/server/internal/modules/dnf/dungeon"
|
||||
"longheng.io/server/internal/modules/dnf/equip"
|
||||
"longheng.io/server/internal/modules/dnf/monster"
|
||||
"longheng.io/server/internal/modules/dnf/reward"
|
||||
"longheng.io/server/internal/modules/dnf/skill"
|
||||
)
|
||||
|
||||
// DefaultLists 返回静态数据总装配默认需要解析的 `.lst` 路径。
|
||||
func DefaultLists() []string {
|
||||
return []string{
|
||||
equip.DefaultList,
|
||||
skill.DefaultList,
|
||||
monster.DefaultList,
|
||||
dungeon.DefaultList,
|
||||
drop.DefaultList,
|
||||
reward.DefaultList,
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeOptions(options Options) Options {
|
||||
if options.Equip.ListPath == "" {
|
||||
options.Equip.ListPath = equip.DefaultList
|
||||
}
|
||||
if options.Skill.ListPath == "" {
|
||||
options.Skill.ListPath = skill.DefaultList
|
||||
}
|
||||
if options.Monster.ListPath == "" {
|
||||
options.Monster.ListPath = monster.DefaultList
|
||||
}
|
||||
if options.Dungeon.ListPath == "" {
|
||||
options.Dungeon.ListPath = dungeon.DefaultList
|
||||
}
|
||||
if options.Drop.ListPath == "" {
|
||||
options.Drop.ListPath = drop.DefaultList
|
||||
}
|
||||
if options.Reward.ListPath == "" {
|
||||
options.Reward.ListPath = reward.DefaultList
|
||||
}
|
||||
options.Build.Lists = mergeLists(options.Build.Lists, []string{
|
||||
options.Equip.ListPath,
|
||||
options.Skill.ListPath,
|
||||
options.Monster.ListPath,
|
||||
options.Dungeon.ListPath,
|
||||
options.Drop.ListPath,
|
||||
options.Reward.ListPath,
|
||||
})
|
||||
return options
|
||||
}
|
||||
|
||||
func mergeLists(base []string, required []string) []string {
|
||||
out := make([]string, 0, len(base)+len(required))
|
||||
seen := make(map[string]struct{}, len(base)+len(required))
|
||||
for _, value := range append(append([]string(nil), base...), required...) {
|
||||
key := listKey(value)
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
if _, exists := seen[key]; exists {
|
||||
continue
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
out = append(out, cleanList(value))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func listKey(value string) string {
|
||||
return strings.ToLower(cleanList(value))
|
||||
}
|
||||
|
||||
func cleanList(value string) string {
|
||||
value = strings.TrimSpace(strings.ReplaceAll(value, "\\", "/"))
|
||||
for strings.HasPrefix(value, "./") || strings.HasPrefix(value, "/") {
|
||||
value = strings.TrimPrefix(value, "./")
|
||||
value = strings.TrimPrefix(value, "/")
|
||||
}
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
clean := strings.TrimSuffix(path.Clean(value), "/")
|
||||
if clean == "." {
|
||||
return ""
|
||||
}
|
||||
return clean
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// 本文件定义 DNF 静态数据总装配后的只读查询入口。
|
||||
package staticdata
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"longheng.io/server/internal/modules/dnf/drop"
|
||||
"longheng.io/server/internal/modules/dnf/dungeon"
|
||||
"longheng.io/server/internal/modules/dnf/equip"
|
||||
"longheng.io/server/internal/modules/dnf/monster"
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
"longheng.io/server/internal/modules/dnf/reward"
|
||||
"longheng.io/server/internal/modules/dnf/skill"
|
||||
)
|
||||
|
||||
var ErrSourceRequired = errors.New("dnf staticdata source is required")
|
||||
|
||||
type Options struct {
|
||||
Build dnfpvf.BuildOptions
|
||||
Equip equip.Options
|
||||
Skill skill.Options
|
||||
Monster monster.Options
|
||||
Dungeon dungeon.Options
|
||||
Drop drop.Options
|
||||
Reward reward.Options
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
Index *dnfpvf.Index
|
||||
Equip *equip.Table
|
||||
Skill *skill.Table
|
||||
Monster *monster.Table
|
||||
Dungeon *dungeon.Table
|
||||
Drop *drop.Table
|
||||
Reward *reward.Table
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
Index dnfpvf.Snapshot `json:"index"`
|
||||
Equip equip.Snapshot `json:"equip"`
|
||||
Skill skill.Snapshot `json:"skill"`
|
||||
Monster monster.Snapshot `json:"monster"`
|
||||
Dungeon dungeon.Snapshot `json:"dungeon"`
|
||||
Drop drop.Snapshot `json:"drop"`
|
||||
Reward reward.Snapshot `json:"reward"`
|
||||
}
|
||||
|
||||
// Snapshot 返回 DNF 静态数据总表规模,用于启动日志、debug 面板和接入验收。
|
||||
func (s *Store) Snapshot() Snapshot {
|
||||
if s == nil {
|
||||
return Snapshot{}
|
||||
}
|
||||
return Snapshot{
|
||||
Index: s.Index.Snapshot(),
|
||||
Equip: s.Equip.Snapshot(),
|
||||
Skill: s.Skill.Snapshot(),
|
||||
Monster: s.Monster.Snapshot(),
|
||||
Dungeon: s.Dungeon.Snapshot(),
|
||||
Drop: s.Drop.Snapshot(),
|
||||
Reward: s.Reward.Snapshot(),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user