示例#1
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);
    }