mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
场景物件实体状态更新
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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) {
|
||||
// 传送玩家
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) }) // 角色战斗属性通知
|
||||
|
||||
Reference in New Issue
Block a user