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

顺便给获取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

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)
}

View File

@@ -84,6 +84,10 @@ func (g *GameManager) MassiveEntityElementOpBatchNotify(player *model.Player, pa
return
}
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
ntf.OpIdx = scene.GetMeeoIndex()
scene.SetMeeoIndex(scene.GetMeeoIndex() + 1)
g.SendToWorldA(world, cmd.MassiveEntityElementOpBatchNotify, player.ClientSeq, ntf)
@@ -100,6 +104,10 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
return
}
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
for _, entry := range req.InvokeList {
switch entry.ArgumentType {
case proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT:
@@ -261,6 +269,10 @@ func (g *GameManager) AoiPlayerMove(player *model.Player, oldPos *model.Vector,
aoiManager, exist := sceneBlockAoiMap[player.SceneId]
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
if exist {
oldGid := aoiManager.GetGidByPos(float32(oldPos.X), 0.0, float32(oldPos.Z))
newGid := aoiManager.GetGidByPos(float32(newPos.X), 0.0, float32(newPos.Z))
@@ -531,6 +543,10 @@ func (g *GameManager) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.
logger.Debug("EvtCreateGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
scene.CreateEntityGadgetClient(&model.Vector{
X: float64(req.InitPos.X),
Y: float64(req.InitPos.Y),
@@ -552,6 +568,10 @@ func (g *GameManager) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb
logger.Debug("EvtDestroyGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
scene.DestroyEntity(req.EntityId)
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{req.EntityId})
}

View File

@@ -36,6 +36,14 @@ func (g *GameManager) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.
logger.Debug("user change avatar fly cloak, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarWearFlycloakReq)
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.AvatarWearFlycloakRsp, player, &proto.AvatarWearFlycloakRsp{})
return
}
// 确保角色存在
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
@@ -44,6 +52,7 @@ func (g *GameManager) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.
return
}
// 确保要更换的风之翼已获得
exist := false
for _, v := range player.FlyCloakList {
if v == req.FlycloakId {
@@ -59,9 +68,6 @@ func (g *GameManager) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.
// 设置角色风之翼
avatar.FlyCloak = req.FlycloakId
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
avatarFlycloakChangeNotify := &proto.AvatarFlycloakChangeNotify{
AvatarGuid: req.AvatarGuid,
FlycloakId: req.FlycloakId,

View File

@@ -81,6 +81,10 @@ func (g *GameManager) TeleportPlayer(player *model.Player, enterReason uint16, s
player.SceneJump = jumpScene
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
oldScene := world.GetSceneById(oldSceneId)
if oldScene == nil {
logger.Error("old scene is nil, sceneId: %v", oldSceneId)
return
}
activeAvatarId := world.GetPlayerActiveAvatarId(player)
g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)})
if jumpScene {
@@ -90,6 +94,10 @@ func (g *GameManager) TeleportPlayer(player *model.Player, enterReason uint16, s
oldScene.RemovePlayer(player)
player.SceneId = newSceneId
newScene := world.GetSceneById(newSceneId)
if newScene == nil {
logger.Error("new scene is nil, sceneId: %v", newSceneId)
return
}
newScene.AddPlayer(player)
}
player.SceneLoadState = model.SceneNone

View File

@@ -400,6 +400,10 @@ func (g *GameManager) UserWorldRemovePlayer(world *World, player *model.Player)
}
}
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
// 仅仅把当前的场上角色的实体消失掉
activeAvatarId := world.GetPlayerActiveAvatarId(player)

View File

@@ -43,6 +43,10 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
logger.Debug("user scene init finish, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
serverTimeNotify := &proto.ServerTimeNotify{
ServerTime: uint64(time.Now().UnixMilli()),
@@ -240,6 +244,10 @@ func (g *GameManager) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Mess
logger.Debug("user enter scene done, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
if world.GetMultiplayer() && world.IsPlayerFirstEnter(player) {
guestPostEnterSceneNotify := &proto.GuestPostEnterSceneNotify{
@@ -323,6 +331,10 @@ func (g *GameManager) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Mess
gameTime := req.GameTime
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
scene.ChangeGameTime(gameTime)
for _, scenePlayer := range scene.GetAllPlayer() {
@@ -412,6 +424,10 @@ func (g *GameManager) CreateConfigEntity(scene *Scene, objectId int64, entityCon
func (g *GameManager) PacketPlayerEnterSceneNotifyLogin(player *model.Player, enterType proto.EnterType) *proto.PlayerEnterSceneNotify {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return new(proto.PlayerEnterSceneNotify)
}
player.EnterSceneToken = uint32(random.GetRandomInt32(5000, 50000))
playerEnterSceneNotify := &proto.PlayerEnterSceneNotify{
SceneId: player.SceneId,
@@ -460,6 +476,10 @@ func (g *GameManager) PacketPlayerEnterSceneNotifyMp(
) *proto.PlayerEnterSceneNotify {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return new(proto.PlayerEnterSceneNotify)
}
player.EnterSceneToken = uint32(random.GetRandomInt32(5000, 50000))
playerEnterSceneNotify := &proto.PlayerEnterSceneNotify{
PrevSceneId: prevSceneId,
@@ -538,6 +558,10 @@ func (g *GameManager) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType
func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType proto.VisionType, entityIdList []uint32, broadcast bool, aec bool) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
// 如果总数量太多则分包发送
times := int(math.Ceil(float64(len(entityIdList)) / float64(ENTITY_MAX_BATCH_SEND_NUM)))
for i := 0; i < times; i++ {

View File

@@ -293,6 +293,10 @@ func (g *GameManager) SkillStartStamina(player *model.Player, casterId uint32, s
func (g *GameManager) VehicleRestoreStaminaHandler(player *model.Player) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
// 玩家暂停状态不更新耐力
if player.Pause {
@@ -323,6 +327,10 @@ func (g *GameManager) VehicleRestoreStaminaHandler(player *model.Player) {
func (g *GameManager) SustainStaminaHandler(player *model.Player) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
// 玩家暂停状态不更新耐力
if player.Pause {
return
@@ -460,6 +468,10 @@ func (g *GameManager) DrownBackHandler(player *model.Player) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
activeAvatar := world.GetPlayerWorldAvatar(player, world.GetPlayerActiveAvatarId(player))
avatarEntity := scene.GetEntity(activeAvatar.GetAvatarEntityId())
if avatarEntity == nil {
@@ -525,6 +537,10 @@ func (g *GameManager) HandleDrown(player *model.Player, stamina uint32) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
activeAvatar := world.GetPlayerWorldAvatar(player, world.GetPlayerActiveAvatarId(player))
avatarEntity := scene.GetEntity(activeAvatar.GetAvatarEntityId())
if avatarEntity == nil {

View File

@@ -18,6 +18,10 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
targetAvatarGuid := req.Guid
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
targetAvatarId := player.GetAvatarIdByGuid(targetAvatarGuid)
oldAvatarId := world.GetPlayerActiveAvatarId(player)
if targetAvatarId == oldAvatarId {
@@ -211,6 +215,10 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
continue
}
worldPlayerScene := world.GetSceneById(worldPlayer.SceneId)
if worldPlayerScene == nil {
logger.Error("scene is nil, sceneId: %v", worldPlayer.SceneId)
return new(proto.SceneTeamUpdateNotify)
}
worldPlayerAvatar := worldPlayer.AvatarMap[worldAvatar.GetAvatarId()]
equipIdList := make([]uint32, 0)
weapon := worldPlayerAvatar.EquipWeapon

View File

@@ -15,6 +15,10 @@ import (
func (g *GameManager) VehicleDestroyMotion(player *model.Player, entity *Entity, state proto.MotionState) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
// 状态等于 MOTION_STATE_DESTROY_VEHICLE 代表请求销毁
if state == proto.MotionState_MOTION_DESTROY_VEHICLE {
@@ -29,6 +33,11 @@ func (g *GameManager) CreateVehicleReq(player *model.Player, payloadMsg pb.Messa
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.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
// 创建载具冷却时间
createVehicleCd := int64(5000) // TODO 冷却时间读取配置表
@@ -190,6 +199,11 @@ func (g *GameManager) VehicleInteractReq(player *model.Player, payloadMsg pb.Mes
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.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
// 获取载具实体
entity := scene.GetEntity(req.EntityId)

View File

@@ -1,6 +1,7 @@
package game
import (
"hk4e/pkg/logger"
"image"
"image/color"
"image/jpeg"
@@ -223,6 +224,10 @@ func (g *GameManager) VideoPlayerUpdate(rgb bool) {
}
world := WORLD_MANAGER.GetAiWorld()
scene := world.GetSceneById(3)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", 3)
return
}
for _, v := range SCREEN_ENTITY_ID_LIST {
scene.DestroyEntity(v)
}

View File

@@ -340,6 +340,10 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
}
}
scene := w.GetSceneById(sceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", sceneId)
return
}
scene.AddPlayer(player)
w.InitPlayerTeamEntityId(player)
}
@@ -459,6 +463,10 @@ func (w *World) GetWorldAvatarByEntityId(avatarEntityId uint32) *WorldAvatar {
// InitPlayerWorldAvatar 初始化某玩家在世界队伍中的所有角色
func (w *World) InitPlayerWorldAvatar(player *model.Player) {
scene := w.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
for _, worldAvatar := range w.GetWorldAvatarList() {
if worldAvatar.uid != player.PlayerID {
continue