private void PlayCardFromOther(PlayerSlotScript player)
 {
     // TEST STOP Player turn's circle if played
     // player.StopCircle();
     //##########
     EventPlayOPCards(player.transform, new string[] { "6C", "7C", "8C" });
 }
    public override void UpdateSeats(JSONObject jsonData)
    {
        JSONArray userList = jsonData.GetObject("gameRoom").GetArray("userGames");

        users = new JSONObject();
        for (int i = 0; i < userList.Length; i++)
        {
            users.Add(userList[i].Obj.GetInt("seatIndex").ToString(), userList[i].Obj);
        }
        // FAKE user joined
        for (int i = 0; i < 4; i++)
        {
            GameObject       tempUser;
            PlayerSlotScript playerScript = playerHolder[i];
            JSONObject       user         = users.ContainsKey(i.ToString()) ? users.GetObject(i.ToString()) : null;
            if (user != null)
            {
                playerScript.Init(user.GetString("userId"), "Dan Choi" + (i + 1), (i + 1) * 200000, string.Empty);
            }
            else
            {
                playerScript.InitEmpty();
            }
        }
    }
 // Show bubble chat at player avatar
 private void DisplayBubbleChat(string text, PlayerSlotScript player) {
   text = Utils.ChatUnescape(text);
   GameObject tempGameObject = NGUITools.AddChild(gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/SpeechBubble", typeof(GameObject)) as GameObject);
  	tempGameObject.name = "SpeechBubble";
  	// fake chat alway from player 1;
  	tempGameObject.transform.position = player.bubbleChatPos;
  	SpeechBubble bubble = tempGameObject.GetComponent<SpeechBubble>();
  	bubble.SetText(text);
 }
 public void OnPlayerJoinRoom(string roomId, JSONObject userData)
 {
     if (this.roomId == roomId)
     {
         PlayerSlotScript playerSlot = GetAvailableSlot(userData.GetString("username"));
         playerSlot.Init(userData.GetString("username"), userData.GetString("displayName"), userData.GetLong("cash"), userData.GetString("avatar"));
     }
     else
     {
         Debug.LogError("Not in this room " + this.roomId + " | " + roomId);
     }
 }
    // Show bubble chat at player avatar
    private void DisplayBubbleChat(string text, PlayerSlotScript player)
    {
        text = Utils.ChatUnescape(text);
        GameObject tempGameObject = NGUITools.AddChild(gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/SpeechBubble", typeof(GameObject)) as GameObject);

        tempGameObject.name = "SpeechBubble";
        // fake chat alway from player 1;
        tempGameObject.transform.position = player.bubbleChatPos;
        SpeechBubble bubble = tempGameObject.GetComponent <SpeechBubble>();

        bubble.SetText(text);
    }
    public override void Init(object[] data)
    {
        base.Init(data);
        EventDelegate.Set(btnBack.onClick, BackToSelectRoom);
        EventDelegate.Set(btnThrowCard.onClick, EventPlayCards);
        Debug.Log(data[1]);
        JSONObject roomData = (JSONObject)data[1];
        JSONArray  userList = roomData.GetObject("gameRoom").GetArray("userGames");

        for (int i = 0; i < userList.Length; i++)
        {
            users.Add(userList[i].Obj.GetInt("seatIndex").ToString(), userList[i].Obj);
        }
        // FAKE user joined
        for (int i = 0; i < 4; i++)
        {
            GameObject tempUser;
            if (i < 2)
            {
                tempUser = NGUITools.AddChild(playerLeftGrid.gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/TienLenMN/PlayerSlot", typeof(GameObject)) as GameObject);
            }
            else
            {
                tempUser = NGUITools.AddChild(playerRightGrid.gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/TienLenMN/PlayerSlot", typeof(GameObject)) as GameObject);
            }
            tempUser.name = "PlayerSlot" + (i + 1);
            PlayerSlotScript playerScript = tempUser.GetComponent <PlayerSlotScript>();
            JSONObject       user         = users.ContainsKey(i.ToString()) ? users.GetObject(i.ToString()) : null;
            if (user != null)
            {
                playerScript.Init(user.GetString("userId"), "Dan Choi" + (i + 1), (i + 1) * 200000, string.Empty);
            }
            else
            {
                playerScript.InitEmpty();
            }
            playerHolder.Add(playerScript);
        }

        playerLeftGrid.Reposition();
        playerRightGrid.Reposition();

        // for (int i = 0; i < playerHolder.Count; i++) {
        //  UIButton tempBtn = playerHolder[i].btnThrowCard;
        //  tempBtn.inputParams = new object[] {playerHolder[i]};
        //       EventDelegate.Set(tempBtn.onClick, delegate() { PlayCardFromOther((PlayerSlotScript)tempBtn.inputParams[0]); });
        //       // Test Player turn circle display
        //       StartCoroutine(DisplayPlayerTurn(i));
        // }

        StartNewGame();
    }
    public void UpdateOtherPlayerCash(string username, long cashVal)
    {
        PlayerSlotScript playerSlot = FindUserSlot(username);

        if (playerSlot != null)
        {
            playerSlot.UpdateCash(cashVal);
        }
        else
        {
            Debug.Log("Cant find user slot " + username);
        }
    }
    private PlayerSlotScript GetAvailableSlot(string username)
    {
        PlayerSlotScript emptySlot       = null;
        PlayerSlotScript alreadyJoinSlot = null;

        for (int i = 0; i < otherPlayers.Length; i++)
        {
            if (otherPlayers[i].IsThisUser(username))
            {
                alreadyJoinSlot = otherPlayers[i];
            }
            else if (otherPlayers[i].IsEmpty() && emptySlot == null)
            {
                emptySlot = otherPlayers[i];
            }
        }
        return(alreadyJoinSlot != null ? alreadyJoinSlot : emptySlot);
    }
    IEnumerator ProcessSpinData(SpinData spinData)
    {
        Debug.Log("ProcessSpinData " + spinData.spawnSkills.Count);
        if (spinData.newBossData != null)
        {
            Debug.Log("ProcessSpinData~~~~~~~~~ ");
            PauseSpawnSkill();
        }
        // Show Glow on user slot if not you
        Vector3 fromPos = Vector3.zero;

        if (!spinData.isYou)
        {
            PlayerSlotScript playerSlot = FindUserSlot(spinData.username);
            if (playerSlot != null)
            {
                fromPos = playerSlot.transform.position;
                playerSlot.ShowGlow();
            }
        }
        else
        {
            fromPos = userAvatarTexture.transform.position;
            if (!bigWinPanel.isShowing && spinData.newBossData == null)
            {
                slotMachine.Wait();
                if (!IsInvoking("ReleaseSlotPause"))
                {
                    Invoke("ReleaseSlotPause", 1f * spinData.spawnSkills.Count);
                }
            }
        }
        for (int i = 0; i < spinData.spawnSkills.Count; i++)
        {
            SpawnSkill(spinData.spawnSkills[i], fromPos, spinData.isYou);
            yield return(new WaitForSeconds(0.5f));
        }
        if (spinData.newBossData != null)
        {
            yield return(new WaitForSeconds(2f));

            DisplayBossDrop(spinData.dropCash, spinData.dropGem, spinData.newBossData);
        }
    }
 public void OnPlayerLeaveRoom(string roomId, string username)
 {
     if (this.roomId == roomId)
     {
         PlayerSlotScript playerSlot = FindUserSlot(username);
         if (playerSlot != null)
         {
             playerSlot.InitEmpty();
         }
         else
         {
             Debug.Log("Cant find user slot " + username);
         }
     }
     else
     {
         Debug.LogError("Not in this room " + this.roomId + " | " + roomId);
     }
 }
	private void PlayCardFromOther(PlayerSlotScript player) {
	  // TEST STOP Player turn's circle if played
    // player.StopCircle();
	  //##########
		EventPlayOPCards(player.transform, new string[] {"6C", "7C", "8C"});
	}