场景物件实体状态更新

This commit is contained in:
flswld
2023-03-27 20:58:38 +08:00
parent f4802e1448
commit ca79a5bbf0
6 changed files with 87 additions and 29 deletions

View File

@@ -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
}

View File

@@ -559,11 +559,11 @@ 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))
groupConfig := gdconf.GetSceneGroup(int32(entity.groupId))
if groupConfig == nil {
continue
return
}
group := scene.GetGroupById(entity.groupId)
for suiteId := range group.GetAllSuite() {
suiteConfig := groupConfig.SuiteList[suiteId-1]
for _, triggerName := range suiteConfig.TriggerNameList {
@@ -573,8 +573,8 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui
}
if triggerConfig.Condition != "" {
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
&LuaCtx{uid: player.PlayerID},
&LuaEvt{targetEntityId: entityId})
&LuaCtx{uid: player.PlayerID, groupId: entity.groupId},
&LuaEvt{})
if !cond {
continue
}
@@ -592,7 +592,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 {

View File

@@ -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) {
// 传送玩家

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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) }) // 角色战斗属性通知