public void ChangePrepareStateResult(JObject jsonData) { 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) { string playerId = (string)jsonData.SelectToken("Paras.PlayerId"); bool prepareState = (bool)jsonData.SelectToken("Paras.PrepareState"); if (playerId == _localPlayer.UserID) { _changePrepareStateInterceptor.EndWaitResponse(); } PlayerManager.Instance.GetPlayer(playerId).PrepareState = prepareState; SendNotification(NotifyConsts.RoomNotification.ChangePrepareStateResult, Tuple.Create <bool, string, string, bool>(true, info, playerId, prepareState), null); } else { _changePrepareStateInterceptor.EndWaitResponse(); SendNotification(NotifyConsts.RoomNotification.ChangePrepareStateResult, Tuple.Create <bool, string, string, bool>(false, info, null, false), null); } }
public void RefreshRoomListResult(JObject jsonData) { _refreshRoomListInterceptor.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) { List <RoomVO> roomList = new List <RoomVO>(); foreach (JToken jToken in jsonData.SelectTokens("Paras.RoomList").Children()) { var roomId = (string)jToken.SelectToken("RoomInfo.RoomId"); var roomName = (string)jToken.SelectToken("RoomInfo.RoomName"); var ownerId = (string)jToken.SelectToken("RoomInfo.OwnerId"); var ownerName = (string)jToken.SelectToken("RoomInfo.OwnerName"); var roomMode = (string)jToken.SelectToken("RoomInfo.RoomMode"); var roomMap = (string)jToken.SelectToken("RoomInfo.RoomMap"); var playerNum = (int)jToken.SelectToken("RoomInfo.PlayerNum"); RoomVO room = new RoomVO(roomId, roomName, ownerId, ownerName, Enum.TryParse(roomMode, true, out RoomMode roomModeType) ? roomModeType : throw new InvalidCastException(nameof(roomMode)), Enum.TryParse(roomMap, true, out RoomMap roomMapType) ? roomMapType : throw new InvalidCastException(nameof(roomMap)), playerNum); roomList.Add(room); } SendNotification(NotifyConsts.LobbyNotification.RefreshRoomListResult, Tuple.Create(true, info, roomList), nameof(Tuple <bool, string, List <RoomVO> >)); } else { SendNotification(NotifyConsts.LobbyNotification.RefreshRoomListResult, Tuple.Create <bool, string, List <RoomVO> >(false, info, null), nameof(Tuple <bool, string, List <RoomVO> >)); } }
public void KickPlayerResult(JObject jsonData) { if (jsonData == null) { throw new ArgumentNullException(nameof(jsonData)); } if (PlayerManager.Instance.RoomOwner.UserID == _localPlayer.UserID) { _kickPlayerInterceptor.EndWaitResponse(); } string result = (string)jsonData.SelectToken("Paras.Result"); string info = (string)jsonData.SelectToken("Paras.Info"); if (result == NotifyConsts.CommonNotification.Succeed) { string kickPlayerId = (string)jsonData.SelectToken("Paras.KickPlayerId"); if (kickPlayerId == _localPlayer.UserID) { PlayerManager.Instance.RoomOwner = null; PlayerManager.Instance.RemoveAllNetPlayer(); SendNotification(NotifyConsts.RoomNotification.KickPlayerResult, Tuple.Create <bool, string, string, List <PlayerVO> >(true, info, kickPlayerId, null), null); } else { PlayerManager.Instance.RemoveNetPlayer(kickPlayerId); var playerList = new List <PlayerVO>(); foreach (JToken jToken in jsonData.SelectTokens("Paras.RoomInfo.PlayerList").Children()) { var playerId = (string)jToken.SelectToken("PlayerId"); var playerName = (string)jToken.SelectToken("PlayerName"); var playerLevel = (string)jToken.SelectToken("PlayerLevel"); var prepareState = (bool)jToken.SelectToken("PrepareState"); //var playerTeam = (string)jToken.SelectToken("PlayerTeam"); var vehicleId = (string)jToken.SelectToken("VehicleInfo.Id"); var vehicleName = (string)jToken.SelectToken("VehicleInfo.Name"); var vehicleType = (string)jToken.SelectToken("VehicleInfo.Type"); var vehicleAttack = (float)jToken.SelectToken("VehicleInfo.Attack"); var vehicleDefend = (float)jToken.SelectToken("VehicleInfo.Defend"); var vehicleMotility = (float)jToken.SelectToken("VehicleInfo.Motility"); var vehicleMaxHealth = (float)jToken.SelectToken("VehicleInfo.MaxHealth"); var vehicle = new VehicleVO(vehicleId, vehicleName, Enum.TryParse(vehicleType, true, out VehicleType vt) ? vt : throw new InvalidCastException(nameof(vehicleType)), vehicleAttack, vehicleMotility, vehicleDefend, (int)vehicleMaxHealth, 0, null); var player = new PlayerVO(playerId, playerName, int.Parse(playerLevel), vehicle) { PrepareState = prepareState, //Team = Enum.TryParse(playerTeam, true, out Team team) ? team : throw new InvalidCastException(nameof(playerTeam)) }; playerList.Add(player); //用于界面显示 } SendNotification(NotifyConsts.RoomNotification.KickPlayerResult, Tuple.Create <bool, string, string, List <PlayerVO> >(true, info, kickPlayerId, playerList), null); } } else { SendNotification(NotifyConsts.RoomNotification.KickPlayerResult, Tuple.Create <bool, string, string, List <PlayerVO> >(false, info, null, null), null); } }
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>)); } }
public void StartGameResult(JObject jsonData) { _startGameInterceptor.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) { SendNotification(NotifyConsts.RoomNotification.StartGameResult, Tuple.Create(true, info), null); } else { SendNotification(NotifyConsts.RoomNotification.StartGameResult, Tuple.Create(false, info), null); } }
public void ChangePasswordResult(JObject jsonData) { _changePwdInterceptor.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) { PlayerManager.Instance.RemoveAllPlayer(); SendNotification(NotifyConsts.MainMenuNotification.ChangePasswordResult, Tuple.Create(true, info), nameof(Tuple <bool, string>)); } else { SendNotification(NotifyConsts.MainMenuNotification.ChangePasswordResult, Tuple.Create(false, info), nameof(Tuple <bool, string>)); } }
public void LogoutResult(JObject jsonData) { _logoutInterceptor.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) { bool normalLogout = (bool)jsonData.SelectToken("Paras.NormalLogout"); PlayerManager.Instance.RemoveAllPlayer(); SendNotification(NotifyConsts.LoginNotification.LogoutResult, Tuple.Create(true, info, normalLogout), nameof(Tuple <bool, string>)); } else { SendNotification(NotifyConsts.LoginNotification.LogoutResult, Tuple.Create(false, info, false), nameof(Tuple <bool, string>)); } }
public void CreateRoomResult(JObject jsonData) { _createRoomInterceptor.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) { var roomId = (string)jsonData.SelectToken("Paras.RoomInfo.RoomId"); var roomName = (string)jsonData.SelectToken("Paras.RoomInfo.RoomName"); var ownerId = (string)jsonData.SelectToken("Paras.RoomInfo.OwnerId"); var ownerName = (string)jsonData.SelectToken("Paras.RoomInfo.OwnerName"); var roomMode = (string)jsonData.SelectToken("Paras.RoomInfo.RoomMode"); var roomMap = (string)jsonData.SelectToken("Paras.RoomInfo.RoomMap"); var playerNum = (int)jsonData.SelectToken("Paras.RoomInfo.PlayerNum"); var room = new RoomVO(roomId, roomName, ownerId, ownerName, Enum.TryParse(roomMode, true, out RoomMode roomModeType) ? roomModeType : throw new InvalidCastException(nameof(roomMode)), Enum.TryParse(roomMap, true, out RoomMap roomMapType) ? roomMapType : throw new InvalidCastException(nameof(roomMap)), playerNum); var playerList = new List <PlayerVO> { PlayerManager.Instance.LocalPlayer }; room.PlayerList = playerList; PlayerManager.Instance.RoomOwner = PlayerManager.Instance.LocalPlayer; SendNotification(NotifyConsts.LobbyNotification.CreateRoomResult, Tuple.Create(true, info), nameof(Tuple <bool, string>)); SendNotification(NotifyConsts.RoomNotification.InitRoomInfo, room, nameof(RoomVO)); } else { SendNotification(NotifyConsts.LobbyNotification.CreateRoomResult, Tuple.Create(false, info), nameof(Tuple <bool, string>)); } }
public void ChangeVehicleResult(JObject jsonData) { _changeVehicleInterceptor.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) { var curVehicleId = (string)jsonData.SelectToken("Paras.UserInfo.CurVehicleId"); _localPlayer.CurVehicle = _localPlayer.FindVehicle(curVehicleId); SendNotification(NotifyConsts.GarageNotification.ChangeVehicleResult, Tuple.Create(true, info, curVehicleId), nameof(Tuple <bool, string, string>)); SendNotification(NotifyConsts.MainMenuNotification.UpdateUserInfo, _localPlayer, nameof(LocalPlayerVO)); } else { SendNotification(NotifyConsts.GarageNotification.ChangeVehicleResult, Tuple.Create <bool, string, string>(false, info, null), nameof(Tuple <bool, string, string>)); } }
public void PurchaseItemResult(JObject jsonData) { _purchaseInterceptor.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) { var userMoney = (int)jsonData.SelectToken("Paras.UserInfo.Money"); _localPlayer.Money = userMoney; var vehicleId = (string)jsonData.SelectToken("Paras.VehicleInfo.Id"); var vehicleName = (string)jsonData.SelectToken("Paras.VehicleInfo.Name"); var vehicleType = (string)jsonData.SelectToken("Paras.VehicleInfo.Type"); var vehicleAttack = (float)jsonData.SelectToken("Paras.VehicleInfo.Attack"); var vehicleMotility = (float)jsonData.SelectToken("Paras.VehicleInfo.Motility"); var vehicleDefend = (float)jsonData.SelectToken("Paras.VehicleInfo.Defend"); var vehicleMaxHealth = (int)(float)jsonData.SelectToken("Paras.VehicleInfo.MaxHealth"); var vehiclePrice = (int)jsonData.SelectToken("Paras.VehicleInfo.Price"); var vehicleIntro = (string)jsonData.SelectToken("Paras.VehicleInfo.Intro"); var vehicle = new VehicleVO(vehicleId, vehicleName, Enum.TryParse(vehicleType, true, out VehicleType type) ? type : throw new InvalidCastException(nameof(vehicleType)), vehicleAttack, vehicleMotility, vehicleDefend, vehicleMaxHealth, vehiclePrice, vehicleIntro); _localPlayer.VehicleList.Add(vehicle); SendNotification(NotifyConsts.StoreNotification.PurchaseItemResult, Tuple.Create(true, info, vehicle), nameof(Tuple <bool, string, VehicleVO>)); SendNotification(NotifyConsts.MainMenuNotification.UpdateUserInfo, _localPlayer, nameof(LocalPlayerVO)); } else { SendNotification(NotifyConsts.StoreNotification.PurchaseItemResult, Tuple.Create <bool, string, VehicleVO>(false, info, null), nameof(Tuple <bool, string, VehicleVO>)); } }
public void JoinRoomResult(JObject jsonData) { 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) { string joinPlayerId = (string)jsonData.SelectToken("Paras.JoinPlayerId"); if (joinPlayerId == _localPlayer.UserID) { _joinRoomInterceptor.EndWaitResponse(); var roomId = (string)jsonData.SelectToken("Paras.RoomInfo.RoomId"); var roomName = (string)jsonData.SelectToken("Paras.RoomInfo.RoomName"); var ownerId = (string)jsonData.SelectToken("Paras.RoomInfo.OwnerId"); var ownerName = (string)jsonData.SelectToken("Paras.RoomInfo.OwnerName"); var roomMode = (string)jsonData.SelectToken("Paras.RoomInfo.RoomMode"); var roomMap = (string)jsonData.SelectToken("Paras.RoomInfo.RoomMap"); var playerNum = (int)jsonData.SelectToken("Paras.RoomInfo.PlayerNum"); //获取房间信息 var room = new RoomVO(roomId, roomName, ownerId, ownerName, Enum.TryParse(roomMode, true, out RoomMode roomModeType) ? roomModeType : throw new InvalidCastException(nameof(roomMode)), Enum.TryParse(roomMap, true, out RoomMap roomMapType) ? roomMapType : throw new InvalidCastException(nameof(roomMap)), playerNum); //获取玩家列表 var playerList = new List <PlayerVO>(); foreach (JToken jToken in jsonData.SelectTokens("Paras.RoomInfo.PlayerList").Children()) { var playerId = (string)jToken.SelectToken("PlayerId"); var playerName = (string)jToken.SelectToken("PlayerName"); var playerLevel = (string)jToken.SelectToken("PlayerLevel"); var prepareState = (bool)jToken.SelectToken("PrepareState"); //var playerTeam = (string)jToken.SelectToken("PlayerTeam"); var vehicleId = (string)jToken.SelectToken("VehicleInfo.Id"); var vehicleName = (string)jToken.SelectToken("VehicleInfo.Name"); var vehicleType = (string)jToken.SelectToken("VehicleInfo.Type"); var vehicleAttack = (float)jToken.SelectToken("VehicleInfo.Attack"); var vehicleDefend = (float)jToken.SelectToken("VehicleInfo.Defend"); var vehicleMotility = (float)jToken.SelectToken("VehicleInfo.Motility"); var vehicleMaxHealth = (float)jToken.SelectToken("VehicleInfo.MaxHealth"); //获取玩家载具信息 var vehicle = new VehicleVO(vehicleId, vehicleName, Enum.TryParse(vehicleType, true, out VehicleType vt) ? vt : throw new InvalidCastException(nameof(vehicleType)), vehicleAttack, vehicleMotility, vehicleDefend, (int)vehicleMaxHealth, 0, null); //获取玩家信息 var player = new PlayerVO(playerId, playerName, int.Parse(playerLevel), vehicle) { PrepareState = prepareState, //Team = Enum.TryParse(playerTeam, true, out Team team) ? team : throw new InvalidCastException(nameof(playerTeam)) }; playerList.Add(player); //用于界面显示 if (player.UserID == ownerId) { PlayerManager.Instance.RoomOwner = player; } if (playerId != _localPlayer.UserID) { PlayerManager.Instance.AddNetPlayer(player); //用于后台玩家数据 } } room.PlayerList = playerList; SendNotification(NotifyConsts.LobbyNotification.JoinRoomResult, Tuple.Create(true, info), nameof(Tuple <bool, string>)); SendNotification(NotifyConsts.RoomNotification.InitRoomInfo, room, nameof(RoomVO)); } else { var playerList = new List <PlayerVO>(); PlayerVO joinPlayer = null; foreach (JToken jToken in jsonData.SelectTokens("Paras.RoomInfo.PlayerList").Children()) { var playerId = (string)jToken.SelectToken("PlayerId"); var playerName = (string)jToken.SelectToken("PlayerName"); var playerLevel = (string)jToken.SelectToken("PlayerLevel"); var prepareState = (bool)jToken.SelectToken("PrepareState"); //var playerTeam = (string)jToken.SelectToken("PlayerTeam"); var vehicleId = (string)jToken.SelectToken("VehicleInfo.Id"); var vehicleName = (string)jToken.SelectToken("VehicleInfo.Name"); var vehicleType = (string)jToken.SelectToken("VehicleInfo.Type"); var vehicleAttack = (float)jToken.SelectToken("VehicleInfo.Attack"); var vehicleDefend = (float)jToken.SelectToken("VehicleInfo.Defend"); var vehicleMotility = (float)jToken.SelectToken("VehicleInfo.Motility"); var vehicleMaxHealth = (float)jToken.SelectToken("VehicleInfo.MaxHealth"); var vehicle = new VehicleVO(vehicleId, vehicleName, Enum.TryParse(vehicleType, true, out VehicleType t) ? t : throw new InvalidCastException(nameof(vehicleType)), vehicleAttack, vehicleMotility, vehicleDefend, (int)vehicleMaxHealth, 0, null); var player = new PlayerVO(playerId, playerName, int.Parse(playerLevel), vehicle) { PrepareState = prepareState, //Team = Enum.TryParse(playerTeam, true, out Team team) ? team : throw new InvalidCastException(nameof(playerTeam)) }; if (player.UserID == joinPlayerId) { joinPlayer = player; } playerList.Add(player); } if (joinPlayer != null) { PlayerManager.Instance.AddNetPlayer(joinPlayer); } SendNotification(NotifyConsts.RoomNotification.NewPlayerJoinRoom, Tuple.Create(joinPlayer, playerList), nameof(Tuple <PlayerVO, List <PlayerVO> >)); } } else { _joinRoomInterceptor.EndWaitResponse(); SendNotification(NotifyConsts.LobbyNotification.JoinRoomResult, Tuple.Create(false, info), nameof(Tuple <bool, string>)); } }