Exemplo n.º 1
0
    protected override void HandleMsg(EPhotonMsg pReceivedMsg, object[] pParams, ByteBuffer bb)
    {
        //Debug.Log($"Game HandleMsg {pReceivedMsg}");
        switch (pReceivedMsg)
        {
        case EPhotonMsg.Game_PlayerLoadedScene:
            if (!PhotonNetwork.IsMasterClient)
            {
                Debug.LogError("Only master should receive PlayerLoadedScene");
                return;
            }

            PhotonPlayer player =
                PhotonNetwork.CurrentRoom.GetPlayer((int)pParams[0]);
            Debug.Log(player + " loaded game");
            game.PlayerManager.OnRemotePlayerLoadedScene(player);
            break;

        //case EPhotonMsg.Game_Activate:
        //	game.Activate();
        //	break;

        case EPhotonMsg.Game_Ui_ShowTimeValue:
            int timeValue = (int)pParams[0];
            game.UIGameTime.ShowTimeValue(timeValue);
            break;

        case EPhotonMsg.Game_UpdatePlayerScore:
            int playerNumber = (int)pParams[0];
            int kills        = (int)pParams[1];
            int deaths       = (int)pParams[2];
            game.Results.UpdatePlayerScore(playerNumber, kills, deaths);
            break;

        case EPhotonMsg.Game_EndGame:

            GameResultInfoS infoS          = GameResultInfoS.GetRootAsGameResultInfoS(bb);
            GameResultInfo  gameResultInfo = GameResultInfo.Deserialize(infoS);
            Debug.Log("Game_SetGameResultInfo");
            Debug.Log(gameResultInfo);

            game.GameEnd.OnReceiveEndGame(gameResultInfo);
            break;

        case EPhotonMsg.Game_Lighting_SetMode:
            bool night = (bool)pParams[0];
            game.Lighting.SetMode(night);
            break;

        case EPhotonMsg.Game_HandleEffect:
            EGameEffect effect = (EGameEffect)pParams[0];
            game.GameEffect.HandleEffect(effect);
            break;

        default:
            Debug.LogError("Message not handled");
            break;
        }
    }
Exemplo n.º 2
0
 public void SetGameResultInfo(List <PlayerScoreInfo> pResults, int pTimePassed)
 {
     GameResultInfo = new GameResultInfo
     {
         PlayerResults = pResults,
         PlayTime      = pTimePassed
     };
 }
Exemplo n.º 3
0
        private void GetTurnResultImpl(GetTurnResultReq req, GetTurnResultResp resp)
        {
            GameResultInfo gr = Server.GameManager.GetTurnResultForPlayer(req.PlayerId, req.Auth.GetClientCode());

            resp.Turn         = gr.Turn;
            resp.GameState    = gr.GameState.ToString();
            resp.PlayerStates = gr.PlayerStates.Select(p => new EnPlayerState(p)).ToArray();
        }
Exemplo n.º 4
0
    internal static GameResultInfo Deserialize(GameResultInfoS pInfoS)
    {
        GameResultInfo gameResultInfo = new GameResultInfo();

        gameResultInfo.PlayTime = pInfoS.PlayTime;
        for (int i = 0; i < pInfoS.PlayerResultsLength; i++)
        {
            PlayerResultInfoS?playerS = pInfoS.PlayerResults(i);
            if (playerS != null)
            {
                gameResultInfo.PlayerResults.Add(PlayerScoreInfo.Deserialize((PlayerResultInfoS)playerS));
            }
        }
        return(gameResultInfo);
    }
