mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
修复未在队伍角色无法更换时装的问题
顺便给获取scene的都判断了下nil
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user