diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 88a18d66..b867eef2 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -556,8 +556,14 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui g.SendToWorldA(scene.world, cmd.LifeStateChangeNotify, 0, ntf) g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.id}) // 删除实体 - scene.DestroyEntity(entity.id) - + group := scene.GetGroupById(entity.groupId) + if group == nil { + logger.Error("get scene group is nil, groupId: %v, uid: %v", entity.groupId, player.PlayerID) + return + } + group.DestroyEntity(entity.GetId()) + scene.DestroyEntity(entity.GetId()) + // 怪物死亡触发器 if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { if entity.groupId == 133003095 { logger.Debug("==========1==========") @@ -567,11 +573,6 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui logger.Error("get group config is nil, groupId: %v, uid: %v", entity.groupId, player.PlayerID) return } - group := scene.GetGroupById(entity.groupId) - if group == nil { - logger.Error("get scene group is nil, groupId: %v, uid: %v", entity.groupId, player.PlayerID) - return - } for suiteId := range group.GetAllSuite() { if entity.groupId == 133003095 { logger.Debug("==========2==========") diff --git a/gs/game/world_scene.go b/gs/game/world_scene.go index ca50a536..5a9204de 100644 --- a/gs/game/world_scene.go +++ b/gs/game/world_scene.go @@ -519,6 +519,17 @@ func (g *Group) GetEntityByConfigId(configId uint32) *Entity { return nil } +func (g *Group) DestroyEntity(entityId uint32) { + for _, suite := range g.suiteMap { + for _, entity := range suite.entityMap { + if entity.id == entityId { + delete(suite.entityMap, entity.id) + return + } + } + } +} + func (s *Suite) GetEntityById(entityId uint32) *Entity { return s.entityMap[entityId] }