public override bool IsActionPossible(CardSlot source, CardSlot target)
        {
            var actionPoints = source.Card.GetComponent <ActionPointsComponent>();

            if (actionPoints != null && actionPoints.CurrentActionPoints < Cost)
            {
                Utilities.SpawnFloatingText("Insufficient action points!", Color.red, source.Card.transform);
                return(false);
            }
            var targetHealthComponent = target.Card.GetComponent <HealthComponent>();

            if (targetHealthComponent == null)
            {
                Utilities.SpawnFloatingText("Invalid target!", Color.red, source.Card.transform);
                return(false);
            }
            var rowManager = source.transform.parent.GetComponent <RowManager>();

            if (rowManager != target.transform.parent.GetComponent <RowManager>())
            {
                Utilities.SpawnFloatingText("Invalid row!", Color.red, source.Card.transform);
                return(false);
            }
            if (IsTargetOutsideRange(rowManager, source, target))
            {
                Utilities.SpawnFloatingText("Outside range!", Color.red, source.Card.transform);
                return(false);
            }
            return(true);
        }
Beispiel #2
0
 public int GetDistanceBetweenCards(CardSlot slot1, CardSlot slot2)
 {
     Assert.IsNotNull(slot1);
     Assert.IsNotNull(slot2);
     Assert.IsFalse(slot1 == slot2);
     return(Mathf.Abs(currentCardSlots.IndexOf(slot1) - currentCardSlots.IndexOf(slot2)));
 }
Beispiel #3
0
        public override bool IsActionPossible(CardSlot source, CardSlot target)
        {
            var actionPoints = source.Card.GetComponent <ActionPointsComponent>();

            if (actionPoints != null && actionPoints.CurrentActionPoints < Cost)
            {
                Utilities.SpawnFloatingText("Insufficient action points!", Color.red, source.Card.transform);
                return(false);
            }
            var rowManager = source.transform.parent.GetComponent <RowManager>();

            if (rowManager != target.transform.parent.GetComponent <RowManager>())
            {
                Utilities.SpawnFloatingText("Invalid row!", Color.red, source.Card.transform);
                return(false);
            }
            int selectedIndex = rowManager.GetIndexOfCard(source.Card);
            int otherIndex    = rowManager.GetIndexOfCard(target.Card);

            if (Mathf.Abs(selectedIndex - otherIndex) == 1)
            {
                return(true);
            }
            else
            {
                Utilities.SpawnFloatingText("Outside range!", Color.red, source.Card.transform);
                return(false);
            }
        }
Beispiel #4
0
 private void OnCardSlotSelectionChange(CardSlot previous, CardSlot current)
 {
     if (InputManager.Instance != null)
     {
         var availableActions = InputManager.Instance.GetAvailableActions();
         if (availableActions.Count > 0)
         {
             for (int i = 0; i < buttons.Length; ++i)
             {
                 if (i >= availableActions.Count)
                 {
                     buttons[i].SetActionIndex(-1);
                 }
                 else
                 {
                     buttons[i].SetActionIndex(i);
                 }
             }
             GetComponent <Image>().enabled = true;
         }
         else
         {
             for (int i = 0; i < buttons.Length; ++i)
             {
                 buttons[i].SetActionIndex(-1);
             }
             GetComponent <Image>().enabled = false;
         }
     }
 }
Beispiel #5
0
 public void RemoveCard(CardSlot slotWithCard)
 {
     Assert.IsTrue(currentCardSlots.Contains(slotWithCard));
     slotWithCard.RemoveCard();
     currentCardSlots.Remove(slotWithCard);
     slotWithCard.LifecycleComponent.OnLifecycleComponentDestroyed -= OnSlotDestroyed;
     Destroy(slotWithCard.gameObject);
 }
Beispiel #6
0
 private void OnSlotSelected(CardSlot previous, CardSlot current)
 {
     if (current == this)
     {
         button.colors = selectedColorBlock;
     }
     else
     {
         button.colors = defaultColorBlock;
     }
 }
