Ejemplo n.º 1
0
    public void UpdateFromModel()
    {
        //to be destroyed?
        bool toBeDestroyed = false;

        if (Model != null)
        {
            foreach (CastedCard cc in Model.Effects)
            {
                if (cc.Params.ContainsKey(CastedCardParamType.Destroy))
                {
                    toBeDestroyed = true;
                }
            }
        }

        if (Model != null && (Model.ActualHealth <= 0 || toBeDestroyed))
        {
            //is dead
            _Model.GetMyHero().Minions.Remove(_Model);
            _Model = null;
        }

        AvatarModel heroModel = Model != null?Model.GetMyHero() : null;

        PanelAvatarCard.GetComponent <PanelAvatarCard>().PreviewModel(heroModel, Model, PanelMinigame.Me.ActualTurnModel.IsItYourMinion(Model) || PanelMinigame.Me.ActualTurnModel == heroModel);
    }
Ejemplo n.º 2
0
    internal AvatarModel Cast(AvatarModel castingOn, Card c)
    {
        Hand.Remove(c);

        //minion
        if (c.CardPersistency == CardPersistency.Minion)
        {
            if (castingOn != null && !c.Params.ContainsKey(ParamType.ReplaceExisting))
            {
                //can not cast minion on other minion
                throw new Exception("Casting card: " + c.Name + " on " + castingOn.Card.Name + " this can not happen");
            }
            AvatarModel owner = GetMyHero();
            if (c.Params.ContainsKey(ParamType.ReplaceExisting))
            {
                owner = castingOn.GetMyHero();
                owner.Minions.Remove(castingOn);
                PanelMinigame.Me.AnimationRequests.Add(new AnimationRequestStruct(this, AnimationRequest.ReplaceMinionOn, castingOn));
            }
            else
            {
                PanelMinigame.Me.AnimationRequests.Add(new AnimationRequestStruct(this, AnimationRequest.PutMinionOnTile, castingOn));
            }
            castingOn = new AvatarModel(c, true, owner);
            //minions will be a flat structure. there is no need for deep one.
            owner.Minions.Add(castingOn);
        }

        //is null for totemic might. where the actual spell does nothing, the battlecry throws totem
        if (castingOn != null)
        {
            //check if there is already an effect like this and marked to remove. we will unmark it
            bool foundTheSame = false;
            foreach (CastedCard cc in castingOn.Effects)
            {
                if (cc.Card == c && cc.MarkedToRemove)
                {
                    cc.MarkedToRemove = false;
                    foundTheSame      = true;
                    break;
                }
            }

            if (!foundTheSame)
            {
                CastedCard castedCard = new CastedCard(this, castingOn, c);

                if (c.CardPersistency != CardPersistency.Instant && castedCard.Params.Count > 0)
                {
                    Debug.Log("Casting " + c.Name + " on " + castingOn.Card.Name);
                    castingOn.Effects.Add(castedCard);
                }
                //because of healing this has to be after adding castedCard to effect. (max health update then healing)
                castedCard.DealInstants(this, castingOn);
            }
        }
        return(castingOn);
    }
Ejemplo n.º 3
0
 internal AvatarModel GetMyHero()
 {
     if (_Creator == null)
     {
         return(this);
     }
     if (_Creator.Card.CardPersistency == CardPersistency.Hero)
     {
         return(_Creator);
     }
     return(_Creator.GetMyHero());
 }
Ejemplo n.º 4
0
    internal void DealInstants(AvatarModel castingBy, AvatarModel castingOn)
    {
        foreach (KeyValuePair <CastedCardParamType, int> kvp in Params.ToArray())
        {
            string on = castingOn != null ? castingOn.Card.Name : "empty";
            //Debug.Log("Dealing instant: " + kvp.Key + " on " + on);
            PanelMinigame.Me.AnimationRequests.Add(new AnimationRequestStruct(castingOn, AnimationRequest.DealInstantOn, kvp));
            switch (kvp.Key)
            {
            case CastedCardParamType.DealDamage:
                castingOn.ActualHealth -= kvp.Value;
                Params.Remove(kvp.Key);
                break;

            case CastedCardParamType.HealthAdd:
                castingOn.ActualHealth += kvp.Value;
                break;

            case CastedCardParamType.Heal:
                castingOn.ActualHealth += kvp.Value;
                Params.Remove(kvp.Key);
                break;

            case CastedCardParamType.HealFull:
                castingOn.ActualHealth = castingOn.MaxHealth;
                Params.Remove(kvp.Key);
                break;

            case CastedCardParamType.HeroDrawsCard:
                for (int i = 0; i < kvp.Value; i++)
                {
                    castingBy.GetMyHero().PullCardFromDeck();
                }
                Params.Remove(kvp.Key);
                break;

            case CastedCardParamType.DealDamageSpell:
                castingOn.ActualHealth -= kvp.Value;
                Params.Remove(kvp.Key);
                break;

            case CastedCardParamType.ArmorAdd:
                castingOn.Armor += kvp.Value;
                Params.Remove(kvp.Key);
                break;
            }
        }
    }
