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

129 lines
5.2 KiB
Go

package dnfbridge
import (
"encoding/binary"
"testing"
dnfmonster "longheng.io/server/internal/modules/dnf/monster"
"longheng.io/server/internal/modules/dnf/worldmap"
)
func buildCurrentDungeonBossMutationTestRequest(token, objectKey uint16, monsterID uint32) []byte {
body := make([]byte, currentDungeonBossMutationRequestLength)
binary.LittleEndian.PutUint32(body[0:4], currentDungeonBossMutationMagic)
body[4] = currentDungeonBossMutationVersion
binary.LittleEndian.PutUint16(body[6:8], token)
binary.LittleEndian.PutUint16(body[8:10], objectKey)
binary.LittleEndian.PutUint32(body[12:16], monsterID)
return body
}
func TestCurrentDungeonBossMutationRequestRequiresExactEnvelope(t *testing.T) {
body := buildCurrentDungeonBossMutationTestRequest(7, 42, 1234)
request, ok := parseCurrentDungeonBossMutationRequest(body)
if !ok || request.Token != 7 || request.ObjectKey != 42 || request.MonsterID != 1234 {
t.Fatalf("parse request = %#v, %v", request, ok)
}
if !isCurrentDungeonBossMutationEnvelope(body) {
t.Fatal("BMU1 envelope was not recognized")
}
mutations := []func([]byte){
func(value []byte) { value[4]++ },
func(value []byte) { value[5] = 1 },
func(value []byte) { binary.LittleEndian.PutUint16(value[6:8], 0) },
func(value []byte) { binary.LittleEndian.PutUint16(value[8:10], 0) },
func(value []byte) { binary.LittleEndian.PutUint16(value[10:12], 1) },
func(value []byte) { binary.LittleEndian.PutUint32(value[12:16], 0) },
}
for index, mutate := range mutations {
candidate := append([]byte(nil), body...)
mutate(candidate)
if _, accepted := parseCurrentDungeonBossMutationRequest(candidate); accepted {
t.Fatalf("mutation %d unexpectedly accepted", index)
}
}
if _, accepted := parseCurrentDungeonBossMutationRequest(body[:len(body)-1]); accepted {
t.Fatal("truncated request unexpectedly accepted")
}
}
func TestCurrentDungeonBossMutationDecisionBody(t *testing.T) {
body := buildCurrentDungeonBossMutationDecisionBody(currentDungeonBossMutationDecision{
Token: 7, MonsterID: 1234, ObjectKey: 42, Allowed: true,
Reason: currentDungeonBossMutationReasonAllowed,
})
if len(body) != currentDungeonBossMutationResponseLength ||
body[0] != currentDungeonBossMutationResponseType ||
body[1] != currentDungeonBossMutationResponseVersion ||
binary.LittleEndian.Uint16(body[2:4]) != 7 ||
binary.LittleEndian.Uint32(body[4:8]) != 1234 ||
binary.LittleEndian.Uint16(body[8:10]) != 42 || body[10] != 1 || body[11] != 0 {
t.Fatalf("decision body = %v", body)
}
}
func newCurrentDungeonBossMutationTestRoom(rank string) *runtimeDungeonRoom {
monster := runtimeDungeonMonster{
ObjectKey: 42,
Spawn: worldmap.MonsterSpawn{
MonsterID: 1234,
Rank: rank,
},
Definition: dnfmonster.Monster{Rank: rank},
State: runtimeDungeonMonsterAnnounced,
}
return &runtimeDungeonRoom{
monsters: []runtimeDungeonMonster{monster},
byObjectKey: map[uint32]int{42: 0},
}
}
func TestRuntimeDungeonBossMutationIsOneShot(t *testing.T) {
room := newCurrentDungeonBossMutationTestRoom("boss")
monster, allowed, reason := room.resolveBossMutation(42, 1234, 0)
if !allowed || reason != currentDungeonBossMutationReasonAllowed ||
!monster.BossMutationAttempted || !monster.BossMutationAllowed {
t.Fatalf("first decision = monster=%#v allowed=%v reason=%d", monster, allowed, reason)
}
monster, allowed, reason = room.resolveBossMutation(42, 1234, 0)
if allowed || reason != currentDungeonBossMutationReasonAlreadyAttempted ||
!monster.BossMutationAttempted || !monster.BossMutationAllowed {
t.Fatalf("repeat decision = monster=%#v allowed=%v reason=%d", monster, allowed, reason)
}
}
func TestRuntimeDungeonBossMutationLotteryMissConsumesAttempt(t *testing.T) {
room := newCurrentDungeonBossMutationTestRoom("boss")
monster, allowed, reason := room.resolveBossMutation(42, 1234, 9)
if allowed || reason != currentDungeonBossMutationReasonLotteryMiss ||
!monster.BossMutationAttempted || monster.BossMutationAllowed {
t.Fatalf("miss decision = monster=%#v allowed=%v reason=%d", monster, allowed, reason)
}
_, allowed, reason = room.resolveBossMutation(42, 1234, 0)
if allowed || reason != currentDungeonBossMutationReasonAlreadyAttempted {
t.Fatalf("miss retry = allowed=%v reason=%d", allowed, reason)
}
}
func TestRuntimeDungeonBossMutationRejectsUnprovedTargets(t *testing.T) {
tests := []struct {
name string
room *runtimeDungeonRoom
objectKey uint32
monsterID int64
want byte
}{
{name: "unknown object", room: newCurrentDungeonBossMutationTestRoom("boss"), objectKey: 43, monsterID: 1234, want: currentDungeonBossMutationReasonTargetUnknown},
{name: "wrong template", room: newCurrentDungeonBossMutationTestRoom("boss"), objectKey: 42, monsterID: 9999, want: currentDungeonBossMutationReasonTargetMismatch},
{name: "not boss", room: newCurrentDungeonBossMutationTestRoom("normal"), objectKey: 42, monsterID: 1234, want: currentDungeonBossMutationReasonNotBoss},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, allowed, reason := test.room.resolveBossMutation(test.objectKey, test.monsterID, 0)
if allowed || reason != test.want {
t.Fatalf("decision = allowed=%v reason=%d, want %d", allowed, reason, test.want)
}
})
}
}