mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Beginning of proper implementation of Cephalid Snitch Methods
This commit is contained in:
parent
6c8379fcdc
commit
24f6dc6031
2 changed files with 101 additions and 3 deletions
|
@ -27,19 +27,35 @@
|
|||
*/
|
||||
package mage.cards.c;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.costs.common.SacrificeSourceCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.continuous.LoseAbilityTargetEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.abilities.keyword.ProtectionAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.FilterObject;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
/**
|
||||
|
@ -56,8 +72,7 @@ public class CephalidSnitch extends CardImpl {
|
|||
this.toughness = new MageInt(1);
|
||||
|
||||
// Sacrifice Cephalid Snitch: Target creature loses protection from black until end of turn.
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new LoseAbilityTargetEffect(
|
||||
ProtectionAbility.from(ObjectColor.BLACK), Duration.EndOfTurn), new SacrificeSourceCost());
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CephalidSnitchEffect(), new SacrificeSourceCost());
|
||||
ability.addTarget(new TargetCreaturePermanent());
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
@ -71,3 +86,78 @@ public class CephalidSnitch extends CardImpl {
|
|||
return new CephalidSnitch(this);
|
||||
}
|
||||
}
|
||||
class CephalidSnitchEffect extends LoseAbilityTargetEffect{
|
||||
|
||||
public CephalidSnitchEffect() {
|
||||
super(ProtectionAbility.from(ObjectColor.BLACK), Duration.EndOfTurn);
|
||||
staticText = "Target creature loses protection from black until end of turn.";
|
||||
}
|
||||
|
||||
public CephalidSnitchEffect(final CephalidSnitchEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CephalidSnitchEffect copy() {
|
||||
return new CephalidSnitchEffect(this);
|
||||
}
|
||||
|
||||
public String filterNameAssembler(List<ObjectColor> unsortedColors) {
|
||||
//Order colors properly by WUBRG (skipping black of course) and construct string to be displayed for ability.
|
||||
List<ObjectColor> colors = new ArrayList<>();
|
||||
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) {
|
||||
return colors.get(0).getDescription();
|
||||
} else if (colors.size() == 2) {
|
||||
return colors.get(0).getDescription() + " and from " + colors.get(1).getDescription();
|
||||
} else if (colors.size() == 3) {
|
||||
return colors.get(0).getDescription() + ", from " + colors.get(1).getDescription() + " and from " + colors.get(2).getDescription();
|
||||
} 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 "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (targetCreature != null) {
|
||||
|
||||
//Go through protection abilities and sort out any containing black, then record the colors other than black
|
||||
for(ProtectionAbility a: targetCreature.getAbilities().getProtectionAbilities()) {
|
||||
List<ObjectColor> objectColors = new ArrayList<>();
|
||||
if(a.getColors().contains(ObjectColor.BLACK))
|
||||
for (ObjectColor o : a.getColors()) {
|
||||
if (!objectColors.contains(o) && !o.isBlack())
|
||||
objectColors.add(o);
|
||||
}
|
||||
//Construct a card filter excluding black
|
||||
if(objectColors.size() > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.ObjectColor;
|
||||
|
@ -53,6 +55,7 @@ public class ProtectionAbility extends StaticAbility {
|
|||
|
||||
protected Filter filter;
|
||||
protected boolean removeAuras;
|
||||
protected static List<ObjectColor> objectColors = new ArrayList<>();
|
||||
protected UUID auraIdNotToBeRemoved; // defines an Aura objectId that will not be removed from this protection ability
|
||||
|
||||
public ProtectionAbility(Filter filter) {
|
||||
|
@ -72,12 +75,15 @@ public class ProtectionAbility extends StaticAbility {
|
|||
public static ProtectionAbility from(ObjectColor color) {
|
||||
FilterObject filter = new FilterObject(color.getDescription());
|
||||
filter.add(new ColorPredicate(color));
|
||||
objectColors.add(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)));
|
||||
objectColors.add(color1);
|
||||
objectColors.add(color2);
|
||||
return new ProtectionAbility(filter);
|
||||
}
|
||||
|
||||
|
@ -140,6 +146,8 @@ public class ProtectionAbility extends StaticAbility {
|
|||
return removeAuras;
|
||||
}
|
||||
|
||||
public List<ObjectColor> getColors() { return objectColors; }
|
||||
|
||||
public UUID getAuraIdNotToBeRemoved() {
|
||||
return auraIdNotToBeRemoved;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue