多人世界队伍

This commit is contained in:
huangxiaolei
2022-12-09 02:01:25 +08:00
parent 3615ad194a
commit 5e8d457344
7 changed files with 325 additions and 58 deletions

View File

@@ -87,9 +87,8 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
}
avatarGuidList := req.AvatarTeamGuidList
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
multiTeam := teamId == 4
selfTeam := teamId == uint32(player.TeamConfig.GetActiveTeamId())
if (multiTeam && len(avatarGuidList) == 0) || (selfTeam && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 || world.multiplayer {
if (selfTeam && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 || world.multiplayer {
setUpAvatarTeamRsp := &proto.SetUpAvatarTeamRsp{
Retcode: int32(proto.Retcode_RETCODE_RET_SVR_ERROR),
}
@@ -204,6 +203,7 @@ func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb
func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change mp team, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
currAvatarGuid := req.CurAvatarGuid
avatarGuidList := req.AvatarGuidList
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -214,38 +214,42 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
g.SendMsg(cmd.ChangeMpTeamAvatarRsp, player.PlayerID, player.ClientSeq, changeMpTeamAvatarRsp)
return
}
avatarIdList := make([]uint32, 0)
for _, avatarGuid := range avatarGuidList {
for avatarId, avatar := range player.AvatarMap {
if avatarGuid == avatar.Guid {
avatarIdList = append(avatarIdList, avatarId)
}
avatarId := player.GetAvatarIdByGuid(avatarGuid)
avatarIdList = append(avatarIdList, avatarId)
}
world.SetPlayerLocalTeam(player, avatarIdList)
currAvatarId := player.GetAvatarIdByGuid(currAvatarGuid)
localTeam := world.multiplayerTeam.localTeamMap[player.PlayerID]
avatarIndex := 0
for index, worldTeamAvatar := range localTeam {
if worldTeamAvatar.avatarId == 0 {
continue
}
if worldTeamAvatar.avatarId == currAvatarId {
avatarIndex = index
}
}
player.TeamConfig.ClearTeamAvatar(3)
for _, avatarId := range avatarIdList {
player.TeamConfig.AddAvatarToTeam(avatarId, 3)
}
player.TeamConfig.CurrAvatarIndex = 0
player.TeamConfig.UpdateTeam()
world.SetPlayerLocalAvatarIndex(player, avatarIndex)
world.UpdateMultiplayerTeam()
scene := world.GetSceneById(player.SceneId)
scene.UpdatePlayerTeamEntity(player)
for _, worldPlayer := range world.playerMap {
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotifyMp(world)
g.SendMsg(cmd.SceneTeamUpdateNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTeamUpdateNotify)
}
avatarId := world.GetPlayerActiveAvatarId(player)
avatar := player.AvatarMap[avatarId]
changeMpTeamAvatarRsp := &proto.ChangeMpTeamAvatarRsp{
CurAvatarGuid: player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Guid,
AvatarGuidList: make([]uint64, 0),
}
team := player.TeamConfig.GetTeamByIndex(3)
for _, avatarId := range team.AvatarIdList {
if avatarId == 0 {
break
}
changeMpTeamAvatarRsp.AvatarGuidList = append(changeMpTeamAvatarRsp.AvatarGuidList, player.AvatarMap[avatarId].Guid)
CurAvatarGuid: avatar.Guid,
AvatarGuidList: req.AvatarGuidList,
}
g.SendMsg(cmd.ChangeMpTeamAvatarRsp, player.PlayerID, player.ClientSeq, changeMpTeamAvatarRsp)
}
@@ -352,3 +356,104 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
}
return sceneTeamUpdateNotify
}
func (g *GameManager) PacketSceneTeamUpdateNotifyMp(world *World) *proto.SceneTeamUpdateNotify {
sceneTeamUpdateNotify := &proto.SceneTeamUpdateNotify{
IsInMp: world.multiplayer,
}
empty := new(proto.AbilitySyncStateInfo)
for _, worldTeamAvatar := range world.multiplayerTeam.worldTeam {
if worldTeamAvatar.avatarId == 0 {
continue
}
worldPlayer := USER_MANAGER.GetOnlineUser(worldTeamAvatar.uid)
worldPlayerScene := world.GetSceneById(worldPlayer.SceneId)
worldPlayerTeamEntity := worldPlayerScene.GetPlayerTeamEntity(worldPlayer.PlayerID)
worldPlayerAvatar := worldPlayer.AvatarMap[worldTeamAvatar.avatarId]
equipIdList := make([]uint32, 0)
weapon := worldPlayerAvatar.EquipWeapon
equipIdList = append(equipIdList, weapon.ItemId)
for _, reliquary := range worldPlayerAvatar.EquipReliquaryList {
equipIdList = append(equipIdList, reliquary.ItemId)
}
sceneTeamAvatar := &proto.SceneTeamAvatar{
PlayerUid: worldPlayer.PlayerID,
AvatarGuid: worldPlayerAvatar.Guid,
SceneId: worldPlayer.SceneId,
EntityId: worldPlayerTeamEntity.avatarEntityMap[worldTeamAvatar.avatarId],
SceneEntityInfo: g.PacketSceneEntityInfoAvatar(worldPlayerScene, worldPlayer, worldTeamAvatar.avatarId),
WeaponGuid: worldPlayerAvatar.EquipWeapon.Guid,
WeaponEntityId: worldPlayerTeamEntity.weaponEntityMap[worldPlayerAvatar.EquipWeapon.WeaponId],
IsPlayerCurAvatar: world.GetPlayerActiveAvatarId(worldPlayer) == worldTeamAvatar.avatarId,
IsOnScene: world.GetPlayerActiveAvatarId(worldPlayer) == worldTeamAvatar.avatarId,
AvatarAbilityInfo: empty,
WeaponAbilityInfo: empty,
AbilityControlBlock: new(proto.AbilityControlBlock),
}
if world.multiplayer {
sceneTeamAvatar.AvatarInfo = g.PacketAvatarInfo(worldPlayerAvatar)
sceneTeamAvatar.SceneAvatarInfo = g.PacketSceneAvatarInfo(worldPlayerScene, worldPlayer, worldTeamAvatar.avatarId)
}
// add AbilityControlBlock
avatarDataConfig := gdc.CONF.AvatarDataMap[int32(worldTeamAvatar.avatarId)]
acb := sceneTeamAvatar.AbilityControlBlock
embryoId := 0
// add avatar abilities
if avatarDataConfig != nil {
for _, abilityId := range avatarDataConfig.Abilities {
embryoId++
emb := &proto.AbilityEmbryo{
AbilityId: uint32(embryoId),
AbilityNameHash: uint32(abilityId),
AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
}
// add default abilities
for _, abilityId := range constant.GameConstantConst.DEFAULT_ABILITY_HASHES {
embryoId++
emb := &proto.AbilityEmbryo{
AbilityId: uint32(embryoId),
AbilityNameHash: uint32(abilityId),
AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
// add team resonances
for id := range worldPlayer.TeamConfig.TeamResonancesConfig {
embryoId++
emb := &proto.AbilityEmbryo{
AbilityId: uint32(embryoId),
AbilityNameHash: uint32(id),
AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
// add skill depot abilities
skillDepot := gdc.CONF.AvatarSkillDepotDataMap[int32(worldPlayerAvatar.SkillDepotId)]
if skillDepot != nil && len(skillDepot.Abilities) != 0 {
for _, id := range skillDepot.Abilities {
embryoId++
emb := &proto.AbilityEmbryo{
AbilityId: uint32(embryoId),
AbilityNameHash: uint32(id),
AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
}
// add equip abilities
for skill := range worldPlayerAvatar.ExtraAbilityEmbryos {
embryoId++
emb := &proto.AbilityEmbryo{
AbilityId: uint32(embryoId),
AbilityNameHash: uint32(endec.Hk4eAbilityHashCode(skill)),
AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
sceneTeamUpdateNotify.SceneTeamAvatarList = append(sceneTeamUpdateNotify.SceneTeamAvatarList, sceneTeamAvatar)
}
return sceneTeamUpdateNotify
}