mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-17 10:02:25 +08:00
实现跨服加入世界&玩家跨服在线迁移功能(部分完成)
This commit is contained in:
@@ -3,6 +3,7 @@ package game
|
||||
import (
|
||||
"time"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/logger"
|
||||
@@ -77,31 +78,6 @@ func (g *GameManager) ClientTimeNotify(userId uint32, clientTime uint32) {
|
||||
player.ClientTime = clientTime
|
||||
}
|
||||
|
||||
func (g *GameManager) FightServerSelectNotify(userId uint32, fightAppId string) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
logger.Debug("fight server select notify, uid: %v, fightAppId: %v", userId, fightAppId)
|
||||
player.FightAppId = fightAppId
|
||||
// 创建世界
|
||||
world := WORLD_MANAGER.CreateWorld(player)
|
||||
GAME_MANAGER.messageQueue.SendToFight(fightAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeFight,
|
||||
EventId: mq.AddFightRoutine,
|
||||
FightMsg: &mq.FightMsg{
|
||||
FightRoutineId: world.id,
|
||||
GateServerAppId: player.GateAppId,
|
||||
},
|
||||
})
|
||||
world.AddPlayer(player, player.SceneId)
|
||||
player.WorldId = world.id
|
||||
// 进入场景
|
||||
player.SceneLoadState = model.SceneNone
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, userId, player.ClientSeq, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_SELF))
|
||||
}
|
||||
|
||||
func (g *GameManager) ServerAnnounceNotify(announceId uint32, announceMsg string) {
|
||||
for _, onlinePlayer := range USER_MANAGER.GetAllOnlineUserList() {
|
||||
now := uint32(time.Now().Unix())
|
||||
@@ -146,3 +122,84 @@ func (g *GameManager) SetEntityClientDataNotify(player *model.Player, payloadMsg
|
||||
ntf := payloadMsg.(*proto.SetEntityClientDataNotify)
|
||||
g.SendMsg(cmd.SetEntityClientDataNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
func (g *GameManager) ServerAppidBindNotify(userId uint32, fightAppId string, joinHostUserId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
if joinHostUserId != 0 {
|
||||
hostPlayer := USER_MANAGER.GetOnlineUser(joinHostUserId)
|
||||
g.HostEnterMpWorld(hostPlayer, player.PlayerID)
|
||||
g.JoinOtherWorld(player, hostPlayer)
|
||||
return
|
||||
}
|
||||
logger.Debug("server appid bind notify, uid: %v, fightAppId: %v", userId, fightAppId)
|
||||
player.FightAppId = fightAppId
|
||||
// 创建世界
|
||||
world := WORLD_MANAGER.CreateWorld(player)
|
||||
GAME_MANAGER.messageQueue.SendToFight(fightAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeFight,
|
||||
EventId: mq.AddFightRoutine,
|
||||
FightMsg: &mq.FightMsg{
|
||||
FightRoutineId: world.id,
|
||||
GateServerAppId: player.GateAppId,
|
||||
},
|
||||
})
|
||||
world.AddPlayer(player, player.SceneId)
|
||||
player.WorldId = world.id
|
||||
// 进入场景
|
||||
player.SceneLoadState = model.SceneNone
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, userId, player.ClientSeq, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_SELF))
|
||||
}
|
||||
|
||||
func (g *GameManager) ServerGetUserBaseInfoReq(userBaseInfo *mq.UserBaseInfo, gsAppId string) {
|
||||
player := USER_MANAGER.GetOnlineUser(userBaseInfo.UserId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userBaseInfo.UserId)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerGetUserBaseInfoRsp,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
UserBaseInfo: &mq.UserBaseInfo{
|
||||
OriginInfo: userBaseInfo.OriginInfo,
|
||||
UserId: player.PlayerID,
|
||||
Nickname: player.NickName,
|
||||
PlayerLevel: player.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_LEVEL],
|
||||
MpSettingType: uint8(player.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_MP_SETTING_TYPE]),
|
||||
NameCardId: player.NameCard,
|
||||
Signature: player.Signature,
|
||||
HeadImageId: player.HeadImage,
|
||||
WorldPlayerNum: uint32(world.GetWorldPlayerNum()),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GameManager) ServerGetUserBaseInfoRsp(userBaseInfo *mq.UserBaseInfo) {
|
||||
switch userBaseInfo.OriginInfo.CmdName {
|
||||
case "GetOnlinePlayerInfoReq":
|
||||
player := USER_MANAGER.GetOnlineUser(userBaseInfo.OriginInfo.UserId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userBaseInfo.OriginInfo.UserId)
|
||||
return
|
||||
}
|
||||
g.SendMsg(cmd.GetOnlinePlayerInfoRsp, player.PlayerID, player.ClientSeq, &proto.GetOnlinePlayerInfoRsp{
|
||||
TargetUid: userBaseInfo.UserId,
|
||||
TargetPlayerInfo: &proto.OnlinePlayerInfo{
|
||||
Uid: userBaseInfo.UserId,
|
||||
Nickname: userBaseInfo.Nickname,
|
||||
PlayerLevel: userBaseInfo.PlayerLevel,
|
||||
MpSettingType: proto.MpSettingType(userBaseInfo.MpSettingType),
|
||||
NameCardId: userBaseInfo.NameCardId,
|
||||
Signature: userBaseInfo.Signature,
|
||||
ProfilePicture: &proto.ProfilePicture{AvatarId: userBaseInfo.HeadImageId},
|
||||
CurPlayerNumInWorld: userBaseInfo.WorldPlayerNum,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user