Ejemplo n.º 5
0
    public void RevalidateEffects()
    {
        PanelBoardFront.GetComponent <PanelTiles>().UpdateAdjacentModels();

        //mark to remove all every action revalidate effects
        List <AvatarModel> allModels = PanelBoardFront.GetComponent <PanelTiles>().GetAllAvatarModels();

        foreach (AvatarModel am in allModels)
        {
            foreach (CastedCard cc in am.Effects.ToArray())
            {
                if (cc.Card.CardPersistency == CardPersistency.EveryActionRevalidate)
                {
                    cc.MarkedToRemove = true;
                }
            }
        }

        //add all every action revalidate effects
        foreach (PanelTile pt in PanelBoardFront.GetComponent <PanelTiles>().GetAllPanelTiles())
        {
            AvatarModel am = pt.PanelAvatar.GetComponent <PanelAvatar>().Model;
            if (am != null)
            {
                AvatarModel myHero = am.GetMyHero();

                foreach (KeyValuePair <Effect, Card[]> e in am.Card.Effects)
                {
                    foreach (Card card in e.Value)
                    {
                        if (e.Key == Effect.WhileAlive && card.CardPersistency == CardPersistency.EveryActionRevalidate)
                        {
                            CastSpell(pt, card, pt, pt, true, 0, true);
                        }
                    }
                }
            }
        }

        //remove all effect which are still marked to remove
        foreach (PanelTile pt in PanelBoardFront.GetComponent <PanelTiles>().GetAllPanelTiles())
        {
            AvatarModel am = pt.PanelAvatar.GetComponent <PanelAvatar>().Model;
            if (am != null)
            {
                foreach (CastedCard cc in am.Effects.ToArray())
                {
                    if (cc.Card.CardPersistency == CardPersistency.EveryActionRevalidate)
                    {
                        if (cc.MarkedToRemove)
                        {
                            am.Effects.Remove(cc);
                        }
                    }
                }
            }
            pt.PanelAvatar.GetComponent <PanelAvatar>().UpdateFromModel();
        }
        //to update the hand
        PanelMyHeroStatus.GetComponent <PanelHeroStatus>().HeroModel = ActualTurnModel;
        //update the top status
        PanelEnemyStatus.GetComponent <PanelHeroStatus>().HeroModel = MyModel == ActualTurnModel ? EnemysModel : MyModel;
    }
Ejemplo n.º 6
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.º 7
0
    public CastedCard(AvatarModel castingBy, AvatarModel castingOn, Card c)
    {
        Card = c;

        if (c.Params.ContainsKey(ParamType.DealDamage))
        {
            Params.Add(CastedCardParamType.DealDamage, c.Params[ParamType.DealDamage]);
        }

        if (c.Params.ContainsKey(ParamType.Heal))
        {
            Params.Add(CastedCardParamType.Heal, c.Params[ParamType.Heal]);
        }

        if (c.Params.ContainsKey(ParamType.HeroDrawsCard))
        {
            Params.Add(CastedCardParamType.HeroDrawsCard, c.Params[ParamType.HeroDrawsCard]);
        }

        if (c.Params.ContainsKey(ParamType.AttackAdd))
        {
            Params.Add(CastedCardParamType.AttackAdd, c.Params[ParamType.AttackAdd]);
        }

        if (c.Params.ContainsKey(ParamType.HealthAdd))
        {
            Params.Add(CastedCardParamType.HealthAdd, c.Params[ParamType.HealthAdd]);
        }
        if (c.Params.ContainsKey(ParamType.HealthAddOfOtherFriendlyMinionNumber))
        {
            Params.Add(CastedCardParamType.HealthAdd, AvatarModel.MyMinionsNumber(castingOn.GetMyHero()) - 1);           //because itself doesn't count and its already casted
        }

        if (c.Params.ContainsKey(ParamType.AttackAddOfOtherFriendlyMinionNumber))
        {
            Params.Add(CastedCardParamType.AttackAdd, AvatarModel.MyMinionsNumber(castingOn.GetMyHero()) - 1);             //because itself doesn't count and its already casted
        }

        if (c.Params.ContainsKey(ParamType.Taunt))
        {
            Params.Add(CastedCardParamType.Taunt, c.Params[ParamType.Taunt]);
        }

        if (c.Params.ContainsKey(ParamType.Sticky))
        {
            Params.Add(CastedCardParamType.Sticky, 1);
        }
        if (c.Params.ContainsKey(ParamType.Destroy))
        {
            Params.Add(CastedCardParamType.Destroy, 1);
        }

        if (c.Params.ContainsKey(ParamType.SpellDamageAdd))
        {
            Params.Add(CastedCardParamType.SpellDamageAdd, c.Params[ParamType.SpellDamageAdd]);
        }

        if (c.Params.ContainsKey(ParamType.DealDamageSpell))
        {
            Params.Add(CastedCardParamType.DealDamageSpell, c.Params[ParamType.DealDamageSpell] + castingBy.SpellDamageAdd());
        }

        if (c.Params.ContainsKey(ParamType.HealFull))
        {
            Params.Add(CastedCardParamType.HealFull, 1);
        }

        if (c.Params.ContainsKey(ParamType.ManaCrystalAdd))
        {
            Params.Add(CastedCardParamType.ManaCrystalAdd, c.Params[ParamType.ManaCrystalAdd]);
        }

        if (c.Params.ContainsKey(ParamType.ManaCrystalEmptyAdd))
        {
            Params.Add(CastedCardParamType.ManaCrystalEmptyAdd, c.Params[ParamType.ManaCrystalEmptyAdd]);
        }

        if (c.Params.ContainsKey(ParamType.ArmorAdd))
        {
            Params.Add(CastedCardParamType.ArmorAdd, c.Params[ParamType.ArmorAdd]);
        }
        if (c.Params.ContainsKey(ParamType.TakeControl))
        {
            castingOn.GetMyHero().Minions.Remove(castingOn);
            castingOn.Creator = castingBy.GetMyHero();
            castingBy.Minions.Add(castingOn);
            castingOn.MovesLeft = castingOn.Card.Params.ContainsKey(ParamType.Charge)?castingOn.Card.Params[ParamType.Speed]:0;
        }
        if (c.Params.ContainsKey(ParamType.Charge))
        {
            castingOn.RefillMovements();
        }
    }
Ejemplo n.º 8
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);
    }