修复未在队伍角色无法更换时装的问题

顺便给获取scene的都判断了下nil
This commit is contained in:
UnKownOwO
2023-02-15 19:39:44 +08:00
parent 2e2159f309
commit 76b417f3f4
11 changed files with 136 additions and 7 deletions
+20 -4
View File
@@ -36,6 +36,14 @@ func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb
logger.Debug("user change avatar costume, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarChangeCostumeReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
g.SendError(cmd.AvatarChangeCostumeRsp, player, &proto.AvatarChangeCostumeRsp{})
return
}
// 确保角色存在
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
@@ -44,6 +52,7 @@ func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb
return
}
// 确保要更换的时装已获得
exist := false
for _, v := range player.CostumeList {
if v == req.CostumeId {
@@ -62,11 +71,18 @@ func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb
// 设置角色时装
avatar.Costume = req.CostumeId
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
// 角色更换时装通知
avatarChangeCostumeNotify := new(proto.AvatarChangeCostumeNotify)
avatarChangeCostumeNotify.EntityInfo = g.PacketSceneEntityInfoAvatar(scene, player, avatar.AvatarId)
// 要更换时装的角色实体不存在代表更换的是仓库内的角色
if scene.GetWorld().GetPlayerWorldAvatarEntityId(player, avatar.AvatarId) == 0 {
avatarChangeCostumeNotify.EntityInfo = &proto.SceneEntityInfo{
Entity: &proto.SceneEntityInfo_Avatar{
Avatar: g.PacketSceneAvatarInfo(scene, player, avatar.AvatarId),
},
}
} else {
avatarChangeCostumeNotify.EntityInfo = g.PacketSceneEntityInfoAvatar(scene, player, avatar.AvatarId)
}
for _, scenePlayer := range scene.GetAllPlayer() {
g.SendMsg(cmd.AvatarChangeCostumeNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, avatarChangeCostumeNotify)
}