public UdpSendUtils CreateConnection(BattleRoyaleClientMatchModel matchData) { if (matchData == null) { throw new Exception("Нет данных о матче. Симуляция не работает."); } int matchId = matchData.MatchId; int gameServerPort = matchData.GameServerPort; string gameServerIp = matchData.GameServerIp; IPEndPoint serverIpEndPoint = new IPEndPoint(IPAddress.Parse(gameServerIp), gameServerPort); log.Info("Установка прослушки udp."); UdpClient udpClient = new UdpClient { Client = { Blocking = false } }; udpClient.Connect(serverIpEndPoint); udpClientWrapper = new UdpClientWrapper(udpClient); UdpSendUtils udpSendUtils = new UdpSendUtils(matchId, udpClientWrapper); return(udpSendUtils); }
private IEnumerator GetMatchDataAndLoadScene(CancellationToken cancellationToken, string playerId, int currentWarshipId) { log.Info("Поиск матча..."); Task <BattleRoyaleClientMatchModel> task = matchmakerNegotiator.GetMatchDataAsync(cancellationToken, playerId, currentWarshipId); yield return(new WaitUntil(() => task.IsCompleted)); if (cancellationToken.IsCancellationRequested) { yield break; } BattleRoyaleClientMatchModel matchModel = task.Result; if (task.Result != null) { LoadBattleScene(matchModel, playerId); } else { log.Error($"{nameof(matchModel)} was null"); } }
private void Start() { BattleRoyaleClientMatchModel matchModel = matchModelStorage.GetMatchModel(); UdpSendUtils udpSendUtils = udpManager.CreateConnection(matchModel); PingStatisticsStorage pingStatisticsStorage = new PingStatisticsStorage(udpSendUtils); clientMatchSimulation = new ClientMatchSimulation(battleUiController, udpSendUtils, matchModel, pingStatisticsStorage); var playersStorage = clientMatchSimulation.GetPlayersStorage(); var transformStorage = clientMatchSimulation.GetTransformStorage(); var healthPointsStorage = clientMatchSimulation.GetHealthPointsStorage(); var maxHealthPointsMessagePackStorage = clientMatchSimulation.GetMaxHealthPointsMessagePackStorage(); IKillMessageStorage killMessageStorage = clientMatchSimulation.GetKillMessageStorage(); var messageWrapperHandler = new MessageWrapperHandler(udpSendUtils, matchModel.MatchId, transformStorage, playersStorage, healthPointsStorage, maxHealthPointsMessagePackStorage, pingStatisticsStorage, killMessageStorage); IByteArrayHandler byteArrayHandler = new ByteArrayHandler(messageWrapperHandler); udpManager.StartListening(byteArrayHandler); }
private void Awake() { //Если в прошлом бою уже был создан UdpClient udpClientWrapper?.Stop(); BattleRoyaleClientMatchModel matchData = MyMatchDataStorage.Instance.GetMatchModel(); int matchId = matchData.MatchId; int gameServerPort = matchData.GameServerPort; string gameServerIp = matchData.GameServerIp; IPEndPoint serverIpEndPoint = new IPEndPoint(IPAddress.Parse(gameServerIp), gameServerPort); UdpMediator udpMediator = new UdpMediator(); log.Info("Установка прослушки udp."); UdpClient udpClient = new UdpClient { Client = { Blocking = false } }; udpClient.Connect(serverIpEndPoint); udpClientWrapper = new BattleUdpClientWrapper(udpMediator, udpClient); udpSendUtils = new UdpSendUtils(matchId, udpClientWrapper); udpMediator.Initialize(udpSendUtils, matchId); udpClientWrapper.StartReceiveThread(); }
private static void SetMatchData(BattleRoyaleClientMatchModel matchData) { MyMatchDataStorage.Instance.SetMatchData(matchData); ushort playerTemporaryIdForOneMatch = matchData.PlayerTemporaryId; PlayerIdStorage.SetTmpPlayerId(playerTemporaryIdForOneMatch); }
private IEnumerator ShowPlayerAchievementsCoroutine() { //Достать данные из глобальных классов BattleRoyaleClientMatchModel matchModel = MatchModelStorage.Instance.GetMatchModel(); int matchId = matchModel.MatchId; if (PlayerIdStorage.TryGetServiceId(out string playerServiceId)) { if (playerServiceId == null) { throw new Exception($"{nameof(playerServiceId)} is null"); } //Загрузить данные с профиль-сервера Task <MatchResultDto> task = ExperimentalDich.GetMatchReward(matchId, playerServiceId); yield return(new WaitUntil(() => task.IsCompleted)); MatchResultDto matchResultDto = task.Result; //Если не загрузилось, перейти в лобби if (matchResultDto == null || task.IsFaulted || task.IsCanceled) { if (matchResultDto == null) { log.Error($"matchResultDto is null"); } else { PlayerAchievementsUtils.LogPlayerAchievements(matchResultDto); } if (task.IsFaulted) { log.Error($"task.IsFaulted"); } if (task.IsCanceled) { log.Error($"task.IsCanceled"); } log.Error("Не удалось загрузить результат боя игрока."); lobbyLoaderController.LoadLobbyScene(); } PlayerAchievementsUtils.LogPlayerAchievements(matchResultDto); //Показать анимацию ShowPlayerAchievements(matchResultDto); } else { log.Error($"{nameof(ShowPlayerAchievementsCoroutine)} {nameof(playerServiceId)} is null"); } }
private void LoadBattleScene(BattleRoyaleClientMatchModel gameRoomData, string playerId) { log.Info("Матч найден"); //Начать писать статистику боя NetworkStatisticsStorage.Instance.StartRecordingNewMatch(gameRoomData.MatchId, gameRoomData.PlayerTemporaryId); gameRoomData.GameServerIp = NetworkGlobals.GameServerIp; log.Info(nameof(gameRoomData.GameServerIp) + " " + gameRoomData.GameServerIp); log.Info(nameof(gameRoomData.GameServerPort) + " " + gameRoomData.GameServerPort); SetMatchData(gameRoomData); lobbySceneSwitcher.LoadSceneAsync("BattleScene"); }
public ClientMatchSimulation(BattleUiController battleUiController, UdpSendUtils udpSendUtils, BattleRoyaleClientMatchModel matchModel, PingStatisticsStorage pingStatisticsStorage) { this.battleUiController = battleUiController; this.pingStatisticsStorage = pingStatisticsStorage; if (matchModel == null) { log.Error("Симуляция матча не запущена "); return; } systems = CreateSystems(udpSendUtils, matchModel, pingStatisticsStorage); systems.ActivateReactiveSystems(); systems.Initialize(); }
public PlayerNameHelper(BattleRoyaleClientMatchModel matchModel) { this.matchModel = matchModel; }
public void SetMatchData(BattleRoyaleClientMatchModel matchModel) { matchData = matchModel; }
private readonly Dictionary <int, BattleRoyalePlayerModel> playerInfos; //accountId, account public UpdatePlayersSystem(Contexts contexts, BattleRoyaleClientMatchModel matchModel) { gameContext = contexts.serverGame; playerInfos = matchModel.PlayerModels .ToDictionary(item => item.AccountId); }
private Entitas.Systems CreateSystems(UdpSendUtils udpSendUtils, BattleRoyaleClientMatchModel matchModel, PingStatisticsStorage statisticsStorage) { GameSceneFactory gameSceneFactory = new GameSceneFactory(); var matchScene = gameSceneFactory.Create(); PhysicsSpawner physicsSpawner = new PhysicsSpawner(matchScene); contexts = Contexts.sharedInstance; var updatePlayersSystem = new UpdatePlayersSystem(contexts, matchModel); playersStorage = updatePlayersSystem; var healthUpdaterSystem = new HealthUpdaterSystem(contexts); healthPointsStorage = healthUpdaterSystem; var maxHealthUpdaterSystem = new MaxHealthUpdaterSystem(contexts); maxHealthPointsMessagePackStorage = maxHealthUpdaterSystem; Vector3 cameraShift = new Vector3(0, 60, -30); ushort playerTmpId = matchModel.PlayerTemporaryId; int matchId = matchModel.MatchId; Text pingText = battleUiController.GetPingText(); pingSystem = new PingSystem(pingText, statisticsStorage); ClientInputMessagesHistory clientInputMessagesHistory = new ClientInputMessagesHistory(playerTmpId, matchId); ClientPrefabsStorage clientPrefabsStorage = new ClientPrefabsStorage(); PhysicsVelocityManager physicsVelocityManager = new PhysicsVelocityManager(); ArrangeTransformSystem[] arrangeCollidersSystems = { new WithHpArrangeTransformSystem(contexts) }; PhysicsRollbackManager physicsRollbackManager = new PhysicsRollbackManager(arrangeCollidersSystems); PhysicsRotationManager physicsRotationManager = new PhysicsRotationManager(); SnapshotFactory snapshotFactory = new SnapshotFactory(contexts.serverGame); PlayerPredictor playerPredictor = new PlayerPredictor(physicsRollbackManager, matchScene, contexts.serverGame, physicsVelocityManager, physicsRotationManager, snapshotFactory); PlayerEntityComparer playerEntityComparer = new PlayerEntityComparer(); PredictedSnapshotsStorage predictedSnapshotsStorage = new PredictedSnapshotsStorage(); AverageInputManager averageInputManager = new AverageInputManager(); PredictionChecker predictionChecker = new PredictionChecker(playerEntityComparer, predictedSnapshotsStorage); SimulationCorrector simulationCorrector = new SimulationCorrector(playerPredictor, averageInputManager, clientInputMessagesHistory, predictedSnapshotsStorage); var predictionManager = new PredictionManager(predictionChecker, simulationCorrector); Joystick movementJoystick = battleUiController.GetMovementJoystick(); Joystick attackJoystick = battleUiController.GetAttackJoystick(); LastInputIdStorage lastInputIdStorage = new LastInputIdStorage(); SnapshotBuffer snapshotBuffer = new SnapshotBuffer(); var snapshotInterpolator = new SnapshotInterpolator(snapshotBuffer); var consoleStub = new ConsoleNetworkProblemWarningView(); NetworkTimeManager timeManager = new NetworkTimeManager(pingStatisticsStorage, snapshotBuffer, consoleStub); INetworkTimeManager networkTimeManager = timeManager; ITimeUpdater timeUpdater = timeManager; snapshotManager = new SnapshotManager(snapshotBuffer, snapshotInterpolator); transformStorage = new TransformMessageHandler(snapshotBuffer, timeUpdater); MatchTimeSystem matchTimeSystem = new MatchTimeSystem(networkTimeManager); IMatchTimeStorage matchTimeStorage = matchTimeSystem; var updateTransformSystem = new UpdateTransformSystem(contexts, snapshotManager, matchTimeStorage); SpawnManager spawnManager = new SpawnManager(clientPrefabsStorage, physicsSpawner); var killsIndicatorSystem = new KillsIndicatorSystem(battleUiController.GetKillMessage(), battleUiController.GetKillIndicator(), battleUiController.GetKillsText(), battleUiController.GetAliveText(), matchModel.PlayerModels.Length, new PlayerNameHelper(matchModel)); killMessageStorage = killsIndicatorSystem; systems = new Entitas.Systems() .Add(matchTimeSystem) .Add(new ServerGameStateDebugSystem(snapshotBuffer, clientPrefabsStorage)) .Add(new PredictionСheckSystem(snapshotBuffer, predictionManager)) .Add(updateTransformSystem) .Add(updatePlayersSystem) .Add(new PrefabSpawnerSystem(contexts, spawnManager)) .Add(new InputSystem(movementJoystick, attackJoystick, clientInputMessagesHistory, snapshotManager, matchTimeStorage, lastInputIdStorage)) .Add(new PlayerStopSystem(contexts)) .Add(new PlayerPredictionSystem(contexts, clientInputMessagesHistory, playerPredictor)) .Add(new CameraMoveSystem(contexts, battleUiController.GetMainCamera(), cameraShift)) .Add(new LoadingImageSwitcherSystem(contexts, battleUiController.GetLoadingImage())) .Add(killsIndicatorSystem) .Add(healthUpdaterSystem) .Add(maxHealthUpdaterSystem) .Add(new HealthBarSpawnSystem(contexts, new HealthBarStorage())) .Add(new HealthBarSliderUpdaterSystem(contexts)) .Add(new HealthBarPositionUpdaterSystem(contexts)) .Add(new HealthBarRotatingSystem(contexts, cameraShift)) .Add(new HealthTextUpdatingSystem(contexts)) .Add(new HealthBarDestroyHelperSystem(contexts)) .Add(new DestroyViewSystem(contexts)) .Add(new InputSenderSystem(udpSendUtils, clientInputMessagesHistory)) .Add(new RudpMessagesSenderSystem(udpSendUtils)) .Add(new GameContextClearSystem(contexts)) .Add(new PredictedSnapshotHistoryUpdater(contexts, predictedSnapshotsStorage, matchTimeStorage, lastInputIdStorage)) ; return(systems); }