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

149 lines
5.7 KiB
Go

package dnfbridge
import (
"bytes"
"errors"
"testing"
"longheng.io/server/internal/modules/dnf/worldmap"
)
func TestCurrentDungeonTrapEventMonsterScopeUsesPVFMechanismShape(t *testing.T) {
runtime, scene, room := currentDungeonTrapEventMonsterTestFixture()
if !currentDungeonTrapEventMonsterScope(runtime, scene, room) {
t.Fatal("PVF event-monster/trap room was not selected")
}
tests := []struct {
name string
mutate func(*runtimeDungeonState, *worldmap.DungeonRoomScene, *runtimeDungeonRoom)
}{
{name: "missing dungeon definition", mutate: func(runtime *runtimeDungeonState, _ *worldmap.DungeonRoomScene, _ *runtimeDungeonRoom) {
runtime.Dungeon.Metadata.EventMonsters = nil
}},
{name: "missing random-map selector", mutate: func(runtime *runtimeDungeonState, _ *worldmap.DungeonRoomScene, _ *runtimeDungeonRoom) {
runtime.Dungeon.Metadata.EventMonsterRandomMap = worldmap.OptionalInt{}
}},
{name: "missing map positions", mutate: func(_ *runtimeDungeonState, scene *worldmap.DungeonRoomScene, _ *runtimeDungeonRoom) {
scene.Map.Map.EventMonsterPositions = nil
}},
{name: "non-trap special child", mutate: func(_ *runtimeDungeonState, scene *worldmap.DungeonRoomScene, _ *runtimeDungeonRoom) {
scene.SpecialPassiveObjects[0].Spawns[0].Kind = "[monster]"
}},
{name: "other room owner", mutate: func(_ *runtimeDungeonState, _ *worldmap.DungeonRoomScene, room *runtimeDungeonRoom) {
room.mapID++
}},
{name: "boss entrance owns op312", mutate: func(runtime *runtimeDungeonState, _ *worldmap.DungeonRoomScene, _ *runtimeDungeonRoom) {
runtime.Dungeon.Mazes[0].BossRoomEntranceCondition = &worldmap.BossRoomEntranceCondition{Action: "clear action"}
}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
runtime, scene, room := currentDungeonTrapEventMonsterTestFixture()
test.mutate(runtime, &scene, room)
if currentDungeonTrapEventMonsterScope(runtime, scene, room) {
t.Fatalf("unsupported mechanism shape was selected: runtime=%+v scene=%+v room=%+v", runtime.Dungeon.Metadata, scene.Map.Map, room.Snapshot())
}
})
}
}
func TestCurrentDungeonTrapEventMonsterPublishesNativeConditionOnce(t *testing.T) {
runtime, scene, room := currentDungeonTrapEventMonsterTestFixture()
connection := &bufferConn{}
session := &gameSession{conn: connection}
service := &Service{}
if err := service.publishCurrentDungeonTrapEventMonsterAfterStartMap(
session, runtime, scene, room, "test_after_op29",
); err != nil {
t.Fatal(err)
}
packet, rest := splitGameServerUpperPacket(t, connection.write.Bytes())
if len(rest) != 0 || packet.Header.Classification != 0 ||
packet.Header.MsgID != currentDungeonCompleteConditionPassGateMsgID ||
!bytes.Equal(packet.Body, []byte{0, 0, 0, 0, 0}) {
t.Fatalf("event-monster packet class=%d msg=%d body=%x rest=%x",
packet.Header.Classification, packet.Header.MsgID, packet.Body, rest)
}
if !room.Snapshot().EventMonsterConditionPublished {
t.Fatal("successful op312 did not commit the room publication marker")
}
written := connection.write.Len()
if err := service.publishCurrentDungeonTrapEventMonsterAfterStartMap(
session, runtime, scene, room, "test_duplicate",
); err != nil {
t.Fatal(err)
}
if connection.write.Len() != written {
t.Fatalf("duplicate publication wrote=%x", connection.write.Bytes()[written:])
}
}
func TestCurrentDungeonTrapEventMonsterWriteFailureRemainsRetryable(t *testing.T) {
runtime, scene, room := currentDungeonTrapEventMonsterTestFixture()
wantErr := errors.New("event-monster op312 write failed")
session := &gameSession{conn: &failNthDungeonWriteConn{failAt: 1, err: wantErr}}
service := &Service{}
if err := service.publishCurrentDungeonTrapEventMonsterAfterStartMap(
session, runtime, scene, room, "test_failed_write",
); !errors.Is(err, wantErr) {
t.Fatalf("write failure=%v want=%v", err, wantErr)
}
if room.Snapshot().EventMonsterConditionPublished {
t.Fatal("failed op312 write consumed the room publication marker")
}
connection := &bufferConn{}
session.conn = connection
if err := service.publishCurrentDungeonTrapEventMonsterAfterStartMap(
session, runtime, scene, room, "test_retry",
); err != nil {
t.Fatal(err)
}
packet, rest := splitGameServerUpperPacket(t, connection.write.Bytes())
if len(rest) != 0 || packet.Header.MsgID != currentDungeonCompleteConditionPassGateMsgID ||
!bytes.Equal(packet.Body, []byte{0, 0, 0, 0, 0}) {
t.Fatalf("retry packet msg=%d body=%x rest=%x", packet.Header.MsgID, packet.Body, rest)
}
}
func currentDungeonTrapEventMonsterTestFixture() (
*runtimeDungeonState,
worldmap.DungeonRoomScene,
*runtimeDungeonRoom,
) {
coordinate := worldmap.RoomCoordinate{X: 1, Y: 2}
mapValue := worldmap.Map{
ID: 58708,
EventMonsterPositions: []worldmap.Point3{
{X: 640, Y: 215}, {X: 865, Y: 262}, {X: 931, Y: 288}, {X: 753, Y: 277},
},
SpecialPassiveObjects: []worldmap.SpecialPassiveObject{{
PassiveObject: worldmap.PassiveObject{ObjectID: 781},
Spawns: []worldmap.SpecialObjectSpawn{{Kind: "[trap]", Code: 48021}},
}},
}
scene := worldmap.DungeonRoomScene{
Coordinate: coordinate,
Map: worldmap.ResolvedMap{Map: mapValue},
SpecialPassiveObjects: append([]worldmap.SpecialPassiveObject(nil), mapValue.SpecialPassiveObjects...),
}
room := &runtimeDungeonRoom{coordinate: coordinate, mapID: mapValue.ID}
runtime := &runtimeDungeonState{
Dungeon: worldmap.Dungeon{
ID: 26,
Metadata: worldmap.DungeonMetadata{
EventMonsterRandomMap: worldmap.OptionalInt{Value: 0, Set: true},
EventMonsters: []worldmap.DungeonEventMonsterDefinition{{
Kind: "event monster", Values: []int64{1, 1000, 21100, 1, 1000, 1, 1, 5},
}},
},
Mazes: []worldmap.Maze{{}},
},
MazeIndex: 0,
Room: room,
}
return runtime, scene, room
}