Search in sources :

Example 21 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CardTestPlayerAPIImpl method assertColor.

/**
 * Assert permanent color
 *
 * @param player       player to check
 * @param cardName     card name on battlefield from player
 * @param searchColors colors list with searchable values
 * @param mustHave     must or not must have that colors
 */
public void assertColor(Player player, String cardName, ObjectColor searchColors, boolean mustHave) {
    // Assert.assertNotEquals("", cardName);
    Assert.assertNotEquals("must setup colors to search", 0, searchColors.getColorCount());
    Permanent card = getPermanent(cardName, player);
    ObjectColor cardColor = card.getColor(currentGame);
    List<ObjectColor> colorsHave = new ArrayList<>();
    List<ObjectColor> colorsDontHave = new ArrayList<>();
    for (ObjectColor searchColor : searchColors.getColors()) {
        if (cardColor.shares(searchColor)) {
            colorsHave.add(searchColor);
        } else {
            colorsDontHave.add(searchColor);
        }
    }
    if (mustHave) {
        Assert.assertEquals("must contain colors [" + searchColors + "] but found only [" + cardColor.toString() + "]", 0, colorsDontHave.size());
    } else {
        Assert.assertEquals("must not contain colors [" + searchColors + "] but found [" + cardColor.toString() + "]", 0, colorsHave.size());
    }
}
Also used : Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor)

Example 22 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ProtectionChosenColorSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
        if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
            chosenColor = color;
            FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
            protectionFilter.add(new ColorPredicate(chosenColor));
            protectionAbility = new ProtectionAbility(protectionFilter);
        }
        if (protectionAbility != null) {
            permanent.addAbility(protectionAbility, source.getSourceId(), game);
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 23 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ProtectionChosenColorAttachedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent attachement = game.getPermanent(source.getSourceId());
    if (attachement != null && attachement.getAttachedTo() != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(attachement.getId() + "_color");
        if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
            chosenColor = color;
            FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
            protectionFilter.add(new ColorPredicate(chosenColor));
            protectionAbility = new ProtectionAbility(protectionFilter);
            if (notRemoveItself) {
                protectionAbility.setAuraIdNotToBeRemoved(source.getSourceId());
            }
            if (notRemoveControlled) {
                protectionAbility.setDoesntRemoveControlled(true);
                protectionAbility.setRemoveEquipment(false);
                protectionAbility.setRemovesAuras(false);
            }
        }
        if (protectionAbility != null) {
            Permanent attachedTo = game.getPermanent(attachement.getAttachedTo());
            if (attachedTo != null) {
                attachedTo.addAbility(protectionAbility, source.getSourceId(), game);
            }
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 24 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class SamiteElderEffect method apply.

public boolean apply(Game game, Ability source) {
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (target != null) {
        for (ObjectColor color : target.getColor(game).getColors()) {
            FilterCard filter = new FilterCard(color.getDescription());
            filter.add(new ColorPredicate(color));
            game.addEffect(new GainAbilityControlledEffect(new ProtectionAbility(filter), Duration.EndOfTurn, new FilterControlledCreaturePermanent()), source);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 25 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class DrawCardForEachColorAmongControlledPermanentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<ObjectColor> colors = new HashSet<>();
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
            if (permanent.getColor(game).isBlack()) {
                colors.add(ObjectColor.BLACK);
            }
            if (permanent.getColor(game).isBlue()) {
                colors.add(ObjectColor.BLUE);
            }
            if (permanent.getColor(game).isRed()) {
                colors.add(ObjectColor.RED);
            }
            if (permanent.getColor(game).isGreen()) {
                colors.add(ObjectColor.GREEN);
            }
            if (permanent.getColor(game).isWhite()) {
                colors.add(ObjectColor.WHITE);
            }
        }
        controller.drawCards(colors.size(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) HashSet(java.util.HashSet)

Aggregations

ObjectColor (mage.ObjectColor)82 Permanent (mage.game.permanent.Permanent)50 Player (mage.players.Player)27 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)19 UUID (java.util.UUID)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 Card (mage.cards.Card)13 FilterPermanent (mage.filter.FilterPermanent)13 Spell (mage.game.stack.Spell)12 Ability (mage.abilities.Ability)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 ChoiceColor (mage.choices.ChoiceColor)9 Mana (mage.Mana)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 ArrayList (java.util.ArrayList)7 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)7 FilterCard (mage.filter.FilterCard)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)6 MageObject (mage.MageObject)5