Ejemplo n.º 1
0
    internal bool CanHeHaveThisSpell(PanelTile target, PanelTile onWhat, Card card)
    {
        AvatarModel casterModel = PanelAvatar.GetComponent <PanelAvatar>().Model;
        AvatarModel targetModel = target.PanelAvatar.GetComponent <PanelAvatar>().Model;
        AvatarModel onWhatModel = onWhat.PanelAvatar.GetComponent <PanelAvatar>().Model;

        bool canIHave = false;

        switch (card.IsCastOn)
        {
        case IsCastOn.Target:
            canIHave = onWhat == target;
            break;

        case IsCastOn.FriendlyMinions:
            canIHave = onWhatModel != null && casterModel.GetMyHero().IsItYourMinion(onWhatModel);
            break;

        case IsCastOn.AdjacentCharacters:
            if (onWhatModel != null)
            {
                foreach (Side s in SideMethods.AllSides())
                {
                    //we have to compare panelTiles instead of AvatarModels, because we could compare null to null
                    if (target.Neighbours.ContainsKey(s) && target.Neighbours[s] == onWhat)
                    {
                        canIHave = true;
                    }
                }
            }
            break;

        case IsCastOn.AllCharactersInLineFromThis:
            //define the line
            int dRow = target.Row - Row;
            int dCol = target.Column - Column;

            Side      s2           = SideMethods.GetSide(dRow, dCol);
            PanelTile tmp          = target;
            bool      thisIsOnLine = false;

            while (tmp != null)
            {
                thisIsOnLine = tmp == onWhat;
                if (thisIsOnLine)
                {
                    break;
                }
                if (tmp.Neighbours.ContainsKey(s2))
                {
                    tmp = tmp.Neighbours[s2];
                }
                else
                {
                    break;
                }
            }
            canIHave = thisIsOnLine;
            break;

        case IsCastOn.AdjacentMinions:

            if (onWhatModel != null && onWhatModel.Card.CardPersistency == CardPersistency.Minion)
            {
                foreach (Side s in SideMethods.AllSides())
                {
                    //we have to compare panelTiles instead of AvatarModels, because we could compare null to null
                    if (target.Neighbours.ContainsKey(s) && target.Neighbours[s] == onWhat)
                    {
                        canIHave = true;
                    }
                }
            }
            break;

        case IsCastOn.FriendlyAdjacentMinions:
            if (onWhatModel != null && casterModel.GetMyHero().IsItYourMinion(onWhatModel))
            {
                foreach (Side s in SideMethods.AllSides())
                {
                    //we have to compare panelTiles instead of AvatarModels, because we could compare null to null
                    if (Neighbours.ContainsKey(s) && Neighbours[s] == onWhat)
                    {
                        canIHave = true;
                    }
                }
            }
            break;

        case IsCastOn.FriendlyAdjacentCharacters:
            if (onWhatModel != null && (casterModel.GetMyHero().IsItYourMinion(onWhatModel) || targetModel.GetMyHero() == casterModel))
            {
                foreach (Side s in SideMethods.AllSides())
                {
                    //we have to compare panelTiles instead of AvatarModels, because we could compare null to null
                    if (Neighbours.ContainsKey(s) && Neighbours[s] == onWhat)
                    {
                        canIHave = true;
                    }
                }
            }
            break;

        case IsCastOn.OtherFriendlyMinions:
            canIHave = onWhatModel != null && casterModel.GetMyHero().IsItYourMinion(onWhatModel) && targetModel != onWhatModel;
            break;

        case IsCastOn.EnemyCharacters:
            canIHave = onWhatModel != null && onWhatModel.GetMyHero() != casterModel.GetMyHero();
            break;

        case IsCastOn.OtherItsCharacters:
            canIHave = onWhatModel != null && onWhatModel != targetModel && targetModel.GetMyHero() == onWhatModel.GetMyHero();
            break;

        case IsCastOn.FriendlyHero:
            canIHave = casterModel.GetMyHero() == onWhatModel;
            break;

        case IsCastOn.EnemyMinions:
            canIHave = onWhatModel != null && onWhatModel.GetMyHero() != casterModel.GetMyHero() && onWhatModel.GetMyHero().IsItYourMinion(onWhatModel);
            break;

        case IsCastOn.FriendlyCharacters:
            canIHave = onWhatModel != null && casterModel.IsFriendlyCharacter(onWhatModel);
            break;

        case IsCastOn.EnemyHero:
            canIHave = onWhatModel != null && onWhatModel.Card.CardPersistency == CardPersistency.Hero && !onWhatModel.IsFriendlyCharacter(casterModel);
            break;

        default:
            throw new NotImplementedException("Implement case: " + card.IsCastOn);
        }
        return(canIHave);
    }
