use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.
the class GainAbilityAttachedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent;
if (affectedObjectsSet) {
permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent == null) {
discard();
return true;
}
} else {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
permanent = game.getPermanentOrLKIBattlefield(equipment.getAttachedTo());
} else {
permanent = null;
}
}
if (permanent != null) {
if (doesntRemoveItself && ability instanceof ProtectionAbility) {
((ProtectionAbility) ability).setAuraIdNotToBeRemoved(source.getSourceId());
}
permanent.addAbility(ability, source.getSourceId(), game);
afterGain(game, source, permanent, ability);
}
return true;
}
use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.
the class GainProtectionFromColorSourceEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor colorChoice = new ChoiceColor(true);
colorChoice.setMessage("Choose color for protection ability");
if (controller.choose(outcome, colorChoice, game)) {
game.informPlayers("Choosen color: " + colorChoice.getColor());
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
protectionFilter.setMessage(colorChoice.getChoice());
((ProtectionAbility) ability).setFilter(protectionFilter);
return;
}
}
discard();
}
use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.
the class ApostlesBlessingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact();
if (controller.choose(outcome, choice, game)) {
FilterCard protectionFilter = new FilterCard();
if (choice.isArtifactSelected()) {
protectionFilter.add(CardType.ARTIFACT.getPredicate());
} else {
protectionFilter.add(new ColorPredicate(choice.getColor()));
}
protectionFilter.setMessage(choice.getChoice());
ProtectionAbility protectionAbility = new ProtectionAbility(protectionFilter);
ContinuousEffect effect = new GainAbilityTargetEffect(protectionAbility, Duration.EndOfTurn);
effect.setTargetPointer(getTargetPointer());
game.addEffect(effect, source);
return true;
}
}
return false;
}
use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.
the class CephalidSnitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
if (targetCreature != null) {
List<Ability> toRemove = new ArrayList<>();
// Go through protection abilities and sort out any containing black
for (ProtectionAbility a : targetCreature.getAbilities().getProtectionAbilities()) {
ObjectColor colors = a.getFromColor();
if (colors.isBlack()) {
List<ObjectColor> nonBlackColors = colors.intersection(NONBLACK).getColors();
if (!nonBlackColors.isEmpty()) {
// If the ability is protection from multiple colors, construct a new filter excluding black
FilterCard filter = new FilterCard(filterNameAssembler(nonBlackColors));
if (nonBlackColors.size() == 1)
filter.add(new ColorPredicate(nonBlackColors.get(0)));
else if (nonBlackColors.size() == 2)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1))));
else if (nonBlackColors.size() == 3)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2))));
else if (nonBlackColors.size() == 4)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2)), new ColorPredicate(nonBlackColors.get(3))));
a.setFilter(filter);
} else {
// if the ability is just protection from black, remove it from the creature
toRemove.add(a);
}
}
}
targetCreature.removeAbilities(toRemove, source.getSourceId(), game);
return true;
}
return false;
}
Aggregations