Ejemplo n.º 1
0
        public void HoverPlayerCardOnBattleground(Player player, BoardCard card, HandBoardCard handCard)
        {
            Card libraryCard = card.WorkingCard.LibraryCard;

            if (libraryCard.CardKind == Enumerators.CardKind.CREATURE)
            {
                int   newIndexOfCard          = 0;
                float newCreatureCardPosition = card.Transform.position.x;

                // set correct position on board depends from card view position
                for (int i = 0; i < player.BoardCards.Count; i++)
                {
                    if (newCreatureCardPosition > player.BoardCards[i].Transform.position.x)
                    {
                        newIndexOfCard = i + 1;
                    }
                    else
                    {
                        break;
                    }
                }

                if (player.BoardCards.Count > 0 && _indexOfCard != newIndexOfCard)
                {
                    _indexOfCard = newIndexOfCard;

                    List <BoardUnit> playerCards   = _gameplayManager.CurrentPlayer.BoardCards;
                    List <BoardUnit> toArrangeList = new List <BoardUnit>();

                    for (int i = 0; i < playerCards.Count; i++)
                    {
                        toArrangeList.Add(playerCards[i]);
                    }

                    if (_fakeBoardCard != null)
                    {
                        Object.Destroy(_fakeBoardCard.GameObject);
                        _fakeBoardCard = null;
                    }

                    _fakeBoardCard = new BoardUnit(_playerBoard.transform);
                    toArrangeList.Insert(_indexOfCard, _fakeBoardCard);

                    _battlegroundController.UpdatePositionOfBoardUnitsOfPlayer(toArrangeList);
                }
            }
        }
