Beispiel #1
0
        private void ReviveUnit(WorkingCard workingCard)
        {
            Player playerOwner = workingCard.Owner;

            if (playerOwner.BoardCards.Count >= Constants.MaxBoardUnits)
            {
                return;
            }

            Card libraryCard = workingCard.LibraryCard.Clone();

            WorkingCard card = new WorkingCard(libraryCard, playerOwner);
            BoardUnit   unit = BattlegroundController.CreateBoardUnit(playerOwner, card);

            playerOwner.RemoveCardFromGraveyard(workingCard);
            playerOwner.AddCardToBoard(card);
            playerOwner.BoardCards.Add(unit);

            if (playerOwner.IsLocalPlayer)
            {
                BattlegroundController.PlayerBoardCards.Add(unit);
                BattlegroundController.UpdatePositionOfBoardUnitsOfPlayer(GameplayManager.CurrentPlayer.BoardCards);
            }
            else
            {
                BattlegroundController.OpponentBoardCards.Add(unit);
                BattlegroundController.UpdatePositionOfBoardUnitsOfOpponent();
            }
        }
        public void DrawCardInfo(WorkingCard card)
        {
            GameObject go;
            BoardCard  boardCard;

            switch (card.LibraryCard.CardKind)
            {
            case Enumerators.CardKind.CREATURE:
                go = Object.Instantiate(
                    _loadObjectsManager.GetObjectByPath <GameObject>("Prefabs/Gameplay/Cards/CreatureCard"));
                boardCard = new UnitBoardCard(go);
                break;

            case Enumerators.CardKind.SPELL:
                go = Object.Instantiate(
                    _loadObjectsManager.GetObjectByPath <GameObject>("Prefabs/Gameplay/Cards/SpellCard"));
                boardCard = new SpellBoardCard(go);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            boardCard.Init(card);
            go.transform.position   = new Vector3(-6, 0, 0);
            go.transform.localScale = Vector3.one * .3f;
            boardCard.SetHighlightingEnabled(false);

            Object.Destroy(go, 2f);
        }
        public void AddCardToHand(Player player, WorkingCard card = null)
        {
            if (card == null)
            {
                if (player.CardsInDeck.Count == 0)
                {
                    if (!_tutorialManager.IsTutorial)
                    {
                        player.DamageByNoMoreCardsInDeck++;
                        player.Health -= player.DamageByNoMoreCardsInDeck;
                        _vfxController.SpawnGotDamageEffect(player, -player.DamageByNoMoreCardsInDeck);
                    }
                    return;
                }

                card = player.CardsInDeck[0];
            }

            if (CheckIsMoreThanMaxCards(card, player))
            {
                return;
            }

            player.RemoveCardFromDeck(card);
            player.AddCardToHand(card);
        }
        public GameObject AddCardToHand(WorkingCard card, bool silent = false)
        {
            BoardCard boardCard = CreateBoardCard(card);

            if (_battlegroundController.CurrentTurn == 0)
            {
                boardCard.SetDefaultAnimation(boardCard.WorkingCard.Owner.CardsInHand.Count);
            }

            _battlegroundController.PlayerHandCards.Add(boardCard);

            if (silent)
            {
                boardCard.HandBoardCard.Enabled = false;

                _timerManager.AddTimer(
                    x =>
                {
                    boardCard.HandBoardCard.Enabled = true;
                    boardCard.HandBoardCard.CheckStatusOfHighlight();
                },
                    null,
                    2f);
            }
            else
            {
                boardCard.HandBoardCard.CheckStatusOfHighlight();
            }

            return(boardCard.GameObject);
        }
        public void ReturnCardToHand(BoardUnit unit)
        {
            Player      unitOwner     = unit.OwnerPlayer;
            WorkingCard returningCard = unit.Card;

            returningCard.InitialCost = returningCard.LibraryCard.Cost;
            returningCard.RealCost    = returningCard.InitialCost;

            Vector3 unitPosition = unit.Transform.position;

            _timerManager.AddTimer(
                x =>
            {
                // STEP 1 - REMOVE UNIT FROM BOARD
                unitOwner.BoardCards.Remove(unit);

                // STEP 2 - DESTROY UNIT ON THE BOARD OR ANIMATE
                unit.Die(true);
                Object.Destroy(unit.GameObject);

                // STEP 3 - REMOVE WORKING CARD FROM BOARD
                unitOwner.RemoveCardFromBoard(returningCard);

                // STEP 4 - RETURN CARD TO HAND
                ReturnToHandBoardUnit(returningCard, unitOwner, unitPosition);

                // STEP 4 - REARRANGE HANDS
                _gameplayManager.RearrangeHands();
            },
                null,
                2f);
        }
        private BoardUnit CreateBoardUnit(WorkingCard card, Player owner)
        {
            GameObject playerBoard = owner.IsLocalPlayer ?
                                     BattlegroundController.PlayerBoardObject :
                                     BattlegroundController.OpponentBoardObject;

            BoardUnit boardUnit = new BoardUnit(playerBoard.transform);

            boardUnit.Transform.tag      = owner.IsLocalPlayer ? SRTags.PlayerOwned : SRTags.OpponentOwned;
            boardUnit.Transform.parent   = playerBoard.transform;
            boardUnit.Transform.position =
                new Vector2(2f * owner.BoardCards.Count, owner.IsLocalPlayer ? -1.66f : 1.66f);
            boardUnit.OwnerPlayer = owner;
            boardUnit.SetObjectInfo(card);

            if (!owner.Equals(GameplayManager.CurrentTurnPlayer))
            {
                boardUnit.IsPlayable = true;
            }

            boardUnit.PlayArrivalAnimation();

            GameplayManager.CanDoDragActions = true;

            return(boardUnit);
        }
Beispiel #7
0
        private bool CardCanBePlayable(WorkingCard card)
        {
#if !DEV_MODE
            return(card.LibraryCard.Cost <= _gameplayManager.OpponentPlayer.Goo &&
                   _gameplayManager.OpponentPlayer.Turn > MinTurnForAttack);
#else
            return(true);
#endif
        }
        public GameObject AddCardToOpponentHand(WorkingCard card, bool silent = false)
        {
            GameObject go = CreateOpponentBoardCard();

            _battlegroundController.OpponentHandCards.Add(go);

            _abilitiesController.CallAbilitiesInHand(null, card);

            return(go);
        }
        public void AddCardToDistributionState(Player player, WorkingCard card)
        {
            BoardCard    boardCard    = CreateBoardCard(card);
            SortingGroup sortingGroup = boardCard.GameObject.GetComponent <SortingGroup>();

            sortingGroup.sortingLayerID = SRSortingLayers.GameUI1;
            player.CardsPreparingToHand.Add(boardCard);
            boardCard.HandBoardCard.Enabled = false;
            boardCard.MoveCardFromDeckToCenter();
        }
Beispiel #10
0
        private void CardPlayedHandler(WorkingCard card)
        {
            if (!card.Equals(MainWorkingCard))
            {
                return;
            }

            PlayerCallerOfAbility.HandChanged -= HandChangedHandler;
            PlayerCallerOfAbility.CardPlayed  -= CardPlayedHandler;
        }
        private bool CheckIsMoreThanMaxCards(WorkingCard workingCard, Player player)
        {
            if (player.CardsInHand.Count >= Constants.MaxCardsInHand)
            {
                // IMPROVE ANIMATION
                return(true);
            }

            return(false);
        }
Beispiel #12
0
        public BoardSpell(GameObject obj, WorkingCard card)
        {
            GameObject = obj;
            Transform  = obj.transform;

            Card = card;

            _eventHandler = GameObject.GetComponent <OnBehaviourHandler>();

            _eventHandler.Destroying += DestroyingHandler;
        }
        public void CallAbilitiesInHand(BoardCard boardCard, WorkingCard card)
        {
            List <AbilityData> handAbilities =
                card.LibraryCard.Abilities.FindAll(x => x.AbilityCallType.Equals(Enumerators.AbilityCallType.IN_HAND));

            foreach (AbilityData ability in handAbilities)
            {
                CreateActiveAbility(ability, card.LibraryCard.CardKind, boardCard, card.Owner, card.LibraryCard, card)
                .Ability.Activate();
            }
        }
Beispiel #14
0
        public virtual void Init(WorkingCard card)
        {
            WorkingCard = card;

            LibraryCard = WorkingCard.LibraryCard;

            NameText.text = LibraryCard.Name;
            BodyText.text = LibraryCard.Description;
            CostText.text = LibraryCard.Cost.ToString();

            IsNewCard = true;

            InitialCost = WorkingCard.InitialCost;
            ManaCost    = InitialCost;

            WorkingCard.Owner.PlayerGooChanged += PlayerGooChangedHandler;

            string rarity = Enum.GetName(typeof(Enumerators.CardRank), WorkingCard.LibraryCard.CardRank);

            string setName = LibraryCard.CardSetType.ToString();

            string frameName = string.Format("Images/Cards/Frames/frame_{0}_{1}", setName, rarity);

            if (!string.IsNullOrEmpty(LibraryCard.Frame))
            {
                frameName = "Images/Cards/Frames/" + LibraryCard.Frame;
            }

            BackgroundSprite.sprite = LoadObjectsManager.GetObjectByPath <Sprite>(frameName);
            PictureSprite.sprite    = LoadObjectsManager.GetObjectByPath <Sprite>(string.Format(
                                                                                      "Images/Cards/Illustrations/{0}_{1}_{2}", setName.ToLower(), rarity.ToLower(),
                                                                                      WorkingCard.LibraryCard.Picture.ToLower()));

            AmountText.transform.parent.gameObject.SetActive(false);
            DistibuteCardObject.SetActive(false);

            if (LibraryCard.CardKind == Enumerators.CardKind.CREATURE)
            {
                ParentOfLeftBlockOfCardInfo  = Transform.Find("Group_LeftBlockInfo");
                ParentOfRightBlockOfCardInfo = Transform.Find("Group_RightBlockInfo");

                if (!InternalTools.IsTabletScreen())
                {
                    ParentOfLeftBlockOfCardInfo.transform.localScale    = new Vector3(.7f, .7f, .7f);
                    ParentOfLeftBlockOfCardInfo.transform.localPosition = new Vector3(10f, 6.8f, 0f);

                    ParentOfRightBlockOfCardInfo.transform.localScale    = new Vector3(.7f, .7f, .7f);
                    ParentOfRightBlockOfCardInfo.transform.localPosition = new Vector3(17f, 6.8f, 0f);
                }
            }
        }
        public void CreateNewCardByNameAndAddToHand(Player player, string name)
        {
            float animationDuration = 1.5f;

            Card        card        = _dataManager.CachedCardsLibraryData.GetCardFromName(name).Clone();
            WorkingCard workingCard = new WorkingCard(card, player);

            if (CheckIsMoreThanMaxCards(workingCard, player))
            {
                return;
            }

            if (player.IsLocalPlayer)
            {
                BoardCard boardCard = CreateBoardCard(workingCard);

                boardCard.Transform.position   = Vector3.zero;
                boardCard.Transform.localScale = Vector3.zero;

                boardCard.Transform.DOScale(Vector3.one * .3f, animationDuration);

                _timerManager.AddTimer(
                    x =>
                {
                    _battlegroundController.PlayerHandCards.Add(boardCard);

                    player.CardsInHand.Add(workingCard);

                    _battlegroundController.UpdatePositionOfCardsInPlayerHand(true);
                },
                    null,
                    animationDuration);
            }
            else
            {
                GameObject boardCard = AddCardToOpponentHand(workingCard);
                boardCard.transform.position   = Vector3.zero;
                boardCard.transform.localScale = Vector3.zero;

                boardCard.transform.DOScale(Vector3.one, animationDuration);

                _timerManager.AddTimer(
                    x =>
                {
                    player.CardsInHand.Add(workingCard);
                    _battlegroundController.UpdatePositionOfCardsInOpponentHand(true);
                },
                    null,
                    animationDuration);
            }
        }
        public void PlayOpponentCard(
            Player player, WorkingCard card, object target, Action <WorkingCard, object> completePlayCardCallback)
        {
            GameObject randomCard =
                _battlegroundController.OpponentHandCards[
                    Random.Range(0, _battlegroundController.OpponentHandCards.Count)];

            _battlegroundController.OpponentHandCards.Remove(randomCard);

            _tutorialManager.ReportAction(Enumerators.TutorialReportAction.MOVE_CARD);

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

            player.ThrowPlayCardEvent(card);

            randomCard.transform.DOMove(Vector3.up * 2.5f, 0.6f).OnComplete(
                () =>
            {
                randomCard.transform.Find("RemoveCardParticle").GetComponent <ParticleSystem>().Play();

                randomCard.transform.DOScale(Vector3.one * 1.2f, 0.6f).OnComplete(
                    () =>
                {
                    RemoveOpponentCard(new object[]
                    {
                        randomCard
                    });

                    _timerManager.AddTimer(
                        x =>
                    {
                        completePlayCardCallback?.Invoke(card, target);
                    },
                        null,
                        0.1f);
                    _ranksController.UpdateRanksByElements(player.BoardCards, card.LibraryCard);
                    _timerManager.AddTimer(
                        x =>
                    {
                        player.GraveyardCardsCount++;
                    });
                });
            });

            randomCard.transform.DORotate(Vector3.zero, 0.5f);

            _battlegroundController.UpdatePositionOfCardsInOpponentHand(true);
        }
        public bool HasSpecialUnitOnBoard(WorkingCard workingCard, AbilityData ability)
        {
            if (ability.AbilityTargetTypes.Count == 0)
            {
                return(false);
            }

            Player opponent = workingCard.Owner.Equals(_gameplayManager.CurrentPlayer) ?
                              _gameplayManager.OpponentPlayer :
                              _gameplayManager.CurrentPlayer;
            Player player = workingCard.Owner;

            foreach (Enumerators.AbilityTargetType target in ability.AbilityTargetTypes)
            {
                switch (target)
                {
                case Enumerators.AbilityTargetType.PLAYER_CARD:
                {
                    List <BoardUnit> units =
                        player.BoardCards.FindAll(x =>
                                                  x.InitialUnitType == ability.TargetCardType &&
                                                  x.UnitStatus == ability.TargetUnitStatusType);
                    if (units.Count > 0)
                    {
                        return(true);
                    }

                    break;
                }

                case Enumerators.AbilityTargetType.OPPONENT_CARD:
                {
                    List <BoardUnit> units =
                        opponent.BoardCards.FindAll(x =>
                                                    x.InitialUnitType == ability.TargetCardType &&
                                                    x.UnitStatus == ability.TargetUnitStatusType);
                    if (units.Count > 0)
                    {
                        return(true);
                    }

                    break;
                }
                }
            }

            return(false);
        }
Beispiel #18
0
        private void PlayCardOnBoard(WorkingCard card)
        {
            bool needTargetForAbility = false;

            if (card.LibraryCard.Abilities != null && card.LibraryCard.Abilities.Count > 0)
            {
                needTargetForAbility =
                    card.LibraryCard.Abilities.FindAll(x => x.AbilityTargetTypes.Count > 0).Count > 0;
            }

            object target = null;

            if (needTargetForAbility)
            {
                target = GetAbilityTarget(card);
            }

            switch (card.LibraryCard.CardKind)
            {
            case Enumerators.CardKind.CREATURE
                when _battlegroundController.OpponentBoardCards.Count < Constants.MaxBoardUnits:
                _gameplayManager.OpponentPlayer.RemoveCardFromHand(card);
                _gameplayManager.OpponentPlayer.AddCardToBoard(card);

                _cardsController.PlayOpponentCard(_gameplayManager.OpponentPlayer, card, target,
                                                  PlayCardCompleteHandler);

                _cardsController.DrawCardInfo(card);
                break;

            case Enumerators.CardKind.SPELL:
            {
                if (target != null && needTargetForAbility || !needTargetForAbility)
                {
                    _gameplayManager.OpponentPlayer.RemoveCardFromHand(card);
                    _gameplayManager.OpponentPlayer.AddCardToBoard(card);

                    _cardsController.PlayOpponentCard(_gameplayManager.OpponentPlayer, card, target,
                                                      PlayCardCompleteHandler);
                    _cardsController.DrawCardInfo(card);
                }

                break;
            }
            }

            _gameplayManager.OpponentPlayer.Goo -= card.LibraryCard.Cost;
        }
Beispiel #19
0
        public BoardUnit CreateBoardUnit(Player owner, WorkingCard card)
        {
            GameObject playerBoard = owner.IsLocalPlayer ? PlayerBoardObject : OpponentBoardObject;

            BoardUnit boardUnit = new BoardUnit(playerBoard.transform);

            boardUnit.Transform.tag = owner.IsLocalPlayer ? SRTags.PlayerOwned : SRTags.OpponentOwned;
            boardUnit.Transform.SetParent(playerBoard.transform);
            boardUnit.Transform.position = new Vector2(1.9f * owner.BoardCards.Count, 0);
            boardUnit.OwnerPlayer        = owner;
            boardUnit.SetObjectInfo(card);

            boardUnit.PlayArrivalAnimation();

            return(boardUnit);
        }
        public void SetGooCostOfCardInHand(Player player, WorkingCard card, int value, BoardCard boardCard = null)
        {
            if (player.IsLocalPlayer)
            {
                if (boardCard == null)
                {
                    boardCard = _battlegroundController.PlayerHandCards.Find(x => x.WorkingCard.Equals(card));
                }

                boardCard.SetCardCost(value);
            }
            else
            {
                card.RealCost = Mathf.Clamp(value, 0, 99);
            }
        }
Beispiel #21
0
        private void PushAction(Player owner, BoardSkill boardSkill, HeroSkill skill, object target)
        {
            BoardUnit   targetUnit    = target as BoardUnit;
            Player      unitOwner     = targetUnit.OwnerPlayer;
            WorkingCard returningCard = targetUnit.Card;

            returningCard.InitialCost = returningCard.LibraryCard.Cost;
            returningCard.RealCost    = returningCard.InitialCost;

            Vector3 unitPosition = targetUnit.Transform.position;

            _vfxController.CreateVfx(_loadObjectsManager.GetObjectByPath <GameObject>("Prefabs/VFX/Skills/PushVFX"),
                                     targetUnit);

            _soundManager.PlaySound(Enumerators.SoundType.OVERLORD_ABILITIES, skill.Skill.Trim().ToLower(),
                                    Constants.OverlordAbilitySoundVolume, Enumerators.CardSoundType.NONE);

            _timerManager.AddTimer(
                x =>
            {
                // STEP 1 - REMOVE UNIT FROM BOARD
                unitOwner.BoardCards.Remove(targetUnit);

                // STEP 2 - DESTROY UNIT ON THE BOARD OR ANIMATE;
                targetUnit.Die(true);
                Object.Destroy(targetUnit.GameObject);

                // STEP 3 - REMOVE WORKING CARD FROM BOARD
                unitOwner.RemoveCardFromBoard(returningCard);

                // STEP 4 - RETURN CARD TO HAND
                _cardsController.ReturnToHandBoardUnit(returningCard, unitOwner, unitPosition);

                // STEP 4 - REARRANGE HANDS
                _gameplayManager.RearrangeHands();

                _actionsQueueController.PostGameActionReport(_actionsQueueController.FormatGameActionReport(
                                                                 Enumerators.ActionType.RETURN_TO_HAND_CARD_SKILL, new object[]
                {
                    owner, skill, targetUnit
                }));

                // _gameplayManager.GetController<RanksController>().UpdateRanksBuffs(unitOwner);
            },
                null,
                2f);
        }
        public void ReturnToHandBoardUnit(WorkingCard workingCard, Player player, Vector3 cardPosition)
        {
            if (CheckIsMoreThanMaxCards(workingCard, player))
            {
                return;
            }

            GameObject cardObject = player.AddCardToHand(workingCard, true);

            cardObject.transform.position = cardPosition;

            if (player.IsLocalPlayer)
            {
                cardObject.transform.localScale =
                    new Vector3(0.25f, 0.25f, 0.25f); // size of the cards in hand
            }
        }
        public ActiveAbility CreateActiveAbility(
            AbilityData ability,
            Enumerators.CardKind kind,
            object boardObject,
            Player caller,
            Card cardOwner,
            WorkingCard workingCard)
        {
            lock (_lock)
            {
                ActiveAbility activeAbility = new ActiveAbility
                {
                    Id      = _castedAbilitiesIds++,
                    Ability = CreateAbilityByType(kind, ability)
                };

                activeAbility.Ability.ActivityId            = activeAbility.Id;
                activeAbility.Ability.PlayerCallerOfAbility = caller;
                activeAbility.Ability.CardOwnerOfAbility    = cardOwner;
                activeAbility.Ability.MainWorkingCard       = workingCard;

                if (boardObject != null)
                {
                    if (boardObject is BoardCard)
                    {
                        activeAbility.Ability.BoardCard = boardObject as BoardCard;
                    }
                    else
                    {
                        if (kind == Enumerators.CardKind.CREATURE)
                        {
                            activeAbility.Ability.AbilityUnitOwner = boardObject as BoardUnit;
                        }
                        else
                        {
                            activeAbility.Ability.BoardSpell = boardObject as BoardSpell;
                        }
                    }
                }

                _activeAbilities.Add(activeAbility);

                return(activeAbility);
            }
        }
Beispiel #24
0
        private bool CheckSpecialCardRules(WorkingCard card)
        {
            if (card.LibraryCard.Abilities != null)
            {
                foreach (AbilityData ability in card.LibraryCard.Abilities)
                {
                    if (ability.AbilityType == Enumerators.AbilityType.ATTACK_OVERLORD)
                    {
                        // smart enough HP to use goo carriers
                        if (ability.Value * 2 >= _gameplayManager.OpponentPlayer.Health)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #25
0
        public void RemoveOpponentCardFromBoardToGraveyard(WorkingCard card)
        {
            Vector3   graveyardPos = OpponentGraveyardObject.transform.position + new Vector3(0.0f, -0.2f, 0.0f);
            BoardUnit boardCard    = OpponentBoardCards.Find(x => x.Card == card);

            if (boardCard != null)
            {
                if (boardCard.Transform != null)
                {
                    boardCard.Transform.localPosition = new Vector3(boardCard.Transform.localPosition.x,
                                                                    boardCard.Transform.localPosition.y, -0.2f);
                }

                OpponentBoardCards.Remove(boardCard);

                boardCard.SetHighlightingEnabled(false);
                boardCard.StopSleepingParticles();
                if (boardCard.GameObject != null)
                {
                    boardCard.GameObject.GetComponent <SortingGroup>().sortingLayerID = SRSortingLayers.BoardCards;
                    Object.Destroy(boardCard.GameObject.GetComponent <BoxCollider2D>());
                }

                Debug.Log("Destroy = " + boardCard.CurrentHp + "_" + boardCard.Card.LibraryCard.Name);
            }
            else if (_aiController.CurrentSpellCard != null && card == _aiController.CurrentSpellCard.WorkingCard)
            {
                _aiController.CurrentSpellCard.SetHighlightingEnabled(false);
                _aiController.CurrentSpellCard.GameObject.GetComponent <SortingGroup>().sortingLayerID = SRSortingLayers.BoardCards;
                Object.Destroy(_aiController.CurrentSpellCard.GameObject.GetComponent <BoxCollider2D>());
                Sequence sequence = DOTween.Sequence();
                sequence.PrependInterval(2.0f);
                sequence.Append(_aiController.CurrentSpellCard.Transform.DOMove(graveyardPos, 0.5f));
                sequence.Append(_aiController.CurrentSpellCard.Transform.DOScale(new Vector2(0.6f, 0.6f), 0.5f));
                sequence.OnComplete(
                    () =>
                {
                    _aiController.CurrentSpellCard = null;
                });
            }
        }
Beispiel #26
0
        public void RemovePlayerCardFromBoardToGraveyard(WorkingCard card)
        {
            BoardUnit boardCard = PlayerBoardCards.Find(x => x.Card == card);

            if (boardCard == null)
            {
                return;
            }

            boardCard.Transform.localPosition = new Vector3(boardCard.Transform.localPosition.x,
                                                            boardCard.Transform.localPosition.y, -0.2f);

            PlayerBoardCards.Remove(boardCard);
            PlayerGraveyardCards.Add(boardCard);

            boardCard.SetHighlightingEnabled(false);
            boardCard.StopSleepingParticles();
            boardCard.GameObject.GetComponent <SortingGroup>().sortingLayerID = SRSortingLayers.BoardCards;

            Object.Destroy(boardCard.GameObject.GetComponent <BoxCollider2D>());
        }
        public void LowGooCostOfCardInHand(Player player, WorkingCard card = null, int value = 1)
        {
            if (card == null && player.CardsInHand.Count > 0)
            {
                card = player.CardsInHand[Random.Range(0, player.CardsInHand.Count)];
            }

            if (card == null)
            {
                return;
            }

            if (player.IsLocalPlayer)
            {
                BoardCard boardCard = _battlegroundController.PlayerHandCards.Find(x => x.WorkingCard.Equals(card));

                boardCard.ChangeCardCostOn(value, true);
            }
            else
            {
                card.RealCost = Mathf.Clamp(card.LibraryCard.Cost - value, 0, card.LibraryCard.Cost);
            }
        }
        public override void Action(object info = null)
        {
            base.Action(info);

            if (AbilityUnitOwner.IsReanimated)
            {
                return;
            }

            Player      owner       = AbilityUnitOwner.OwnerPlayer;
            Card        libraryCard = AbilityUnitOwner.Card.LibraryCard.Clone();
            WorkingCard card        = new WorkingCard(libraryCard, owner);
            BoardUnit   unit        = CreateBoardUnit(card, owner);

            unit.IsReanimated             = true;
            AbilityUnitOwner.IsReanimated = true;

            owner.AddCardToBoard(card);
            owner.BoardCards.Add(unit);

            if (!owner.IsLocalPlayer)
            {
                BattlegroundController.OpponentBoardCards.Add(unit);
                BattlegroundController.UpdatePositionOfBoardUnitsOfOpponent();
            }
            else
            {
                BattlegroundController.PlayerBoardCards.Add(unit);
                BattlegroundController.UpdatePositionOfBoardUnitsOfPlayer(GameplayManager.CurrentPlayer.BoardCards);
            }

            ActionsQueueController.PostGameActionReport(ActionsQueueController.FormatGameActionReport(
                                                            Enumerators.ActionType.REANIMATE_UNIT_BY_ABILITY, new object[]
            {
                owner, unit
            }));
        }
        public GameObject CreateCardPreview(WorkingCard card, Vector3 pos)
        {
            BoardCard  boardCard;
            GameObject currentBoardCard;

            CardsController.GetSetOfCard(card.LibraryCard);

            switch (card.LibraryCard.CardKind)
            {
            case Enumerators.CardKind.CREATURE:
                currentBoardCard = Object.Instantiate(CardsController.CreatureCardViewPrefab,
                                                      _reportActionPreviewPanel.transform, false);
                boardCard = new UnitBoardCard(currentBoardCard);
                break;

            case Enumerators.CardKind.SPELL:
                currentBoardCard = Object.Instantiate(CardsController.SpellCardViewPrefab,
                                                      _reportActionPreviewPanel.transform, false);
                boardCard = new SpellBoardCard(currentBoardCard);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            boardCard.Init(card);
            boardCard.SetHighlightingEnabled(false);
            boardCard.IsPreview = true;
            currentBoardCard.transform.localPosition = pos;
            currentBoardCard.transform.localRotation = Quaternion.Euler(Vector3.zero);
            currentBoardCard.transform.localScale    = new Vector2(.4f, .4f);
            currentBoardCard.GetComponent <SortingGroup>().sortingOrder = 1000;
            currentBoardCard.layer = LayerMask.NameToLayer("Ignore Raycast");

            return(currentBoardCard);
        }
        public BoardUnit SpawnUnitOnBoard(Player owner, string name)
        {
            if (owner.BoardCards.Count >= Constants.MaxBoardUnits)
            {
                return(null);
            }

            Card libraryCard = _dataManager.CachedCardsLibraryData.GetCardFromName(name).Clone();

            WorkingCard card = new WorkingCard(libraryCard, owner);
            BoardUnit   unit = CreateBoardUnitForSpawn(card, owner);

            owner.AddCardToBoard(card);
            owner.BoardCards.Add(unit);

            _abilitiesController.ResolveAllAbilitiesOnUnit(unit, true);

            if (!owner.IsLocalPlayer)
            {
                _battlegroundController.OpponentBoardCards.Add(unit);
                _battlegroundController.UpdatePositionOfBoardUnitsOfOpponent();
            }
            else
            {
                _battlegroundController.PlayerBoardCards.Add(unit);
                _battlegroundController.UpdatePositionOfBoardUnitsOfPlayer(owner.BoardCards);
            }

            _actionsQueueController.PostGameActionReport(_actionsQueueController.FormatGameActionReport(
                                                             Enumerators.ActionType.SUMMON_UNIT_CARD, new object[]
            {
                owner, unit
            }));

            return(unit);
        }