Exemplo n.º 5
0
    void FixedUpdate()
    {
        if (PlayDol.isRunAnimation == true)
        {
            return;
        }

        if (isNetworkPlay && isOffLineMode == false)
        {
            if (globalTimeLeft < 0)
            {
                //GameOver();
                if (isOffLineMode == false)
                {
                }

                GameResultInfo gameResultInfo = new GameResultInfo();

                if (myPlyScore > otherPlyScore)
                {
                    gameResultInfo.winnerColor = isMyDolColorBlack == true ? 2 : 1;
                    gameResultInfo.wiinerScore = myPlyScore;
                    gameResultInfo.loseScore   = otherPlyScore;
                    gameResultInfo.wiinnerIsme = true;
                    showResult("You Win", true);
                    ws.Send(gameResultInfo.ToString());
                }
                else if (myPlyScore < otherPlyScore)
                {
                    gameResultInfo.winnerColor = isMyDolColorBlack == true ? 1 : 2;
                    gameResultInfo.wiinerScore = otherPlyScore;
                    gameResultInfo.loseScore   = myPlyScore;
                    gameResultInfo.wiinnerIsme = false;
                    showResult("You Lost", true);
                    ws.Send(gameResultInfo.ToString());
                }
                else
                {
                    gameResultInfo.winnerColor = isMyDolColorBlack == true ? 2 : 1;
                    gameResultInfo.wiinerScore = myPlyScore;
                    gameResultInfo.loseScore   = otherPlyScore;
                    gameResultInfo.wiinnerIsme = true;
                    showResult("Drawgame", true);
                    ws.Send(gameResultInfo.ToString());
                }

                globalTimeLeft = gameInfo.totalTimeBank + 10;
            }
            else
            {
                globalTimeLeft         -= Time.fixedDeltaTime;
                txtTotalRemainTime.text = string.Format("RemainTime:{0}", (int)globalTimeLeft);
            }

            if (isMyTurn)
            {
                if (0 < privateTimeLeft)
                {
                    privateTimeLeft    -= Time.fixedDeltaTime;
                    txtPrivateTime.text = string.Format("You,Limit:{0}", (int)privateTimeLeft);
                }
                else
                {
                    if (Game.selectedDol != null)
                    {
                        Game.selectedDol.indicatorOff();
                    }

                    Game.selectedDol = null;
                    Game.targetDol   = null;
                    Dols.SetOffAllCanMove();
                    MoveInfoReq moveInfoReq = new MoveInfoReq();
                    VectorDol   nullPos     = new VectorDol();
                    nullPos.x = -1;
                    moveInfoReq.source.setPos(nullPos);
                    moveInfoReq.target.setPos(nullPos);
                    send(moveInfoReq.ToString());
                    privateTimeLeft = gameInfo.privateTimeBank;
                }
            }
            else
            {
                if (0 < privateTimeLeft)
                {
                    privateTimeLeft    -= Time.fixedDeltaTime;
                    txtPrivateTime.text = string.Format("He,Limit:{0}", (int)privateTimeLeft);
                }
                else
                {
                    privateTimeLeft = gameInfo.privateTimeBank;
                }
            }
        }

        ProcessPackets();
    }