Ejemplo n.º 2
0
        private BoardCard CreateBoardCard(WorkingCard card)
        {
            GameObject go;
            BoardCard  boardCard;

            switch (card.LibraryCard.CardKind)
            {
            case Enumerators.CardKind.CREATURE:
                go        = Object.Instantiate(CreatureCardViewPrefab);
                boardCard = new UnitBoardCard(go);
                break;

            case Enumerators.CardKind.SPELL:
                go        = Object.Instantiate(SpellCardViewPrefab);
                boardCard = new SpellBoardCard(go);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            boardCard.Init(card);
            boardCard.CurrentTurn = _battlegroundController.CurrentTurn;

            HandBoardCard handCard = new HandBoardCard(go, boardCard);

            handCard.OwnerPlayer    = card.Owner;
            handCard.BoardZone      = _playerBoard;
            boardCard.HandBoardCard = handCard;
            handCard.CheckStatusOfHighlight();
            boardCard.Transform.localScale = Vector3.one * .3f;

            _abilitiesController.CallAbilitiesInHand(boardCard, card);

            return(boardCard);
        }
Ejemplo n.º 3
0
        public void CallAbility(
            Card libraryCard,
            BoardCard card,
            WorkingCard workingCard,
            Enumerators.CardKind kind,
            object boardObject,
            Action <BoardCard> action,
            bool isPlayer,
            Action onCompleteCallback,
            object target          = null,
            HandBoardCard handCard = null)
        {
            ResolveAllAbilitiesOnUnit(boardObject, false);

            bool          canUseAbility = false;
            ActiveAbility activeAbility = null;

            foreach (AbilityData item in libraryCard.Abilities)
            {
                // todo improve it bcoz can have queue of abilities with targets
                activeAbility =
                    CreateActiveAbility(item, kind, boardObject, workingCard.Owner, libraryCard, workingCard);

                if (IsAbilityCanActivateTargetAtStart(item))
                {
                    canUseAbility = true;
                }
                else
                {
                    activeAbility.Ability.Activate();
                }
            }

            if (kind == Enumerators.CardKind.SPELL)
            {
            }
            else
            {
                workingCard.Owner.RemoveCardFromHand(workingCard);
                workingCard.Owner.AddCardToBoard(workingCard);
            }

            if (kind == Enumerators.CardKind.SPELL)
            {
                if (handCard != null && isPlayer)
                {
                    handCard.GameObject.SetActive(false);
                }
            }

            if (canUseAbility)
            {
                AbilityData ability = libraryCard.Abilities.Find(x => IsAbilityCanActivateTargetAtStart(x));

                if (ability.TargetCardType != Enumerators.CardType.NONE &&
                    !HasSpecialUnitOnBoard(workingCard, ability) ||
                    ability.TargetUnitStatusType != Enumerators.UnitStatusType.NONE &&
                    !HasSpecialUnitStatusOnBoard(workingCard, ability))
                {
                    CallPermanentAbilityAction(isPlayer, action, card, target, activeAbility, kind);

                    onCompleteCallback?.Invoke();

                    ResolveAllAbilitiesOnUnit(boardObject);
                    return;
                }

                if (CheckActivateAvailability(kind, ability, workingCard.Owner))
                {
                    activeAbility.Ability.Activate();

                    if (isPlayer)
                    {
                        activeAbility.Ability.ActivateSelectTarget(
                            callback: () =>
                        {
                            if (kind == Enumerators.CardKind.SPELL && isPlayer)
                            {
                                card.WorkingCard.Owner.Goo -= card.ManaCost;
                                _tutorialManager.ReportAction(Enumerators.TutorialReportAction.MOVE_CARD);

                                handCard.GameObject.SetActive(true);
                                card.RemoveCardParticle.Play();     // move it when card should call hide action

                                workingCard.Owner.RemoveCardFromHand(workingCard, true);
                                workingCard.Owner.AddCardToBoard(workingCard);

                                GameClient.Get <ITimerManager>().AddTimer(_cardsController.RemoveCard, new object[]
                                {
                                    card
                                }, 0.5f);

                                GameClient.Get <ITimerManager>().AddTimer(
                                    creat =>
                                {
                                    workingCard.Owner.GraveyardCardsCount++;

                                    _actionsQueueController.PostGameActionReport(
                                        _actionsQueueController.FormatGameActionReport(
                                            Enumerators.ActionType.PLAY_SPELL_CARD, new object[]
                                    {
                                        workingCard.Owner, card
                                    }));
                                },
                                    null,
                                    1.5f);
                            }

                            action?.Invoke(card);

                            onCompleteCallback?.Invoke();

                            ResolveAllAbilitiesOnUnit(boardObject);
                        },
                            failedCallback: () =>
                        {
                            if (kind == Enumerators.CardKind.SPELL && isPlayer)
                            {
                                handCard.GameObject.SetActive(true);
                                handCard.ResetToHandAnimation();
                                handCard.CheckStatusOfHighlight();

                                workingCard.Owner.CardsInHand.Add(card.WorkingCard);
                                _battlegroundController.PlayerHandCards.Add(card);
                                _battlegroundController.UpdatePositionOfCardsInPlayerHand();

                                _playerController.IsCardSelected = false;
                            }
                            else
                            {
                                Debug.Log("RETURN CARD TO HAND MAYBE.. SHOULD BE CASE !!!!!");
                                action?.Invoke(card);
                            }

                            onCompleteCallback?.Invoke();

                            ResolveAllAbilitiesOnUnit(boardObject);
                        });
                    }
                    else
                    {
                        switch (target)
                        {
                        case BoardUnit unit:
                            activeAbility.Ability.TargetUnit = unit;
                            break;

                        case Player player:
                            activeAbility.Ability.TargetPlayer = player;
                            break;
                        }

                        activeAbility.Ability.SelectedTargetAction(true);

                        _battlegroundController.UpdatePositionOfBoardUnitsOfPlayer(_gameplayManager.CurrentPlayer
                                                                                   .BoardCards);
                        _battlegroundController.UpdatePositionOfBoardUnitsOfOpponent();

                        onCompleteCallback?.Invoke();

                        ResolveAllAbilitiesOnUnit(boardObject);
                    }
                }
                else
                {
                    CallPermanentAbilityAction(isPlayer, action, card, target, activeAbility, kind);
                    onCompleteCallback?.Invoke();

                    ResolveAllAbilitiesOnUnit(boardObject);
                }
            }
            else
            {
                CallPermanentAbilityAction(isPlayer, action, card, target, activeAbility, kind);
                onCompleteCallback?.Invoke();

                ResolveAllAbilitiesOnUnit(boardObject);
            }
        }
Ejemplo n.º 4
0
        public void PlayPlayerCard(Player player, BoardCard card, HandBoardCard handCard)
        {
            if (card.CanBePlayed(card.WorkingCard.Owner))
            {
                Card libraryCard = card.WorkingCard.LibraryCard;

                card.Transform.DORotate(Vector3.zero, .1f);
                card.HandBoardCard.Enabled = false;

                _soundManager.PlaySound(Enumerators.SoundType.CARD_FLY_HAND_TO_BATTLEGROUND,
                                        Constants.CardsMoveSoundVolume);

                player.ThrowPlayCardEvent(card.WorkingCard);

                switch (libraryCard.CardKind)
                {
                case Enumerators.CardKind.CREATURE:
                {
                    int   indexOfCard             = 0;
                    float newCreatureCardPosition = card.Transform.position.x;

                    // set correct position on board depends from card view position
                    for (int i = 0; i < player.BoardCards.Count; i++)
                    {
                        if (newCreatureCardPosition > player.BoardCards[i].Transform.position.x)
                        {
                            indexOfCard = i + 1;
                        }
                        else
                        {
                            break;
                        }
                    }

                    BoardUnit boardUnit = new BoardUnit(_playerBoard.transform);
                    boardUnit.Transform.tag      = SRTags.PlayerOwned;
                    boardUnit.Transform.parent   = _playerBoard.transform;
                    boardUnit.Transform.position = new Vector2(1.9f * player.BoardCards.Count, 0);
                    boardUnit.OwnerPlayer        = card.WorkingCard.Owner;
                    boardUnit.SetObjectInfo(card.WorkingCard);

                    _battlegroundController.PlayerHandCards.Remove(card);
                    _battlegroundController.PlayerBoardCards.Add(boardUnit);
                    player.AddCardToBoard(card.WorkingCard);
                    player.RemoveCardFromHand(card.WorkingCard);

                    player.BoardCards.Insert(indexOfCard, boardUnit);

                    _timerManager.AddTimer(
                        creat =>
                        {
                            card.WorkingCard.Owner.GraveyardCardsCount++;
                        });

                    card.RemoveCardParticle.Play();

                    _actionsQueueController.PostGameActionReport(_actionsQueueController.FormatGameActionReport(
                                                                     Enumerators.ActionType.PLAY_UNIT_CARD, new object[]
                        {
                            boardUnit.OwnerPlayer, boardUnit
                        }));

                    UpdateCardsStatusEvent?.Invoke(player);

                    Sequence animationSequence = DOTween.Sequence();
                    animationSequence.Append(card.Transform.DOScale(new Vector3(.27f, .27f, .27f), 1f));
                    animationSequence.OnComplete(
                        () =>
                        {
                            RemoveCard(new object[]
                            {
                                card
                            });

                            _timerManager.AddTimer(
                                param =>
                            {
                                boardUnit.PlayArrivalAnimation();
                                _battlegroundController.UpdatePositionOfBoardUnitsOfPlayer(
                                    _gameplayManager.CurrentPlayer.BoardCards,
                                    () =>
                                {
                                    _abilitiesController.CallAbility(libraryCard, card, card.WorkingCard,
                                                                     Enumerators.CardKind.CREATURE, boardUnit, CallCardPlay, true, null);
                                });
                            },
                                null,
                                0.1f);
                        });

                    player.Goo -= card.ManaCost;
                    _tutorialManager.ReportAction(Enumerators.TutorialReportAction.MOVE_CARD);
                    break;
                }

                case Enumerators.CardKind.SPELL:
                {
                    player.CardsInHand.Remove(card.WorkingCard);
                    _battlegroundController.PlayerHandCards.Remove(card);
                    _battlegroundController.UpdatePositionOfCardsInPlayerHand();

                    card.GameObject.GetComponent <SortingGroup>().sortingLayerID = SRSortingLayers.BoardCards;
                    card.GameObject.GetComponent <SortingGroup>().sortingOrder   = 1000;

                    BoardSpell boardSpell = new BoardSpell(card.GameObject, card.WorkingCard);
                    boardSpell.Transform.position = Vector3.zero;

                    _abilitiesController.CallAbility(libraryCard, card, card.WorkingCard,
                                                     Enumerators.CardKind.SPELL, boardSpell, CallSpellCardPlay, true, null, handCard: handCard);
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                card.HandBoardCard.ResetToInitialPosition();
            }
        }