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,258 @@
|
||||
package combatpower
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
const (
|
||||
equipmentListPath = "equipment/equipment.lst"
|
||||
partSetListPath = "etc/equipmentpartset.etc"
|
||||
)
|
||||
|
||||
type Catalog struct {
|
||||
source dnfpvf.Source
|
||||
|
||||
mu sync.Mutex
|
||||
itemPaths map[int64]string
|
||||
setPaths map[int64]string
|
||||
items map[int64]ItemDefinition
|
||||
sets map[int64]SetDefinition
|
||||
}
|
||||
|
||||
func Load(ctx context.Context, source dnfpvf.Source) (*Catalog, error) {
|
||||
if source == nil {
|
||||
return nil, ErrSourceRequired
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
equipmentText, err := source.ReadText(equipmentListPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read combat power equipment list: %w", err)
|
||||
}
|
||||
equipmentDoc, err := dnfpvf.Parse(equipmentListPath, equipmentText)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse combat power equipment list: %w", err)
|
||||
}
|
||||
itemPaths := make(map[int64]string)
|
||||
for _, entry := range dnfpvf.ParseList(equipmentDoc) {
|
||||
if entry.ID <= 0 {
|
||||
continue
|
||||
}
|
||||
itemPaths[entry.ID] = resolvePVFReference(equipmentListPath, entry.Path)
|
||||
}
|
||||
|
||||
setText, err := source.ReadText(partSetListPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read combat power part-set list: %w", err)
|
||||
}
|
||||
setDoc, err := dnfpvf.Parse(partSetListPath, setText)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse combat power part-set list: %w", err)
|
||||
}
|
||||
setPaths := parsePartSetPaths(setDoc)
|
||||
|
||||
return &Catalog{
|
||||
source: source,
|
||||
itemPaths: itemPaths,
|
||||
setPaths: setPaths,
|
||||
items: make(map[int64]ItemDefinition),
|
||||
sets: make(map[int64]SetDefinition),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Catalog) Snapshot() (items, sets int) {
|
||||
if c == nil {
|
||||
return 0, 0
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return len(c.itemPaths), len(c.setPaths)
|
||||
}
|
||||
|
||||
func (c *Catalog) Aggregate(ctx context.Context, itemIDs []int64) (Result, error) {
|
||||
if c == nil || c.source == nil {
|
||||
return Result{}, ErrSourceRequired
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
result := Result{}
|
||||
setPieces := make(map[int64]int)
|
||||
for _, itemID := range itemIDs {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
if itemID <= 0 {
|
||||
continue
|
||||
}
|
||||
item, err := c.item(ctx, itemID)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
result.Affixes.Add(item.Affixes)
|
||||
result.EquippedItems++
|
||||
if item.EquipmentScore > 0 {
|
||||
result.ScoredItems++
|
||||
result.PVFEquipmentScore += item.EquipmentScore
|
||||
}
|
||||
if item.Rarity == 4 && item.MinimumLevel >= 90 {
|
||||
result.Level90EpicItems++
|
||||
}
|
||||
if item.PartSetID > 0 {
|
||||
setPieces[item.PartSetID]++
|
||||
}
|
||||
}
|
||||
|
||||
setIDs := make([]int64, 0, len(setPieces))
|
||||
for setID := range setPieces {
|
||||
setIDs = append(setIDs, setID)
|
||||
}
|
||||
sort.Slice(setIDs, func(i, j int) bool { return setIDs[i] < setIDs[j] })
|
||||
for _, setID := range setIDs {
|
||||
pieces := setPieces[setID]
|
||||
definition, err := c.set(ctx, setID)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
active := false
|
||||
for _, ability := range definition.Abilities {
|
||||
if ability.RequiredPieces <= 0 || pieces < ability.RequiredPieces {
|
||||
continue
|
||||
}
|
||||
result.Affixes.Add(ability.Affixes)
|
||||
active = true
|
||||
}
|
||||
if active {
|
||||
result.ActiveSets = append(result.ActiveSets, ActiveSet{ID: setID, Pieces: pieces})
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *Catalog) item(ctx context.Context, itemID int64) (ItemDefinition, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if item, ok := c.items[itemID]; ok {
|
||||
return item, nil
|
||||
}
|
||||
itemPath := c.itemPaths[itemID]
|
||||
if itemPath == "" {
|
||||
return ItemDefinition{}, fmt.Errorf("%w: item %d", ErrItemMissing, itemID)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return ItemDefinition{}, err
|
||||
}
|
||||
text, err := c.source.ReadText(itemPath)
|
||||
if err != nil {
|
||||
return ItemDefinition{}, fmt.Errorf("read combat power item %d at %s: %w", itemID, itemPath, err)
|
||||
}
|
||||
doc, err := dnfpvf.Parse(itemPath, text)
|
||||
if err != nil {
|
||||
return ItemDefinition{}, fmt.Errorf("parse combat power item %d at %s: %w", itemID, itemPath, err)
|
||||
}
|
||||
partSetID, _ := doc.Int("part set index")
|
||||
rarity, _ := doc.Int("rarity")
|
||||
minimumLevel, _ := doc.Int("minimum level")
|
||||
grade, _ := doc.Int("grade")
|
||||
equipmentType, _ := doc.Text("equipment type")
|
||||
item := ItemDefinition{
|
||||
ID: itemID,
|
||||
Path: itemPath,
|
||||
PartSetID: partSetID,
|
||||
Rarity: boundedPVFScoreMetadata(rarity, 10),
|
||||
MinimumLevel: boundedPVFScoreMetadata(minimumLevel, 200),
|
||||
Grade: boundedPVFScoreMetadata(grade, 200),
|
||||
EquipmentType: strings.TrimSpace(equipmentType),
|
||||
Affixes: parseDocumentAffixes(doc),
|
||||
}
|
||||
item.EquipmentScore = pvfEquipmentBaseScore(item)
|
||||
c.items[itemID] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// pvfEquipmentBaseScore is the local V6 calibration for the equipment-grade
|
||||
// part of the TGP-style display. The original TGP coefficients were never
|
||||
// published, so this must remain an explicit, auditable projection from the
|
||||
// runtime PVF instead of an item-ID table: required level carries the largest
|
||||
// weight, PVF grade refines items at the same level, and rarity is the final
|
||||
// quality tier. Every current actor slot (including avatars, creature and
|
||||
// creature artifacts) is eligible when its authoritative PVF document carries
|
||||
// these fields.
|
||||
func pvfEquipmentBaseScore(item ItemDefinition) int {
|
||||
return item.MinimumLevel*20 + item.Grade*5 + item.Rarity*100
|
||||
}
|
||||
|
||||
func boundedPVFScoreMetadata(value int64, maximum int) int {
|
||||
if value <= 0 {
|
||||
return 0
|
||||
}
|
||||
if value >= int64(maximum) {
|
||||
return maximum
|
||||
}
|
||||
return int(value)
|
||||
}
|
||||
|
||||
func (c *Catalog) set(ctx context.Context, setID int64) (SetDefinition, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if definition, ok := c.sets[setID]; ok {
|
||||
return definition, nil
|
||||
}
|
||||
setPath := c.setPaths[setID]
|
||||
if setPath == "" {
|
||||
return SetDefinition{}, fmt.Errorf("%w: part set %d", ErrItemMissing, setID)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return SetDefinition{}, err
|
||||
}
|
||||
text, err := c.source.ReadText(setPath)
|
||||
if err != nil {
|
||||
return SetDefinition{}, fmt.Errorf("read combat power part set %d at %s: %w", setID, setPath, err)
|
||||
}
|
||||
doc, err := dnfpvf.Parse(setPath, text)
|
||||
if err != nil {
|
||||
return SetDefinition{}, fmt.Errorf("parse combat power part set %d at %s: %w", setID, setPath, err)
|
||||
}
|
||||
definition := SetDefinition{ID: setID, Path: setPath, Abilities: parseSetAbilities(doc)}
|
||||
c.sets[setID] = definition
|
||||
return definition, nil
|
||||
}
|
||||
|
||||
func parsePartSetPaths(doc *dnfpvf.Document) map[int64]string {
|
||||
out := make(map[int64]string)
|
||||
if doc == nil {
|
||||
return out
|
||||
}
|
||||
for index := 0; index+1 < len(doc.Tokens); index++ {
|
||||
id := doc.Tokens[index]
|
||||
ref := doc.Tokens[index+1]
|
||||
if id.Kind != dnfpvf.TokenInt || id.Int <= 0 ||
|
||||
(ref.Kind != dnfpvf.TokenString && ref.Kind != dnfpvf.TokenIdent) ||
|
||||
!strings.HasSuffix(strings.ToLower(strings.TrimSpace(ref.Value)), ".equ") {
|
||||
continue
|
||||
}
|
||||
out[id.Int] = resolvePVFReference("equipment/equipmentpartset.etc", ref.Value)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func resolvePVFReference(listPath, reference string) string {
|
||||
reference = strings.TrimSpace(strings.Trim(reference, "`\"'"))
|
||||
reference = strings.ReplaceAll(reference, "\\", "/")
|
||||
if strings.HasPrefix(strings.ToLower(reference), "equipment/") {
|
||||
return path.Clean(reference)
|
||||
}
|
||||
return path.Clean(path.Join(path.Dir(listPath), reference))
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package combatpower
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type memorySource map[string]string
|
||||
|
||||
func (s memorySource) ReadText(relativePath string) (string, error) {
|
||||
return s[relativePath], nil
|
||||
}
|
||||
|
||||
func TestCatalogAggregatesPVFDamageCategoriesWithoutConflatingAdditions(t *testing.T) {
|
||||
source := memorySource{
|
||||
"equipment/equipment.lst": `
|
||||
1 ` + "`character/common/a.equ`" + `
|
||||
2 ` + "`character/common/b.equ`" + `
|
||||
3 ` + "`character/common/c.equ`" + `
|
||||
`,
|
||||
"etc/equipmentpartset.etc": `
|
||||
90 ` + "`character/partset2/set_item_90.equ`" + ` ` + "`测试套装`" + `
|
||||
`,
|
||||
"equipment/character/common/a.equ": `
|
||||
[rarity]
|
||||
4
|
||||
[minimum level]
|
||||
90
|
||||
[grade]
|
||||
96
|
||||
[equipment type]
|
||||
` + "`[weapon]`" + `
|
||||
[part set index]
|
||||
90
|
||||
[stat by condition]
|
||||
` + "`add increase damage` `%`" + ` 16
|
||||
[stat by condition]
|
||||
` + "`add increase critical damage` `%`" + ` 18
|
||||
`,
|
||||
"equipment/character/common/b.equ": `
|
||||
[rarity]
|
||||
3
|
||||
[minimum level]
|
||||
85
|
||||
[grade]
|
||||
90
|
||||
[equipment type]
|
||||
` + "`[ring]`" + `
|
||||
[part set index]
|
||||
90
|
||||
[unique increase damage]
|
||||
0 ` + "`%`" + ` 12
|
||||
[unique increase critical damage]
|
||||
0 ` + "`%`" + ` 10
|
||||
`,
|
||||
"equipment/character/common/c.equ": `
|
||||
[rarity]
|
||||
2
|
||||
[minimum level]
|
||||
60
|
||||
[grade]
|
||||
50
|
||||
[equipment type]
|
||||
` + "`[artifact red]`" + `
|
||||
[part set index]
|
||||
90
|
||||
[unique increase damage]
|
||||
0 ` + "`%`" + ` 20
|
||||
`,
|
||||
"equipment/character/partset2/set_item_90.equ": `
|
||||
[piece set ability]
|
||||
2
|
||||
[add absolute damage]
|
||||
` + "`all` `%`" + ` 22
|
||||
[/piece set ability]
|
||||
[piece set ability]
|
||||
3
|
||||
[add absolute damage]
|
||||
` + "`fire` `%`" + ` 15
|
||||
[add absolute damage]
|
||||
` + "`water` `%`" + ` 15
|
||||
[stat by condition]
|
||||
` + "`all attack bonus rate` `%`" + ` 35
|
||||
[/piece set ability]
|
||||
`,
|
||||
}
|
||||
catalog, err := Load(context.Background(), source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := catalog.Aggregate(context.Background(), []int64{1, 2, 3})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := Affixes{
|
||||
WhiteDamage: 37,
|
||||
YellowDamage: 20,
|
||||
CriticalDamage: 10,
|
||||
YellowAdditional: 16,
|
||||
CriticalAdditional: 18,
|
||||
AllAttack: 35,
|
||||
}
|
||||
assertAffixesEqual(t, result.Affixes, want)
|
||||
if result.EquippedItems != 3 || len(result.ActiveSets) != 1 ||
|
||||
result.ActiveSets[0].ID != 90 || result.ActiveSets[0].Pieces != 3 {
|
||||
t.Fatalf("result metadata = %+v", result)
|
||||
}
|
||||
// 90/96/4 -> 2680, 85/90/3 -> 2450, 60/50/2 -> 1650.
|
||||
if result.PVFEquipmentScore != 6780 || result.ScoredItems != 3 ||
|
||||
result.Level90EpicItems != 1 {
|
||||
t.Fatalf("equipment grade metadata = %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPVFEquipmentBaseScoreBoundsUntrustedMetadata(t *testing.T) {
|
||||
item := ItemDefinition{Rarity: 10, MinimumLevel: 200, Grade: 200}
|
||||
if got, want := pvfEquipmentBaseScore(item), 6000; got != want {
|
||||
t.Fatalf("bounded equipment score=%d want=%d", got, want)
|
||||
}
|
||||
if got := boundedPVFScoreMetadata(-1, 200); got != 0 {
|
||||
t.Fatalf("negative metadata bound=%d", got)
|
||||
}
|
||||
if got := boundedPVFScoreMetadata(9999, 200); got != 200 {
|
||||
t.Fatalf("large metadata bound=%d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogDoesNotActivateIncompleteSet(t *testing.T) {
|
||||
source := memorySource{
|
||||
"equipment/equipment.lst": "1 `character/common/a.equ`\n",
|
||||
"etc/equipmentpartset.etc": "90 `character/partset2/set_item_90.equ` `测试套装`\n",
|
||||
"equipment/character/common/a.equ": "[part set index]\n90\n",
|
||||
"equipment/character/partset2/set_item_90.equ": "[piece set ability]\n2\n[add absolute damage]\n`all` `%` 22\n[/piece set ability]\n",
|
||||
}
|
||||
catalog, err := Load(context.Background(), source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := catalog.Aggregate(context.Background(), []int64{1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Affixes.WhiteDamage != 0 || len(result.ActiveSets) != 0 {
|
||||
t.Fatalf("incomplete set result = %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func assertAffixesEqual(t *testing.T, got, want Affixes) {
|
||||
t.Helper()
|
||||
values := [][3]any{
|
||||
{"white", got.WhiteDamage, want.WhiteDamage},
|
||||
{"yellow", got.YellowDamage, want.YellowDamage},
|
||||
{"critical", got.CriticalDamage, want.CriticalDamage},
|
||||
{"yellow_additional", got.YellowAdditional, want.YellowAdditional},
|
||||
{"critical_additional", got.CriticalAdditional, want.CriticalAdditional},
|
||||
{"all_attack", got.AllAttack, want.AllAttack},
|
||||
}
|
||||
for _, value := range values {
|
||||
if math.Abs(value[1].(float64)-value[2].(float64)) > 0.0001 {
|
||||
t.Fatalf("%s = %v want %v", value[0], value[1], value[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package combatpower
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
)
|
||||
|
||||
func parseDocumentAffixes(doc *dnfpvf.Document) Affixes {
|
||||
var out Affixes
|
||||
if doc == nil {
|
||||
return out
|
||||
}
|
||||
for _, section := range doc.Sections {
|
||||
applyAffixSection(&out, section.Name, sectionTokens(doc, section))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func parseSetAbilities(doc *dnfpvf.Document) []SetAbility {
|
||||
if doc == nil {
|
||||
return nil
|
||||
}
|
||||
var abilities []SetAbility
|
||||
var current *SetAbility
|
||||
for _, section := range doc.Sections {
|
||||
name := normalizeName(section.Name)
|
||||
switch name {
|
||||
case "piece set ability":
|
||||
if current != nil && current.RequiredPieces > 0 {
|
||||
abilities = append(abilities, *current)
|
||||
}
|
||||
current = &SetAbility{RequiredPieces: firstInteger(sectionTokens(doc, section))}
|
||||
case "/piece set ability":
|
||||
if current != nil && current.RequiredPieces > 0 {
|
||||
abilities = append(abilities, *current)
|
||||
}
|
||||
current = nil
|
||||
default:
|
||||
if current != nil {
|
||||
applyAffixSection(¤t.Affixes, section.Name, sectionTokens(doc, section))
|
||||
}
|
||||
}
|
||||
}
|
||||
if current != nil && current.RequiredPieces > 0 {
|
||||
abilities = append(abilities, *current)
|
||||
}
|
||||
return abilities
|
||||
}
|
||||
|
||||
func applyAffixSection(out *Affixes, sectionName string, tokens []dnfpvf.Token) {
|
||||
if out == nil || !hasPercent(tokens) {
|
||||
return
|
||||
}
|
||||
value, ok := lastNumber(tokens)
|
||||
if !ok || value <= 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return
|
||||
}
|
||||
name := normalizeName(sectionName)
|
||||
if name == "stat by condition" || name == "stat" {
|
||||
if statName := firstText(tokens); statName != "" {
|
||||
name = normalizeName(statName)
|
||||
}
|
||||
}
|
||||
switch name {
|
||||
case "add absolute damage", "additional damage":
|
||||
// One item or one set threshold may contain mutually-exclusive fire,
|
||||
// water, light, and dark branches. They describe one white-damage
|
||||
// option, so keep the greatest branch here; independent documents are
|
||||
// combined later by Affixes.Add.
|
||||
if value > out.WhiteDamage {
|
||||
out.WhiteDamage = value
|
||||
}
|
||||
case "unique increase damage", "increase damage":
|
||||
if value > out.YellowDamage {
|
||||
out.YellowDamage = value
|
||||
}
|
||||
case "unique increase critical damage", "critical damage":
|
||||
if value > out.CriticalDamage {
|
||||
out.CriticalDamage = value
|
||||
}
|
||||
case "add increase damage":
|
||||
out.YellowAdditional += value
|
||||
case "add increase critical damage":
|
||||
out.CriticalAdditional += value
|
||||
case "all attack bonus rate":
|
||||
// Reinforcement-dependent equipment commonly repeats this stat for
|
||||
// every mutually-exclusive threshold in one document. Until the
|
||||
// projection carries the proved condition selector, never sum those
|
||||
// alternatives into an impossible value.
|
||||
if value > out.AllAttack {
|
||||
out.AllAttack = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sectionTokens(doc *dnfpvf.Document, section dnfpvf.Section) []dnfpvf.Token {
|
||||
if doc == nil || section.Start < 0 || section.End < section.Start || section.End > len(doc.Tokens) {
|
||||
return nil
|
||||
}
|
||||
return doc.Tokens[section.Start:section.End]
|
||||
}
|
||||
|
||||
func normalizeName(value string) string {
|
||||
return strings.ToLower(strings.Join(strings.Fields(strings.TrimSpace(value)), " "))
|
||||
}
|
||||
|
||||
func firstText(tokens []dnfpvf.Token) string {
|
||||
for _, token := range tokens {
|
||||
if token.Kind == dnfpvf.TokenString || token.Kind == dnfpvf.TokenIdent {
|
||||
value := strings.TrimSpace(token.Value)
|
||||
if value != "" && value != "%" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func firstInteger(tokens []dnfpvf.Token) int {
|
||||
for _, token := range tokens {
|
||||
if token.Kind == dnfpvf.TokenInt && token.Int > 0 && token.Int <= math.MaxInt32 {
|
||||
return int(token.Int)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func lastNumber(tokens []dnfpvf.Token) (float64, bool) {
|
||||
for index := len(tokens) - 1; index >= 0; index-- {
|
||||
switch tokens[index].Kind {
|
||||
case dnfpvf.TokenInt:
|
||||
return float64(tokens[index].Int), true
|
||||
case dnfpvf.TokenFloat:
|
||||
return tokens[index].Float, true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func hasPercent(tokens []dnfpvf.Token) bool {
|
||||
for _, token := range tokens {
|
||||
if strings.TrimSpace(token.Value) == "%" || strings.TrimSpace(token.Raw) == "%" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package combatpower
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
dnfpvf "longheng.io/server/internal/modules/dnf/pvf"
|
||||
platformpvf "longheng.io/server/internal/platform/pvf"
|
||||
)
|
||||
|
||||
func TestInspectCurrentCombatPowerEquipmentPVF(t *testing.T) {
|
||||
pvfPath := os.Getenv("DNFBRIDGE_REAL_PVF_SMOKE")
|
||||
if pvfPath == "" {
|
||||
t.Skip("set DNFBRIDGE_REAL_PVF_SMOKE to inspect current combat-power equipment")
|
||||
}
|
||||
archive, err := platformpvf.LoadArchive(platformpvf.Options{Path: pvfPath})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog, err := Load(context.Background(), archive)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
itemIDs := []int64{
|
||||
112550232, 112560208, 112570168, 112500235, 112510219,
|
||||
112540236, 112520208, 112530202, 112580095, 101590068,
|
||||
112600041, 101590023, 101030741, 400330106, 100070551,
|
||||
100170519, 100120544, 100270515, 100220519, 100300733,
|
||||
100312425, 100322294, 100344527, 100352839, 100390011,
|
||||
400990168, 10006783, 10006784, 10006785, 100330501,
|
||||
}
|
||||
for _, itemID := range itemIDs {
|
||||
item, err := catalog.item(context.Background(), itemID)
|
||||
if err != nil {
|
||||
t.Fatalf("item %d: %v", itemID, err)
|
||||
}
|
||||
text, err := archive.ReadText(item.Path)
|
||||
if err != nil {
|
||||
t.Fatalf("read item %d at %s: %v", itemID, item.Path, err)
|
||||
}
|
||||
doc, err := dnfpvf.Parse(item.Path, text)
|
||||
if err != nil {
|
||||
t.Fatalf("parse item %d at %s: %v", itemID, item.Path, err)
|
||||
}
|
||||
t.Logf("item=%d path=%s set=%d rarity=%v min_level=%v grade=%v type=%v sub_type=%v",
|
||||
itemID, item.Path, item.PartSetID,
|
||||
doc.Numbers("rarity"), doc.Numbers("minimum level"),
|
||||
doc.Numbers("grade"), doc.Texts("equipment type"), doc.Texts("sub type"))
|
||||
}
|
||||
result, err := catalog.Aggregate(context.Background(), itemIDs)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.EquippedItems != 30 || result.ScoredItems != 30 ||
|
||||
result.Level90EpicItems != 12 || result.PVFEquipmentScore != 38835 {
|
||||
t.Fatalf("real PVF equipment score result=%+v", result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Package combatpower derives the damage-affix view used by the local
|
||||
// combat-power sidecar from the authoritative runtime PVF.
|
||||
package combatpower
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrSourceRequired = errors.New("dnf combat power pvf source is required")
|
||||
ErrItemMissing = errors.New("dnf combat power equipment definition is missing")
|
||||
)
|
||||
|
||||
// Affixes keeps the 90-era damage categories separate. In particular,
|
||||
// YellowAdditional and CriticalAdditional must never be folded into the
|
||||
// mutually-exclusive yellow/critical base categories while parsing PVF.
|
||||
type Affixes struct {
|
||||
WhiteDamage float64
|
||||
YellowDamage float64
|
||||
CriticalDamage float64
|
||||
YellowAdditional float64
|
||||
CriticalAdditional float64
|
||||
AllAttack float64
|
||||
}
|
||||
|
||||
// Add combines independent equipment/set contributions. YellowDamage and
|
||||
// CriticalDamage are unique categories in this PVF and therefore keep only
|
||||
// the greatest equipped value; the additive categories accumulate.
|
||||
func (a *Affixes) Add(other Affixes) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
a.WhiteDamage += other.WhiteDamage
|
||||
if other.YellowDamage > a.YellowDamage {
|
||||
a.YellowDamage = other.YellowDamage
|
||||
}
|
||||
if other.CriticalDamage > a.CriticalDamage {
|
||||
a.CriticalDamage = other.CriticalDamage
|
||||
}
|
||||
a.YellowAdditional += other.YellowAdditional
|
||||
a.CriticalAdditional += other.CriticalAdditional
|
||||
a.AllAttack += other.AllAttack
|
||||
}
|
||||
|
||||
type ItemDefinition struct {
|
||||
ID int64
|
||||
Path string
|
||||
PartSetID int64
|
||||
Rarity int
|
||||
MinimumLevel int
|
||||
Grade int
|
||||
EquipmentType string
|
||||
EquipmentScore int
|
||||
Affixes Affixes
|
||||
}
|
||||
|
||||
type SetAbility struct {
|
||||
RequiredPieces int
|
||||
Affixes Affixes
|
||||
}
|
||||
|
||||
type SetDefinition struct {
|
||||
ID int64
|
||||
Path string
|
||||
Abilities []SetAbility
|
||||
}
|
||||
|
||||
type ActiveSet struct {
|
||||
ID int64
|
||||
Pieces int
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Affixes Affixes
|
||||
EquippedItems int
|
||||
ScoredItems int
|
||||
Level90EpicItems int
|
||||
PVFEquipmentScore int
|
||||
ActiveSets []ActiveSet
|
||||
}
|
||||
Reference in new issue
Block a user