mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
add ProtectionAbility helpers
for the most common 1 and 2 color cases
This commit is contained in:
parent
3f7d75b6ca
commit
ce6087bda6
142 changed files with 209 additions and 1268 deletions
|
|
@ -29,6 +29,8 @@ package mage.abilities.keyword;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
|
|
@ -38,6 +40,8 @@ import mage.filter.FilterCard;
|
|||
import mage.filter.FilterObject;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
|
|
@ -67,6 +71,18 @@ public class ProtectionAbility extends StaticAbility {
|
|||
this.auraIdNotToBeRemoved = ability.auraIdNotToBeRemoved;
|
||||
}
|
||||
|
||||
public static ProtectionAbility from(ObjectColor color) {
|
||||
FilterObject filter = new FilterObject(color.getDescription());
|
||||
filter.add(new ColorPredicate(color));
|
||||
return new ProtectionAbility(filter);
|
||||
}
|
||||
|
||||
public static ProtectionAbility from(ObjectColor color1, ObjectColor color2) {
|
||||
FilterObject filter = new FilterObject(color1.getDescription() + " and from " + color2.getDescription());
|
||||
filter.add(Predicates.or(new ColorPredicate(color1), new ColorPredicate(color2)));
|
||||
return new ProtectionAbility(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectionAbility copy() {
|
||||
return new ProtectionAbility(this);
|
||||
|
|
@ -97,8 +113,8 @@ public class ProtectionAbility extends StaticAbility {
|
|||
return !filter.match(source, game);
|
||||
}
|
||||
// Problem here is that for the check if a player can play a Spell, the source
|
||||
// object is still a card and not a spell yet. So retunr only if the source object can't be a spell
|
||||
// otherwise the following FilterObject check will be appied
|
||||
// object is still a card and not a spell yet. So return only if the source object can't be a spell
|
||||
// otherwise the following FilterObject check will be applied
|
||||
if (source instanceof StackObject
|
||||
|| (!source.getCardType().contains(CardType.INSTANT) && !source.getCardType().contains(CardType.SORCERY))) {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue