Ejemplo n.º 1
0
    internal void CardInHandSelected(Card card, bool alreadyPaidFor)
    {
        if (Mode != global::Mode.CastingSpellNoCancel)
        {
            AnimationRequests.Add(new AnimationRequestStruct(ActualTurnModel, AnimationRequest.CardInHandSelected, card));
            PanelCardPreview.GetComponent <PanelCardPreview>().PreviewCard(ActualTurnModel, card, WhereAmI.TopInfo);

            DisableAllPanelsInteraction();
            Mode = global::Mode.Ready;

            if (card.Cost <= ActualTurnModel.ActualMana)
            {
                //getting your main character
                PanelTile panelTile = PanelBoardFront.GetComponent <PanelTiles>().FindTileForModel(ActualTurnModel);
                CastSpell(panelTile, card, panelTile, panelTile, false, card.Cost, alreadyPaidFor);
            }
        }
    }
Ejemplo n.º 2
0
    private bool CastEffects(PanelTile panelTile)
    {
        bool allEffectDone         = false;
        bool allEffectsOnceSetTrue = false;

        PanelInteraction     pi          = panelTile.PanelInteraction.GetComponent <PanelInteraction>();
        AvatarModel          heroModel   = panelTile.PanelAvatar.GetComponent <PanelAvatar>().PanelAvatarCard.GetComponent <PanelAvatarCard>().HeroModel;
        AvatarModel          targetModel = panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model;
        PanelInteractionMode whatMode    = pi.Mode;
        Card whatCard = pi.CastersCard;

        List <Card> cardsToCast = new List <Card>();

        if (whatCard.Effects.ContainsKey(Effect.BattlecryNonExistantRandom))
        {
            Card c      = null;
            int  random = new System.Random().Next(whatCard.Effects[Effect.BattlecryNonExistantRandom].Length);
            int  count  = 0;
            do
            {
                random++;
                count++;
                if (count > whatCard.Effects[Effect.BattlecryNonExistantRandom].Length)
                {
                    c = null;
                    break;
                }
                if (random >= whatCard.Effects[Effect.BattlecryNonExistantRandom].Length)
                {
                    random = 0;
                }
                c = whatCard.Effects[Effect.BattlecryNonExistantRandom][random];
                //check if exists on board
            } while (PanelBoardFront.GetComponent <PanelTiles>().IsModelOfCard(c));
            if (c != null)
            {
                cardsToCast.Add(c);
            }
        }
        if (whatCard.Effects.ContainsKey(Effect.Battlecry))
        {
            Debug.Log("There is battlecry for " + whatCard.Name);
            cardsToCast.AddRange(whatCard.Effects[Effect.Battlecry]);
            Card[] battlecryCards = whatCard.Effects[Effect.Battlecry];
        }
        if (whatCard.Effects.ContainsKey(Effect.WhileAlive) && whatCard.Effects[Effect.WhileAlive][0].CardPersistency == CardPersistency.WhileHolderAlive)
        {
            cardsToCast.AddRange(whatCard.Effects[Effect.WhileAlive]);
        }

        foreach (Card battlecryCard in cardsToCast)
        {
            bool explicitly = battlecryCard.CardTarget == CardTarget.Self || battlecryCard.CardTarget == CardTarget.EnemyHero;
            if (explicitly == false)
            {
                PanelCardPreview.GetComponent <PanelCardPreview>().PreviewCard(heroModel, battlecryCard, WhereAmI.TopInfo);
            }
            if (CastSpell(panelTile, battlecryCard, panelTile, pi.Caster, explicitly, 0, true))
            {
                if (!allEffectsOnceSetTrue)
                {
                    allEffectDone         = true;
                    allEffectsOnceSetTrue = true;
                }
            }
            else
            {
                allEffectDone = false;
            }
        }
        return(allEffectDone);
    }
