public void CardClick(ECard card) { if (card != null && currentStep == StepDealCard.WAIT_PICK) { if (pickAfterDealcard == null) { indexPick = Array.FindIndex <GameObject>(listPickObject, obj => obj == card.gameObject); pickAfterDealcard = card; MoveCard_FirstPick(pickAfterDealcard); pickAfterDealcard.gameObject.SetActive(false); } else if (pickAfterDealcard != card) { currentStep = StepDealCard.PICKED; GameModelChan.game.StartCoroutine(OnPickDone(card)); } } }
public void OnInit() { const float radiusOfCircleRotation = 110f; Vector3 vectorTop = GameModelChan.game.mPlaymat.GetPointCircle(GameModelChan.game.mPlaymat.locationRotation[4].localPosition, radiusOfCircleRotation, 270f); GameModelChan.game.mPlaymat.locationRotation[0].localPosition = vectorTop; Vector3 vectorLeft = GameModelChan.game.mPlaymat.GetPointCircle(GameModelChan.game.mPlaymat.locationRotation[4].localPosition, radiusOfCircleRotation, 180f); GameModelChan.game.mPlaymat.locationRotation[1].localPosition = vectorLeft; Vector3 vectorBottom = GameModelChan.game.mPlaymat.GetPointCircle(GameModelChan.game.mPlaymat.locationRotation[4].localPosition, radiusOfCircleRotation, 90f); GameModelChan.game.mPlaymat.locationRotation[2].localPosition = vectorBottom; Vector3 vectorRight = GameModelChan.game.mPlaymat.GetPointCircle(GameModelChan.game.mPlaymat.locationRotation[4].localPosition, radiusOfCircleRotation, 0f); GameModelChan.game.mPlaymat.locationRotation[3].localPosition = vectorRight; serverRequestUpdateHandStep1 = false; serverRequestUpdateHandStep2 = false; currentStep = StepDealCard.START; GameModelChan.game.StartCoroutine(DealCard()); }
IEnumerator DealCard() { float time = 0.3f; #region CHIA BAI Hashtable hash = iTween.Hash("islocal", true, "time", time, "position", Vector3.zero); int index = 0; GameObject[] oldObj = new GameObject[2]; while (index < 2) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { ChanCard c = new ChanCard(0, -1); c.Instantiate(GameModelChan.game.mPlaymat.locationDealCard[i + (j * 5)]); GameObject obj = c.gameObject; obj.name = "Card " + index + " " + i + " " + j + " - " + (index * (i + 1) + (j)); Vector3 pos; if (oldObj[j] != null) { pos = oldObj[j].transform.parent.localPosition - GameModelChan.game.mPlaymat.locationDealCard[i + (j * 5)].localPosition; } else { pos = GameModelChan.game.mPlaymat.locationDealCard[i + (j * 5)].localPosition; } obj.transform.localPosition = pos; obj.transform.localScale /= 1.75f; obj.transform.localRotation = new Quaternion(0f, 0f, 0.9f, 0.4f); iTween.MoveTo(obj, hash); oldObj[j] = obj; } yield return(new WaitForSeconds(time)); } index++; } #endregion yield return(new WaitForSeconds(0.5f)); #region GỘP BÀI for (int i = 0; i < 5; i++) { if (i < 2) { while (GameModelChan.game.mPlaymat.locationDealCard[i + (1 * 5)].childCount > 0) { Transform tran = GameModelChan.game.mPlaymat.locationDealCard[i + (1 * 5)].GetChild(0); tran.parent = GameModelChan.game.mPlaymat.locationDealCard[i + (0 * 5)]; iTween.MoveTo(tran.gameObject, hash); } } else { while (GameModelChan.game.mPlaymat.locationDealCard[i + (0 * 5)].childCount > 0) { Transform tran = GameModelChan.game.mPlaymat.locationDealCard[i + (0 * 5)].GetChild(0); tran.parent = GameModelChan.game.mPlaymat.locationDealCard[i + (1 * 5)]; iTween.MoveTo(tran.gameObject, hash); } } } #endregion yield return(new WaitForSeconds(time + 0.05f)); #region DI CHUYỂN BÀI CHO ĐỀU for (int i = 0; i < 2; i++) { while (GameModelChan.game.mPlaymat.locationDealCard[i].childCount > 0) { Transform tran = GameModelChan.game.mPlaymat.locationDealCard[i].GetChild(0); tran.parent = GameModelChan.game.mPlaymat.locationDealCard[4 - i]; iTween.MoveTo(tran.gameObject, hash); } } //Destroy hết child giữ lại 1 card List <GameObject> listObj = new List <GameObject>(); foreach (Transform trans in GameModelChan.game.mPlaymat.locationDealCard) //for(int i=0;i<GameModel.game.mPlaymat.locationDealCard.Length;i++) { //Transform trans = GameModel.game.mPlaymat.locationDealCard[i]; while (trans.childCount >= 2) { GameObject obj = trans.GetChild(0).gameObject; obj.transform.parent = null; GameObject.Destroy(obj); } if (trans.childCount > 0) { listObj.Add(trans.GetChild(0).gameObject); } } listPickObject[0] = listObj[0]; listPickObject[1] = listObj[1]; listPickObject[2] = listObj[2]; listPickObject[3] = listObj[3]; listPickObject[4] = listObj[4]; #endregion currentStep = StepDealCard.WAIT_PICK; if (EventResponseMessage != null) { EventResponseMessage(); } }
public void OnDestroy() { currentStep = StepDealCard.NONE; Array.ForEach <GameObject>(listPickObject, obj => GameObject.Destroy(obj)); GameModelChan.DealCardDone = true; }
/// <summary> /// Thực hiện sau khi người chơi pick lần thứ 2 /// </summary> IEnumerator OnPickDone(ECard card) { #region THÔNG BÁO VỚI SERVER LÀ ĐÃ THỰC HIỆN XONG BƯỚC 2 if (!serverRequestUpdateHandStep2 && GameModelChan.YourController != null && GameModelChan.IndexInTurn == GameModelChan.YourController.slotServer) { int index = Array.FindIndex <GameObject>(listPickObject, obj => obj == card.gameObject); GameManager.Server.DoRequestPluginGame(Utility.SetEsObject(Fields.GAMEPLAY.PLAY, new object[] { Fields.ACTION, "getHand", "slotChoice", Utility.SetEsObject(null, "donePick", index) })); } #endregion #region CHỜ SERVER TRẢ VỀ THÔNG TIN NGƯỜI CHƠI while (string.IsNullOrEmpty(firstPlayer) || firstCardServerResponse == -1) { yield return(new WaitForEndOfFrame()); } pickAfterDealcard.CardId = firstCardServerResponse; pickAfterDealcard.gameObject.transform.parent = card.gameObject.transform.parent; pickAfterDealcard.gameObject.transform.localPosition = Vector3.zero; pickAfterDealcard.gameObject.SetActive(true); pickAfterDealcard.gameObject.transform.localPosition = new Vector3(pickAfterDealcard.gameObject.transform.localPosition.x, pickAfterDealcard.gameObject.transform.localPosition.y, -2f); iTween.RotateTo(pickAfterDealcard.gameObject, new Vector3(0f, 0f, 0f), 0.5f); yield return(new WaitForSeconds(0.5f)); #endregion List <DealCardRotation> listDealcard = new List <DealCardRotation>(); #region QUY ĐỊNH VỊ TRÍ SẼ ĐẾN CỦA CÁC MÔ BÀI PlayerControllerChan playerFirst = GameModelChan.ListPlayerInGame.Find(p => p.username == firstPlayer); DealCardRotation dealFirst = DealCardRotation.GetListRotation.Find(d => d.transform.childCount == 2); listDealcard.Add(dealFirst); dealFirst.StartRotate(playerFirst.mSide); PlayerControllerChan nextPlayer = GameModelChan.GetNextPlayer(playerFirst.slotServer); DealCardRotation nextDeal = dealFirst.GetNextAvalible; for (int i = 0; i < GameModelChan.ListPlayerInGame.Count - 1; i++) { listDealcard.Add(nextDeal); nextDeal.StartRotate(nextPlayer.mSide); nextPlayer = GameModelChan.GetNextPlayer(nextPlayer.slotServer); nextDeal = nextDeal.GetNextAvalible; } #endregion while (!listDealcard.TrueForAll(d => d.isComplete)) { yield return(new WaitForFixedUpdate()); } #region DI CHUYỂN VỀ VỊ TRÍ CÓ AVATAR DealCardRotation.GetListRotation.ForEach(dealCard => { if (dealCard.transform.childCount > 0) { MoveAllChildToTransform(dealCard.transform, GameModelChan.ListPlayerInGame.Find(p => p.mSide == dealCard.sideEnd).cuiPlayer.transform, 0.5f); } } ); #endregion yield return(new WaitForSeconds(0.6f)); currentStep = StepDealCard.DONE; Array.ForEach <GameObject>(listPickObject, obj => GameObject.Destroy(obj)); }