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,2 @@
|
||||
// Package reward 把 DNF PVF 奖励文本索引加载成只读内存表。
|
||||
package reward
|
||||
@@ -0,0 +1,53 @@
|
||||
// 本文件负责从 DNF PVF 内存索引加载奖励强类型表。
|
||||
package reward
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
// Load 从已构建的 DNF PVF 内存索引加载奖励表。
|
||||
// 这里不扣疲劳、不发金币、不写背包,只准备结算 owner 后续要查的静态数据。
|
||||
func Load(ctx context.Context, index *dnfpvf.Index, options Options) (*Table, error) {
|
||||
if index == nil {
|
||||
return nil, ErrIndexRequired
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
listPath := options.ListPath
|
||||
if listPath == "" {
|
||||
listPath = DefaultList
|
||||
}
|
||||
entries := index.List(listPath)
|
||||
if len(entries) == 0 {
|
||||
return nil, fmt.Errorf("%w: %s", ErrListEmpty, listPath)
|
||||
}
|
||||
table := &Table{
|
||||
rewards: make([]Reward, 0, len(entries)),
|
||||
byID: make(map[int64]int, len(entries)),
|
||||
byPath: make(map[string]int, len(entries)),
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc, ok := index.Document(entry.Path)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %s", ErrDocMissing, entry.Path)
|
||||
}
|
||||
reward := parse(entry.ID, entry.Path, doc)
|
||||
idx := len(table.rewards)
|
||||
table.rewards = append(table.rewards, reward)
|
||||
if _, exists := table.byID[reward.ID]; !exists {
|
||||
table.byID[reward.ID] = idx
|
||||
}
|
||||
key := pathKey(reward.Path)
|
||||
if key != "" {
|
||||
table.byPath[key] = idx
|
||||
}
|
||||
}
|
||||
return table, nil
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// 本文件验证奖励表加载只依赖内存 PVF 索引。
|
||||
package reward
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
func TestLoadBuildsRewardTable(t *testing.T) {
|
||||
table, err := Load(context.Background(), testIndex(t), Options{})
|
||||
if err != nil {
|
||||
t.Fatalf("load reward: %v", err)
|
||||
}
|
||||
if snapshot := table.Snapshot(); snapshot.Rewards != 1 {
|
||||
t.Fatalf("unexpected snapshot: %+v", snapshot)
|
||||
}
|
||||
reward, ok := table.Find(6001)
|
||||
if !ok {
|
||||
t.Fatalf("expected reward")
|
||||
}
|
||||
if reward.Name != "training reward" || reward.Kind != "clear" || reward.Gold != 300 || reward.Exp != 800 {
|
||||
t.Fatalf("unexpected reward: %+v", reward)
|
||||
}
|
||||
if len(reward.DropIDs) != 2 || reward.DropIDs[0] != 5001 {
|
||||
t.Fatalf("unexpected drop ids: %+v", reward.DropIDs)
|
||||
}
|
||||
if len(reward.ItemPaths) != 1 || reward.ItemPaths[0] != "equipment/training_sword.equ" {
|
||||
t.Fatalf("unexpected item paths: %+v", reward.ItemPaths)
|
||||
}
|
||||
reward.DropIDs[0] = 1
|
||||
reward.ItemPaths[0] = "changed"
|
||||
reward.Scalars["exp"] = 1
|
||||
again, _ := table.FindPath("./REWARD/training.rwd")
|
||||
if again.DropIDs[0] != 5001 || again.ItemPaths[0] != "equipment/training_sword.equ" || again.Scalars["exp"] != 800 {
|
||||
t.Fatalf("table returned mutable reward: %+v", again)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRequiresIndex(t *testing.T) {
|
||||
_, err := Load(context.Background(), nil, Options{})
|
||||
if !errors.Is(err, ErrIndexRequired) {
|
||||
t.Fatalf("expected ErrIndexRequired, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadReportsEmptyList(t *testing.T) {
|
||||
index, err := dnfpvf.Build(context.Background(), textSource{
|
||||
"reward/reward.lst": "6001 `reward/missing.rwd`\n",
|
||||
}, dnfpvf.BuildOptions{Paths: []string{"reward/reward.lst"}})
|
||||
if err != nil {
|
||||
t.Fatalf("build index: %v", err)
|
||||
}
|
||||
_, err = Load(context.Background(), index, Options{})
|
||||
if !errors.Is(err, ErrListEmpty) {
|
||||
t.Fatalf("expected ErrListEmpty, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testIndex(t *testing.T) *dnfpvf.Index {
|
||||
t.Helper()
|
||||
index, err := dnfpvf.Build(context.Background(), textSource{
|
||||
"reward/reward.lst": "6001 `reward/training.rwd`\n",
|
||||
"reward/training.rwd": `
|
||||
[name]
|
||||
` + "`training reward`" + `
|
||||
[reward type]
|
||||
` + "`clear`" + `
|
||||
[drops]
|
||||
5001 5002
|
||||
[drop paths]
|
||||
` + "`drop/training.drop`" + `
|
||||
[items]
|
||||
1001
|
||||
[item paths]
|
||||
` + "`equipment/training_sword.equ`" + `
|
||||
[gold]
|
||||
300
|
||||
[exp]
|
||||
800
|
||||
`,
|
||||
}, dnfpvf.BuildOptions{Lists: []string{DefaultList}})
|
||||
if err != nil {
|
||||
t.Fatalf("build index: %v", err)
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
type textSource map[string]string
|
||||
|
||||
func (s textSource) ReadText(relativePath string) (string, error) {
|
||||
for key, value := range s {
|
||||
if pathKey(key) == pathKey(relativePath) {
|
||||
return value, nil
|
||||
}
|
||||
}
|
||||
return "", dnfpvf.ErrDocNotFound
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// 本文件负责把通用 PVF Document 转成奖励领域字段。
|
||||
package reward
|
||||
|
||||
import dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
|
||||
// parse 把单个奖励 PVF 文档收敛成稳定字段。
|
||||
// 奖励真正提交必须在 reward/bag/equip owner 中完成,不能在 loader 里产生副作用。
|
||||
func parse(id int64, rewardPath string, doc *dnfpvf.Document) Reward {
|
||||
reward := Reward{
|
||||
ID: id,
|
||||
Path: rewardPath,
|
||||
Name: firstText(doc, "name", "display name"),
|
||||
Kind: firstText(doc, "reward type", "type", "kind"),
|
||||
DropIDs: firstInts(doc, "drops", "drop ids", "drop table", "drop tables"),
|
||||
DropPaths: firstTexts(doc, "drop paths", "drop path", "drop table paths"),
|
||||
ItemIDs: firstInts(doc, "items", "item ids", "item list", "reward items"),
|
||||
ItemPaths: firstTexts(doc, "item paths", "item path", "reward item paths"),
|
||||
Gold: firstInt(doc, "gold", "reward gold", "money"),
|
||||
Exp: firstInt(doc, "exp", "experience", "reward exp"),
|
||||
Scalars: scalars(doc),
|
||||
}
|
||||
if reward.Name == "" {
|
||||
reward.Name = reward.Path
|
||||
}
|
||||
return reward
|
||||
}
|
||||
|
||||
// scalars 提取奖励结算常用数值,启动后直接走内存查询。
|
||||
func scalars(doc *dnfpvf.Document) map[string]float64 {
|
||||
names := map[string][]string{
|
||||
"gold": {"gold", "reward gold", "money"},
|
||||
"exp": {"exp", "experience", "reward exp"},
|
||||
"clear_exp": {"clear exp"},
|
||||
"fatigue": {"fatigue", "fatigue cost"},
|
||||
"item_count": {"item count", "reward item count"},
|
||||
"drop_count": {"drop count"},
|
||||
}
|
||||
out := make(map[string]float64)
|
||||
for key, aliases := range names {
|
||||
if value, ok := firstNumber(doc, aliases...); ok {
|
||||
out[key] = value
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func firstText(doc *dnfpvf.Document, names ...string) string {
|
||||
for _, name := range names {
|
||||
if value, ok := doc.Text(name); ok {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func firstTexts(doc *dnfpvf.Document, names ...string) []string {
|
||||
for _, name := range names {
|
||||
values := doc.Texts(name)
|
||||
if len(values) > 0 {
|
||||
return values
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func firstInt(doc *dnfpvf.Document, names ...string) int64 {
|
||||
for _, name := range names {
|
||||
if value, ok := doc.Int(name); ok {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func firstInts(doc *dnfpvf.Document, names ...string) []int64 {
|
||||
for _, name := range names {
|
||||
values := doc.Ints(name)
|
||||
if len(values) > 0 {
|
||||
return values
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func firstNumber(doc *dnfpvf.Document, names ...string) (float64, bool) {
|
||||
for _, name := range names {
|
||||
if value, ok := doc.Number(name); ok {
|
||||
return value, true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// 本文件负责奖励表路径 key 的归一化。
|
||||
package reward
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func pathKey(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 strings.ToLower(clean)
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// 本文件定义 DNF 奖励表的内存视图和查询接口。
|
||||
package reward
|
||||
|
||||
import "errors"
|
||||
|
||||
const DefaultList = "reward/reward.lst"
|
||||
|
||||
var (
|
||||
ErrIndexRequired = errors.New("dnf reward index is required")
|
||||
ErrListEmpty = errors.New("dnf reward list is empty")
|
||||
ErrDocMissing = errors.New("dnf reward document is missing")
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
ListPath string
|
||||
}
|
||||
|
||||
type Reward struct {
|
||||
ID int64 `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
DropIDs []int64 `json:"drop_ids,omitempty"`
|
||||
DropPaths []string `json:"drop_paths,omitempty"`
|
||||
ItemIDs []int64 `json:"item_ids,omitempty"`
|
||||
ItemPaths []string `json:"item_paths,omitempty"`
|
||||
Gold int64 `json:"gold,omitempty"`
|
||||
Exp int64 `json:"exp,omitempty"`
|
||||
Scalars map[string]float64 `json:"scalars,omitempty"`
|
||||
}
|
||||
|
||||
type Table struct {
|
||||
rewards []Reward
|
||||
byID map[int64]int
|
||||
byPath map[string]int
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
Rewards int `json:"rewards"`
|
||||
}
|
||||
|
||||
// Rewards 返回奖励表副本,避免调用方改坏内存索引。
|
||||
func (t *Table) Rewards() []Reward {
|
||||
if t == nil || len(t.rewards) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]Reward, len(t.rewards))
|
||||
for idx, reward := range t.rewards {
|
||||
out[idx] = cloneReward(reward)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Find 按 `.lst` 中的奖励 id 查询内存表。
|
||||
func (t *Table) Find(id int64) (Reward, bool) {
|
||||
if t == nil {
|
||||
return Reward{}, false
|
||||
}
|
||||
idx, ok := t.byID[id]
|
||||
if !ok {
|
||||
return Reward{}, false
|
||||
}
|
||||
return cloneReward(t.rewards[idx]), true
|
||||
}
|
||||
|
||||
// FindPath 按 PVF 相对路径查询内存表。
|
||||
func (t *Table) FindPath(rewardPath string) (Reward, bool) {
|
||||
if t == nil {
|
||||
return Reward{}, false
|
||||
}
|
||||
idx, ok := t.byPath[pathKey(rewardPath)]
|
||||
if !ok {
|
||||
return Reward{}, false
|
||||
}
|
||||
return cloneReward(t.rewards[idx]), true
|
||||
}
|
||||
|
||||
// Snapshot 返回奖励表当前规模,用于启动日志和 debug 面板。
|
||||
func (t *Table) Snapshot() Snapshot {
|
||||
if t == nil {
|
||||
return Snapshot{}
|
||||
}
|
||||
return Snapshot{Rewards: len(t.rewards)}
|
||||
}
|
||||
|
||||
// cloneReward 复制切片和 map,保证加载后的表只读。
|
||||
func cloneReward(reward Reward) Reward {
|
||||
reward.DropIDs = append([]int64(nil), reward.DropIDs...)
|
||||
reward.DropPaths = append([]string(nil), reward.DropPaths...)
|
||||
reward.ItemIDs = append([]int64(nil), reward.ItemIDs...)
|
||||
reward.ItemPaths = append([]string(nil), reward.ItemPaths...)
|
||||
if len(reward.Scalars) > 0 {
|
||||
scalars := make(map[string]float64, len(reward.Scalars))
|
||||
for key, value := range reward.Scalars {
|
||||
scalars[key] = value
|
||||
}
|
||||
reward.Scalars = scalars
|
||||
}
|
||||
return reward
|
||||
}
|
||||
Reference in new issue
Block a user