예제 #1
0
 public PlayerVO(string userID, string userName, int level, VehicleVO curVehicle)
 {
     UserID     = userID ?? throw new ArgumentNullException(nameof(userID));
     UserName   = userName ?? throw new ArgumentNullException(nameof(userName));
     Level      = level;
     CurVehicle = curVehicle ?? throw new ArgumentNullException(nameof(curVehicle));
 }
예제 #2
0
        public void LoginResult(JObject jsonData)
        {
            _loginInterceptor.EndWaitResponse();
            if (jsonData == null)
            {
                throw new ArgumentNullException(nameof(jsonData));
            }

            string result = (string)jsonData.SelectToken("Paras.Result");
            string info   = (string)jsonData.SelectToken("Paras.Info");

            if (result == NotifyConsts.CommonNotification.Succeed)
            {
                //更新VO
                var userId                   = (string)jsonData.SelectToken("Paras.UserInfo.Id");
                var userName                 = (string)jsonData.SelectToken("Paras.UserInfo.UserName");
                var token                    = (string)jsonData.SelectToken("Paras.UserInfo.Token");
                var experience               = (int)jsonData.SelectToken("Paras.UserInfo.Experience");
                var money                    = (int)jsonData.SelectToken("Paras.UserInfo.Money");
                var level                    = (int)jsonData.SelectToken("Paras.UserInfo.Level");
                var curVehicleId             = (string)jsonData.SelectToken("Paras.UserInfo.CurVehicleId");
                var registerTime             = (string)jsonData.SelectToken("Paras.UserInfo.RegisterTime");
                var loginTime                = (string)jsonData.SelectToken("Paras.UserInfo.LastLoginTime");
                List <VehicleVO> vehicleList = new List <VehicleVO>();
                VehicleVO        curVehicle  = null;
                foreach (JToken jToken in jsonData.SelectTokens("Paras.UserInfo.VehicleList").Children())
                {
                    var       vehicleId        = (string)jToken.SelectToken("Id");
                    var       vehicleName      = (string)jToken.SelectToken("Name");
                    var       vehicleType      = (string)jToken.SelectToken("Type");
                    var       vehicleAttack    = (float)jToken.SelectToken("Attack");
                    var       vehicleMotility  = (float)jToken.SelectToken("Motility");
                    var       vehicleDefend    = (float)jToken.SelectToken("Defend");
                    var       vehicleMaxHealth = (int)(float)jToken.SelectToken("MaxHealth");
                    var       vehiclePrice     = (int)jToken.SelectToken("Price");
                    var       vehicleIntro     = (string)jToken.SelectToken("Intro");
                    VehicleVO vehicle          = new VehicleVO(vehicleId, vehicleName, Enum.TryParse(vehicleType, true, out VehicleType type) ? type : throw new InvalidCastException(nameof(vehicleType)), vehicleAttack, vehicleMotility, vehicleDefend, vehicleMaxHealth, vehiclePrice, vehicleIntro);
                    vehicleList.Add(vehicle);
                    if (vehicle.VehicleID == curVehicleId)
                    {
                        curVehicle = vehicle;
                    }
                }

                PlayerManager.Instance.InitLocalPlayer(userId, userName, token, level, experience, money, registerTime, loginTime, curVehicle, vehicleList);

                SendNotification(NotifyConsts.LoginNotification.LoginResult, Tuple.Create(true, info), nameof(Tuple <bool, string>));
            }
            else
            {
                SendNotification(NotifyConsts.LoginNotification.LoginResult, Tuple.Create(false, info), nameof(Tuple <bool, string>));
            }
        }