Files
90CNServer/server/internal/modules/dnf/skill/parse.go
T
hanfuit 645b64fe21 DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go):
- GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面
- GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新
- 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新)
- 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍
- 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0)
- 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算

启动器(Python/JS):
- 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭
- GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐)
- 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
2026-11-04 14:31:55 +08:00

175 lines
5.8 KiB
Go

// This file maps one current PVF .skl document into domain fields.
package skill
import (
"fmt"
"math"
"strings"
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
)
func parseSkill(job byte, id uint16, skillPath string, doc *dnfpvf.Document) (Skill, error) {
kind := firstText(doc, "skill type", "type", "kind")
fixedLevelBase, fixedLevelValue := doc.Int("fixed level skill")
_, fixedLevelSection := doc.Section("fixed level skill")
fixedLevelSkill := fixedLevelValue || fixedLevelSection
if fixedLevelSection && !fixedLevelValue {
fixedLevelBase = 1
}
fixedLevelInterval := firstIntValue(doc, "interval level")
if fixedLevelInterval <= 0 {
fixedLevelInterval = 1
}
fixedLevelIncrement := firstIntValue(doc, "add level per interval")
if fixedLevelIncrement <= 0 {
fixedLevelIncrement = 1
}
prerequisites, err := parsePrerequisites(doc)
if err != nil {
return Skill{}, err
}
definition := Skill{
Job: job,
ID: id,
Path: skillPath,
Name: firstText(doc, "name", "display name"),
Kind: kind,
Active: skillIsActive(kind, doc),
RequiredLevel: firstIntValue(doc, "required level", "minimum level", "level"),
RequiredLevelRange: firstIntValue(doc, "required level range"),
MaximumLevel: firstIntValue(doc, "maximum level", "max level"),
FixedLevelSkill: fixedLevelSkill,
FixedLevelBase: int(fixedLevelBase),
FixedLevelInterval: fixedLevelInterval,
FixedLevelIncrement: fixedLevelIncrement,
SkillClass: firstIntValue(doc, "skill class"),
GrowTypes: intValues(doc, "skill fitness growtype"),
GrowTypeMaximumLevels: intValues(doc, "growtype maximum level"),
SecondGrowTypes: intValues(doc, "skill fitness second growtype"),
SecondGrowTypeMaximumLevels: intValues(doc, "second growtype maximum level"),
FeatureSkillType: firstIntValue(doc, "feature skill type"),
FeatureSkillIndex: firstIntValue(doc, "feature skill index"),
Prerequisites: prerequisites,
PurchaseCost: intValues(doc, "purchase cost"),
SpecialPurchaseCost: intValues(doc, "special purchase cost"),
CoolTime: firstNumberOrZero(doc, "cool time", "cooltime", "cool down time"),
MPCost: firstInt(doc, "mp consume", "mp cost", "consume mp"),
CastTime: firstNumberOrZero(doc, "casting time", "cast time"),
Command: firstText(doc, "command", "input command"),
Icon: firstText(doc, "icon", "icon path"),
Scalars: scalars(doc),
}
if definition.Name == "" {
definition.Name = definition.Path
}
return definition, nil
}
// skillIsActive keeps the explicit [type] declaration authoritative, while
// accepting the two 90-era Wind Mage high-level skills whose PVF documents
// intentionally omit [type]. Those documents still have an executable-state
// section, which is the client-facing marker that the skill can be cast. A
// passive skill has an explicit non-active type or no executable states, so it
// cannot be promoted merely because it has a cost/stat section.
func skillIsActive(kind string, doc *dnfpvf.Document) bool {
kind = strings.ToLower(strings.TrimSpace(kind))
if strings.Contains(kind, "active") {
return true
}
if kind != "" || doc == nil {
return false
}
states := doc.Texts("executable states")
return len(states) != 0
}
func parsePrerequisites(doc *dnfpvf.Document) ([]Prerequisite, error) {
values := doc.Ints("pre required skill")
if len(values) == 0 {
return nil, nil
}
if len(values)%2 != 0 {
return nil, fmt.Errorf("%w: odd value count %d", ErrPrerequisite, len(values))
}
out := make([]Prerequisite, 0, len(values)/2)
for idx := 0; idx < len(values); idx += 2 {
if values[idx] < 0 || values[idx] > math.MaxUint16 || values[idx+1] < 0 {
return nil, fmt.Errorf("%w: skill=%d level=%d", ErrPrerequisite, values[idx], values[idx+1])
}
out = append(out, Prerequisite{SkillID: uint16(values[idx]), Level: int(values[idx+1])})
}
return out, nil
}
func scalars(doc *dnfpvf.Document) map[string]float64 {
names := map[string][]string{
"power": {"power", "attack power"},
"hit_count": {"hit count", "multi hit count"},
"range": {"range", "attack range"},
"duration": {"duration", "buff duration"},
"cool_time": {"cool time", "cooltime"},
"cast_time": {"casting time", "cast time"},
"consume_mp": {"mp consume", "mp cost", "consume mp"},
"required_sp": {"required sp", "sp cost"},
}
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 firstInt(doc *dnfpvf.Document, names ...string) int64 {
for _, name := range names {
if value, ok := doc.Int(name); ok {
return value
}
}
return 0
}
func firstIntValue(doc *dnfpvf.Document, names ...string) int {
return int(firstInt(doc, names...))
}
func intValues(doc *dnfpvf.Document, name string) []int {
values := doc.Ints(name)
if len(values) == 0 {
return nil
}
out := make([]int, len(values))
for idx, value := range values {
out[idx] = int(value)
}
return out
}
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
}
func firstNumberOrZero(doc *dnfpvf.Document, names ...string) float64 {
value, _ := firstNumber(doc, names...)
return value
}