Ejemplo n.º 2
0
    private bool CanBeCastedOn(PanelTile caster, PanelTile castedOn, Card card)
    {
        AvatarModel castersModel  = caster.PanelAvatar.GetComponent <PanelAvatar>().Model;
        AvatarModel castedOnModel = castedOn.PanelAvatar.GetComponent <PanelAvatar>().Model;

        bool canCast = false;

        switch (card.CardTarget)
        {
        case CardTarget.Minion:
            canCast = castedOnModel != null && castedOnModel.Card.CardPersistency != CardPersistency.Hero;
            break;

        case CardTarget.Empty:
            canCast = castedOnModel == null;
            break;

        case CardTarget.FriendlyMinion:
            canCast = castedOnModel != null && castedOnModel.Card.CardPersistency != CardPersistency.Hero && castersModel.GetMyHero().IsItYourMinion(castedOnModel);
            break;

        case CardTarget.EnemyMinion:
            canCast = castedOnModel != null && castedOnModel.Card.CardPersistency == CardPersistency.Minion && castedOnModel.GetMyHero() != castersModel.GetMyHero();
            break;

        case CardTarget.Self:
            canCast = castersModel == castedOnModel;
            break;

        case CardTarget.Character:
            canCast = castedOnModel != null;
            break;

        case CardTarget.OtherFriendlyMinion:
            canCast = castersModel != castedOnModel && castedOnModel != null && castedOnModel.Card.CardPersistency != CardPersistency.Hero && castersModel.GetMyHero().IsItYourMinion(castedOnModel);
            break;

        case CardTarget.OtherCharacter:
            canCast = castersModel != castedOnModel && castedOnModel != null;
            break;

        case CardTarget.AnyOther:
            canCast = castersModel != castedOnModel;
            break;

        case CardTarget.Any:
            canCast = true;
            break;

        case CardTarget.EnemyCharacter:
            canCast = castedOnModel != null && !castersModel.GetMyHero().IsItYourMinion(castedOnModel) && castersModel.GetMyHero() != castedOnModel.GetMyHero();
            break;

        case CardTarget.EnemyHero:
            canCast = castedOnModel != null && !castersModel.IsFriendlyCharacter(castedOnModel) && castedOnModel.Card.CardPersistency == CardPersistency.Hero;
            break;

        default:
            throw new NotImplementedException("Not implemented " + card.CardTarget);
        }

        //we have to check the distance
        if (canCast)
        {
            int distance = caster.GetDistanceTo(castedOn);
            //Debug.Log("Distance between " + castersModel.Card.Name + " and " + castedOn.Row + ", " + castedOn.Column + " is " + distance);
            canCast = distance <= card.CastDistance;
        }

        return(canCast);
    }
Ejemplo n.º 3
0
    public bool SetInteractionToMoveAround()
    {
        bool canMove = false;

        //check for adjacent taunt
        //check for adjacent sticky enemy characters
        bool        foundTaunt       = false;
        bool        foundStickyEnemy = false;
        List <Side> whereTaunts      = new List <Side>();

        foreach (Side s in SideMethods.AllSides())
        {
            if (Neighbours.ContainsKey(s))
            {
                AvatarModel m = Neighbours[s].PanelAvatar.GetComponent <PanelAvatar>().Model;
                if (m != null && !m.IsFriendlyCharacter(PanelAvatar.GetComponent <PanelAvatar>().Model))
                {
                    foreach (CastedCard cc in m.Effects)
                    {
                        if (cc.Params.ContainsKey(CastedCardParamType.Taunt))
                        {
                            foundTaunt = true;
                            whereTaunts.Add(s);
                        }
                        if (cc.Params.ContainsKey(CastedCardParamType.Sticky))
                        {
                            foundStickyEnemy = true;
                        }
                    }
                }
            }
        }

        AvatarModel am = PanelAvatar.GetComponent <PanelAvatar>().Model;

        foreach (Side s in SideMethods.AllSides())
        {
            if (Neighbours.ContainsKey(s))
            {
                PanelTile whereMove = Neighbours[s];

                if (whereMove.PanelAvatar.GetComponent <PanelAvatar>().Model == null)
                {
                    if (!foundStickyEnemy)
                    {
                        whereMove.PanelInteraction.GetComponent <PanelInteraction>().CanMoveHere(this);
                        canMove = true;
                    }
                }
                else if (!PanelAvatar.GetComponent <PanelAvatar>().Model.IsFriendlyCharacter(whereMove.PanelAvatar.GetComponent <PanelAvatar>().Model) &&
                         am.ActualAttack > 0 &&
                         (!foundTaunt || whereTaunts.Contains(s)))
                {
                    whereMove.PanelInteraction.GetComponent <PanelInteraction>().CanAttackHere(this);
                    canMove = true;
                }
            }
        }

        return(canMove);
    }