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);
        }
Exemplo n.º 2
0
        public void LoadData(int resId)
        {
            SetLinkId(resId);
            m_LevelupConfig = PlayerConfigProvider.Instance.GetPlayerLevelupConfigById(resId);
            Data_PlayerConfig playerData = PlayerConfigProvider.Instance.GetPlayerConfigById(resId);

            if (null != playerData)
            {
                SetName(playerData.m_Name);
                SetModel(playerData.m_Model);
                SetActionList(playerData.m_ActionList);

                m_AiEquipment      = playerData.m_AiEquipment;
                m_AiAttackSkill    = playerData.m_AiAttackSkill;
                m_AiMoveSkill      = playerData.m_AiMoveSkill;
                m_AiControlSkill   = playerData.m_AiControlSkill;
                m_AiSelfAssitSkill = playerData.m_AiSelfAssitSkill;
                m_AiTeamAssitSkill = playerData.m_AiTeamAssitSkill;
                ///
                GetAiStateInfo().AiLogic = playerData.m_AiLogic;

                m_Scale         = playerData.m_Scale;
                AvoidanceRadius = playerData.m_AvoidanceRadius;
                Shape           = new Circle(new Vector3(0, 0, 0), playerData.m_Radius);

                ViewRange           = playerData.m_ViewRange;
                ReleaseTime         = playerData.m_ReleaseTime;
                HeadUiPos           = playerData.m_HeadUiPos;
                CostType            = playerData.m_CostType;
                ShootBuffLifeTime   = playerData.m_ShootBuffLifeTime;
                NoGunRunEnterTimeMs = playerData.m_NoGunRunEnterTimeMs;

                int   hp                = (int)playerData.m_AttrData.GetAddHpMax(0, 0);
                int   energy            = (int)playerData.m_AttrData.GetAddNpMax(0, 0);
                int   energyCore        = (int)playerData.m_AttrData.GetAddEpMax(0, 0);
                float moveSpeed         = playerData.m_AttrData.GetAddSpd(0, 0);
                int   hpMax             = (int)playerData.m_AttrData.GetAddHpMax(0, 0);
                int   energyMax         = (int)playerData.m_AttrData.GetAddNpMax(0, 0);
                int   energyCoreMax     = (int)playerData.m_AttrData.GetAddEpMax(0, 0);
                int   crgMax            = (int)playerData.m_AttrData.GetAddCrgMax(0, 0);
                float hpRecover         = playerData.m_AttrData.GetAddHpRecover(0, 0);
                float energyRecover     = playerData.m_AttrData.GetAddNpRecover(0, 0);
                float energyCoreRecover = playerData.m_AttrData.GetAddEpRecover(0, 0);
                int   attackBase        = (int)playerData.m_AttrData.GetAddAd(0, 0);
                int   defenceBase       = (int)playerData.m_AttrData.GetAddDp(0, 0);
                float critical          = playerData.m_AttrData.GetAddCri(0, 0);
                float criticalPow       = playerData.m_AttrData.GetAddPow(0, 0);
                float armorPenetration  = playerData.m_AttrData.GetAddAndp(0, 0);
                float energyIntensity   = playerData.m_AttrData.GetAddAp(0, 0);
                float energyArmor       = playerData.m_AttrData.GetAddTay(0, 0);
                float attackRange       = playerData.m_AttrData.GetAddRange(0, 0);

                m_MuzzlePos = playerData.m_GunEndRelativePos;

                GetBaseProperty().SetMoveSpeed(Operate_Type.OT_Absolute, moveSpeed);
                GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, hpMax);
                GetBaseProperty().SetRageMax(Operate_Type.OT_Absolute, (int)playerData.m_AttrData.GetAddRageMax(0, 0));
                GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, energyMax);
                GetBaseProperty().SetEnergyCoreMax(Operate_Type.OT_Absolute, energyCoreMax);
                GetBaseProperty().SetCrgMax(Operate_Type.OT_Absolute, crgMax);
                GetBaseProperty().SetHpRecover(Operate_Type.OT_Absolute, hpRecover);
                GetBaseProperty().SetEnergyRecover(Operate_Type.OT_Absolute, energyRecover);
                GetBaseProperty().SetEnergyCoreRecover(Operate_Type.OT_Absolute, energyCoreRecover);
                GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, attackBase);
                GetBaseProperty().SetDefenceBase(Operate_Type.OT_Absolute, defenceBase);
                GetBaseProperty().SetCritical(Operate_Type.OT_Absolute, critical);
                GetBaseProperty().SetCriticalPow(Operate_Type.OT_Absolute, criticalPow);
                GetBaseProperty().SetArmorPenetration(Operate_Type.OT_Absolute, armorPenetration);
                GetBaseProperty().SetEnergyIntensity(Operate_Type.OT_Absolute, energyIntensity);
                GetBaseProperty().SetEnergyArmor(Operate_Type.OT_Absolute, energyArmor);
                GetBaseProperty().SetAttackRange(Operate_Type.OT_Absolute, attackRange);

                // 技能数据
                for (int i = 0; i < 4; i++)
                {
                    GetSkillStateInfo().AddSkill(i, new SkillInfo(i + 1));
                }
                GetSkillStateInfo().AddSkill(4, new SkillInfo(playerData.m_RollSkill));

                // 武器数据
                for (int i = 0; i < playerData.m_WeaponList.Count; ++i)
                {
                    WeaponInfo      weaponInfo = new WeaponInfo(playerData.m_WeaponList[i]);
                    WeaponLogicData weaponData = weaponInfo.ConfigData;
                    if (null != weaponData)
                    {
                        GetShootStateInfo().AddWeapon(i, weaponInfo);
                        if (null == GetShootStateInfo().GetCurWeaponInfo())
                        {
                            GetShootStateInfo().SetCurWeaponInfo(weaponInfo.WeaponId);
                            GetShootStateInfo().CurrentWeaponIndex = i;
                        }
                        //todo:先按武器表里的武器配置上,后续需要从db里读取升级数据并初始化升级配置数据
                        EquipmentDataInfo equipDataInfo = new EquipmentDataInfo();
                        equipDataInfo.EquipmentConfig = EquipmentConfigProvider.Instance.GetEquipmentConfigById(weaponData.m_EquipmentId);
                        GetEquipmentStateInfo().EquipmentInfo.Weapons[i] = equipDataInfo;
                    }
                }

                //装备数据
                for (int i = 0; i < ShopEquipmentsId.Length; ++i)
                {
                    ShopEquipmentsId[i] = -1;
                }
                UserAttrCalculator.Calc(this);
                SetHp(Operate_Type.OT_Absolute, GetActualProperty().HpMax);
                SetRage(Operate_Type.OT_Absolute, 0);
                SetEnergy(Operate_Type.OT_Absolute, GetActualProperty().EnergyMax);
                SetEnergyCore(Operate_Type.OT_Absolute, GetActualProperty().EnergyCoreMax);
                for (int i = 0; i < playerData.m_WeaponList.Count; ++i)
                {
                    WeaponInfo      weaponInfo = GetShootStateInfo().GetWeaponInfoById(playerData.m_WeaponList[i]);
                    WeaponLogicData weaponData = weaponInfo.ConfigData;
                    if (null != weaponData)
                    {
                        //暴击数值
                        float CRIRATE_   = (float)(GetActualProperty().Critical / 480.0);
                        float CRIRATE_C_ = CriticalConfigProvider.Instance.GetC(CRIRATE_);
                        weaponInfo.CurCritical = CRIRATE_C_;
                    }
                }
            }
        }