Exemplo n.º 1
0
        internal bool AddNewUser(User newUser)
        {
            foreach (User us in room_users_)
            {
                if (us != null && us.Guid == newUser.Guid)
                {
                    //当前玩家已在游戏房间内
                    LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                               cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                    LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                    user_pool_.FreeUser(newUser.LocalID);
                    return(true);
                }
            }
            can_close_time_       = 0;
            newUser.EnterRoomTime = TimeUtility.GetServerMilliseconds();
            newUser.OwnRoom       = this;
            newUser.RegisterObservers(room_observers_);
            newUser.Info = m_UserMgr.AddUser(newUser.HeroId);
            newUser.Info.SetUnitId(GlobalVariables.GetUnitIdByCampId(newUser.CampId));
            newUser.Info.SetCampId(newUser.CampId);
            newUser.Info.SetLevel(newUser.Level);
            if ((int)UserControlState.Ai == newUser.UserControlState)
            {
                newUser.Info.GetAiStateInfo().AiLogic = (int)AiStateLogicId.PvpUser_General;
                newUser.IsEntered = true;
            }
            if (m_ActiveScene >= 0 && m_Scenes.Count > m_ActiveScene)
            {
                Scene scene = m_Scenes[m_ActiveScene];
                scene.EnterScene(newUser.Info);
                if ((int)UserControlState.Ai == newUser.UserControlState)
                {
                    Data_Unit unit = scene.MapData.ExtractData(DataMap_Type.DT_Unit, newUser.Info.GetUnitId()) as Data_Unit;
                    if (null != unit)
                    {
                        newUser.Info.GetMovementStateInfo().SetPosition(unit.m_Pos);
                        newUser.Info.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                    }
                }
            }
            foreach (User otheruser in room_users_)
            {
                if (otheruser != null)
                {
                    otheruser.AddSameRoomUser(newUser);
                    newUser.AddSameRoomUser(otheruser);
                }
            }
            room_users_.Add(newUser);
            LogSys.Log(LOG_TYPE.DEBUG, "Add user success ! RoomID:{0} , UserGuid:{1}({2})",
                       cur_room_id_, newUser.Guid, newUser.GetKey());

            if (null != newUser.Skill && 4 == newUser.Skill.Count)
            {
                newUser.Info.GetSkillStateInfo().RemoveAllSkill();
                newUser.Info.ResetSkill();
                for (int index = 0; index < newUser.Skill.Count; index++)
                {
                    if (newUser.Skill[index].SkillId > 0)
                    {
                        SkillInfo info = new SkillInfo(newUser.Skill[index].SkillId);
                        info.SkillLevel = newUser.Skill[index].SkillLevel;
                        info.Postions.SetCurSkillSlotPos(newUser.PresetIndex, (SlotPosition)(index + 1));
                        SkillCategory cur_skill_pos = SkillCategory.kNone;
                        if ((index + 1) == (int)SlotPosition.SP_A)
                        {
                            cur_skill_pos = SkillCategory.kSkillA;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_B)
                        {
                            cur_skill_pos = SkillCategory.kSkillB;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_C)
                        {
                            cur_skill_pos = SkillCategory.kSkillC;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_D)
                        {
                            cur_skill_pos = SkillCategory.kSkillD;
                        }
                        info.ConfigData.Category = cur_skill_pos;
                        newUser.Info.GetSkillStateInfo().AddSkill(info);
                        newUser.Info.ResetSkill();
                        ///
                        AddSubSkill(newUser, info.SkillId, cur_skill_pos, info.SkillLevel);
                    }
                }
                Data_PlayerConfig playerData = PlayerConfigProvider.Instance.GetPlayerConfigById(newUser.HeroId);
                if (null != playerData && null != playerData.m_FixedSkillList &&
                    playerData.m_FixedSkillList.Count > 0)
                {
                    foreach (int skill_id in playerData.m_FixedSkillList)
                    {
                        if (null == newUser.Info.GetSkillStateInfo().GetSkillInfoById(skill_id))
                        {
                            SkillInfo info = new SkillInfo(skill_id, 1);
                            newUser.Info.GetSkillStateInfo().AddSkill(info);
                            newUser.Info.ResetSkill();
                        }
                    }
                }
            }
            if (null != newUser.Equip && newUser.Equip.Count > 0)
            {
                newUser.Info.GetEquipmentStateInfo().Reset();
                for (int index = 0; index < newUser.Equip.Count; index++)
                {
                    if (newUser.Equip[index].ItemId > 0)
                    {
                        ItemDataInfo info = new ItemDataInfo(newUser.Equip[index].ItemRandomProperty);
                        info.ItemId         = newUser.Equip[index].ItemId;
                        info.Level          = newUser.Equip[index].ItemLevel;
                        info.RandomProperty = newUser.Equip[index].ItemRandomProperty;
                        info.ItemConfig     = ItemConfigProvider.Instance.GetDataById(info.ItemId);
                        newUser.Info.GetEquipmentStateInfo().SetEquipmentData(index, info);
                    }
                }
            }
            if (null != newUser.Legacy && newUser.Legacy.Count > 0)
            {
                newUser.Info.GetLegacyStateInfo().Reset();
                for (int index = 0; index < newUser.Legacy.Count; index++)
                {
                    if (null != newUser.Legacy[index] && newUser.Legacy[index].ItemId > 0 &&
                        newUser.Legacy[index].IsUnlock)
                    {
                        ItemDataInfo info = new ItemDataInfo(newUser.Legacy[index].ItemRandomProperty);
                        info.ItemId         = newUser.Legacy[index].ItemId;
                        info.Level          = newUser.Legacy[index].ItemLevel;
                        info.RandomProperty = newUser.Legacy[index].ItemRandomProperty;
                        info.IsUnlock       = newUser.Legacy[index].IsUnlock;
                        info.ItemConfig     = ItemConfigProvider.Instance.GetDataById(info.ItemId);
                        newUser.Info.GetLegacyStateInfo().SetLegacyData(index, info);
                    }
                }
                newUser.Info.GetLegacyStateInfo().UpdateLegacyComplexAttr();
            }
            if (null != newUser.Partner)
            {
                newUser.Info.SetPartnerInfo(newUser.Partner);
            }
            return(true);
        }