Exemplo n.º 6
0
    private void ProcessPackets()
    {
        string curWsData = "";

        lock (packetList)
        {
            if (packetList.Count > 0)
            {
                curWsData = packetList.Dequeue();
            }
        }

        if (curWsData.Length < 1)
        {
            return;
        }

        var    jsonObject = JsonUtility.FromJson <WebDataRes>(curWsData);
        string pid        = jsonObject.pid;

        switch (pid)
        {
        case "Connected":
            LoginInfo loginInfo = new LoginInfo();
            loginInfo.deviceId = deviceId;
            loginInfo.nickName = PlayerPrefs.GetString("playerName");
            if (Debug.isDebugBuild)
            {
                System.Random rnd    = new System.Random();
                int           random = rnd.Next(1, 1000);
                loginInfo.deviceId = deviceId + random;
            }
            ws.Send(loginInfo.ToString());
            txtServerState.text = "Conneted Server";
            setOnLine(true);
            break;

        case "Disconnected":
            dols.CleanDols();
            isNetworkPlay       = true;
            txtServerState.text = "Disconneted Server";
            isNetworkPlay       = false;
            setOnLine(false);
            //Application.Quit();
            break;

        case "LoginInfoRes":
            isOffLineMode = false;
            LoginInfoRes loginRes = new LoginInfoRes();
            loginRes.FromJsonOverwrite(jsonObject.data);
            Debug.Log("LoginInfoRes: " + loginRes.ToString());
            if (loginRes.loginResult > 0)
            {
                txtServerState.text = "Wait Opponent Player(You Can run PracticeMode during waiting)";
                QuickSeatReq quickSeat = new QuickSeatReq();
                ws.Send(quickSeat.ToString());
            }
            else
            {
                txtServerState.text = "Login Failed...";
            }
            break;

        case "GameInfo":
            GameInfo gameInfoRes = new GameInfo();
            gameInfoRes.FromJsonOverwrite(jsonObject.data);
            gameInfo       = gameInfoRes;
            globalTimeLeft = (float)gameInfoRes.totalTimeBank;
            break;

        case "DolsInfo":
            setOnLine(true);
            globalTimeLeft = (float)gameInfo.totalTimeBank;
            isOffLineMode  = false;
            isNetworkPlay  = true;
            DolsInfo dolsinfo = new DolsInfo();
            dolsinfo.FromJsonOverwrite(jsonObject.data);
            Debug.Log("DolsInfo: " + dolsinfo.ToString());

            if (dolsinfo.isBlack == false)
            {
                dols.firstWplayDols = dolsinfo;
            }
            else
            {
                dols.firstBplayDols = dolsinfo;
                dols.CleanDols();
                dols.InitDols();
            }

            if (dolsinfo.nickName.Length > 0)
            {
                if (dolsinfo.isMe)
                {
                    txtYour_name.text = dolsinfo.nickName;
                }
                else
                {
                    txtOtherName.text = dolsinfo.nickName;
                }
            }
            onStageInit();
            break;

        case "MoveInfoRes":
            MoveInfoRes moveInfoRes = new MoveInfoRes();
            moveInfoRes.FromJsonOverwrite(jsonObject.data);
            SwapDolPos(moveInfoRes.source, moveInfoRes.target);
            break;

        case "TurnInfo":
            TurnInfo turnInfo = new TurnInfo();
            turnInfo.FromJsonOverwrite(jsonObject.data);
            string txtTurnInfo     = "";
            string currentDolColor = turnInfo.isBlack == true ? "black" : "white";
            if (turnInfo.isMe)
            {
                txtTurnInfo       = string.Format("Your({0}) turn", currentDolColor);
                isMyTurn          = true;
                isMyDolColorBlack = turnInfo.isBlack;
                privateTimeLeft   = gameInfo.privateTimeBank;
            }
            else
            {
                txtTurnInfo       = string.Format("Wait other player({0}) Action", currentDolColor);
                isMyTurn          = false;
                isMyDolColorBlack = !turnInfo.isBlack;
                privateTimeLeft   = gameInfo.privateTimeBank;
            }

            if (isOffLineMode)
            {
                isMyDolColorBlack = turnInfo.isBlack;
                txtTurnInfo       = string.Format("{0} Turn", currentDolColor);

                if (isAIMode)
                {
                    if (turnInfo.isBlack == true)
                    {
                        //dols.doaskAIAction
                        PlayDol sourceDol = null;
                        PlayDol targetDol = null;
                        dols.askAIAction(2, ref sourceDol, ref targetDol);

                        MoveInfoRes moveInfoReq = new MoveInfoRes();
                        moveInfoReq.source.setPos(sourceDol.GetDolPos());
                        moveInfoReq.target.setPos(targetDol.GetDolPos());
                        Debug.Log("AI:" + moveInfoReq.ToString());
                        sendLocalData("MoveInfoRes", moveInfoReq.ToString());

                        TurnInfo turnChange = new TurnInfo();
                        turnChange.isMe    = true;
                        turnChange.isBlack = false;

                        sendLocalData("TurnInfo", turnChange.ToString());
                    }
                }
            }

            txtServerState.text = txtTurnInfo;
            break;

        case "CrashGameInfo":
            dols.CleanDols();
            txtServerState.text = "Other User Leaver, Wait Other Player";
            isNetworkPlay       = false;
            break;

        case "CheckGame":
            if (isOffLineMode == false)
            {
                if (isMyDolColorBlack == true && curPlayDol.GetMyDolType() == 2)
                {
                    myPlyScore += Dols.checkGame(curPlayDol);
                }

                if (isMyDolColorBlack == true && curPlayDol.GetMyDolType() == 1)
                {
                    otherPlyScore += Dols.checkGame(curPlayDol);
                }

                if (isMyDolColorBlack == false && curPlayDol.GetMyDolType() == 1)
                {
                    myPlyScore += Dols.checkGame(curPlayDol);
                }

                if (isMyDolColorBlack == false && curPlayDol.GetMyDolType() == 2)
                {
                    otherPlyScore += Dols.checkGame(curPlayDol);
                }
            }
            else
            {
                if (curPlayDol.GetMyDolType() == 1)
                {
                    myPlyScore += Dols.checkGame(curPlayDol);
                }
                else
                {
                    otherPlyScore += Dols.checkGame(curPlayDol);
                }
            }

            if (isOffLineMode == false)
            {
                txtMyPlyScore.text     = myPlyScore.ToString();
                txtOtherPlayScore.text = otherPlyScore.ToString();
            }
            else
            {
                txtMyPlyScore.text     = myPlyScore.ToString();
                txtOtherPlayScore.text = otherPlyScore.ToString();
                txtYour_name.text      = "White";
                txtOtherName.text      = "Black";
            }

            GameResultInfo gameResultInfo = new GameResultInfo();
            if (myPlyScore > gameInfo.winScore - 1)
            {
                gameResultInfo.winnerColor = curPlayDol.GetMyDolType();
                gameResultInfo.wiinerScore = myPlyScore;
                gameResultInfo.loseScore   = otherPlyScore;
                gameResultInfo.wiinnerIsme = true;

                if (isOffLineMode == false)
                {
                    showResult("You Win", true);
                    ws.Send(gameResultInfo.ToString());
                }
                else
                {
                    showResult("White Win", true);
                }
            }

            if (otherPlyScore > gameInfo.winScore - 1)
            {
                gameResultInfo.winnerColor = curPlayDol.GetMyDolType();
                gameResultInfo.wiinerScore = otherPlyScore;
                gameResultInfo.loseScore   = myPlyScore;
                gameResultInfo.wiinnerIsme = false;

                if (isOffLineMode == false)
                {
                    showResult("You Lose", true);
                    ws.Send(gameResultInfo.ToString());
                }
                else
                {
                    showResult("Black Win", true);
                }
            }
            break;
        }
    }
