Files
90CNServer/server/internal/services/dnfbridge/dungeon_durability_test.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

154 lines
5.2 KiB
Go

package dnfbridge
import (
"context"
"encoding/binary"
"testing"
"time"
"longheng.io/server/internal/modules/dnf/alignedcmd"
"longheng.io/server/internal/modules/dnf/dnfenum"
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
"longheng.io/server/internal/modules/dnf/worldmap"
)
func TestCurrentDungeonDurabilitySlotAllowlist(t *testing.T) {
allowed := map[int16]bool{12: true, 14: true, 15: true, 16: true, 17: true, 18: true}
for slot := int16(0); slot <= 255; slot++ {
if got := isCurrentDungeonDurabilitySlot(slot); got != allowed[slot] {
t.Fatalf("slot %d allowed=%t, want %t", slot, got, allowed[slot])
}
}
}
func TestDungeonDurabilityPersistsAndRefreshesOneEquipmentSlot(t *testing.T) {
const (
characterID = "77"
itemID = int64(10018)
slot = int16(12)
)
repos := testRepositoryGroup()
raw := make([]byte, currentItemListEntryWireSize)
binary.LittleEndian.PutUint32(raw[2:6], uint32(itemID))
binary.LittleEndian.PutUint16(raw[0x0B:0x0D], 45)
if err := repos.Equipment.Save(context.Background(), dnfrepo.EquipmentRecord{
CharacterID: characterID,
Entries: map[string]dnfrepo.EquipmentEntry{
"12": {SlotIndex: slot, ItemID: itemID, RawEntry: raw},
},
UpdatedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("save equipment: %v", err)
}
service := &Service{
repositoryProvider: func() (dnfrepo.Group, bool) { return repos, true },
repairCostCatalog: &currentRepairCostCatalog{
evidence: map[int64]alignedcmd.RepairCostEvidence{
itemID: {MaxDurability: 45},
},
},
}
connection := &bufferConn{}
session := &gameSession{
conn: connection,
connID: "dungeon-durability-regression",
selectedCharacterID: 77,
dungeon: dungeonSessionState{runtime: &runtimeDungeonState{
Character: dnfrepo.CharacterRecord{CharacterID: characterID},
Session: &worldmap.DungeonSession{},
Room: &runtimeDungeonRoom{},
}},
}
if err := service.handleGameCommand(
session,
byte(dnfenum.GameCmdCommand),
uint16(dnfenum.CmdPacketDecreaseDurability),
[]byte{byte(slot)},
); err != nil {
t.Fatalf("handle op48: %v", err)
}
packet, rest := splitCurrentGameServerUpperPacketAuto(t, connection.write.Bytes())
if len(rest) != 0 {
t.Fatalf("op48 emitted trailing packets=%x", rest)
}
if packet.Header.Classification != 0 || packet.Header.MsgID != uint16(dnfenum.CmdPacketWalkoutPartyMember) {
t.Fatalf("op48 refresh header class=%d msg=%d", packet.Header.Classification, packet.Header.MsgID)
}
if len(packet.Body) != 3+currentItemListEntryWireSize ||
packet.Body[0] != currentSocketListEquipment ||
binary.LittleEndian.Uint16(packet.Body[1:3]) != 1 {
t.Fatalf("op48 refresh body=%x", packet.Body)
}
if got := int16(binary.LittleEndian.Uint16(packet.Body[3:5])); got != slot {
t.Fatalf("op48 refresh slot=%d, want %d", got, slot)
}
if got := binary.LittleEndian.Uint32(packet.Body[5:9]); got != uint32(itemID) {
t.Fatalf("op48 refresh item=%d, want %d", got, itemID)
}
if got := binary.LittleEndian.Uint16(packet.Body[3+0x0B : 3+0x0D]); got != 44 {
t.Fatalf("op48 refresh durability=%d, want 44", got)
}
loaded, found, err := repos.Equipment.Load(context.Background(), characterID)
if err != nil || !found {
t.Fatalf("load equipment found=%t err=%v", found, err)
}
entry := loaded.Entries["12"]
if got := binary.LittleEndian.Uint16(entry.RawEntry[0x0B:0x0D]); got != 44 {
t.Fatalf("persisted durability=%d, want 44", got)
}
}
func TestDungeonDurabilityRejectsNonDurableEquipmentSlot(t *testing.T) {
const (
characterID = "78"
itemID = int64(10019)
slot = int16(13)
)
repos := testRepositoryGroup()
raw := make([]byte, currentItemListEntryWireSize)
binary.LittleEndian.PutUint32(raw[2:6], uint32(itemID))
binary.LittleEndian.PutUint16(raw[0x0B:0x0D], 45)
if err := repos.Equipment.Save(context.Background(), dnfrepo.EquipmentRecord{
CharacterID: characterID,
Entries: map[string]dnfrepo.EquipmentEntry{
"13": {SlotIndex: slot, ItemID: itemID, RawEntry: raw},
},
UpdatedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("save equipment: %v", err)
}
service := &Service{
repositoryProvider: func() (dnfrepo.Group, bool) { return repos, true },
repairCostCatalog: &currentRepairCostCatalog{evidence: map[int64]alignedcmd.RepairCostEvidence{
itemID: {MaxDurability: 45},
}},
}
connection := &bufferConn{}
session := &gameSession{
conn: connection,
connID: "dungeon-durability-rejected-slot",
selectedCharacterID: 78,
dungeon: dungeonSessionState{runtime: &runtimeDungeonState{
Character: dnfrepo.CharacterRecord{CharacterID: characterID},
Session: &worldmap.DungeonSession{},
Room: &runtimeDungeonRoom{},
}},
}
if err := service.handleDungeonDecreaseDurability(session, []byte{byte(slot)}); err != nil {
t.Fatalf("handle rejected op48: %v", err)
}
if connection.write.Len() != 0 {
t.Fatalf("rejected op48 emitted bytes=%d", connection.write.Len())
}
loaded, found, err := repos.Equipment.Load(context.Background(), characterID)
if err != nil || !found {
t.Fatalf("load equipment found=%t err=%v", found, err)
}
if got := binary.LittleEndian.Uint16(loaded.Entries["13"].RawEntry[0x0B:0x0D]); got != 45 {
t.Fatalf("rejected slot durability=%d, want 45", got)
}
}