Ejemplo n.º 3
0
    /* if finished in action */
    internal bool PointerDownOn(PanelTile panelTile)
    {
        bool actionWithBattlecryDone = false;

        Debug.Log("pointer down on: " + panelTile.gameObject.name + ", mode: " + Mode);
        PanelInteraction pi          = panelTile.PanelInteraction.GetComponent <PanelInteraction>();
        AvatarModel      heroModel   = panelTile.PanelAvatar.GetComponent <PanelAvatar>().PanelAvatarCard.GetComponent <PanelAvatarCard>().HeroModel;
        AvatarModel      targetModel = panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model;

        if (Mode != global::Mode.CastingSpellNoCancel)
        {
            PanelCardPreview.GetComponent <PanelCardPreview>().Preview(heroModel, targetModel, WhereAmI.TopInfo);
        }

        bool isYourCharacter = ActualTurnModel.IsItYourMinion(targetModel) || ActualTurnModel == heroModel;

        switch (Mode)
        {
        case global::Mode.Ready: {
            if (isYourCharacter && targetModel != null && targetModel.MovesLeft > 0 && panelTile.SetInteractionToMoveAround())
            {
                Mode = global::Mode.MovingOrAttacking;
                actionWithBattlecryDone = true;
            }
            break;
        }

        case global::Mode.MovingOrAttacking: {
            int                  movesLeft = 0;
            PanelTile            whatWantsToMoveOrAttackHere = pi.WhatMoveOrAttack;
            PanelInteractionMode mode     = pi.Mode;
            bool                 hasMoved = false;
            if (pi.Mode == PanelInteractionMode.Moving || pi.Mode == PanelInteractionMode.Attacking)
            {
                whatWantsToMoveOrAttackHere = pi.WhatMoveOrAttack;
                if (!isYourCharacter)
                {
                    whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model.MovesLeft--;
                    movesLeft = whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model.MovesLeft;
                    actionWithBattlecryDone = true;
                }
                //is here something?
                if (heroModel != null && !isYourCharacter)
                {
                    //battle
                    whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().BattleOutWith(panelTile.PanelAvatar.GetComponent <PanelAvatar>());
                    if (panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model == null)
                    {
                        //move if killed
                        panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model = whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model;
                        whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model = null;
                        hasMoved = true;
                    }
                }
                else
                {
                    //move
                    panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model = whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model;
                    whatWantsToMoveOrAttackHere.PanelAvatar.GetComponent <PanelAvatar>().Model = null;
                    hasMoved = true;
                }
            }
            DisableAllPanelsInteraction();
            Mode = global::Mode.Ready;
            //automatically enter next move interaction if moves are left
            if (movesLeft > 0)
            {
                Debug.Log("Moves left: " + movesLeft);
                if (panelTile.PanelAvatar.GetComponent <PanelAvatar>().Model != null && hasMoved)
                {
                    PointerDownOn(panelTile);
                }
                else
                {
                    PointerDownOn(whatWantsToMoveOrAttackHere);
                }
            }

            break;
        }

        case global::Mode.CastingSpellNoCancel: {
            if (pi.Mode == PanelInteractionMode.Casting)
            {
                actionWithBattlecryDone = CastSpell(panelTile, pi.CastersCard, pi.Caster, pi.Caster, true, 0, true);                                 //if no cancel, then it is already paid (hero power or battlecry)
                DisableAllPanelsInteraction();
                Mode = global::Mode.Ready;
                actionWithBattlecryDone = CastEffects(panelTile);
            }
            break;
        }

        case global::Mode.CastingSpell: {
            PanelInteractionMode pim = pi.Mode;
            if (pim == PanelInteractionMode.Casting)
            {
                actionWithBattlecryDone = CastSpell(panelTile, pi.CastersCard, pi.Caster, pi.Caster, true, pi.CastersCard.Cost, false);
            }
            DisableAllPanelsInteraction();
            Mode = global::Mode.Ready;
            if (pim == PanelInteractionMode.Casting && pi.CastersCard != null)
            {
                actionWithBattlecryDone = CastEffects(panelTile);
            }
            break;
        }

        default: throw new NotImplementedException("Implement working with mode: " + Mode);
        }

        //revalidate effects
        RevalidateEffects();

        return(actionWithBattlecryDone);
    }