From fa4f53bf7a458f7e029a88b3d6920bf603cdff4e Mon Sep 17 00:00:00 2001 From: flswld Date: Fri, 24 May 2024 16:38:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=AE=9E=E4=BD=93=E9=9D=A2?= =?UTF-8?q?=E5=90=91=E5=AF=B9=E8=B1=A1=E7=BB=A7=E6=89=BF=E5=A4=9A=E6=80=81?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/audio_video.go | 4 +- gs/game/game_command_gm.go | 8 +- gs/game/game_physics_engine.go | 16 +- gs/game/game_plugin_pubg.go | 56 ++-- gs/game/game_world_manager.go | 4 +- gs/game/game_world_scene.go | 523 ++++++++++++++++----------------- gs/game/lua_func.go | 24 +- gs/game/player_avatar.go | 2 +- gs/game/player_common.go | 13 +- gs/game/player_fight_sync.go | 73 ++--- gs/game/player_scene.go | 127 ++++---- gs/game/player_stamina.go | 46 +-- gs/game/player_team.go | 6 +- gs/game/player_vehicle.go | 66 +++-- gs/game/player_world.go | 21 +- 15 files changed, 506 insertions(+), 483 deletions(-) diff --git a/gs/game/audio_video.go b/gs/game/audio_video.go index 61861de8..c7d27d27 100644 --- a/gs/game/audio_video.go +++ b/gs/game/audio_video.go @@ -318,7 +318,7 @@ func UpdateFrame(fileData []byte, basePos *model.Vector, rgb bool) { Z: leftTopPos.Z, }, new(model.Vector), uint32(FRAME_COLOR[w][h]), uint32(constant.GADGET_STATE_DEFAULT), - new(GadgetNormalEntity), 0, 0, constant.VISION_LEVEL_SUPER) + false, 0, 0, 0, 0, constant.VISION_LEVEL_SUPER) SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, entityId) } else { if !FRAME[w][h] { @@ -329,7 +329,7 @@ func UpdateFrame(fileData []byte, basePos *model.Vector, rgb bool) { Z: leftTopPos.Z, }, new(model.Vector), uint32(GADGET_ID), uint32(constant.GADGET_STATE_DEFAULT), - new(GadgetNormalEntity), 0, 0, constant.VISION_LEVEL_SUPER) + false, 0, 0, 0, 0, constant.VISION_LEVEL_SUPER) SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, entityId) } } diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index 2bf9dff5..ab9a54ae 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -191,7 +191,8 @@ func (g *GMCmd) GMKillMonster(userId uint32, entityId uint32) { return } // 确保为怪物 - if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER { + _, ok := entity.(*MonsterEntity) + if !ok { return } // 杀死怪物 @@ -218,7 +219,8 @@ func (g *GMCmd) GMKillAllMonster(userId uint32) { // 杀死视野内所有怪物实体 for _, entity := range GAME.GetVisionEntity(scene, GAME.GetPlayerPos(player)) { // 确保为怪物 - if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER { + _, ok := entity.(*MonsterEntity) + if !ok { continue } // 杀死怪物 @@ -413,7 +415,7 @@ func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32, count uint32) { return } for i := 0; i < int(count); i++ { - GAME.CreateGadget(player, nil, gadgetId, nil) + GAME.CreateGadget(player, nil, gadgetId, false, 0, 0) } } diff --git a/gs/game/game_physics_engine.go b/gs/game/game_physics_engine.go index 258acbd9..811b53e5 100644 --- a/gs/game/game_physics_engine.go +++ b/gs/game/game_physics_engine.go @@ -65,13 +65,13 @@ func (p *PhysicsEngine) ShowAvatarCollider() { entity := p.world.GetPlayerActiveAvatarEntity(player) avatarPos := entity.GetPos() avatarPos.Y += float64(p.avatarYOffset) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y + AVATAR_HEIGHT/2.0, Z: avatarPos.Z}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y - AVATAR_HEIGHT/2.0, Z: avatarPos.Z}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X + AVATAR_RADIUS, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X - AVATAR_RADIUS, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z + AVATAR_RADIUS}, GADGET_GREEN, nil) - GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z - AVATAR_RADIUS}, GADGET_GREEN, nil) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y + AVATAR_HEIGHT/2.0, Z: avatarPos.Z}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y - AVATAR_HEIGHT/2.0, Z: avatarPos.Z}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X + AVATAR_RADIUS, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X - AVATAR_RADIUS, Y: avatarPos.Y, Z: avatarPos.Z}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z + AVATAR_RADIUS}, GADGET_GREEN, false, 0, 0) + GAME.CreateGadget(p.world.GetOwner(), &model.Vector{X: avatarPos.X, Y: avatarPos.Y, Z: avatarPos.Z - AVATAR_RADIUS}, GADGET_GREEN, false, 0, 0) } } } @@ -124,7 +124,7 @@ func (p *PhysicsEngine) Update(now int64) []*RigidBody { X: float64(rigidBody.position.X), Y: float64(rigidBody.position.Y), Z: float64(rigidBody.position.Z), - }, GADGET_RED, nil) + }, GADGET_RED, false, 0, 0) } } p.lastUpdateTime = now diff --git a/gs/game/game_plugin_pubg.go b/gs/game/game_plugin_pubg.go index bd22f924..227c1cbb 100644 --- a/gs/game/game_plugin_pubg.go +++ b/gs/game/game_plugin_pubg.go @@ -227,7 +227,11 @@ func (p *PluginPubg) EventEvtDoSkillSucc(iEvent IPluginEvent) { scene := world.GetSceneById(player.GetSceneId()) avatarEntity := scene.GetEntity(worldAvatar.GetAvatarEntityId()) for _, entity := range scene.GetAllEntity() { - if entity.GetId() == avatarEntity.GetId() || entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + if entity.GetId() == avatarEntity.GetId() { + continue + } + _, ok := entity.(*AvatarEntity) + if !ok { continue } distance3D := math.Sqrt( @@ -267,7 +271,8 @@ func (p *PluginPubg) EventEvtBeingHit(iEvent IPluginEvent) { if defEntity == nil { return } - if defEntity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + defAvatarEntity, ok := defEntity.(*AvatarEntity) + if !ok { return } fightProp := defEntity.GetFightProp() @@ -275,20 +280,25 @@ func (p *PluginPubg) EventEvtBeingHit(iEvent IPluginEvent) { if currHp-attackResult.Damage > 0.0 { return } - defPlayer := USER_MANAGER.GetOnlineUser(defEntity.GetAvatarEntity().GetUid()) + defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetUid()) if defPlayer == nil { return } atkEntity := scene.GetEntity(attackResult.AttackerId) - if atkEntity != nil && atkEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { - atkPlayer := USER_MANAGER.GetOnlineUser(atkEntity.GetAvatarEntity().GetUid()) - if atkPlayer == nil { - return - } - info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName) - GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) - p.CreateUserTimer(defPlayer.PlayerId, 10, p.UserTimerPubgDieExit, p.world.GetId()) + if atkEntity == nil { + return } + atkAvatarEntity, ok := atkEntity.(*AvatarEntity) + if !ok { + return + } + atkPlayer := USER_MANAGER.GetOnlineUser(atkAvatarEntity.GetUid()) + if atkPlayer == nil { + return + } + info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName) + GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) + p.CreateUserTimer(defPlayer.PlayerId, 10, p.UserTimerPubgDieExit, p.world.GetId()) } // EvtCreateGadget 创建物件实体事件 @@ -518,7 +528,7 @@ func (p *PluginPubg) StartPubg() { p.world.GetOwner(), &model.Vector{X: float64(pubgWorldGadgetDataConfig.X), Y: float64(pubgWorldGadgetDataConfig.Y), Z: float64(pubgWorldGadgetDataConfig.Z)}, uint32(pubgWorldGadgetDataConfig.GadgetId), - nil, + false, 0, 0, ) p.entityIdWorldGadgetIdMap[entityId] = pubgWorldGadgetDataConfig.WorldGadgetId } @@ -697,19 +707,19 @@ func (p *PluginPubg) GetAlivePlayerList() []*model.Player { } func (p *PluginPubg) PubgHit(scene *Scene, defAvatarEntityId uint32, atkAvatarEntityId uint32, isBow bool) { - defAvatarEntity := scene.GetEntity(defAvatarEntityId) - if defAvatarEntity == nil { + defEntity := scene.GetEntity(defAvatarEntityId) + if defEntity == nil { return } - defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) + defPlayer := USER_MANAGER.GetOnlineUser(defEntity.(*AvatarEntity).GetUid()) if defPlayer == nil { return } - atkAvatarEntity := scene.GetEntity(atkAvatarEntityId) - if atkAvatarEntity == nil { + atkEntity := scene.GetEntity(atkAvatarEntityId) + if atkEntity == nil { return } - atkPlayer := USER_MANAGER.GetOnlineUser(atkAvatarEntity.GetAvatarEntity().GetUid()) + atkPlayer := USER_MANAGER.GetOnlineUser(atkEntity.(*AvatarEntity).GetUid()) if atkPlayer == nil { return } @@ -719,7 +729,7 @@ func (p *PluginPubg) PubgHit(scene *Scene, defAvatarEntityId uint32, atkAvatarEn return } p.playerHitTimeMap[atkPlayer.PlayerId] = now - atk := atkAvatarEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK] + atk := atkEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK] dmg := float32(0.0) if isBow { dmg = atk / PUBG_BOW_ATTACK_ATK_RATIO @@ -728,8 +738,8 @@ func (p *PluginPubg) PubgHit(scene *Scene, defAvatarEntityId uint32, atkAvatarEn } GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ AttackResult: &proto.AttackResult{ - AttackerId: atkAvatarEntity.GetId(), - DefenseId: defAvatarEntity.GetId(), + AttackerId: atkEntity.GetId(), + DefenseId: defEntity.GetId(), Damage: dmg, DamageShield: dmg, }, @@ -742,8 +752,8 @@ func (p *PluginPubg) PubgHit(scene *Scene, defAvatarEntityId uint32, atkAvatarEn AttackResult: attackResultTemplate, FrameNum: 0, } - evtBeingHitInfo.AttackResult.AttackerId = atkAvatarEntity.GetId() - evtBeingHitInfo.AttackResult.DefenseId = defAvatarEntity.GetId() + evtBeingHitInfo.AttackResult.AttackerId = atkEntity.GetId() + evtBeingHitInfo.AttackResult.DefenseId = defEntity.GetId() evtBeingHitInfo.AttackResult.Damage = dmg if evtBeingHitInfo.AttackResult.HitCollision == nil { return diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index e725698e..35dc507c 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -586,7 +586,7 @@ func (w *World) GetPlayerAvatarIndexByAvatarId(player *model.Player, avatarId ui } // GetPlayerActiveAvatarEntity 获取玩家当前活跃角色场景实体 -func (w *World) GetPlayerActiveAvatarEntity(player *model.Player) *Entity { +func (w *World) GetPlayerActiveAvatarEntity(player *model.Player) IEntity { activeAvatarId := w.GetPlayerActiveAvatarId(player) avatarEntityId := w.GetPlayerWorldAvatarEntityId(player, activeAvatarId) scene := w.GetSceneById(player.GetSceneId()) @@ -872,7 +872,7 @@ func (w *World) CreateScene(sceneId uint32) *Scene { id: sceneId, world: w, playerMap: make(map[uint32]*model.Player), - entityMap: make(map[uint32]*Entity), + entityMap: make(map[uint32]IEntity), groupMap: make(map[uint32]*Group), createTime: time.Now().UnixMilli(), meeoIndex: 0, diff --git a/gs/game/game_world_scene.go b/gs/game/game_world_scene.go index 2a740306..c27af418 100644 --- a/gs/game/game_world_scene.go +++ b/gs/game/game_world_scene.go @@ -17,7 +17,7 @@ type Scene struct { id uint32 world *World playerMap map[uint32]*model.Player - entityMap map[uint32]*Entity // 场景中全部的实体 + entityMap map[uint32]IEntity // 场景中全部的实体 groupMap map[uint32]*Group // 场景中按group->suite分类的实体 createTime int64 // 场景创建时间 meeoIndex uint32 // 客户端风元素染色同步协议的计数器 @@ -36,7 +36,7 @@ func (s *Scene) GetAllPlayer() map[uint32]*model.Player { return s.playerMap } -func (s *Scene) GetAllEntity() map[uint32]*Entity { +func (s *Scene) GetAllEntity() map[uint32]IEntity { return s.entityMap } @@ -98,44 +98,46 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 logger.Error("get avatar is nil, avatarId: %v", avatar) return 0 } - entity := &Entity{ - id: entityId, - scene: s, - lifeState: avatar.LifeState, - pos: player.GetPos(), - rot: player.GetRot(), - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: avatar.FightPropMap, // 使用角色结构的数据 - entityType: constant.ENTITY_TYPE_AVATAR, - avatarEntity: &AvatarEntity{ - uid: player.PlayerId, - avatarId: avatarId, + entity := &AvatarEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: avatar.LifeState, + pos: player.GetPos(), + rot: player.GetRot(), + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: avatar.FightPropMap, // 使用角色结构的数据 + entityType: constant.ENTITY_TYPE_AVATAR, + visionLevel: constant.VISION_LEVEL_NORMAL, }, - visionLevel: constant.VISION_LEVEL_NORMAL, + uid: player.PlayerId, + avatarId: avatarId, } return s.CreateEntity(entity) } func (s *Scene) CreateEntityWeapon(pos, rot *model.Vector) uint32 { entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_WEAPON) - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: map[uint32]float32{ - constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, - constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, - constant.FIGHT_PROP_BASE_HP: float32(1), + entity := &WeaponEntity{ + &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: map[uint32]float32{ + constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, + constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, + constant.FIGHT_PROP_BASE_HP: float32(1), + }, + entityType: constant.ENTITY_TYPE_WEAPON, + visionLevel: constant.VISION_LEVEL_NORMAL, }, - entityType: constant.ENTITY_TYPE_WEAPON, - visionLevel: constant.VISION_LEVEL_NORMAL, } return s.CreateEntity(entity) } @@ -147,116 +149,118 @@ func (s *Scene) CreateEntityMonster(pos, rot *model.Vector, monsterId uint32, le fightPropMap[constant.FIGHT_PROP_MAX_HP] = fightPropMap[constant.FIGHT_PROP_BASE_HP] fightPropMap[constant.FIGHT_PROP_CUR_HP] = fightPropMap[constant.FIGHT_PROP_MAX_HP] entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_MONSTER) - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: fightPropMap, - entityType: constant.ENTITY_TYPE_MONSTER, - level: level, - monsterEntity: &MonsterEntity{ - monsterId: monsterId, + entity := &MonsterEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: fightPropMap, + level: level, + entityType: constant.ENTITY_TYPE_MONSTER, + configId: configId, + groupId: groupId, + visionLevel: visionLevel, }, - configId: configId, - groupId: groupId, - visionLevel: visionLevel, + monsterId: monsterId, } return s.CreateEntity(entity) } func (s *Scene) CreateEntityNpc(pos, rot *model.Vector, npcId, roomId, parentQuestId, blockId, configId, groupId uint32) uint32 { entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_NPC) - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: map[uint32]float32{ - constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, - constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, - constant.FIGHT_PROP_BASE_HP: float32(1), + entity := &NpcEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: map[uint32]float32{ + constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, + constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, + constant.FIGHT_PROP_BASE_HP: float32(1), + }, + entityType: constant.ENTITY_TYPE_NPC, + configId: configId, + groupId: groupId, + visionLevel: constant.VISION_LEVEL_NORMAL, }, - entityType: constant.ENTITY_TYPE_NPC, - npcEntity: &NpcEntity{ - npcId: npcId, - roomId: roomId, - parentQuestId: parentQuestId, - blockId: blockId, - }, - configId: configId, - groupId: groupId, - visionLevel: constant.VISION_LEVEL_NORMAL, + npcId: npcId, + roomId: roomId, + parentQuestId: parentQuestId, + blockId: blockId, } return s.CreateEntity(entity) } -func (s *Scene) CreateEntityGadgetNormal(pos, rot *model.Vector, gadgetId, gadgetState uint32, gadgetNormalEntity *GadgetNormalEntity, configId, groupId uint32, visionLevel int) uint32 { +func (s *Scene) CreateEntityGadgetNormal(pos, rot *model.Vector, gadgetId, gadgetState uint32, isDrop bool, itemId, count uint32, configId, groupId uint32, visionLevel int) uint32 { entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_GADGET) - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: map[uint32]float32{ - constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, - constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, - constant.FIGHT_PROP_BASE_HP: float32(1), + entity := &GadgetNormalEntity{ + GadgetEntity: &GadgetEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: map[uint32]float32{ + constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, + constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, + constant.FIGHT_PROP_BASE_HP: float32(1), + }, + entityType: constant.ENTITY_TYPE_GADGET, + configId: configId, + groupId: groupId, + visionLevel: visionLevel, + }, + gadgetId: gadgetId, + gadgetState: gadgetState, }, - entityType: constant.ENTITY_TYPE_GADGET, - gadgetEntity: &GadgetEntity{ - gadgetId: gadgetId, - gadgetState: gadgetState, - gadgetType: GADGET_TYPE_NORMAL, - gadgetNormalEntity: gadgetNormalEntity, - }, - configId: configId, - groupId: groupId, - visionLevel: visionLevel, + isDrop: isDrop, + itemId: itemId, + count: count, } return s.CreateEntity(entity) } func (s *Scene) CreateEntityGadgetClient(pos, rot *model.Vector, entityId, configId, campId, campType, ownerEntityId, targetEntityId, propOwnerEntityId uint32) bool { - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: map[uint32]float32{ - constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, - constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, - constant.FIGHT_PROP_BASE_HP: float32(1), - }, - entityType: constant.ENTITY_TYPE_GADGET, - gadgetEntity: &GadgetEntity{ - gadgetType: GADGET_TYPE_CLIENT, - gadgetClientEntity: &GadgetClientEntity{ - configId: configId, - campId: campId, - campType: campType, - ownerEntityId: ownerEntityId, - targetEntityId: targetEntityId, - propOwnerEntityId: propOwnerEntityId, + entity := &GadgetClientEntity{ + GadgetEntity: &GadgetEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: map[uint32]float32{ + constant.FIGHT_PROP_CUR_HP: math.MaxFloat32, + constant.FIGHT_PROP_MAX_HP: math.MaxFloat32, + constant.FIGHT_PROP_BASE_HP: float32(1), + }, + entityType: constant.ENTITY_TYPE_GADGET, + visionLevel: constant.VISION_LEVEL_NORMAL, + configId: configId, }, }, - visionLevel: constant.VISION_LEVEL_NORMAL, + campId: campId, + campType: campType, + ownerEntityId: ownerEntityId, + targetEntityId: targetEntityId, + propOwnerEntityId: propOwnerEntityId, } if s.CreateEntity(entity) == 0 { return false @@ -272,46 +276,45 @@ func (s *Scene) CreateEntityGadgetVehicle(ownerUid uint32, pos, rot *model.Vecto return 0 } entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_GADGET) - entity := &Entity{ - id: entityId, - scene: s, - lifeState: constant.LIFE_STATE_ALIVE, - pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, - moveState: uint16(proto.MotionState_MOTION_NONE), - lastMoveSceneTimeMs: 0, - lastMoveReliableSeq: 0, - fightProp: map[uint32]float32{ - constant.FIGHT_PROP_BASE_DEFENSE: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.DefenseBase, - constant.FIGHT_PROP_CUR_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP, - constant.FIGHT_PROP_MAX_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP, - constant.FIGHT_PROP_CUR_ATTACK: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.Attack, - }, - entityType: constant.ENTITY_TYPE_GADGET, - gadgetEntity: &GadgetEntity{ - gadgetType: GADGET_TYPE_VEHICLE, - gadgetVehicleEntity: &GadgetVehicleEntity{ - vehicleId: vehicleId, - worldId: s.world.id, - ownerUid: ownerUid, - maxStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit, - curStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit, - restoreDelay: 0, - memberMap: make(map[uint32]*model.Player), + entity := &GadgetVehicleEntity{ + GadgetEntity: &GadgetEntity{ + Entity: &Entity{ + id: entityId, + scene: s, + lifeState: constant.LIFE_STATE_ALIVE, + pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, + rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z}, + moveState: uint16(proto.MotionState_MOTION_NONE), + lastMoveSceneTimeMs: 0, + lastMoveReliableSeq: 0, + fightProp: map[uint32]float32{ + constant.FIGHT_PROP_BASE_DEFENSE: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.DefenseBase, + constant.FIGHT_PROP_CUR_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP, + constant.FIGHT_PROP_MAX_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP, + constant.FIGHT_PROP_CUR_ATTACK: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.Attack, + }, + entityType: constant.ENTITY_TYPE_GADGET, + visionLevel: constant.VISION_LEVEL_NORMAL, }, }, - visionLevel: constant.VISION_LEVEL_NORMAL, + vehicleId: vehicleId, + worldId: s.world.id, + ownerUid: ownerUid, + maxStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit, + curStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit, + restoreDelay: 0, + memberMap: make(map[uint32]uint32), } return s.CreateEntity(entity) } -func (s *Scene) CreateEntity(entity *Entity) uint32 { +func (s *Scene) CreateEntity(entity IEntity) uint32 { if len(s.entityMap) >= ENTITY_MAX_SEND_NUM && !ENTITY_NUM_UNLIMIT { - logger.Error("above max scene entity num limit: %v, id: %v, pos: %v", ENTITY_MAX_SEND_NUM, entity.id, entity.pos) + logger.Error("above max scene entity num limit: %v, id: %v, pos: %v", ENTITY_MAX_SEND_NUM, entity.GetId(), entity.GetPos()) return 0 } - s.entityMap[entity.id] = entity - return entity.id + s.entityMap[entity.GetId()] = entity + return entity.GetId() } func (s *Scene) DestroyEntity(entityId uint32) { @@ -319,14 +322,14 @@ func (s *Scene) DestroyEntity(entityId uint32) { if entity == nil { return } - delete(s.entityMap, entity.id) + delete(s.entityMap, entity.GetId()) } -func (s *Scene) GetEntity(entityId uint32) *Entity { +func (s *Scene) GetEntity(entityId uint32) IEntity { return s.entityMap[entityId] } -func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8, entityMap map[uint32]*Entity) { +func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8, entityMap map[uint32]IEntity) { group, exist := s.groupMap[groupId] if !exist { group = &Group{ @@ -339,7 +342,7 @@ func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8, entityMap map[uint3 if !exist { suite = &Suite{ id: suiteId, - entityMap: make(map[uint32]*Entity), + entityMap: make(map[uint32]IEntity), } group.suiteMap[suiteId] = suite } @@ -360,7 +363,7 @@ func (s *Scene) RemoveGroupSuite(groupId uint32, suiteId uint8) { return } for _, entity := range suite.entityMap { - s.DestroyEntity(entity.id) + s.DestroyEntity(entity.GetId()) } delete(group.suiteMap, suiteId) if len(group.suiteMap) == 0 { @@ -375,7 +378,7 @@ type Group struct { type Suite struct { id uint8 - entityMap map[uint32]*Entity + entityMap map[uint32]IEntity } func (g *Group) GetId() uint32 { @@ -390,20 +393,20 @@ func (g *Group) GetAllSuite() map[uint8]*Suite { return g.suiteMap } -func (g *Group) GetAllEntity() map[uint32]*Entity { - entityMap := make(map[uint32]*Entity) +func (g *Group) GetAllEntity() map[uint32]IEntity { + entityMap := make(map[uint32]IEntity) for _, suite := range g.suiteMap { for _, entity := range suite.entityMap { - entityMap[entity.id] = entity + entityMap[entity.GetId()] = entity } } return entityMap } -func (g *Group) GetEntityByConfigId(configId uint32) *Entity { +func (g *Group) GetEntityByConfigId(configId uint32) IEntity { for _, suite := range g.suiteMap { for _, entity := range suite.entityMap { - if entity.configId == configId { + if entity.GetConfigId() == configId { return entity } } @@ -414,8 +417,8 @@ func (g *Group) GetEntityByConfigId(configId uint32) *Entity { 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) + if entity.GetId() == entityId { + delete(suite.entityMap, entity.GetId()) return } } @@ -426,14 +429,42 @@ func (s *Suite) GetId() uint8 { return s.id } -func (s *Suite) GetEntityById(entityId uint32) *Entity { +func (s *Suite) GetEntityById(entityId uint32) IEntity { return s.entityMap[entityId] } -func (s *Suite) GetAllEntity() map[uint32]*Entity { +func (s *Suite) GetAllEntity() map[uint32]IEntity { return s.entityMap } +// IEntity 场景实体抽象接口 +type IEntity interface { + IsEntity() + GetId() uint32 + GetScene() *Scene + GetLifeState() uint16 + GetLastDieType() int32 + GetPos() *model.Vector + GetRot() *model.Vector + GetMoveState() uint16 + GetLastMoveSceneTimeMs() uint32 + GetLastMoveReliableSeq() uint32 + GetFightProp() map[uint32]float32 + GetLevel() uint8 + GetEntityType() uint8 + GetConfigId() uint32 + GetGroupId() uint32 + GetVisionLevel() int + SetLifeState(lifeState uint16) + SetLastDieType(lastDieType int32) + SetPos(pos *model.Vector) + SetRot(rot *model.Vector) + SetMoveState(moveState uint16) + SetLastMoveSceneTimeMs(lastMoveSceneTimeMs uint32) + SetLastMoveReliableSeq(lastMoveReliableSeq uint32) + SetFightProp(fightProp map[uint32]float32) +} + // Entity 场景实体数据结构 type Entity struct { id uint32 // 实体id @@ -448,14 +479,12 @@ type Entity struct { fightProp map[uint32]float32 // 战斗属性 level uint8 // 等级 entityType uint8 // 实体类型 - // TODO 这堆东西变得有点答辩了 我觉得之后需要重构 做面向对象继承多态接口的设计 - avatarEntity *AvatarEntity - monsterEntity *MonsterEntity - npcEntity *NpcEntity - gadgetEntity *GadgetEntity - configId uint32 // LUA配置相关 - groupId uint32 - visionLevel int + configId uint32 // LUA配置相关 + groupId uint32 + visionLevel int +} + +func (e *Entity) IsEntity() { } func (e *Entity) GetId() uint32 { @@ -470,66 +499,34 @@ func (e *Entity) GetLifeState() uint16 { return e.lifeState } -func (e *Entity) SetLifeState(lifeState uint16) { - e.lifeState = lifeState -} - func (e *Entity) GetLastDieType() int32 { return e.lastDieType } -func (e *Entity) SetLastDieType(lastDieType int32) { - e.lastDieType = lastDieType -} - func (e *Entity) GetPos() *model.Vector { return &model.Vector{X: e.pos.X, Y: e.pos.Y, Z: e.pos.Z} } -func (e *Entity) SetPos(pos *model.Vector) { - e.pos.X, e.pos.Y, e.pos.Z = pos.X, pos.Y, pos.Z -} - func (e *Entity) GetRot() *model.Vector { return &model.Vector{X: e.rot.X, Y: e.rot.Y, Z: e.rot.Z} } -func (e *Entity) SetRot(rot *model.Vector) { - e.rot.X, e.rot.Y, e.rot.Z = rot.X, rot.Y, rot.Z -} - func (e *Entity) GetMoveState() uint16 { return e.moveState } -func (e *Entity) SetMoveState(moveState uint16) { - e.moveState = moveState -} - func (e *Entity) GetLastMoveSceneTimeMs() uint32 { return e.lastMoveSceneTimeMs } -func (e *Entity) SetLastMoveSceneTimeMs(lastMoveSceneTimeMs uint32) { - e.lastMoveSceneTimeMs = lastMoveSceneTimeMs -} - func (e *Entity) GetLastMoveReliableSeq() uint32 { return e.lastMoveReliableSeq } -func (e *Entity) SetLastMoveReliableSeq(lastMoveReliableSeq uint32) { - e.lastMoveReliableSeq = lastMoveReliableSeq -} - func (e *Entity) GetFightProp() map[uint32]float32 { return e.fightProp } -func (e *Entity) SetFightProp(fightProp map[uint32]float32) { - e.fightProp = fightProp -} - func (e *Entity) GetLevel() uint8 { return e.level } @@ -538,22 +535,6 @@ func (e *Entity) GetEntityType() uint8 { return e.entityType } -func (e *Entity) GetAvatarEntity() *AvatarEntity { - return e.avatarEntity -} - -func (e *Entity) GetMonsterEntity() *MonsterEntity { - return e.monsterEntity -} - -func (e *Entity) GetNpcEntity() *NpcEntity { - return e.npcEntity -} - -func (e *Entity) GetGadgetEntity() *GadgetEntity { - return e.gadgetEntity -} - func (e *Entity) GetConfigId() uint32 { return e.configId } @@ -566,7 +547,40 @@ func (e *Entity) GetVisionLevel() int { return e.visionLevel } +func (e *Entity) SetLifeState(lifeState uint16) { + e.lifeState = lifeState +} + +func (e *Entity) SetLastDieType(lastDieType int32) { + e.lastDieType = lastDieType +} + +func (e *Entity) SetPos(pos *model.Vector) { + e.pos.X, e.pos.Y, e.pos.Z = pos.X, pos.Y, pos.Z +} + +func (e *Entity) SetRot(rot *model.Vector) { + e.rot.X, e.rot.Y, e.rot.Z = rot.X, rot.Y, rot.Z +} + +func (e *Entity) SetMoveState(moveState uint16) { + e.moveState = moveState +} + +func (e *Entity) SetLastMoveSceneTimeMs(lastMoveSceneTimeMs uint32) { + e.lastMoveSceneTimeMs = lastMoveSceneTimeMs +} + +func (e *Entity) SetLastMoveReliableSeq(lastMoveReliableSeq uint32) { + e.lastMoveReliableSeq = lastMoveReliableSeq +} + +func (e *Entity) SetFightProp(fightProp map[uint32]float32) { + e.fightProp = fightProp +} + type AvatarEntity struct { + *Entity uid uint32 avatarId uint32 } @@ -579,7 +593,12 @@ func (a *AvatarEntity) GetAvatarId() uint32 { return a.avatarId } +type WeaponEntity struct { + *Entity +} + type MonsterEntity struct { + *Entity monsterId uint32 } @@ -588,6 +607,7 @@ func (m *MonsterEntity) GetMonsterId() uint32 { } type NpcEntity struct { + *Entity npcId uint32 roomId uint32 parentQuestId uint32 @@ -610,23 +630,16 @@ func (n *NpcEntity) GetBlockId() uint32 { return n.blockId } -const ( - GADGET_TYPE_NORMAL = iota - GADGET_TYPE_CLIENT - GADGET_TYPE_VEHICLE // 载具 -) - -type GadgetEntity struct { - gadgetType int - gadgetId uint32 - gadgetState uint32 - gadgetNormalEntity *GadgetNormalEntity - gadgetClientEntity *GadgetClientEntity - gadgetVehicleEntity *GadgetVehicleEntity +type IGadgetEntity interface { + GetGadgetId() uint32 + GetGadgetState() uint32 + SetGadgetState(state uint32) } -func (g *GadgetEntity) GetGadgetType() int { - return g.gadgetType +type GadgetEntity struct { + *Entity + gadgetId uint32 + gadgetState uint32 } func (g *GadgetEntity) GetGadgetId() uint32 { @@ -641,19 +654,8 @@ func (g *GadgetEntity) SetGadgetState(state uint32) { g.gadgetState = state } -func (g *GadgetEntity) GetGadgetNormalEntity() *GadgetNormalEntity { - return g.gadgetNormalEntity -} - -func (g *GadgetEntity) GetGadgetClientEntity() *GadgetClientEntity { - return g.gadgetClientEntity -} - -func (g *GadgetEntity) GetGadgetVehicleEntity() *GadgetVehicleEntity { - return g.gadgetVehicleEntity -} - type GadgetNormalEntity struct { + *GadgetEntity isDrop bool itemId uint32 count uint32 @@ -672,7 +674,7 @@ func (g *GadgetNormalEntity) GetCount() uint32 { } type GadgetClientEntity struct { - configId uint32 + *GadgetEntity campId uint32 campType uint32 ownerEntityId uint32 @@ -680,10 +682,6 @@ type GadgetClientEntity struct { propOwnerEntityId uint32 } -func (g *GadgetClientEntity) GetConfigId() uint32 { - return g.configId -} - func (g *GadgetClientEntity) GetCampId() uint32 { return g.campId } @@ -705,13 +703,14 @@ func (g *GadgetClientEntity) GetPropOwnerEntityId() uint32 { } type GadgetVehicleEntity struct { + *GadgetEntity vehicleId uint32 worldId uint64 ownerUid uint32 maxStamina float32 curStamina float32 - restoreDelay uint8 // 载具耐力回复延时 - memberMap map[uint32]*model.Player // uint32 = pos + restoreDelay uint8 // 载具耐力回复延时 + memberMap map[uint32]uint32 // key:pos value:uid } func (g *GadgetVehicleEntity) GetVehicleId() uint32 { @@ -734,16 +733,16 @@ func (g *GadgetVehicleEntity) GetCurStamina() float32 { return g.curStamina } -func (g *GadgetVehicleEntity) SetCurStamina(curStamina float32) { - g.curStamina = curStamina +func (g *GadgetVehicleEntity) GetRestoreDelay() uint8 { + return g.restoreDelay } -func (g *GadgetVehicleEntity) GetMemberMap() map[uint32]*model.Player { +func (g *GadgetVehicleEntity) GetMemberMap() map[uint32]uint32 { return g.memberMap } -func (g *GadgetVehicleEntity) GetRestoreDelay() uint8 { - return g.restoreDelay +func (g *GadgetVehicleEntity) SetCurStamina(curStamina float32) { + g.curStamina = curStamina } func (g *GadgetVehicleEntity) SetRestoreDelay(restoreDelay uint8) { diff --git a/gs/game/lua_func.go b/gs/game/lua_func.go index 68b15d4e..b1a42d2f 100644 --- a/gs/game/lua_func.go +++ b/gs/game/lua_func.go @@ -254,7 +254,8 @@ func GetGroupMonsterCount(luaState *lua.LState) int { } monsterCount := 0 for _, entity := range group.GetAllEntity() { - if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { + _, ok := entity.(*MonsterEntity) + if ok { monsterCount++ } } @@ -287,7 +288,8 @@ func GetGroupMonsterCountByGroupId(luaState *lua.LState) int { } monsterCount := 0 for _, entity := range group.GetAllEntity() { - if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { + _, ok := entity.(*MonsterEntity) + if ok { monsterCount++ } } @@ -326,7 +328,8 @@ func CheckRemainGadgetCountByGroupId(luaState *lua.LState) int { } gadgetCount := 0 for _, entity := range group.GetAllEntity() { - if entity.GetEntityType() == constant.ENTITY_TYPE_GADGET { + _, ok := entity.(IGadgetEntity) + if ok { gadgetCount++ } } @@ -396,12 +399,12 @@ func GetGadgetStateByConfigId(luaState *lua.LState) int { luaState.Push(lua.LNumber(-1)) return 1 } - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + iGadgetEntity, ok := entity.(IGadgetEntity) + if !ok { luaState.Push(lua.LNumber(-1)) return 1 } - gadgetEntity := entity.GetGadgetEntity() - luaState.Push(lua.LNumber(gadgetEntity.GetGadgetState())) + luaState.Push(lua.LNumber(iGadgetEntity.GetGadgetState())) return 1 } @@ -958,21 +961,24 @@ func KillGroupEntity(luaState *lua.LState) int { } case constant.GROUP_KILL_MONSTER: for _, entity := range entityMap { - if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER { + _, ok := entity.(*MonsterEntity) + if !ok { continue } GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) } case constant.GROUP_KILL_NPC: for _, entity := range entityMap { - if entity.GetEntityType() != constant.ENTITY_TYPE_NPC { + _, ok := entity.(*NpcEntity) + if !ok { continue } GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) } case constant.GROUP_KILL_GADGET: for _, entity := range entityMap { - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + _, ok := entity.(IGadgetEntity) + if !ok { continue } GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) diff --git a/gs/game/player_avatar.go b/gs/game/player_avatar.go index 53fc75f9..190662df 100644 --- a/gs/game/player_avatar.go +++ b/gs/game/player_avatar.go @@ -819,7 +819,7 @@ func (g *Game) SubPlayerAvatarHp(userId uint32, avatarId uint32, value float32, default: dieType = proto.PlayerDieType_PLAYER_DIE_GM } - g.KillPlayerAvatar(player, entity.GetAvatarEntity().GetAvatarId(), dieType) + g.KillPlayerAvatar(player, entity.(*AvatarEntity).GetAvatarId(), dieType) } } diff --git a/gs/game/player_common.go b/gs/game/player_common.go index c69a1383..ee8f829c 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -180,7 +180,8 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { for _, entityId := range scenePlayer.VehicleInfo.CreateEntityIdMap { entity := scene.GetEntity(entityId) // 确保实体类型是否为载具 - if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.GetGadgetEntity().GetGadgetVehicleEntity() != nil { + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if ok { vehicleLocationInfo := &proto.VehicleLocationInfo{ Rot: &proto.Vector{ X: float32(entity.GetRot().X), @@ -189,18 +190,18 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { }, EntityId: entity.GetId(), CurHp: entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP], - OwnerUid: entity.GetGadgetEntity().GetGadgetVehicleEntity().GetOwnerUid(), + OwnerUid: gadgetVehicleEntity.GetOwnerUid(), Pos: &proto.Vector{ X: float32(entity.GetPos().X), Y: float32(entity.GetPos().Y), Z: float32(entity.GetPos().Z), }, - UidList: make([]uint32, 0, len(entity.GetGadgetEntity().GetGadgetVehicleEntity().GetMemberMap())), - GadgetId: entity.GetGadgetEntity().GetGadgetVehicleEntity().GetVehicleId(), + UidList: make([]uint32, 0, len(gadgetVehicleEntity.GetMemberMap())), + GadgetId: gadgetVehicleEntity.GetVehicleId(), MaxHp: entity.GetFightProp()[constant.FIGHT_PROP_MAX_HP], } - for _, p := range entity.GetGadgetEntity().GetGadgetVehicleEntity().GetMemberMap() { - vehicleLocationInfo.UidList = append(vehicleLocationInfo.UidList, p.PlayerId) + for _, uid := range gadgetVehicleEntity.GetMemberMap() { + vehicleLocationInfo.UidList = append(vehicleLocationInfo.UidList, uid) } ntf.VehicleLocList = append(ntf.VehicleLocList, vehicleLocationInfo) } diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index b3c8bcb5..81b3ebaf 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -194,10 +194,10 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr // logger.Error("not found def entity, DefenseId: %v", attackResult.DefenseId) return } - switch defEntity.GetEntityType() { - case constant.ENTITY_TYPE_AVATAR: - g.SubPlayerAvatarHp(player.PlayerId, defEntity.GetAvatarEntity().GetAvatarId(), attackResult.Damage, false, proto.ChangHpReason_CHANGE_HP_SUB_MONSTER) - case constant.ENTITY_TYPE_MONSTER: + switch defEntity.(type) { + case *AvatarEntity: + g.SubPlayerAvatarHp(player.PlayerId, defEntity.(*AvatarEntity).GetAvatarId(), attackResult.Damage, false, proto.ChangHpReason_CHANGE_HP_SUB_MONSTER) + case *MonsterEntity: if scene.GetMonsterWudi() { return } @@ -217,9 +217,9 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr if defEntity.GetGroupId() == 0 { return } - monsterDataConfig := gdconf.GetMonsterDataById(int32(defEntity.GetMonsterEntity().GetMonsterId())) + monsterDataConfig := gdconf.GetMonsterDataById(int32(defEntity.(*MonsterEntity).GetMonsterId())) if monsterDataConfig == nil { - logger.Error("get monster data config is nil, monsterId: %v", defEntity.GetMonsterEntity().GetMonsterId()) + logger.Error("get monster data config is nil, monsterId: %v", defEntity.(*MonsterEntity).GetMonsterId()) return } lastHpPercent := lastHp / maxHp * 100.0 @@ -229,9 +229,8 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr g.monsterDrop(player, MonsterDropTypeHp, hpDrop.Id, defEntity) } } - case constant.ENTITY_TYPE_GADGET: - gadgetEntity := defEntity.GetGadgetEntity() - gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId())) + case IGadgetEntity: + gadgetDataConfig := gdconf.GetGadgetDataById(int32(defEntity.(IGadgetEntity).GetGadgetId())) if gadgetDataConfig == nil { // logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId()) return @@ -246,9 +245,9 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene if entity == nil { return } - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { + avatarEntity, ok := entity.(*AvatarEntity) + if ok { // 玩家实体在移动 - avatarEntity := entity.GetAvatarEntity() if avatarEntity.GetUid() != player.PlayerId { return } @@ -301,8 +300,8 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene entity.SetRot(rot) if !force { motionInfo := moveInfo.MotionInfo - switch entity.GetEntityType() { - case constant.ENTITY_TYPE_AVATAR: + switch entity.(type) { + case *AvatarEntity: switch motionInfo.State { case proto.MotionState_MOTION_STANDBY, proto.MotionState_MOTION_WALK, proto.MotionState_MOTION_RUN, proto.MotionState_MOTION_DASH, 58, 59, 60, 64, 65, 66: @@ -337,13 +336,13 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene } fightProp := entity.GetFightProp() maxHp := fightProp[constant.FIGHT_PROP_MAX_HP] - g.SubPlayerAvatarHp(player.PlayerId, entity.GetAvatarEntity().GetAvatarId(), maxHp*rate, false, proto.ChangHpReason_CHANGE_HP_SUB_FALL) + g.SubPlayerAvatarHp(player.PlayerId, avatarEntity.GetAvatarId(), maxHp*rate, false, proto.ChangHpReason_CHANGE_HP_SUB_FALL) } } player.Speed = &model.Vector{X: float64(motionInfo.Speed.X), Y: float64(motionInfo.Speed.Y), Z: float64(motionInfo.Speed.Z)} - case constant.ENTITY_TYPE_GADGET: - gadgetEntity := entity.GetGadgetEntity() - if gadgetEntity.GetGadgetVehicleEntity() != nil { + case IGadgetEntity: + _, ok := entity.(*GadgetVehicleEntity) + if ok { // 处理耐力消耗 g.ImmediateStamina(player, motionInfo.State) // 处理载具销毁请求 @@ -418,12 +417,13 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList) for _, delEntityId := range delEntityIdList { entity := scene.GetEntity(delEntityId) - if entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + avatarEntity, ok := entity.(*AvatarEntity) + if !ok { continue } - otherPlayer := USER_MANAGER.GetOnlineUser(entity.GetAvatarEntity().GetUid()) + otherPlayer := USER_MANAGER.GetOnlineUser(avatarEntity.GetUid()) if otherPlayer == nil { - logger.Error("get player is nil, target uid: %v, uid: %v", entity.GetAvatarEntity().GetUid(), player.PlayerId) + logger.Error("get player is nil, target uid: %v, uid: %v", avatarEntity.GetUid(), player.PlayerId) continue } g.RemoveSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MISS, []uint32{avatarEntityId}) @@ -433,15 +433,16 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false) for _, addEntityId := range addEntityIdList { entity := scene.GetEntity(addEntityId) - if entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + avatarEntity, ok := entity.(*AvatarEntity) + if !ok { continue } - otherPlayer := USER_MANAGER.GetOnlineUser(entity.GetAvatarEntity().GetUid()) + otherPlayer := USER_MANAGER.GetOnlineUser(avatarEntity.GetUid()) if otherPlayer == nil { - logger.Error("get player is nil, target uid: %v, uid: %v", entity.GetAvatarEntity().GetUid(), player.PlayerId) + logger.Error("get player is nil, target uid: %v, uid: %v", avatarEntity.GetUid(), player.PlayerId) continue } - sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, player, scene.GetEntity(avatarEntityId).GetAvatarEntity().GetAvatarId()) + sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, player, scene.GetEntity(avatarEntityId).(*AvatarEntity).GetAvatarId()) g.AddSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MEET, []*proto.SceneEntityInfo{sceneEntityInfoAvatar}) } } @@ -553,7 +554,8 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S newVisionEntityMap := g.GetVisionEntity(scene, newPos) delEntityIdList := make([]uint32, 0) for entityId, entity := range oldVisionEntityMap { - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { + _, ok := entity.(*AvatarEntity) + if ok { continue } _, exist := newVisionEntityMap[entityId] @@ -565,7 +567,8 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S } addEntityIdList := make([]uint32, 0) for entityId, entity := range newVisionEntityMap { - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { + _, ok := entity.(*AvatarEntity) + if ok { continue } _, exist := oldVisionEntityMap[entityId] @@ -980,20 +983,20 @@ func (g *Game) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) { // TODO 一些很low的解决方案 我本来是不想写的 有多low?要多low有多low! -func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity, hitElementType uint32) { +func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity IEntity, hitElementType uint32) { world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.GetSceneId()) - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + iGadgetEntity, ok := entity.(IGadgetEntity) + if !ok { return } - gadgetEntity := entity.GetGadgetEntity() - gadgetId := gadgetEntity.GetGadgetId() + gadgetId := iGadgetEntity.GetGadgetId() gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetId)) if gadgetDataConfig == nil { - logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId()) + logger.Error("get gadget data config is nil, gadgetId: %v", iGadgetEntity.GetGadgetId()) return } if strings.Contains(gadgetDataConfig.Name, "火把") || @@ -1052,17 +1055,17 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3 if modifierChange.Action != proto.ModifierAction_REMOVED { return } - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + iGadgetEntity, ok := entity.(IGadgetEntity) + if !ok { return } - gadgetEntity := entity.GetGadgetEntity() - gadgetId := gadgetEntity.GetGadgetId() + gadgetId := iGadgetEntity.GetGadgetId() if gadgetId == 0 { return } gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetId)) if gadgetDataConfig == nil { - logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId()) + logger.Error("get gadget data config is nil, gadgetId: %v", iGadgetEntity.GetGadgetId()) return } if strings.Contains(gadgetDataConfig.Name, "碎石堆") || diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index ec6ad4a9..06f49b25 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -379,7 +379,8 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { entityIdList := make([]uint32, 0) for entityId, entity := range visionEntityMap { if WORLD_MANAGER.IsAiWorld(world) { - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { + _, ok := entity.(*AvatarEntity) + if ok { continue } } @@ -753,26 +754,27 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio logger.Error("get entity is nil, entityId: %v", entityId) continue } - switch entity.GetEntityType() { - case constant.ENTITY_TYPE_AVATAR: - scenePlayer := USER_MANAGER.GetOnlineUser(entity.GetAvatarEntity().GetUid()) + switch entity.(type) { + case *AvatarEntity: + avatarEntity := entity.(*AvatarEntity) + scenePlayer := USER_MANAGER.GetOnlineUser(avatarEntity.GetUid()) if scenePlayer == nil { logger.Error("get scene player is nil, world id: %v, scene id: %v", world.GetId(), scene.GetId()) continue } sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)) entityList = append(entityList, sceneEntityInfoAvatar) - case constant.ENTITY_TYPE_MONSTER: + case *MonsterEntity: sceneEntityInfoMonster := g.PacketSceneEntityInfoMonster(scene, entity.GetId()) entityList = append(entityList, sceneEntityInfoMonster) - case constant.ENTITY_TYPE_NPC: + case *NpcEntity: sceneEntityInfoNpc := g.PacketSceneEntityInfoNpc(scene, entity.GetId()) entityList = append(entityList, sceneEntityInfoNpc) - case constant.ENTITY_TYPE_GADGET: + case IGadgetEntity: sceneEntityInfoGadget := g.PacketSceneEntityInfoGadget(player, scene, entity.GetId()) entityList = append(entityList, sceneEntityInfoGadget) default: - logger.Error("not support entity type: %v, stack: %v", entity.GetEntityType(), logger.Stack()) + logger.Error("not support entity: %v, stack: %v", entity, logger.Stack()) continue } } @@ -789,7 +791,7 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio } // EntityFightPropUpdateNotifyBroadcast 场景实体战斗属性变更通知广播 -func (g *Game) EntityFightPropUpdateNotifyBroadcast(scene *Scene, entity *Entity) { +func (g *Game) EntityFightPropUpdateNotifyBroadcast(scene *Scene, entity IEntity) { ntf := &proto.EntityFightPropUpdateNotify{ FightPropMap: entity.GetFightProp(), EntityId: entity.GetId(), @@ -890,7 +892,8 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d } g.SendToSceneA(scene, cmd.LifeStateChangeNotify, 0, ntf, 0) - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { + _, ok := entity.(*AvatarEntity) + if ok { return } @@ -913,13 +916,13 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d group.DestroyEntity(entity.GetId()) - switch entity.GetEntityType() { - case constant.ENTITY_TYPE_MONSTER: + switch entity.(type) { + case *MonsterEntity: // 随机掉落 g.monsterDrop(player, MonsterDropTypeKill, 0, entity) // 怪物死亡触发器检测 g.MonsterDieTriggerCheck(player, group) - case constant.ENTITY_TYPE_GADGET: + case IGadgetEntity: // 物件死亡触发器检测 g.GadgetDieTriggerCheck(player, group, entity.GetConfigId()) } @@ -937,15 +940,15 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui logger.Error("get entity is nil, entityId: %v", entityId) return } - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { + iGadgetEntity, ok := entity.(IGadgetEntity) + if !ok { logger.Error("entity is not gadget, entityId: %v", entityId) return } - gadgetEntity := entity.GetGadgetEntity() - gadgetEntity.SetGadgetState(state) + iGadgetEntity.SetGadgetState(state) ntf := &proto.GadgetStateNotify{ GadgetEntityId: entity.GetId(), - GadgetState: gadgetEntity.GetGadgetState(), + GadgetState: iGadgetEntity.GetGadgetState(), IsEnableInteract: true, } g.SendMsg(cmd.GadgetStateNotify, player.PlayerId, player.ClientSeq, ntf) @@ -962,31 +965,33 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui if sceneGroup == nil { return } - sceneGroup.ChangeGadgetState(entity.GetConfigId(), uint8(gadgetEntity.GetGadgetState())) + sceneGroup.ChangeGadgetState(entity.GetConfigId(), uint8(iGadgetEntity.GetGadgetState())) // 物件状态变更触发器检测 - g.GadgetStateChangeTriggerCheck(player, group, entity.GetConfigId(), uint8(gadgetEntity.GetGadgetState())) + g.GadgetStateChangeTriggerCheck(player, group, entity.GetConfigId(), uint8(iGadgetEntity.GetGadgetState())) } // GetVisionEntity 获取某位置视野内的全部实体 -func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Entity { +func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]IEntity { allEntityMap := scene.GetAllEntity() - visionEntity := make(map[uint32]*Entity) + visionEntity := make(map[uint32]IEntity) for _, entity := range allEntityMap { if !g.IsInVision(pos, entity.GetPos(), entity.GetVisionLevel()) { continue } - if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { - scenePlayer := USER_MANAGER.GetOnlineUser(entity.GetAvatarEntity().GetUid()) + avatarEntity, ok := entity.(*AvatarEntity) + if ok { + scenePlayer := USER_MANAGER.GetOnlineUser(avatarEntity.GetUid()) if scenePlayer == nil { - logger.Error("get scene player is nil, target uid: %v", entity.GetAvatarEntity().GetUid()) + logger.Error("get scene player is nil, target uid: %v", avatarEntity.GetUid()) continue } if !scene.GetWorld().IsPlayerActiveAvatarEntity(scenePlayer, entity.GetId()) { continue } } - if entity.GetEntityType() == constant.ENTITY_TYPE_WEAPON { + _, ok = entity.(*WeaponEntity) + if ok { continue } visionEntity[entity.GetId()] = entity @@ -1214,7 +1219,7 @@ func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupI if sceneGroup == nil { return } - entityMap := make(map[uint32]*Entity) + entityMap := make(map[uint32]IEntity) for _, monsterConfigId := range suiteConfig.MonsterConfigIdList { monsterConfig, exist := groupConfig.MonsterMap[monsterConfigId] if !exist { @@ -1302,11 +1307,9 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any &model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)}, uint32(gatherDataConfig.GadgetId), uint32(constant.GADGET_STATE_DEFAULT), - &GadgetNormalEntity{ - isDrop: false, - itemId: uint32(gatherDataConfig.ItemId), - count: 1, - }, + false, + uint32(gatherDataConfig.ItemId), + 1, uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), @@ -1322,7 +1325,9 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any &model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)}, uint32(gadget.GadgetId), uint32(state), - new(GadgetNormalEntity), + false, + 0, + 0, uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), @@ -1378,7 +1383,7 @@ func (g *Game) SceneGroupCreateEntity(player *model.Player, groupId uint32, conf } entity := scene.GetEntity(entityId) // 实体添加到场景小组 - scene.AddGroupSuite(groupId, uint8(initSuiteId), map[uint32]*Entity{entity.GetId(): entity}) + scene.AddGroupSuite(groupId, uint8(initSuiteId), map[uint32]IEntity{entity.GetId(): entity}) // 通知客户端 g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false) // 触发器检测 @@ -1423,24 +1428,16 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId if entity == nil { return 0 } - entity.level = level g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false) return entityId } // CreateGadget 创建物件实体 -func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId uint32, normalEntity *GadgetNormalEntity) uint32 { +func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId uint32, isDrop bool, itemId, count uint32) uint32 { if gadgetId == 0 { - logger.Error("create gadget id is zero, pos: %+v, normalEntity: %+v, uid: %v", pos, normalEntity, player.PlayerId) + logger.Error("create gadget id is zero, pos: %+v, isDrop: %v, itemId: %v, count: %v, uid: %v", pos, isDrop, itemId, count, player.PlayerId) return 0 } - if normalEntity == nil { - normalEntity = &GadgetNormalEntity{ - isDrop: false, - itemId: 0, - count: 0, - } - } world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return 0 @@ -1455,7 +1452,7 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui rot.Y = random.GetRandomFloat64(0.0, 360.0) entityId := scene.CreateEntityGadgetNormal( pos, rot, - gadgetId, constant.GADGET_STATE_DEFAULT, normalEntity, + gadgetId, constant.GADGET_STATE_DEFAULT, isDrop, itemId, count, 0, 0, constant.VISION_LEVEL_NORMAL, ) g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false) @@ -1464,11 +1461,7 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui // CreateDropGadget 创建掉落物的物件实体 func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetId, itemId, count uint32) uint32 { - entityId := g.CreateGadget(player, pos, gadgetId, &GadgetNormalEntity{ - isDrop: true, - itemId: itemId, - count: count, - }) + entityId := g.CreateGadget(player, pos, gadgetId, true, itemId, count) return entityId } @@ -1915,7 +1908,7 @@ func (g *Game) PacketSceneEntityInfoNpc(scene *Scene, entityId uint32) *proto.Sc LifeState: uint32(entity.GetLifeState()), AnimatorParaList: make([]*proto.AnimatorParameterValueInfoPair, 0), Entity: &proto.SceneEntityInfo_Npc{ - Npc: g.PacketSceneNpcInfo(entity.GetNpcEntity()), + Npc: g.PacketSceneNpcInfo(entity.(*NpcEntity)), }, EntityClientData: new(proto.EntityClientData), EntityAuthorityInfo: &proto.EntityAuthorityInfo{ @@ -1971,19 +1964,18 @@ func (g *Game) PacketSceneEntityInfoGadget(player *model.Player, scene *Scene, e BornPos: pos, }, } - gadgetEntity := entity.GetGadgetEntity() - switch gadgetEntity.GetGadgetType() { - case GADGET_TYPE_NORMAL: + switch entity.(type) { + case *GadgetNormalEntity: sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{ Gadget: g.PacketSceneGadgetInfoNormal(player, entity), } - case GADGET_TYPE_CLIENT: + case *GadgetClientEntity: sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{ - Gadget: g.PacketSceneGadgetInfoClient(gadgetEntity.GetGadgetClientEntity()), + Gadget: g.PacketSceneGadgetInfoClient(entity.(*GadgetClientEntity)), } - case GADGET_TYPE_VEHICLE: + case *GadgetVehicleEntity: sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{ - Gadget: g.PacketSceneGadgetInfoVehicle(gadgetEntity.GetGadgetVehicleEntity()), + Gadget: g.PacketSceneGadgetInfoVehicle(entity.(*GadgetVehicleEntity)), } } return sceneEntityInfo @@ -2038,14 +2030,14 @@ func (g *Game) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarI return sceneAvatarInfo } -func (g *Game) PacketSceneMonsterInfo(entity *Entity) *proto.SceneMonsterInfo { +func (g *Game) PacketSceneMonsterInfo(entity IEntity) *proto.SceneMonsterInfo { blockId := uint32(0) if entity.GetGroupId() != 0 { groupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId())) blockId = uint32(groupConfig.BlockId) } sceneMonsterInfo := &proto.SceneMonsterInfo{ - MonsterId: entity.GetMonsterEntity().GetMonsterId(), + MonsterId: entity.(*MonsterEntity).GetMonsterId(), AuthorityPeerId: 1, BornType: proto.MonsterBornType_MONSTER_BORN_DEFAULT, BlockId: blockId, @@ -2065,22 +2057,25 @@ func (g *Game) PacketSceneNpcInfo(entity *NpcEntity) *proto.SceneNpcInfo { return sceneNpcInfo } -func (g *Game) PacketSceneGadgetInfoNormal(player *model.Player, entity *Entity) *proto.SceneGadgetInfo { - gadgetEntity := entity.GetGadgetEntity() - gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId())) +func (g *Game) PacketSceneGadgetInfoNormal(player *model.Player, entity IEntity) *proto.SceneGadgetInfo { + iGadgetEntity, ok := entity.(IGadgetEntity) + if !ok { + return new(proto.SceneGadgetInfo) + } + gadgetDataConfig := gdconf.GetGadgetDataById(int32(iGadgetEntity.GetGadgetId())) if gadgetDataConfig == nil { - logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId()) + logger.Error("get gadget data config is nil, gadgetId: %v", iGadgetEntity.GetGadgetId()) return new(proto.SceneGadgetInfo) } sceneGadgetInfo := &proto.SceneGadgetInfo{ - GadgetId: gadgetEntity.GetGadgetId(), + GadgetId: iGadgetEntity.GetGadgetId(), GroupId: entity.GetGroupId(), ConfigId: entity.GetConfigId(), - GadgetState: gadgetEntity.GetGadgetState(), + GadgetState: iGadgetEntity.GetGadgetState(), IsEnableInteract: true, AuthorityPeerId: 1, } - gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity() + gadgetNormalEntity := entity.(*GadgetNormalEntity) if gadgetNormalEntity.GetIsDrop() { dbItem := player.GetDbItem() sceneGadgetInfo.Content = &proto.SceneGadgetInfo_TrifleItem{ diff --git a/gs/game/player_stamina.go b/gs/game/player_stamina.go index 560f14f9..13f23b0b 100644 --- a/gs/game/player_stamina.go +++ b/gs/game/player_stamina.go @@ -181,20 +181,20 @@ func (g *Game) RestoreCountStaminaHandler(player *model.Player) { continue } // 确保实体类型是否为载具 - gadgetEntity := entity.GetGadgetEntity() - if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil { + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { continue } // 获取载具配置表 - vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())) + vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetVehicleEntity.GetVehicleId())) if vehicleDataConfig == nil { - logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()) + logger.Error("vehicle config error, vehicleId: %v", gadgetVehicleEntity.GetVehicleId()) continue } - restoreDelay := gadgetEntity.GetGadgetVehicleEntity().GetRestoreDelay() + restoreDelay := gadgetVehicleEntity.GetRestoreDelay() // 做个限制不然一直加就panic了 if restoreDelay < uint8(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaRecoverWaitTime*10) { - gadgetEntity.GetGadgetVehicleEntity().SetRestoreDelay(restoreDelay + 1) + gadgetVehicleEntity.SetRestoreDelay(restoreDelay + 1) } } // 处理玩家 @@ -276,40 +276,43 @@ func (g *Game) GetChangeStamina(curStamina int32, maxStamina int32, staminaCost } // UpdateVehicleStamina 更新载具耐力 -func (g *Game) UpdateVehicleStamina(player *model.Player, vehicleEntity *Entity, staminaCost int32) { +func (g *Game) UpdateVehicleStamina(player *model.Player, entity IEntity, staminaCost int32) { // 耐力消耗为0代表不更改 仍然执行后面的话会导致回复出问题 if staminaCost == 0 { return } staminaInfo := player.StaminaInfo // 确保载具实体存在 - if vehicleEntity == nil { + if entity == nil { + return + } + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { return } - gadgetEntity := vehicleEntity.GetGadgetEntity() // 获取载具配置表 - vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())) + vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetVehicleEntity.GetVehicleId())) if vehicleDataConfig == nil { - logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()) + logger.Error("vehicle config error, vehicleId: %v", gadgetVehicleEntity.GetVehicleId()) return } // 添加的耐力大于0为恢复 if staminaCost > 0 { // 耐力延迟1.5s(15 ticks)恢复 动作状态为加速将立刻恢复耐力 - restoreDelay := gadgetEntity.GetGadgetVehicleEntity().GetRestoreDelay() + restoreDelay := gadgetVehicleEntity.GetRestoreDelay() if restoreDelay < uint8(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaRecoverWaitTime*10) && staminaInfo.State != proto.MotionState_MOTION_SKIFF_POWERED_DASH { return // 不恢复耐力 } } else { // 消耗耐力重新计算恢复需要延迟的tick - gadgetEntity.GetGadgetVehicleEntity().SetRestoreDelay(0) + gadgetVehicleEntity.SetRestoreDelay(0) } // 因为载具的耐力需要换算 // 这里先*100后面要用的时候再换算 为了确保精度 // 最大耐力值 - maxStamina := int32(gadgetEntity.GetGadgetVehicleEntity().GetMaxStamina() * 100) + maxStamina := int32(gadgetVehicleEntity.GetMaxStamina() * 100) // 现行耐力值 - curStamina := int32(gadgetEntity.GetGadgetVehicleEntity().GetCurStamina() * 100) + curStamina := int32(gadgetVehicleEntity.GetCurStamina() * 100) // 将被变更的耐力 stamina := g.GetChangeStamina(curStamina, maxStamina, staminaCost) // 当前无变动不要频繁发包 @@ -317,7 +320,7 @@ func (g *Game) UpdateVehicleStamina(player *model.Player, vehicleEntity *Entity, return } // 更改载具耐力 (换算) - g.SetVehicleStamina(player, vehicleEntity, float32(stamina)/100) + g.SetVehicleStamina(player, entity, float32(stamina)/100) } // UpdatePlayerStamina 更新玩家耐力 @@ -388,14 +391,17 @@ func (g *Game) HandleDrown(player *model.Player, stamina uint32) { } // SetVehicleStamina 设置载具耐力 -func (g *Game) SetVehicleStamina(player *model.Player, vehicleEntity *Entity, stamina float32) { +func (g *Game) SetVehicleStamina(player *model.Player, entity IEntity, stamina float32) { // 设置载具的耐力 - gadgetEntity := vehicleEntity.GetGadgetEntity() - gadgetEntity.GetGadgetVehicleEntity().SetCurStamina(stamina) + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { + return + } + gadgetVehicleEntity.SetCurStamina(stamina) // logger.Debug("vehicle stamina set, stamina: %v", stamina) vehicleStaminaNotify := new(proto.VehicleStaminaNotify) - vehicleStaminaNotify.EntityId = vehicleEntity.GetId() + vehicleStaminaNotify.EntityId = entity.GetId() vehicleStaminaNotify.CurStamina = stamina g.SendMsg(cmd.VehicleStaminaNotify, player.PlayerId, player.ClientSeq, vehicleStaminaNotify) } diff --git a/gs/game/player_team.go b/gs/game/player_team.go index 4b32091c..7040b4eb 100644 --- a/gs/game/player_team.go +++ b/gs/game/player_team.go @@ -86,7 +86,7 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) { } g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0) - sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId()) + sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.(*AvatarEntity).GetAvatarId()) sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{ AppearType: proto.VisionType_VISION_REPLACE, Param: oldAvatarEntity.GetId(), @@ -144,7 +144,7 @@ func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Messag } g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0) - sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId()) + sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.(*AvatarEntity).GetAvatarId()) sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{ AppearType: proto.VisionType_VISION_REPLACE, Param: oldAvatarEntity.GetId(), @@ -215,7 +215,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message } g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0) - sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId()) + sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.(*AvatarEntity).GetAvatarId()) sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{ AppearType: proto.VisionType_VISION_REPLACE, Param: oldAvatarEntity.GetId(), diff --git a/gs/game/player_vehicle.go b/gs/game/player_vehicle.go index 0b747490..0d6c06ba 100644 --- a/gs/game/player_vehicle.go +++ b/gs/game/player_vehicle.go @@ -3,7 +3,6 @@ package game import ( "time" - "hk4e/common/constant" "hk4e/gdconf" "hk4e/gs/model" "hk4e/pkg/logger" @@ -86,9 +85,9 @@ func (g *Game) VehicleInteractReq(player *model.Player, payloadMsg pb.Message) { return } // 判断实体类型是否为载具 - gadgetEntity := entity.GetGadgetEntity() - if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil { - logger.Error("vehicle entity error, entityType: %v", entity.GetEntityType()) + _, ok := entity.(*GadgetVehicleEntity) + if ok { + logger.Error("vehicle entity error, entity: %v", entity) g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_GADGET_NOT_VEHICLE) return } @@ -110,7 +109,7 @@ func (g *Game) VehicleInteractReq(player *model.Player, payloadMsg pb.Message) { /************************************************** 游戏功能 **************************************************/ // VehicleDestroyMotion 载具销毁动作 -func (g *Game) VehicleDestroyMotion(player *model.Player, entity *Entity, state proto.MotionState) { +func (g *Game) VehicleDestroyMotion(player *model.Player, entity IEntity, state proto.MotionState) { world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId) @@ -120,22 +119,19 @@ func (g *Game) VehicleDestroyMotion(player *model.Player, entity *Entity, state // 状态等于 MOTION_STATE_DESTROY_VEHICLE 代表请求销毁 if state == proto.MotionState_MOTION_DESTROY_VEHICLE { - gadgetEntity := entity.GetGadgetEntity() - g.DestroyVehicleEntity(player, scene, gadgetEntity.GetGadgetVehicleEntity().GetVehicleId(), entity.GetId()) + gadgetVehicleEntity := entity.(*GadgetVehicleEntity) + g.DestroyVehicleEntity(player, scene, gadgetVehicleEntity.GetVehicleId(), entity.GetId()) } } // IsPlayerInVehicle 判断玩家是否在载具中 -func (g *Game) IsPlayerInVehicle(player *model.Player, entity *Entity) bool { - if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET { +func (g *Game) IsPlayerInVehicle(player *model.Player, entity IEntity) bool { + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { return false } - gadgetVehicleEntity := entity.GetGadgetEntity().GetGadgetVehicleEntity() - if gadgetVehicleEntity == nil { - return false - } - for _, p := range gadgetVehicleEntity.GetMemberMap() { - if p == player { + for _, uid := range gadgetVehicleEntity.GetMemberMap() { + if uid == player.PlayerId { return true } } @@ -149,17 +145,17 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI return } // 确保实体类型是否为载具 - gadgetEntity := entity.GetGadgetEntity() - if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil { + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { return } // 目前原神仅有一种载具 多载具目前理论上是兼容了 到时候有问题再改 // 确保载具Id为将要创建的 (每种载具允许存在1个) - if gadgetEntity.GetGadgetVehicleEntity().GetVehicleId() != vehicleId { + if gadgetVehicleEntity.GetVehicleId() != vehicleId { return } // 该载具是否为此玩家的 - if gadgetEntity.GetGadgetVehicleEntity().GetOwnerUid() != player.PlayerId { + if gadgetVehicleEntity.GetOwnerUid() != player.PlayerId { return } // 如果玩家正在载具中 @@ -177,17 +173,20 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI } // EnterVehicle 进入载具 -func (g *Game) EnterVehicle(player *model.Player, entity *Entity, avatarGuid uint64) { - gadgetEntity := entity.GetGadgetEntity() +func (g *Game) EnterVehicle(player *model.Player, entity IEntity, avatarGuid uint64) { + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { + return + } // 获取载具配置表 - vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())) + vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetVehicleEntity.GetVehicleId())) if vehicleDataConfig == nil { - logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()) + logger.Error("vehicle config error, vehicleId: %v", gadgetVehicleEntity.GetVehicleId()) return } maxSlot := int(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.MaxSeatCount) // 判断载具是否已满 - if len(gadgetEntity.GetGadgetVehicleEntity().GetMemberMap()) >= maxSlot { + if len(gadgetVehicleEntity.GetMemberMap()) >= maxSlot { g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_VEHICLE_SLOT_OCCUPIED) return } @@ -195,11 +194,11 @@ func (g *Game) EnterVehicle(player *model.Player, entity *Entity, avatarGuid uin // 找出载具空闲的位置 var freePos uint32 for i := uint32(0); i < uint32(maxSlot); i++ { - p := gadgetEntity.GetGadgetVehicleEntity().GetMemberMap()[i] + uid := gadgetVehicleEntity.GetMemberMap()[i] // 玩家如果已进入载具重复记录不进行报错 - if p == player || p == nil { + if uid == player.PlayerId || uid == 0 { // 载具成员记录玩家 - gadgetEntity.GetGadgetVehicleEntity().GetMemberMap()[i] = player + gadgetVehicleEntity.GetMemberMap()[i] = player.PlayerId freePos = i } } @@ -221,9 +220,12 @@ func (g *Game) EnterVehicle(player *model.Player, entity *Entity, avatarGuid uin } // ExitVehicle 离开载具 -func (g *Game) ExitVehicle(player *model.Player, entity *Entity, avatarGuid uint64) { +func (g *Game) ExitVehicle(player *model.Player, entity IEntity, avatarGuid uint64) { // 玩家是否进入载具 - gadgetEntity := entity.GetGadgetEntity() + gadgetVehicleEntity, ok := entity.(*GadgetVehicleEntity) + if !ok { + return + } if !g.IsPlayerInVehicle(player, entity) { logger.Error("vehicle not has player, uid: %v", player.PlayerId) g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_NOT_IN_VEHICLE) @@ -231,9 +233,9 @@ func (g *Game) ExitVehicle(player *model.Player, entity *Entity, avatarGuid uint } // 载具成员删除玩家 var memberPos uint32 - memberMap := gadgetEntity.GetGadgetVehicleEntity().GetMemberMap() - for pos, p := range memberMap { - if p == player { + memberMap := gadgetVehicleEntity.GetMemberMap() + for pos, uid := range memberMap { + if uid == player.PlayerId { memberPos = pos delete(memberMap, pos) } diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 49775b32..8359afd3 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -413,12 +413,11 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { } interactType := proto.InteractType_INTERACT_NONE - switch entity.GetEntityType() { - case constant.ENTITY_TYPE_GADGET: - gadgetEntity := entity.GetGadgetEntity() - gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId())) + switch entity.(type) { + case IGadgetEntity: + gadgetDataConfig := gdconf.GetGadgetDataById(int32(entity.(IGadgetEntity).GetGadgetId())) if gadgetDataConfig == nil { - logger.Error("get gadget data config is nil, gadgetId: %v, uid: %v", gadgetEntity.GetGadgetId(), player.PlayerId) + logger.Error("get gadget data config is nil, gadgetId: %v, uid: %v", entity.(IGadgetEntity).GetGadgetId(), player.PlayerId) return } logger.Debug("[GadgetInteractReq] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, entity.GetId(), player.PlayerId) @@ -426,13 +425,13 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { case constant.GADGET_TYPE_GADGET, constant.GADGET_TYPE_EQUIP, constant.GADGET_TYPE_ENERGY_BALL: // 掉落物捡起 interactType = proto.InteractType_INTERACT_PICK_ITEM - gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity() + gadgetNormalEntity := entity.(*GadgetNormalEntity) g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetNormalEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP) g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) case constant.GADGET_TYPE_GATHER_OBJECT: // 采集物摘取 interactType = proto.InteractType_INTERACT_GATHER - gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity() + gadgetNormalEntity := entity.(*GadgetNormalEntity) g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetNormalEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GATHER) g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) case constant.GADGET_TYPE_CHEST: @@ -454,11 +453,11 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { default: logger.Error("not support gadget type: %v, uid: %v", gadgetDataConfig.Type, player.PlayerId) } - case constant.ENTITY_TYPE_MONSTER: + case *MonsterEntity: // TODO 环境动物掉落道具 g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) default: - logger.Error("not support entity type: %v, uid: %v", entity.GetEntityType(), player.PlayerId) + logger.Error("not support entity: %v, uid: %v", entity, player.PlayerId) } rsp := &proto.GadgetInteractRsp{ @@ -570,7 +569,7 @@ const ( MonsterDropTypeKill ) -func (g *Game) monsterDrop(player *model.Player, monsterDropType int, hpDropId int32, entity *Entity) { +func (g *Game) monsterDrop(player *model.Player, monsterDropType int, hpDropId int32, entity IEntity) { dropId := int32(0) dropCount := int32(0) switch monsterDropType { @@ -628,7 +627,7 @@ func (g *Game) monsterDrop(player *model.Player, monsterDropType int, hpDropId i } } -func (g *Game) chestDrop(player *model.Player, entity *Entity) { +func (g *Game) chestDrop(player *model.Player, entity IEntity) { sceneGroupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId())) if sceneGroupConfig == nil { logger.Error("get scene group config is nil, groupId: %v, uid: %v", entity.GetGroupId(), player.PlayerId)