예제 #1
0
    public bool AddPassive(Passive passive)
    {
        if (passive.SourceUpgrade != null)
        {
            if (passive.SourceUpgrade.ResourcePrerequisites.Any() && !passive.SourceUpgrade.ResourcePrerequisites.Intersect(UsedResources).Any())
            {
                return(false);
            }

            if (passive.SourceUpgrade.ClassPrerequisites.Any() && !passive.SourceUpgrade.ClassPrerequisites.Contains(PlayerClass))
            {
                return(false);
            }
        }

        Passives.Add(passive);

        var cardList = new List <Card>();

        cardList.AddRange(Deck.cardList);
        cardList.AddRange(Hand.cardList);
        cardList.AddRange(Graveyard.cardList);
        cardList.AddRange(Discard.cardList);
        cardList.AddRange(DeployedUnits.Select(x => x.Unit));
        cardList.AddRange(RedeployUnits);

        if (passive.CostAdjustment != null)
        {
            foreach (var card in cardList)
            {
                if (!card.IsHero)
                {
                    if (passive.PassiveApplies(card))
                    {
                        card.ModifyCost(passive.CostAdjustment);
                    }
                }
            }
        }

        if (passive.Enchantment != null)
        {
            foreach (var card in cardList.Where(x => x.Type == CardTypes.Unit).Cast <Unit>())
            {
                if (passive.PassiveApplies(card))
                {
                    card.AddEnchantment(passive.Enchantment);
                }
            }
        }

        switch (passive.SpecialPassive)
        {
        case SpecialPassiveEffects.LunarEclipse:
            foreach (var unit in DeployedUnits.Select(x => x.Unit))
            {
                unit.AddProtected(passive.SpecialPassiveProperty);
            }
            break;

        default:
            break;
        }

        return(true);
    }