Beispiel #7
0
        private void ProcessAction(CardSlot otherSlot)
        {
            var selectedCard    = SelectedCardSlot.Card;
            var playerOwnedCard = selectedCard as IActionProvider;

            Assert.IsNotNull(playerOwnedCard);
            var availableActions = playerOwnedCard.GetAvailableActions();

            Assert.IsTrue(SelectedActionIndex >= 0 && SelectedActionIndex < availableActions.Count);
            availableActions[SelectedActionIndex].ExecuteAction(SelectedCardSlot, otherSlot);
            SelectedCardSlot = selectedCard.GetComponentInParent <CardSlot>();
        }
        private bool IsTargetOutsideRange(RowManager rowManager, CardSlot source, CardSlot target)
        {
            int selectedIndex = rowManager.GetIndexOfCard(source.Card);
            int otherIndex    = rowManager.GetIndexOfCard(target.Card);
            int distance      = Mathf.Abs(selectedIndex - otherIndex);

            if (distance >= MinRange && distance <= MaxRange)
            {
                return(false);
            }
            return(true);
        }
 public override void ExecuteAction(CardSlot source, CardSlot target)
 {
     if (IsActionPossible(source, target))
     {
         var actionPoints = source.Card.GetComponent <ActionPointsComponent>();
         if (actionPoints != null)
         {
             actionPoints.Spend(Cost);
         }
         var targetHealthComponent = target.Card.GetComponent <HealthComponent>();
         targetHealthComponent.Damage(Damage);
         Utilities.SpawnFloatingText(Name, Color.grey, source.Card.transform);
         LogManager.Instance.AddMessage(source.Card.CardName + " attacked " + target.Card.CardName + " with " + Name + " for " + Damage.ToString() + " damage");
         AudioManager.Instance.PlaySound(Name);
     }
 }
Beispiel #10
0
 public override void ExecuteAction(CardSlot source, CardSlot target)
 {
     if (IsActionPossible(source, target))
     {
         var actionPoints = source.Card.GetComponent <ActionPointsComponent>();
         if (actionPoints != null)
         {
             actionPoints.Spend(Cost);
         }
         var rowManager  = source.transform.parent.GetComponent <RowManager>();
         int sourceIndex = rowManager.GetIndexOfCard(source.Card);
         int targetIndex = rowManager.GetIndexOfCard(target.Card);
         Utilities.SpawnFloatingText("Move", Color.grey, source.Card.transform);
         if (sourceIndex < targetIndex)
         {
             rowManager.MoveCardRight(source);
         }
         else if (sourceIndex > targetIndex)
         {
             rowManager.MoveCardLeft(source);
         }
     }
 }
 public override void ExecuteAction(CardSlot source, CardSlot target)
 {
     if (IsActionPossible(source, target))
     {
         var actionPoints = source.Card.GetComponent <ActionPointsComponent>();
         Utilities.SpawnFloatingText("Switch row", Color.grey, source.Card.transform);
         if (actionPoints != null)
         {
             actionPoints.Spend(Cost);
         }
         var targetRowManager = target.transform.parent.GetComponent <RowManager>();
         int targetIndex      = targetRowManager.GetIndexOfCard(target.Card);
         if (targetIndex == 0)
         {
             targetRowManager.AddCardToRowOnLeft(source.Card);
         }
         else
         {
             targetRowManager.AddCardToRowOnRight(source.Card);
         }
         source.transform.parent.GetComponent <RowManager>().RemoveCard(source);
     }
 }
Beispiel #12
0
 private void CardSlotClicked(CardSlot cardSlot)
 {
     Assert.IsNotNull(cardSlot);
     if (inputBlockade)
     {
         return;
     }
     inputBlockade = true;
     if (SelectedCardSlot == cardSlot)
     {
         SelectedCardSlot = null;
     }
     else
     {
         if (SelectedActionIndex != NO_ACTION)
         {
             ProcessAction(cardSlot);
         }
         else
         {
             SelectedCardSlot = cardSlot;
         }
     }
 }
Beispiel #13
0
 public void MoveCardToIndex(CardSlot slotWithCard, int destinationIndex)
 {
     Assert.IsTrue(currentCardSlots.Contains(slotWithCard));
     MoveCardToIndex(currentCardSlots.IndexOf(slotWithCard), destinationIndex);
 }
Beispiel #14
0
 public void MoveCardRight(CardSlot slotWithCard)
 {
     Assert.IsTrue(currentCardSlots.Contains(slotWithCard));
     MoveCardRight(currentCardSlots.IndexOf(slotWithCard));
 }
Beispiel #15
0
 private void OnSelectedCardDestroyed(LifecycleComponent lifecycleComponent)
 {
     SelectedCardSlot = null;
 }
Beispiel #16
0
 private void OnTurnEnd()
 {
     SelectedCardSlot = null;
 }