public static EndTurnRequestEvent Create(int playerId, List <MoveRequest> moveList) { var request = new EndTurnRequestEvent(); request.playerId = playerId; request.moveRequestList = moveList; return(request); }
private void onEndTurn(List <MoveRequest> moveList) { EndTurnRequestEvent endTurnRequest = EndTurnRequestEvent.Create(PhotonNetwork.player.ID, moveList); RaiseEventOptions options = new RaiseEventOptions(); options.Receivers = ReceiverGroup.MasterClient; string requestJson = JsonUtility.ToJson(endTurnRequest); PhotonNetwork.RaiseEvent(NetworkOpCodes.PLAYER_TURN_COMPLETED, requestJson, true, options); }
private void onCustomEvent(byte eventCode, object content, int senderId) { bool isSenderThisPlayer = senderId == PhotonNetwork.player.ID; if (eventCode == NetworkOpCodes.PLAYER_TURN_COMPLETED) { Assert.IsTrue(PhotonNetwork.isMasterClient); _shockClock.Stop(); EndTurnRequestEvent endTurn = JsonUtility.FromJson <EndTurnRequestEvent>(content as string); if (isSenderThisPlayer) { sendTurnOverEvent(endTurn.moveRequestList); } else if (attemptMoves(senderId, endTurn.moveRequestList, true)) { sendTurnOverEvent(endTurn.moveRequestList); } if (_gameMatchCore.isGameOver) { sendGameOverEvent(); } } else if (eventCode == NetworkOpCodes.BEGIN_NEXT_PLAYER_TURN) { ChangeTurnEvent changeTurn = JsonUtility.FromJson <ChangeTurnEvent>(content as string); Debug.Log("Active Player: " + changeTurn.activePlayerIndex); int previousPlayerId = _gameMatchCore.playerGroup.GetPlayerByIndex(changeTurn.previousPlayerIndex).id; bool isSamePlayer = previousPlayerId == PhotonNetwork.player.ID; if (!PhotonNetwork.isMasterClient && !isSamePlayer) { attemptMoves(previousPlayerId, changeTurn.moveRequestList, true); simulateOtherPlayerMakingMoves(changeTurn.moveResultList, () => onCompleteOtherPlayerAnimation(changeTurn)); } else if (!isSamePlayer) { simulateOtherPlayerMakingMoves(changeTurn.moveResultList, () => onCompleteOtherPlayerAnimation(changeTurn)); } else { onCompleteOtherPlayerAnimation(changeTurn); } _moveResultList.Clear(); } else if (eventCode == NetworkOpCodes.MATCH_OVER) { MatchOverEvent matchOver = JsonUtility.FromJson <MatchOverEvent>(content as string); _gameOverPopupController.Start(matchOver.playerRanking, () => { if (_onGameOverCallback != null) { _onGameOverCallback(); } }); } else if (eventCode == NetworkOpCodes.PLAYBACK_CONFIRMED) { _playbackConfirm.Push(senderId); Debug.LogErrorFormat("Confirmed Count: {0}/{1}", _playbackConfirm.Count, _playerList.Count); //All players confirmed if (_playbackConfirm.Count >= _playerList.Count) { Debug.LogError("Engage Timer!"); _playbackConfirm.Clear(); _shockClock.Start( kShockClockTurnTime, kShockClockInterval, onShockClockInterval, onShockClockFinished); } } else if (eventCode == NetworkOpCodes.TIMER_UPDATE) { double time = (double)content; Debug.Log("Time: " + time); if (_playFieldController != null) { double timeLeft = (kShockClockTurnTime - time) / 1000.0; if (_playFieldController.shockClockView != null) { _playFieldController.shockClockView.timerText = ((int)timeLeft).ToString(); } if ((int)timeLeft <= 0 && isLocalPlayerActive) { _playFieldController.ForceEndTurn(); } } } }