Ejemplo n.º 1
0
        internal void SyncForNewObserver(Observer observer)
        {
            if (null != observer)
            {
                Room room = GetRoom();
                if (null != room && null != room.GetActiveScene())
                {
                    //同步其他玩家数据与物品给自己
                    foreach (User other in room.RoomUsers)
                    {
                        if (!other.IsEntered)
                        {
                            continue;
                        }
                        UserInfo otherInfo = other.Info;
                        if (null != otherInfo)
                        {
                            Vector3 pos = otherInfo.GetMovementStateInfo().GetPosition3D();
                            ArkCrossEngineMessage.Position pos_bd = new ArkCrossEngineMessage.Position();
                            pos_bd.x = (float)pos.X;
                            pos_bd.z = (float)pos.Z;
                            Msg_CRC_Create bd = new Msg_CRC_Create();
                            bd.role_id        = other.RoleId;
                            bd.hero_id        = other.HeroId;
                            bd.camp_id        = other.CampId;
                            bd.role_level     = other.Level;
                            bd.is_player_self = false;
                            bd.position       = pos_bd;
                            bd.face_dirction  = (float)otherInfo.GetMovementStateInfo().GetFaceDir();
                            for (int index = 0; index < otherInfo.GetSkillStateInfo().GetAllSkill().Count; index++)
                            {
                                bd.skill_levels.Add(otherInfo.GetSkillStateInfo().GetSkillInfoByIndex(index).SkillLevel);
                            }
                            bd.scene_start_time = StartTime;
                            bd.nickname         = other.Name;
                            observer.SendMessage(bd);

                            DataSyncUtility.SyncBuffListToObserver(otherInfo, observer);

                            Msg_RC_SyncProperty propBuilder = DataSyncUtility.BuildSyncPropertyMessage(otherInfo);
                            observer.SendMessage(propBuilder);

                            Msg_RC_SyncCombatStatisticInfo combatBuilder = DataSyncUtility.BuildSyncCombatStatisticInfo(otherInfo);
                            observer.SendMessage(combatBuilder);

                            LogSys.Log(LOG_TYPE.DEBUG, "send user {0} msg to observer {1}", other.RoleId, observer.Guid);
                        }
                    }
                    //同步场景数据给观察者
                    for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
                    {
                        NpcInfo npc = linkNode.Value;
                        if (null != npc)
                        {
                            Msg_RC_CreateNpc bder = DataSyncUtility.BuildCreateNpcMessage(npc);
                            observer.SendMessage(bder);
                        }
                    }

                    int totalKillCountForBlue = 0;
                    int totalKillCountForRed  = 0;
                    for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
                    {
                        UserInfo user_info = linkNode.Value;
                        if (user_info.GetCampId() == (int)CampIdEnum.Blue)
                        {
                            totalKillCountForBlue += user_info.GetCombatStatisticInfo().KillHeroCount;
                        }
                        else
                        {
                            totalKillCountForRed += user_info.GetCombatStatisticInfo().KillHeroCount;
                        }
                    }

                    Msg_RC_PvpCombatInfo combat_bd = new Msg_RC_PvpCombatInfo();
                    combat_bd.kill_hero_count_for_blue = totalKillCountForBlue;
                    combat_bd.kill_hero_count_for_red  = totalKillCountForRed;
                    combat_bd.link_id_for_killer       = -1;
                    combat_bd.link_id_for_killed       = -1;
                    combat_bd.killed_nickname          = "";
                    combat_bd.killer_nickname          = "";
                    observer.SendMessage(combat_bd);
                }
            }
        }