From 64699c23d76e201124c058479aec1686e886478a Mon Sep 17 00:00:00 2001
From: UnKownOwO <80520429@qq.com>
Date: Thu, 19 Oct 2023 13:00:40 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=80=AA=E7=89=A9=E3=80=81?=
=?UTF-8?q?=E7=89=A9=E4=BB=B6=E7=94=9F=E6=88=90=E5=91=BD=E4=BB=A4=EF=BC=8C?=
=?UTF-8?q?@@GM=E5=91=BD=E4=BB=A4=E9=9C=80=E8=A6=81=E6=9D=83=E9=99=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
gs/game/game_command_controller.go | 86 +++++++++++++++++++++++++++++-
gs/game/game_command_gm.go | 26 +++++++--
gs/game/player_common.go | 5 ++
gs/game/player_scene.go | 13 ++++-
4 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/gs/game/game_command_controller.go b/gs/game/game_command_controller.go
index ad3a2431..3b00e6f3 100644
--- a/gs/game/game_command_controller.go
+++ b/gs/game/game_command_controller.go
@@ -24,9 +24,7 @@ type CommandController struct {
// InitController 初始化命令控制器
func (c *CommandManager) InitController() {
controllerList := []*CommandController{
- // 权限等级 1: GM 1级
c.NewAssignCommandController(),
- // 权限等级 0: 普通玩家
c.NewHelpCommandController(),
c.NewGotoCommandController(),
c.NewJumpCommandController(),
@@ -35,6 +33,8 @@ func (c *CommandManager) InitController() {
c.NewAvatarCommandController(),
c.NewGiveCommandController(),
c.NewKillCommandController(),
+ c.NewMonsterCommandController(),
+ c.NewGadgetCommandController(),
c.NewQuestCommandController(),
c.NewPointCommandController(),
c.NewXLuaDebugCommandController(),
@@ -623,6 +623,88 @@ func (c *CommandManager) KillCommand(content *CommandContent) bool {
})
}
+// 生成怪物命令
+
+func (c *CommandManager) NewMonsterCommandController() *CommandController {
+ return &CommandController{
+ Name: "生成怪物",
+ AliasList: []string{"monster"},
+ Description: "{alias} 生成原魔",
+ UsageList: []string{
+ "{alias} <怪物ID> [数量] [等级] [姿势 (暂时无效)] [坐标X] [坐标Y] [坐标Z] 生成怪物",
+ },
+ Perm: CommandPermNormal,
+ Func: c.MonsterCommand,
+ }
+}
+
+func (c *CommandManager) MonsterCommand(content *CommandContent) bool {
+ var monsterId uint32 // 怪物id
+ var count uint32 = 1 // 数量
+ var level uint8 = 1 // 等级
+ // var pose uint32 // 姿势
+ var posX = content.AssignPlayer.Pos.X // 坐标x
+ var posY = content.AssignPlayer.Pos.Y // 坐标y
+ var posZ = content.AssignPlayer.Pos.Z // 坐标z
+
+ return content.Dynamic("uint32", func(param any) bool {
+ monsterId = param.(uint32)
+ return true
+ }).Option("uint32", func(param any) bool {
+ count = param.(uint32)
+ return true
+ }).Option("uint8", func(param any) bool {
+ level = param.(uint8)
+ return true
+ }).Option("uint32", func(param any) bool {
+ // pose = param.(uint32)
+ return true
+ }).Option("float64", func(param any) bool {
+ posX = param.(float64)
+ return true
+ }).Option("float64", func(param any) bool {
+ posY = param.(float64)
+ return true
+ }).Option("float64", func(param any) bool {
+ posZ = param.(float64)
+ return true
+ }).Execute(func() bool {
+ c.gmCmd.GMCreateMonster(content.AssignPlayer.PlayerId, monsterId, posX, posY, posZ, count, level)
+ return true
+ })
+}
+
+// 生成物件命令
+
+func (c *CommandManager) NewGadgetCommandController() *CommandController {
+ return &CommandController{
+ Name: "生成物件",
+ AliasList: []string{"gadget"},
+ Description: "{alias} 生成物件",
+ UsageList: []string{
+ "{alias} <物件ID> [数量] 附近生成物件",
+ },
+ Perm: CommandPermNormal,
+ Func: c.GadgetCommand,
+ }
+}
+
+func (c *CommandManager) GadgetCommand(content *CommandContent) bool {
+ var gadgetId uint32 // 物件id
+ var count uint32 = 1 // 数量
+
+ return content.Dynamic("uint32", func(param any) bool {
+ gadgetId = param.(uint32)
+ return true
+ }).Option("uint32", func(param any) bool {
+ count = param.(uint32)
+ return true
+ }).Execute(func() bool {
+ c.gmCmd.GMCreateGadget(content.AssignPlayer.PlayerId, gadgetId, count)
+ return true
+ })
+}
+
// 管理任务命令
func (c *CommandManager) NewQuestCommandController() *CommandController {
diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go
index 640ec018..4ea1520a 100644
--- a/gs/game/game_command_gm.go
+++ b/gs/game/game_command_gm.go
@@ -378,23 +378,41 @@ func (g *GMCmd) GMUnlockAllPoint(userId uint32, sceneId uint32) {
}
// GMCreateMonster 在玩家附近创建怪物
-func (g *GMCmd) GMCreateMonster(userId uint32, monsterId uint32) {
+func (g *GMCmd) GMCreateMonster(userId uint32, monsterId uint32, posX, posY, posZ float64, count uint32, level uint8) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
return
}
- GAME.CreateMonster(player, nil, monsterId)
+ world := WORLD_MANAGER.GetWorldById(player.WorldId)
+ if world == nil {
+ logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
+ return
+ }
+ scene := world.GetSceneById(player.SceneId)
+ if scene == nil {
+ logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
+ return
+ }
+ for i := 0; i < int(count); i++ {
+ GAME.CreateMonster(player, &model.Vector{
+ X: posX,
+ Y: posY,
+ Z: posZ,
+ }, monsterId, level)
+ }
}
// GMCreateGadget 在玩家附近创建物件
-func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32) {
+func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32, count uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
return
}
- GAME.CreateGadget(player, nil, gadgetId, nil)
+ for i := 0; i < int(count); i++ {
+ GAME.CreateGadget(player, nil, gadgetId, nil)
+ }
}
// 系统级GM指令
diff --git a/gs/game/player_common.go b/gs/game/player_common.go
index dba1e7bd..e5b12825 100644
--- a/gs/game/player_common.go
+++ b/gs/game/player_common.go
@@ -292,6 +292,11 @@ func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) {
g.SendMsg(cmd.GmTalkRsp, player.PlayerId, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "GM函数解析失败", Msg: req.Msg})
return
}
+ // 判断玩家权限是否足够
+ if CommandPerm(player.CmdPerm) < CommandPermGM {
+ g.SendMsg(cmd.GmTalkRsp, player.PlayerId, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "权限不足", Msg: req.Msg})
+ return
+ }
funcName := commandText[:beginIndex]
paramList := strings.Split(commandText[beginIndex+1:endIndex], ",")
commandMessageInput <- &CommandMessage{
diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go
index 5672daed..ff57209a 100644
--- a/gs/game/player_scene.go
+++ b/gs/game/player_scene.go
@@ -1151,12 +1151,15 @@ func (g *Game) SceneGroupCreateEntity(player *model.Player, groupId uint32, conf
}
// CreateMonster 创建怪物实体
-func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId uint32) {
+func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId uint32, level uint8) uint32 {
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
- return
+ return 0
}
scene := world.GetSceneById(player.SceneId)
+ if scene == nil {
+ return 0
+ }
if pos == nil {
pos = &model.Vector{
X: player.Pos.X + random.GetRandomFloat64(1.0, 10.0),
@@ -1171,7 +1174,13 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId
monsterId, uint8(random.GetRandomInt32(1, 90)), getTempFightPropMap(),
0, 0,
)
+ entity := scene.GetEntity(entityId)
+ if entity == nil {
+ return 0
+ }
+ entity.level = level
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
+ return entityId
}
// CreateGadget 创建物件实体