完善场景物件交互协议

This commit is contained in:
flswld
2023-03-28 15:59:53 +08:00
parent e71d581e8b
commit ddf8700c33
8 changed files with 215 additions and 34 deletions

View File

@@ -72,7 +72,7 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
TICK_MANAGER = NewTickManager()
COMMAND_MANAGER = NewCommandManager()
GCG_MANAGER = NewGCGManager()
RegLuaLibFunc()
RegLuaScriptLibFunc()
// 创建本服的Ai世界
uid := AiBaseUid + gsId
name := AiName

View File

@@ -33,6 +33,7 @@ type LuaEvt struct {
targetEntityId uint32
}
// CallLuaFunc 调用LUA方法
func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEvt *LuaEvt) bool {
ctx := luaState.NewTable()
luaState.SetField(ctx, "uid", lua.LNumber(luaCtx.uid))
@@ -72,7 +73,36 @@ func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEv
}
}
func RegLuaLibFunc() {
// GetContextPlayer 获取上下文中的玩家对象
func GetContextPlayer(ctx *lua.LTable, luaState *lua.LState) *model.Player {
uid, ok := luaState.GetField(ctx, "uid").(lua.LNumber)
if !ok {
return nil
}
player := USER_MANAGER.GetOnlineUser(uint32(uid))
return player
}
// GetContextGroup 获取上下文中的场景组对象
func GetContextGroup(player *model.Player, ctx *lua.LTable, luaState *lua.LState) *Group {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
return nil
}
groupId, ok := luaState.GetField(ctx, "groupId").(lua.LNumber)
if !ok {
return nil
}
scene := world.GetSceneById(player.SceneId)
group := scene.GetGroupById(uint32(groupId))
if group == nil {
return nil
}
return group
}
// RegLuaScriptLibFunc 注册LUA侧ScriptLib调用的Golang方法
func RegLuaScriptLibFunc() {
gdconf.RegScriptLibFunc("GetEntityType", GetEntityType)
gdconf.RegScriptLibFunc("GetQuestState", GetQuestState)
gdconf.RegScriptLibFunc("PrintLog", PrintLog)
@@ -130,7 +160,7 @@ func PrintContextLog(luaState *lua.LState) int {
return 0
}
logInfo := luaState.ToString(2)
logger.Info("[LUA CTX LOG] %v [UID %v]", logInfo, uid)
logger.Info("[LUA CTX LOG] %v [UID: %v]", logInfo, uid)
return 0
}
@@ -250,33 +280,7 @@ func MarkPlayerAction(luaState *lua.LState) int {
param1 := luaState.ToInt(2)
param2 := luaState.ToInt(3)
param3 := luaState.ToInt(4)
logger.Debug("[MarkPlayerAction] [%v %v %v] uid: %v", param1, param2, param3, player.PlayerID)
logger.Debug("[MarkPlayerAction] [%v %v %v] [UID: %v]", param1, param2, param3, player.PlayerID)
luaState.Push(lua.LNumber(0))
return 1
}
func GetContextPlayer(ctx *lua.LTable, luaState *lua.LState) *model.Player {
uid, ok := luaState.GetField(ctx, "uid").(lua.LNumber)
if !ok {
return nil
}
player := USER_MANAGER.GetOnlineUser(uint32(uid))
return player
}
func GetContextGroup(player *model.Player, ctx *lua.LTable, luaState *lua.LState) *Group {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
return nil
}
groupId, ok := luaState.GetField(ctx, "groupId").(lua.LNumber)
if !ok {
return nil
}
scene := world.GetSceneById(player.SceneId)
group := scene.GetGroupById(uint32(groupId))
if group == nil {
return nil
}
return group
}

View File

@@ -286,12 +286,68 @@ func (g *GameManager) PlayerQuitDungeonReq(player *model.Player, payloadMsg pb.M
func (g *GameManager) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.GadgetInteractReq)
logger.Debug("GadgetInteractReq: %+v, uid: %v", req, player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
scene := world.GetSceneById(player.SceneId)
entity := scene.GetEntity(req.GadgetEntityId)
if entity == nil {
logger.Error("get entity is nil, entityId: %v, uid: %v", req.GadgetEntityId, player.PlayerID)
return
}
if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET {
logger.Error("entity type is not gadget, entityType: %v, uid: %v", entity.GetEntityType(), player.PlayerID)
return
}
gadgetEntity := entity.GetGadgetEntity()
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId()))
if gadgetDataConfig == nil {
logger.Error("get gadget data config is nil, gadgetId: %v, uid: %v", gadgetEntity.GetGadgetId(), player.PlayerID)
return
}
if gadgetDataConfig.CanInteract == 0 {
logger.Error("gadget can not be interact, gadgetId: %v, uid: %v", gadgetEntity.GetGadgetId(), player.PlayerID)
return
}
interactType := proto.InteractType_INTERACT_NONE
switch gadgetDataConfig.Type {
case constant.GADGET_TYPE_GADGET:
logger.Debug("==========GADGET_TYPE_GADGET==========")
// 掉落物捡起
interactType = proto.InteractType_INTERACT_PICK_ITEM
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
case constant.GADGET_TYPE_ENERGY_BALL:
logger.Debug("==========GADGET_TYPE_ENERGY_BALL==========")
// 元素能量球吸收
interactType = proto.InteractType_INTERACT_PICK_ITEM
case constant.GADGET_TYPE_GATHER_OBJECT:
logger.Debug("==========GADGET_TYPE_GATHER_OBJECT==========")
// 采集物摘取
interactType = proto.InteractType_INTERACT_GATHER
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
case constant.GADGET_TYPE_CHEST:
logger.Debug("==========GADGET_TYPE_CHEST==========")
// 宝箱开启
interactType = proto.InteractType_INTERACT_OPEN_CHEST
if req.OpType == proto.InterOpType_INTER_OP_FINISH {
// 宝箱交互结束 开启宝箱
g.SendMsg(cmd.WorldChestOpenNotify, player.PlayerID, player.ClientSeq, &proto.WorldChestOpenNotify{
GroupId: entity.GetGroupId(),
SceneId: scene.GetId(),
ConfigId: entity.GetConfigId(),
})
g.ChangeGadgetState(player, scene.GetId(), constant.GADGET_STATE_CHEST_OPENED)
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
}
}
rsp := &proto.GadgetInteractRsp{
GadgetEntityId: req.GadgetEntityId,
InteractType: 0,
OpType: req.OpType,
GadgetId: req.GadgetId,
OpType: req.OpType,
InteractType: interactType,
}
g.SendMsg(cmd.GadgetInteractRsp, player.PlayerID, player.ClientSeq, rsp)
}

View File

@@ -429,7 +429,7 @@ func (s *Scene) createConfigEntity(groupId uint32, entityConfig any) uint32 {
}, uint32(npc.NpcId), 0, 0, 0, uint32(npc.ConfigId), groupId)
case *gdconf.Gadget:
gadget := entityConfig.(*gdconf.Gadget)
// 70500000并不是实际的装置id 根据节点类型对应采集物配置表
// 70500000并不是实际的物件id 根据节点类型对应采集物配置表
if gadget.PointType != 0 && gadget.GadgetId == 70500000 {
gatherDataConfig := gdconf.GetGatherDataByPointType(gadget.PointType)
if gatherDataConfig == nil {