public static void OnDraggedCardUpdate(Vector2 mousePos, CardRoot draggedCardRoot, bool inTableZone)
 {
     foreach (var obs in _observers)
     {
         obs.OnDraggedCardUpdate(mousePos, draggedCardRoot, inTableZone);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Called by InputManager whenever i drop card on table
        /// </summary>
        public override void OnCardDroppedOnTableByMe(CardRoot heldCard)
        {
            StopAnimationGlowingCardsOnTable();

            if (State != RoomState.Playing)
            {
                return;
            }

            if (AllPassed ||
                (AllButDefenderPassed && AllCardsCovered))
            {
                return;
            }

            //if i am defending.
            if (MeDefending)
            {
                var closestCardOnTable = GetClosestCardOnTableTo(Input.mousePosition);
                // check if action is correct
                if (CanCoverThisCardWith(closestCardOnTable, heldCard))
                {
                    CoverThisCardWith(closestCardOnTable, heldCard);
                }
            }
            else if (IcanAddCards && CanAddThisCard(heldCard)) //if i am attacking and can add this card
            {
                MeAddCardToTable(heldCard);
            }

            // else if i am not attacking nor defenfing and cant add cards
            // then wait till attacker passes priority
        }
Esempio n. 3
0
 private void AddCardToHand(CardRoot cardRootScript)
 {
     CardsInHand.Add(cardRootScript);
     //disable interaction
     cardRootScript.InteractionDisable();
     cardsN++;
 }
Esempio n. 4
0
        //Methods that have an implementation and used by RoomLogic

        #region Protected methods

        /// <summary>
        /// Do table contains card of same value with held card?
        /// </summary>
        protected bool CanAddThisCard(CardRoot heldCard)
        {
            // You always can add to an empty table
            if (TableIsEmpty)
            {
                return(true);
            }

            // check If trying to drop wrong card

            // get card value from the held card
            int heldCardValue = heldCard.GetCardValue();

            // find at least one card on table with same value
            if (!GetAllCardsOnTable().Any(card => card.Value == heldCardValue)) //bug: can add carn not on your turn
            {
                // say 'Cant add this card to table'
                GameplayMessageManager.Instance.ShowFullScreenText("Эту карту нельзя подкинуть");
                return(false);
            }


            // if table is not full (5 cards on first turn, 6 on any other)
            // and player defending has cards
            if (TableIsFull || !DefenderHasCardsToDefend)
            {
                // say 'Too much cards on table'
                GameplayMessageManager.Instance.ShowFullScreenText("Перебор");
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
 /// <summary>
 /// Covers card on table with dropped card. Adds to covered cards list
 /// </summary>
 protected override void AnimateCoverCardBy(CardRoot cardOnTable, CardRoot heldCard)
 {
     //Disable interactions
     cardOnTable.InteractionDisable();
     //Animate
     heldCard.AnimateMoveToTransform(cardOnTable.CoveredCardContainer);
     cardOnTable.CoveredCardContainer.SetAsLastSibling();
 }
Esempio n. 6
0
 public void DraggedCardDrop(Vector2 mousePos, CardRoot cardRoot)
 {
     //if it was dropped insude table rect
     if (RectTransformUtility.RectangleContainsScreenPoint(TableDropZone, mousePos))
     {
         FoolObservable.OnCardDroppedOnTableByMe(cardRoot);
     }
 }
Esempio n. 7
0
        public void PickUpCard(CardRoot cardRoot)
        {
            CardsInHand.Add(cardRoot);

            //Enable interactions
            cardRoot.InteractionEnable();

            cardRoot.AnimateMoveToTransform(HandContainer);
        }
        public static void OnCardDroppedOnTableByMe(CardRoot cardRoot)
        {
            StaticRoomData.MyPlayer.TakeCards(-1);

            foreach (var obs in _observers)
            {
                obs.OnCardDroppedOnTableByMe(cardRoot);
            }
        }
Esempio n. 9
0
        protected override CardRoot AnimateEnemyCoversCard(int slotN, CardRoot cardOnTable, string cardCodeHeld)
        {
            var heldCard = _playersInfosManager.AnimateEnemySpawnCard(slotN, cardCodeHeld);


            AnimateCoverCardBy(cardOnTable, heldCard);

            return(heldCard);
        }
Esempio n. 10
0
 /// <summary>
 /// Called on each frame when i drag card
 /// </summary>
 public void DraggedCardUpdate(Vector2 mousePos, CardRoot cardRoot)
 {
     //if it was dragged insude table rect
     if (RectTransformUtility.RectangleContainsScreenPoint(TableDropZone, mousePos))
     {
         FoolObservable.OnDraggedCardUpdate(mousePos, cardRoot, true);
     }
     else
     {
         FoolObservable.OnDraggedCardUpdate(mousePos, cardRoot, false);
     }
 }
Esempio n. 11
0
        //todo show discarded card backs
        /// <summary>
        /// Animates moving card to discardpile (отбой)
        /// </summary>
        public void AnimateRemoveCardToDiscardPile(CardRoot cardRoot, float delay = 0f)
        {
            if (cardRoot == null)
            {
                return;
            }
            //bug null reference if other player leaves
            float duration = 1f;

            cardRoot.AnimateMoveToPosition(transform.position, duration, delay);
            cardRoot.DestroyCard(delay + duration);
        }
Esempio n. 12
0
        /// <summary>
        /// Animate taking cards from talon one by one with slight delay between every card
        /// </summary>
        private IEnumerator AnimateCardsFromTalon(int cardsN)
        {
            for (int i = 0; i < cardsN; i++)
            {
                //Spawn card as child of this trahsform.
                CardRoot cardRootScript = SpawnCardInHand();
                cardRootScript.transform.SetParent(_talonTransform, false);

                //Init animation
                cardRootScript.AnimateMoveToTransform(HandContainer);

                yield return(new WaitForSeconds(0.1f)); //StaticParameters.TalonAnimationDelay);
            }

            //UpdateCardsInHand();
        }
Esempio n. 13
0
        /// <summary>
        /// If me dropped card on table while defending then check if action is possible
        /// </summary>
        protected bool CanCoverThisCardWith(CardRoot cardOnTable, CardRoot heldCard)
        {
            //if table is empty
            if (TableIsEmpty || AllCardsCovered)
            {
                // say 'you are defending'
                GameplayMessageManager.Instance.ShowFullScreenText("На вас ходят");
                return(false);
            }

            //if i passed
            if (DefenderPassedPriority)
            {
                // say 'you passed'
                GameplayMessageManager.Instance.ShowFullScreenText("Вы решили брать");
                return(false);
            }

            bool cardOnTableIsTrump = cardOnTable.IsTrump();
            bool droppedCardIsTrump = heldCard.IsTrump();

            if (!cardOnTableIsTrump && droppedCardIsTrump)
            {
                return(true);
            }

            if (cardOnTableIsTrump && droppedCardIsTrump &&
                cardOnTable.Value < heldCard.Value)
            {
                return(true);
            }

            if (!cardOnTableIsTrump && !droppedCardIsTrump &&
                cardOnTable.Suit == heldCard.Suit &&
                cardOnTable.Value < heldCard.Value)
            {
                return(true);
            }

            // else
            {
                // say 'you can not defend with this card'
                GameplayMessageManager.Instance.ShowFullScreenText("Вы не можете побиться этой картой");
                return(false);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Animates covering card on table with held card
        /// </summary>
        protected void CoverThisCardWith(CardRoot cardOnTable, CardRoot heldCard)
        {
            //TODO save action in buffer for in case if server will say no so we can ctrl+z this action
            // Beat it
            AnimateCoverCardBy(cardOnTable, heldCard);

            heldCard.InteractionDisable();

            // add to list
            cardsOnTableCovering.Add(heldCard);
            //Set cards parameters
            cardOnTable.IsCoveredByACard = true;
            cardOnTable.CoveredByCard    = heldCard;


            // Send to server
            ClientSendPackets.Send_CoverCardOnTable(cardOnTable.CardCode, heldCard.CardCode);

            TableUpdated();
        }
Esempio n. 15
0
        /// <summary>
        /// Called on each frame by InputManger when i drag card
        /// Animates cards that can be covered when you are defending
        /// </summary>
        public override void OnDraggedCardUpdate(Vector2 mousePos, CardRoot heldCardRoot, bool inTableZone)
        {
            //Am i defending or attacking?
            if (!MeDefending)
            {
                return;
            }

            //if dragged above a table
            if (inTableZone)
            {
                //Choose cards that can be covered with grabbed card
                var cardsCanBeTargeted = GetCardsCanBeTargetedBy(heldCardRoot);
                if (cardsCanBeTargeted.Count == 0)
                {
                    return;
                }

                //Chose closest beatable card
                var closestCard = GetClosestCardOnTableTo(mousePos);

                //Animate them
                foreach (var cardCanBeTargeted in cardsCanBeTargeted)
                {
                    if (cardCanBeTargeted == closestCard)
                    {
                        cardCanBeTargeted.AnimateTargetedGlow();
                    }
                    else
                    {
                        cardCanBeTargeted.AnimateCanBeTargetedGlow();
                    }
                }
            }
            else
            {
                //if not in table: idle animation
                StopAnimationGlowingCardsOnTable();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Other player covered some card on table
        /// </summary>
        public override void OnOtherPlayerCoversCard(long coveredPlayerId, int slotN,
                                                     string cardOnTableCode, string cardDroppedCode)
        {
            //find card on table
            CardRoot cardOnTable = cardsOnTable.Find(c =>
                                                     !c.IsCoveredByACard && c.CardCode == cardOnTableCode);

            if (cardOnTable == null)
            {
                Debug.LogWarning("Trying to cover non existing card: " + cardOnTableCode + " by " + cardDroppedCode,
                                 this);
                return;
            }

            var droppedCardRoot = AnimateEnemyCoversCard(slotN, cardOnTable, cardDroppedCode);

            //set state
            cardOnTable.IsCoveredByACard = true;
            cardsOnTableCovering.Add(droppedCardRoot);

            TableUpdated();
        }
Esempio n. 17
0
        /// <summary>
        /// Adds card to table from my hand and animates it
        /// </summary>
        protected void MeAddCardToTable(CardRoot heldCard)
        {
            //disable interactions
            heldCard.InteractionDisable();
            //ADD CARD
            cardsOnTable.Add(heldCard);

            //init animation
            AnimateAddCardOnTableFromMyHand(heldCard);

            //TODO save action in buffer for in case if server will say no so we can ctrl+z this action
            //Send to server
            ClientSendPackets.Send_DropCardOnTable(heldCard.CardCode);

            // if my hand is empty then count as pass
            if (StaticRoomData.MyPlayer.CardsNumber == 0 && MeLeadAttack)
            {
                AttackerPassedPriority = true;
            }

            TableUpdated();
        }
Esempio n. 18
0
        /// <summary>
        /// Returns physically closest card to mousePos
        /// </summary>
        protected CardRoot GetClosestCardOnTableTo(Vector2 mousePos)
        {
            CardRoot closest     = null;
            float    minDistance = float.MaxValue;

            foreach (var cardOnTable in cardsOnTable)
            {
                if (cardOnTable.IsCoveredByACard)
                {
                    continue;
                }

                float dist = Vector2.Distance(cardOnTable.transform.position, mousePos);
                if (dist < minDistance)
                {
                    minDistance = dist;
                    closest     = cardOnTable;
                }
            }

            return(closest);
        }
Esempio n. 19
0
        /// <summary>
        /// Find cards which can be targeted (has lower value and same suit)
        /// </summary>
        protected List <CardRoot> GetCardsCanBeTargetedBy(CardRoot heldCard)
        {
            //find cards that wasn't covered already
            var cardsCanBeTargeted = cardsOnTable.Where(card => !card.IsCoveredByACard);

            //held card is a trump?
            if (heldCard.IsTrump())
            {
                //find cards that ...
                return(cardsCanBeTargeted.Where(
                           card => !card.IsTrump() || //.. are not trump
                           (card.IsTrump() && card.Value < heldCard.Value)) //.. or cheaper trump
                       .ToList());                                          // return as list
            }
            else //held card is not a trump
            {
                //find cards that ...
                return(cardsCanBeTargeted.Where(
                           card => card.Value < heldCard.Value && //.. cheaper than held card
                           card.Suit == heldCard.Suit) //.. and has same suit
                       .ToList());                     // return as list
            }
        }
Esempio n. 20
0
 public void RemoveCardFromHand(CardRoot cardRoot)
 {
     CardsInHand.Remove(cardRoot);
 }
Esempio n. 21
0
 protected abstract CardRoot AnimateEnemyCoversCard(int slotN, CardRoot cardOnTable, string cardCodeHeld);
Esempio n. 22
0
 protected abstract void AnimateCoverCardBy(CardRoot cardOnTable, CardRoot heldCard);
Esempio n. 23
0
 protected abstract void AnimateAddCardOnTableFromMyHand(CardRoot cardRoot);
Esempio n. 24
0
 protected override void AnimateAddCardOnTableFromMyHand(CardRoot cardRoot)
 {
     _myPlayerInfoDisplay.RemoveCardFromHand(cardRoot);
     _tableDisplay.AnimateDropCardOnTable(cardRoot);
 }
Esempio n. 25
0
        /// <summary>
        /// Animates drop card on table
        /// </summary>
        public void AnimateDropCardOnTable(CardRoot cardRoot)
        {
            cardRoot.AnimateMoveToTransform(this.transform);

            LayoutRebuilder.ForceRebuildLayoutImmediate(this.transform as RectTransform);
        }
Esempio n. 26
0
        /// <summary>
        /// Animates cover existing card on table
        /// </summary>
        public void AnimateCoverCardOnTable(CardRoot cardOnTable, CardRoot cardHeld)
        {
            cardHeld.AnimateMoveToTransform(cardOnTable.transform);

            LayoutRebuilder.ForceRebuildLayoutImmediate(this.transform as RectTransform);
        }
 /// <summary>
 /// Sent by InputManager when i drag card arund the screen
 /// </summary>
 public virtual void OnDraggedCardUpdate(Vector2 mousePos, CardRoot heldCardRoot, bool inTableZone)
 {
 }
 /// <summary>
 /// Sent by InputManager when i release card from hand
 /// </summary>
 public virtual void OnCardDroppedOnTableByMe(CardRoot heldCard)
 {
 }