Exemplo n.º 7
0
        public ActionResult PushResult(GameResultInfo result)
        {
            if (result.PushPassword != WebConstants.WebPassword)
            {
                return new ContentResult {
                           Content = "Password fail"
                }
            }
            ;
            var context = new UnityContext();
            var users   = context.UserProfiles.ToArray();
            var tags    = users.Select(u => u.CvarcTag).ToArray();

            if (result.Players.Length == 2)
            {
                if (!tags.Contains(result.Players[0].CvarcTag) || !tags.Contains(result.Players[1].CvarcTag))
                {
                    return new ContentResult {
                               Content = "tag fail"
                    }
                }
                ;

                context.GameResults.Add(new GameResults
                {
                    Time = WebConstants.GetCurrentTime(),
                    LeftPlayerUserName  = users.First(u => u.CvarcTag == result.Players[0].CvarcTag).UserName,
                    RightPlayerUserName = users.First(u => u.CvarcTag == result.Players[1].CvarcTag).UserName,
                    LeftPlayerScores    = result.Players[0].Score,
                    RightPlayerScores   = result.Players[1].Score,
                    LogFileName         = result.LogFileName,
                    Type    = result.Tag,
                    Subtype = result.Subtag
                });
                context.SaveChanges();
                return(new ContentResult {
                    Content = "successful"
                });
            }

            var player = result.Players[0];

            if (!tags.Contains(player.CvarcTag))
            {
                return new ContentResult {
                           Content = "tag fail"
                }
            }
            ;

            context.GameResults.Add(new GameResults
            {
                Time = WebConstants.GetCurrentTime(),
                LeftPlayerUserName = users.First(u => u.CvarcTag == player.CvarcTag).UserName,
                LeftPlayerScores   = player.Score,
                LogFileName        = result.LogFileName,
                Type    = result.Tag,
                Subtype = result.Subtag
            });
            context.SaveChanges();
            return(new ContentResult {
                Content = "successful"
            });
        }
Exemplo n.º 8
0
 /// <summary>
 /// End game - called only on clients
 /// </summary>
 public void OnReceiveEndGame(GameResultInfo pGameResultInfo)
 {
     GameEnded = true;
     brainiacs.GameResultInfo = pGameResultInfo;
     game.uiCurtain.SetFade(true, LoadResultScene);
 }