Example #1
0
 /// <summary>
 /// Initializes this panel.
 /// </summary>
 public void Init(Gold goldManager)
 {
     _goldManager = goldManager;
     SetGold(_goldManager.CurrentGold);
 }
        /// <summary>
        /// Handles card play request.
        /// If user playing the card has insufficiend gold or used card can not be played on specified node,
        /// a cancel message is sent to that card owner and its effects don't resolve.
        /// </summary>
        private void HandleCardRequest(MatchMessageCardPlayRequest message, Hand hand, Gold gold)
        {
            int cost = message.Card.CardData.GetCardInfo().Cost;

            if (gold.CurrentGold < cost)
            {
                SendCardCanceledMessage(message);
            }
            else
            {
                bool       isHost       = _connection.BattleConnection.HostId == _connection.Session.UserId;
                Vector3    position     = new Vector3(message.X, message.Y, message.Z);
                Vector2Int nodePosition = ScreenToNodePos(position, isHost, message.Card.CardData.GetCardInfo().DropRegion);
                Node       node         = Nodes[nodePosition.x, nodePosition.y];

                if (node != null && (node.Unit == null || message.Card.CardData.GetCardInfo().CanBeDroppedOverOtherUnits))
                {
                    SendCardPlayedMessage(message, hand, nodePosition);
                }
                else
                {
                    SendCardCanceledMessage(message);
                }
            }
        }