mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
Rework Cephalid Snitch. Fixes #8520
This commit is contained in:
parent
743f9e4b3b
commit
f1390faf58
2 changed files with 41 additions and 41 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package mage.cards.c;
|
package mage.cards.c;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -65,21 +64,9 @@ class CephalidSnitchEffect extends LoseAbilityTargetEffect{
|
||||||
return new CephalidSnitchEffect(this);
|
return new CephalidSnitchEffect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String filterNameAssembler(List<ObjectColor> unsortedColors) {
|
private static final ObjectColor NONBLACK = new ObjectColor("WURG");
|
||||||
//Order colors properly by WUBRG (skipping black of course) and construct string to be displayed for ability.
|
|
||||||
List<ObjectColor> colors = new ArrayList<>();
|
private static String filterNameAssembler(List<ObjectColor> colors) {
|
||||||
if(unsortedColors.contains(ObjectColor.WHITE)){
|
|
||||||
colors.add(ObjectColor.WHITE);
|
|
||||||
}
|
|
||||||
if(unsortedColors.contains(ObjectColor.BLUE)){
|
|
||||||
colors.add(ObjectColor.BLUE);
|
|
||||||
}
|
|
||||||
if(unsortedColors.contains(ObjectColor.RED)){
|
|
||||||
colors.add(ObjectColor.RED);
|
|
||||||
}
|
|
||||||
if(unsortedColors.contains(ObjectColor.GREEN)){
|
|
||||||
colors.add(ObjectColor.GREEN);
|
|
||||||
}
|
|
||||||
if (colors.size() == 1) {
|
if (colors.size() == 1) {
|
||||||
return colors.get(0).getDescription();
|
return colors.get(0).getDescription();
|
||||||
} else if (colors.size() == 2) {
|
} else if (colors.size() == 2) {
|
||||||
|
|
@ -87,7 +74,7 @@ class CephalidSnitchEffect extends LoseAbilityTargetEffect{
|
||||||
} else if (colors.size() == 3) {
|
} else if (colors.size() == 3) {
|
||||||
return colors.get(0).getDescription() + ", from " + colors.get(1).getDescription() + " and from " + colors.get(2).getDescription();
|
return colors.get(0).getDescription() + ", from " + colors.get(1).getDescription() + " and from " + colors.get(2).getDescription();
|
||||||
} else if (colors.size() == 4) {
|
} else if (colors.size() == 4) {
|
||||||
return colors.get(0).getDescription() + ", from " + colors.get(1).getDescription() + ", from " + colors.get(2).getDescription() + " and from " + colors.get(3).getDescription();
|
return colors.get(0).getDescription() + ", from " + colors.get(1).getDescription() + ", from " + colors.get(2).getDescription() + " and from " + colors.get(3).getDescription();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -96,31 +83,33 @@ class CephalidSnitchEffect extends LoseAbilityTargetEffect{
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||||
if (targetCreature != null) {
|
if (targetCreature != null) {
|
||||||
|
List<Ability> toRemove = new ArrayList<>();
|
||||||
//Go through protection abilities and sort out any containing black, then record the colors other than black
|
//Go through protection abilities and sort out any containing black
|
||||||
for(ProtectionAbility a: targetCreature.getAbilities().getProtectionAbilities()) {
|
for (ProtectionAbility a: targetCreature.getAbilities().getProtectionAbilities()) {
|
||||||
List<ObjectColor> objectColors = new ArrayList<>();
|
ObjectColor colors = a.getFromColor();
|
||||||
if(a.getColors().contains(ObjectColor.BLACK))
|
if (colors.isBlack()) {
|
||||||
for (ObjectColor o : a.getColors()) {
|
List<ObjectColor> nonBlackColors = colors.intersection(NONBLACK).getColors();
|
||||||
if (!objectColors.contains(o) && !o.isBlack())
|
if (!nonBlackColors.isEmpty()) {
|
||||||
objectColors.add(o);
|
//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);
|
||||||
}
|
}
|
||||||
//Construct a card filter excluding black
|
|
||||||
if(!objectColors.isEmpty()) {
|
|
||||||
FilterCard filter = new FilterCard(filterNameAssembler(objectColors));
|
|
||||||
if (objectColors.size() == 1)
|
|
||||||
filter.add(new ColorPredicate(objectColors.get(0)));
|
|
||||||
else if (objectColors.size() == 2)
|
|
||||||
filter.add(Predicates.or(new ColorPredicate(objectColors.get(0)), new ColorPredicate(objectColors.get(1))));
|
|
||||||
else if (objectColors.size() == 3)
|
|
||||||
filter.add(Predicates.or(new ColorPredicate(objectColors.get(0)), new ColorPredicate(objectColors.get(1)), new ColorPredicate(objectColors.get(2))));
|
|
||||||
else if (objectColors.size() == 4)
|
|
||||||
filter.add(Predicates.or(new ColorPredicate(objectColors.get(0)), new ColorPredicate(objectColors.get(1)), new ColorPredicate(objectColors.get(2)), new ColorPredicate(objectColors.get(3))));
|
|
||||||
a.setFilter(filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
targetCreature.removeAbilities(toRemove, source.getSourceId(), game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import mage.game.stack.StackObject;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -29,6 +28,7 @@ public class ProtectionAbility extends StaticAbility {
|
||||||
protected boolean removeAuras;
|
protected boolean removeAuras;
|
||||||
protected boolean removeEquipment;
|
protected boolean removeEquipment;
|
||||||
protected boolean doesntRemoveControlled;
|
protected boolean doesntRemoveControlled;
|
||||||
|
protected ObjectColor fromColor;
|
||||||
protected UUID auraIdNotToBeRemoved; // defines an Aura objectId that will not be removed from this protection ability
|
protected UUID auraIdNotToBeRemoved; // defines an Aura objectId that will not be removed from this protection ability
|
||||||
|
|
||||||
public ProtectionAbility(Filter filter) {
|
public ProtectionAbility(Filter filter) {
|
||||||
|
|
@ -37,6 +37,7 @@ public class ProtectionAbility extends StaticAbility {
|
||||||
this.removeAuras = true;
|
this.removeAuras = true;
|
||||||
this.removeEquipment = true;
|
this.removeEquipment = true;
|
||||||
this.doesntRemoveControlled = false;
|
this.doesntRemoveControlled = false;
|
||||||
|
this.fromColor = new ObjectColor();
|
||||||
this.auraIdNotToBeRemoved = null;
|
this.auraIdNotToBeRemoved = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,19 +47,25 @@ public class ProtectionAbility extends StaticAbility {
|
||||||
this.removeAuras = ability.removeAuras;
|
this.removeAuras = ability.removeAuras;
|
||||||
this.removeEquipment = ability.removeEquipment;
|
this.removeEquipment = ability.removeEquipment;
|
||||||
this.doesntRemoveControlled = ability.doesntRemoveControlled;
|
this.doesntRemoveControlled = ability.doesntRemoveControlled;
|
||||||
|
this.fromColor = ability.fromColor;
|
||||||
this.auraIdNotToBeRemoved = ability.auraIdNotToBeRemoved;
|
this.auraIdNotToBeRemoved = ability.auraIdNotToBeRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProtectionAbility from(ObjectColor color) {
|
public static ProtectionAbility from(ObjectColor color) {
|
||||||
FilterObject filter = new FilterObject(getFilterText(color));
|
FilterObject filter = new FilterObject(getFilterText(color));
|
||||||
filter.add(new ColorPredicate(color));
|
filter.add(new ColorPredicate(color));
|
||||||
return new ProtectionAbility(filter);
|
ProtectionAbility ability = new ProtectionAbility(filter);
|
||||||
|
ability.getFromColor().addColor(color);
|
||||||
|
return ability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProtectionAbility from(ObjectColor color1, ObjectColor color2) {
|
public static ProtectionAbility from(ObjectColor color1, ObjectColor color2) {
|
||||||
FilterObject filter = new FilterObject(color1.getDescription() + " and from " + color2.getDescription());
|
FilterObject filter = new FilterObject(color1.getDescription() + " and from " + color2.getDescription());
|
||||||
filter.add(Predicates.or(new ColorPredicate(color1), new ColorPredicate(color2)));
|
filter.add(Predicates.or(new ColorPredicate(color1), new ColorPredicate(color2)));
|
||||||
return new ProtectionAbility(filter);
|
ProtectionAbility ability = new ProtectionAbility(filter);
|
||||||
|
ability.getFromColor().addColor(color1);
|
||||||
|
ability.getFromColor().addColor(color2);
|
||||||
|
return ability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -167,6 +174,10 @@ public class ProtectionAbility extends StaticAbility {
|
||||||
return doesntRemoveControlled;
|
return doesntRemoveControlled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObjectColor getFromColor() {
|
||||||
|
return fromColor;
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getAuraIdNotToBeRemoved() {
|
public UUID getAuraIdNotToBeRemoved() {
|
||||||
return auraIdNotToBeRemoved;
|
return auraIdNotToBeRemoved;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue