Пример #1
0
        public override void OnServerStateEnter()
        {
            infos     = new EventMessages.RoundDrawInfo[players.Count];
            transfers = new List <PointTransfer>();
            switch (RoundDrawType)
            {
            case RoundDrawType.RoundDraw:
                HandleRoundDraw();
                break;

            case RoundDrawType.FourRichis:
                HandleFourRichis();
                break;

            case RoundDrawType.NineOrphans:
            case RoundDrawType.FourWinds:
            case RoundDrawType.FourKongs:
                HandleSpecialType(RoundDrawType);
                break;

            default:
                throw new System.Exception($"Type {RoundDrawType} not implemented");
            }

            // Send messages
            for (int i = 0; i < players.Count; i++)
            {
                var player = CurrentRoundStatus.GetPlayer(i);
                ClientBehaviour.Instance.photonView.RPC("RpcRoundDraw", player, infos[i]);
            }

            firstTime = Time.time;
        }
Пример #2
0
        public override void OnServerStateEnter()
        {
            PhotonNetwork.AddCallbackTarget(this);
            if (IsLingShang)
            {
                justDraw = MahjongSet.DrawLingShang();
            }
            else
            {
                justDraw = MahjongSet.DrawTile();
            }
            CurrentRoundStatus.CurrentPlayerIndex = CurrentPlayerIndex;
            CurrentRoundStatus.LastDraw           = justDraw;
            CurrentRoundStatus.CheckFirstTurn(CurrentPlayerIndex);
            CurrentRoundStatus.BreakTempZhenting(CurrentPlayerIndex);
            Debug.Log($"[Server] Distribute a tile {justDraw} to current turn player {CurrentPlayerIndex}, "
                      + $"first turn: {CurrentRoundStatus.FirstTurn}.");
            var room = PhotonNetwork.CurrentRoom;

            for (int i = 0; i < players.Count; i++)
            {
                if (i == CurrentPlayerIndex)
                {
                    continue;
                }
                var info = new EventMessages.DrawTileInfo
                {
                    PlayerIndex     = i,
                    DrawPlayerIndex = CurrentPlayerIndex,
                    MahjongSetData  = MahjongSet.Data
                };
                var player = CurrentRoundStatus.GetPlayer(i);
                ClientBehaviour.Instance.photonView.RPC("RpcDrawTile", player, info);
            }

            var currentPlayer = CurrentRoundStatus.GetPlayer(CurrentPlayerIndex);

            ClientBehaviour.Instance.photonView.RPC("RpcDrawTile", currentPlayer, new EventMessages.DrawTileInfo
            {
                PlayerIndex     = CurrentPlayerIndex,
                DrawPlayerIndex = CurrentPlayerIndex,
                Tile            = justDraw,
                BonusTurnTime   = CurrentRoundStatus.GetBonusTurnTime(CurrentPlayerIndex),
                Zhenting        = CurrentRoundStatus.IsZhenting(CurrentPlayerIndex),
                Operations      = GetOperations(CurrentPlayerIndex),
                MahjongSetData  = MahjongSet.Data
            });
            firstSendTime = Time.time;
            serverTimeOut = gameSettings.BaseTurnTime
                            + CurrentRoundStatus.GetBonusTurnTime(CurrentPlayerIndex)
                            + ServerConstants.ServerTimeBuffer;
        }
Пример #3
0
        public override void OnServerStateEnter()
        {
            if (CurrentRoundStatus.CurrentPlayerIndex != CurrentPlayerIndex)
            {
                Debug.LogError("CurrentPlayerIndex does not match, this should not happen");
                CurrentRoundStatus.CurrentPlayerIndex = CurrentPlayerIndex;
            }

            firstTime = Time.time;
            // determines the operation to take when turn ends
            operationChosen = ChooseOperations();
            Debug.Log(
                $"The operation chosen by this round is {operationChosen}, operation after choosing: {string.Join(",", Operations)}");
            // if operation is not rong or round-draw, perform richi and test zhenting
            if (operationChosen != OutTurnOperationType.Rong && operationChosen != OutTurnOperationType.RoundDraw)
            {
                CurrentRoundStatus.TryRichi(CurrentPlayerIndex, IsRichiing);
                CurrentRoundStatus.UpdateTempZhenting(CurrentPlayerIndex, DiscardingTile);
                CurrentRoundStatus.UpdateDiscardZhenting();
                CurrentRoundStatus.UpdateRichiZhenting(DiscardingTile);
            }

            // Send messages to clients
            for (int i = 0; i < players.Count; i++)
            {
                var info = new EventMessages.TurnEndInfo
                {
                    PlayerIndex         = i,
                    ChosenOperationType = operationChosen,
                    Operations          = Operations,
                    Points         = CurrentRoundStatus.Points.ToArray(),
                    RichiStatus    = CurrentRoundStatus.RichiStatusArray,
                    RichiSticks    = CurrentRoundStatus.RichiSticks,
                    Zhenting       = CurrentRoundStatus.IsZhenting(i),
                    MahjongSetData = MahjongSet.Data
                };
                var player = CurrentRoundStatus.GetPlayer(i);
                ClientBehaviour.Instance.photonView.RPC("RpcTurnEnd", player, info);
            }

            serverTurnEndTimeOut =
                operationChosen == OutTurnOperationType.Rong || operationChosen == OutTurnOperationType.RoundDraw
                                        ? ServerConstants.ServerTurnEndTimeOutExtra
                                        : ServerConstants.ServerTurnEndTimeOut;
            if (operationChosen == OutTurnOperationType.Chow ||
                operationChosen == OutTurnOperationType.Pong ||
                operationChosen == OutTurnOperationType.Kong)
            {
                CurrentRoundStatus.BreakOneShotsAndFirstTurn();
            }
        }
Пример #4
0
        private void ClientRpcCalls()
        {
            var room = PhotonNetwork.CurrentRoom;

            for (int i = 0; i < CurrentRoundStatus.TotalPlayers; i++)
            {
                var player = CurrentRoundStatus.GetPlayer(i);
                ClientBehaviour.Instance.photonView.RPC("RpcGamePrepare", player, new EventMessages.GamePrepareInfo
                {
                    PlayerIndex = i,
                    Points      = CurrentRoundStatus.Points,
                    PlayerNames = CurrentRoundStatus.PlayerNames,
                    GameSetting = gameSettings.ToString()
                });
            }
        }
Пример #5
0
 public override void OnServerStateEnter()
 {
     PhotonNetwork.AddCallbackTarget(this);
     // update hand data
     UpdateRoundStatus();
     // send messages
     for (int i = 0; i < players.Count; i++)
     {
         var info   = GetInfo(i);
         var player = CurrentRoundStatus.GetPlayer(i);
         ClientBehaviour.Instance.photonView.RPC("RpcOperationPerform", player, info);
     }
     KongOperation();
     firstSendTime = Time.time;
     serverTimeOut = gameSettings.BaseTurnTime + CurrentRoundStatus.MaxBonusTurnTime + ServerConstants.ServerTimeBuffer;
 }
Пример #6
0
 public override void OnServerStateEnter()
 {
     PhotonNetwork.AddCallbackTarget(this);
     // update hand tiles and bei doras
     UpdateRoundStatus();
     // send messages
     for (int i = 0; i < players.Count; i++)
     {
         var info   = GetInfo(i);
         var player = CurrentRoundStatus.GetPlayer(i);
         ClientBehaviour.Instance.photonView.RPC("RpcBeiDora", player, info);
     }
     responds          = new bool[players.Count];
     outTurnOperations = new OutTurnOperation[players.Count];
     firstTime         = Time.time;
     serverTimeOut     = CurrentRoundStatus.MaxBonusTurnTime + gameSettings.BaseTurnTime + ServerConstants.ServerTimeBuffer;
 }
Пример #7
0
        public override void OnServerStateEnter()
        {
            PhotonNetwork.AddCallbackTarget(this);
            if (CurrentRoundStatus.CurrentPlayerIndex != CurrentPlayerIndex)
            {
                Debug.LogError("[Server] currentPlayerIndex does not match, this should not happen");
                CurrentRoundStatus.CurrentPlayerIndex = CurrentPlayerIndex;
            }

            UpdateRoundStatus();
            Debug.Log($"[Server] CurrentRoundStatus: {CurrentRoundStatus}");
            responds   = new bool[players.Count];
            operations = new OutTurnOperation[players.Count];
            var rivers = CurrentRoundStatus.Rivers;

            // Get messages and send them to players
            for (int i = 0; i < players.Count; i++)
            {
                var info = new EventMessages.DiscardOperationInfo
                {
                    PlayerIndex            = i,
                    CurrentTurnPlayerIndex = CurrentPlayerIndex,
                    IsRichiing             = IsRichiing,
                    DiscardingLastDraw     = DiscardLastDraw,
                    Tile          = DiscardTile,
                    BonusTurnTime = CurrentRoundStatus.GetBonusTurnTime(i),
                    Zhenting      = CurrentRoundStatus.IsZhenting(i),
                    Operations    = GetOperations(i),
                    HandTiles     = CurrentRoundStatus.HandTiles(i),
                    Rivers        = rivers
                };
                var player = CurrentRoundStatus.GetPlayer(i);
                ClientBehaviour.Instance.photonView.RPC("RpcDiscardOperation", player, info);
            }

            firstSendTime = Time.time;
            serverTimeOut = gameSettings.BaseTurnTime + CurrentRoundStatus.MaxBonusTurnTime
                            + ServerConstants.ServerTimeBuffer;
        }
Пример #8
0
        public override void OnServerStateEnter()
        {
            MahjongSet.Reset();
            // throwing dice
            var dice = Random.Range(CurrentRoundStatus.GameSettings.DiceMin,
                                    CurrentRoundStatus.GameSettings.DiceMax + 1);

            CurrentRoundStatus.NextRound(dice, NextRound, ExtraRound, KeepSticks);
            // draw initial tiles
            DrawInitial();
            Debug.Log("[Server] Initial tiles distribution done");
            CurrentRoundStatus.SortHandTiles();
            CurrentRoundStatus.SetBonusTurnTime(gameSettings.BonusTurnTime);
            responds = new bool[players.Count];
            var room = PhotonNetwork.CurrentRoom;

            for (int index = 0; index < players.Count; index++)
            {
                var tiles = CurrentRoundStatus.HandTiles(index);
                Debug.Log($"[Server] Hand tiles of player {index}: {string.Join("", tiles)}");
                var info = new EventMessages.RoundStartInfo
                {
                    PlayerIndex      = index,
                    Field            = CurrentRoundStatus.Field,
                    Dice             = CurrentRoundStatus.Dice,
                    Extra            = CurrentRoundStatus.Extra,
                    RichiSticks      = CurrentRoundStatus.RichiSticks,
                    OyaPlayerIndex   = CurrentRoundStatus.OyaPlayerIndex,
                    Points           = CurrentRoundStatus.Points.ToArray(),
                    InitialHandTiles = tiles,
                    MahjongSetData   = MahjongSet.Data
                };
                var player = CurrentRoundStatus.GetPlayer(index);
                ClientBehaviour.Instance.photonView.RPC("RpcRoundStart", player, info);
            }

            firstTime = Time.time;
        }