From ca79a5bbf04d83447728c20893f994ad0e72a752 Mon Sep 17 00:00:00 2001 From: flswld Date: Mon, 27 Mar 2023 20:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=89=A9=E4=BB=B6=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=8A=B6=E6=80=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/lua_func.go | 14 +++++- gs/game/player_scene.go | 71 +++++++++++++++++----------- gs/game/player_world.go | 12 +++++ gs/game/route_manager.go | 1 + gs/game/world_scene.go | 15 ++++++ protocol/cmd/cmd_id_proto_obj_map.go | 3 ++ 6 files changed, 87 insertions(+), 29 deletions(-) diff --git a/gs/game/lua_func.go b/gs/game/lua_func.go index 36f5cc39..40464332 100644 --- a/gs/game/lua_func.go +++ b/gs/game/lua_func.go @@ -192,6 +192,10 @@ func GetGroupMonsterCount(luaState *lua.LState) int { return 1 } group := scene.GetGroupById(uint32(groupId)) + if group == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } monsterCount := 0 for _, entity := range group.GetAllEntity() { if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { @@ -230,13 +234,19 @@ func ChangeGroupGadget(luaState *lua.LState) int { return 1 } group := scene.GetGroupById(uint32(groupId)) - logger.Debug("%v", group) + if group == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } gadgetInfo, ok := luaState.Get(2).(*lua.LTable) if !ok { luaState.Push(lua.LNumber(-1)) return 1 } - logger.Debug("%v", gadgetInfo) + gadgetStateInfo := new(gdconf.Gadget) + gdconf.ParseLuaTableToObject(gadgetInfo, gadgetStateInfo) + entity := group.GetEntityByConfigId(uint32(gadgetStateInfo.ConfigId)) + GAME_MANAGER.ChangeGadgetState(player, scene, entity.GetId(), uint32(gadgetStateInfo.State)) luaState.Push(lua.LNumber(0)) return 1 } diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 7388665b..9d37d622 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -559,35 +559,34 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui scene.DestroyEntity(entity.id) if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { - for groupId, group := range scene.GetAllGroup() { - groupConfig := gdconf.GetSceneGroup(int32(groupId)) - if groupConfig == nil { - continue - } - for suiteId := range group.GetAllSuite() { - suiteConfig := groupConfig.SuiteList[suiteId-1] - for _, triggerName := range suiteConfig.TriggerNameList { - triggerConfig := groupConfig.TriggerMap[triggerName] - if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_DIE { + groupConfig := gdconf.GetSceneGroup(int32(entity.groupId)) + if groupConfig == nil { + return + } + group := scene.GetGroupById(entity.groupId) + for suiteId := range group.GetAllSuite() { + suiteConfig := groupConfig.SuiteList[suiteId-1] + for _, triggerName := range suiteConfig.TriggerNameList { + triggerConfig := groupConfig.TriggerMap[triggerName] + if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_DIE { + continue + } + if triggerConfig.Condition != "" { + cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition, + &LuaCtx{uid: player.PlayerID, groupId: entity.groupId}, + &LuaEvt{}) + if !cond { continue } - if triggerConfig.Condition != "" { - cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition, - &LuaCtx{uid: player.PlayerID}, - &LuaEvt{targetEntityId: entityId}) - if !cond { - continue - } - } - logger.Debug("scene group trigger fire, trigger: %v, uid: %v", triggerConfig, player.PlayerID) - if triggerConfig.Action != "" { - logger.Debug("scene group trigger do action, trigger: %v, uid: %v", triggerConfig, player.PlayerID) - ok := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Action, - &LuaCtx{uid: player.PlayerID, groupId: entity.groupId}, - &LuaEvt{}) - if !ok { - logger.Error("trigger action fail, trigger: %v, uid: %v", triggerConfig, player.PlayerID) - } + } + logger.Debug("scene group trigger fire, trigger: %v, uid: %v", triggerConfig, player.PlayerID) + if triggerConfig.Action != "" { + logger.Debug("scene group trigger do action, trigger: %v, uid: %v", triggerConfig, player.PlayerID) + ok := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Action, + &LuaCtx{uid: player.PlayerID, groupId: entity.groupId}, + &LuaEvt{}) + if !ok { + logger.Error("trigger action fail, trigger: %v, uid: %v", triggerConfig, player.PlayerID) } } } @@ -595,6 +594,24 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui } } +func (g *GameManager) ChangeGadgetState(player *model.Player, scene *Scene, entityId uint32, state uint32) { + entity := scene.GetEntity(entityId) + if entity == nil { + return + } + if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + return + } + gadgetEntity := entity.GetGadgetEntity() + gadgetEntity.SetGadgetState(state) + ntf := &proto.GadgetStateNotify{ + GadgetEntityId: entity.GetId(), + GadgetState: gadgetEntity.GetGadgetState(), + IsEnableInteract: true, + } + g.SendMsg(cmd.GadgetStateNotify, player.PlayerID, player.ClientSeq, ntf) +} + func (g *GameManager) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Entity { visionEntity := make(map[uint32]*Entity) for _, entity := range scene.GetAllEntity() { diff --git a/gs/game/player_world.go b/gs/game/player_world.go index f5248296..e4cc005a 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -284,6 +284,18 @@ func (g *GameManager) PlayerQuitDungeonReq(player *model.Player, payloadMsg pb.M g.SendMsg(cmd.PlayerQuitDungeonRsp, player.PlayerID, player.ClientSeq, rsp) } +func (g *GameManager) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.GadgetInteractReq) + logger.Debug("GadgetInteractReq: %+v, uid: %v", req, player.PlayerID) + rsp := &proto.GadgetInteractRsp{ + GadgetEntityId: req.GadgetEntityId, + InteractType: 0, + OpType: req.OpType, + GadgetId: req.GadgetId, + } + g.SendMsg(cmd.GadgetInteractRsp, player.PlayerID, player.ClientSeq, rsp) +} + // TeleportPlayer 传送玩家至地图上的某个位置 func (g *GameManager) TeleportPlayer(player *model.Player, enterReason uint16, sceneId uint32, pos, rot *model.Vector, dungeonId uint32) { // 传送玩家 diff --git a/gs/game/route_manager.go b/gs/game/route_manager.go index df3cd91a..5fa4effb 100644 --- a/gs/game/route_manager.go +++ b/gs/game/route_manager.go @@ -148,6 +148,7 @@ func (r *RouteManager) initRoute() { r.registerRouter(cmd.DungeonEntryInfoReq, GAME_MANAGER.DungeonEntryInfoReq) r.registerRouter(cmd.PlayerEnterDungeonReq, GAME_MANAGER.PlayerEnterDungeonReq) r.registerRouter(cmd.PlayerQuitDungeonReq, GAME_MANAGER.PlayerQuitDungeonReq) + r.registerRouter(cmd.GadgetInteractReq, GAME_MANAGER.GadgetInteractReq) } func (r *RouteManager) RouteHandle(netMsg *mq.NetMsg) { diff --git a/gs/game/world_scene.go b/gs/game/world_scene.go index 2110b8b4..710e045c 100644 --- a/gs/game/world_scene.go +++ b/gs/game/world_scene.go @@ -508,6 +508,17 @@ func (g *Group) GetAllEntity() map[uint32]*Entity { return entityMap } +func (g *Group) GetEntityByConfigId(configId uint32) *Entity { + for _, suite := range g.suiteMap { + for _, entity := range suite.entityMap { + if entity.configId == configId { + return entity + } + } + } + return nil +} + func (s *Suite) GetEntityById(entityId uint32) *Entity { return s.entityMap[entityId] } @@ -662,6 +673,10 @@ func (g *GadgetEntity) GetGadgetState() uint32 { return g.gadgetState } +func (g *GadgetEntity) SetGadgetState(v uint32) { + g.gadgetState = v +} + func (g *GadgetEntity) GetGadgetClientEntity() *GadgetClientEntity { return g.gadgetClientEntity } diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index b0a56f70..0a709493 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -130,6 +130,9 @@ func (c *CmdProtoMap) registerAllMessage() { c.regMsg(PlayerQuitDungeonRsp, func() any { return new(proto.PlayerQuitDungeonRsp) }) // 退出地牢响应 c.regMsg(DungeonDataNotify, func() any { return new(proto.DungeonDataNotify) }) // 地牢数据通知 c.regMsg(DungeonWayPointNotify, func() any { return new(proto.DungeonWayPointNotify) }) // 地牢路点通知 + c.regMsg(GadgetInteractReq, func() any { return new(proto.GadgetInteractReq) }) // 物件交互请求 + c.regMsg(GadgetInteractRsp, func() any { return new(proto.GadgetInteractRsp) }) // 物件交互响应 + c.regMsg(GadgetStateNotify, func() any { return new(proto.GadgetStateNotify) }) // 物件状态更新通知 // 战斗与同步 c.regMsg(AvatarFightPropNotify, func() any { return new(proto.AvatarFightPropNotify) }) // 角色战斗属性通知