* Not of This World - Fixed cost reduction, tooltip wording and the missing possibility to target also abilities.

This commit is contained in:
LevelX2 2014-03-11 16:44:57 +01:00
parent 604f397d65
commit 815c20fa68

View file

@ -42,53 +42,39 @@ import mage.target.TargetObject;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.effects.common.cost.SpellCostReductionSourceEffect;
import mage.constants.TargetController;
import mage.filter.Filter;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.PowerPredicate;
import static mage.filter.predicate.permanent.ControllerControlsIslandPredicate.filter;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.permanent.Permanent;
import mage.game.stack.StackAbility;
import mage.target.Target;
import mage.target.Targets;
/**
*
*
* @author Rafbill
*/
public class NotOfThisWorld extends CardImpl<NotOfThisWorld> {
public NotOfThisWorld(UUID ownerId) {
super(ownerId, 8, "Not of This World", Rarity.UNCOMMON,
new CardType[] { CardType.INSTANT }, "{7}");
new CardType[]{CardType.INSTANT}, "{7}");
this.expansionSetCode = "ROE";
this.supertype.add("Tribal");
this.subtype.add("Eldrazi");
// Counter target spell or ability that targets a permanent you control.
this.getSpellAbility()
.addTarget(
new TargetSpellTargetingControlledPermanent(
new FilterSpell(
"a spell or ability that targets a creature you control with power 7 or greater.")));
this.getSpellAbility().addTarget(
new TargetSpellTargetingControlledPermanent());
this.getSpellAbility().addEffect(new CounterTargetEffect());
// Not of This World costs {7} less to cast if it targets a spell or
// ability that targets a creature you control with power 7 or greater.
}
@Override
public void adjustCosts(Ability ability, Game game) {
if (ability.getTargets().isChosen()
&& game.getStack().getStackObject(
ability.getTargets().getFirstTarget()) != null
&& game.getPermanent(game.getStack()
.getStackObject(ability.getTargets().getFirstTarget())
.getStackAbility().getTargets().getFirstTarget()) != null
&& game.getPermanent(
game.getStack()
.getStackObject(
ability.getTargets().getFirstTarget())
.getStackAbility().getTargets()
.getFirstTarget()).getPower().getValue() >= 7) {
String adjustedCost = "{0}";
ability.getManaCostsToPay().clear();
ability.getManaCostsToPay().load(adjustedCost);
}
// Not of This World costs {7} less to cast if it targets a spell or ability that targets a creature you control with power 7 or greater.
this.addAbility(new SimpleStaticAbility(Zone.STACK, new SpellCostReductionSourceEffect(7, NotOfThisWorldCondition.getInstance())));
}
public NotOfThisWorld(final NotOfThisWorld card) {
@ -101,49 +87,29 @@ public class NotOfThisWorld extends CardImpl<NotOfThisWorld> {
}
}
class TargetSpellTargetingControlledPermanent extends
TargetObject<TargetSpellTargetingControlledPermanent> {
protected FilterSpell filter;
class TargetSpellTargetingControlledPermanent extends TargetObject<TargetSpellTargetingControlledPermanent> {
public TargetSpellTargetingControlledPermanent() {
this(1, 1, new FilterSpell());
}
public TargetSpellTargetingControlledPermanent(FilterSpell filter) {
this(1, 1, filter);
}
public TargetSpellTargetingControlledPermanent(int numTargets,
FilterSpell filter) {
this(numTargets, numTargets, filter);
}
public TargetSpellTargetingControlledPermanent(int minNumTargets,
int maxNumTargets, FilterSpell filter) {
this.minNumberOfTargets = minNumTargets;
this.maxNumberOfTargets = maxNumTargets;
this.minNumberOfTargets = 1;
this.maxNumberOfTargets = 1;
this.zone = Zone.STACK;
this.filter = filter;
this.targetName = filter.getMessage();
}
public TargetSpellTargetingControlledPermanent(
final TargetSpellTargetingControlledPermanent target) {
public TargetSpellTargetingControlledPermanent(final TargetSpellTargetingControlledPermanent target) {
super(target);
this.filter = target.filter.copy();
}
@Override
public FilterSpell getFilter() {
return filter;
public Filter getFilter() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Spell spell = game.getStack().getSpell(id);
if (spell != null) {
return filter.match(spell, game);
StackObject stackObject = game.getStack().getStackObject(id);
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
return true;
}
return false;
}
@ -155,24 +121,20 @@ class TargetSpellTargetingControlledPermanent extends
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
int count = 0;
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell
&& game.getPlayer(sourceControllerId).getInRange()
.contains(stackObject.getControllerId())
&& filter.match((Spell) stackObject, game)
&& ((Spell) stackObject).getSpellAbility().getTargets()
.isChosen()
&& game.getPermanent(((Spell) stackObject)
.getSpellAbility().getTargets().getFirstTarget()) != null
&& game.getPermanent(
((Spell) stackObject).getSpellAbility()
.getTargets().getFirstTarget())
.getControllerId() == sourceControllerId) {
count++;
if (count >= this.minNumberOfTargets)
return true;
}
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
Targets targets = stackObject.getStackAbility().getTargets();
if(!targets.isEmpty()) {
for (Target target : targets) {
for (UUID targetId : target.getTargets()) {
Permanent targetedPermanent = game.getPermanentOrLKIBattlefield(targetId);
if (targetedPermanent.getControllerId().equals(sourceControllerId)) {
return true;
}
}
}
}
}
}
return false;
}
@ -185,23 +147,22 @@ class TargetSpellTargetingControlledPermanent extends
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<UUID>();
Set<UUID> possibleTargets = new HashSet<>();
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell
&& game.getPlayer(sourceControllerId).getInRange()
.contains(stackObject.getControllerId())
&& filter.match((Spell) stackObject, game)
&& ((Spell) stackObject).getSpellAbility().getTargets()
.isChosen()
&& game.getPermanent(((Spell) stackObject)
.getSpellAbility().getTargets().getFirstTarget()) != null
&& game.getPermanent(
((Spell) stackObject).getSpellAbility()
.getTargets().getFirstTarget())
.getControllerId() == sourceControllerId) {
possibleTargets.add(stackObject.getId());
}
}
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
Targets targets = stackObject.getStackAbility().getTargets();
if(!targets.isEmpty()) {
for (Target target : targets) {
for (UUID targetId : target.getTargets()) {
Permanent targetedPermanent = game.getPermanentOrLKIBattlefield(targetId);
if (targetedPermanent.getControllerId().equals(sourceControllerId)) {
possibleTargets.add(stackObject.getId());
}
}
}
}
}
}
return possibleTargets;
}
@ -211,3 +172,44 @@ class TargetSpellTargetingControlledPermanent extends
}
}
class NotOfThisWorldCondition implements Condition {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control with power 7 or greater");
static {
filter.add(new PowerPredicate(Filter.ComparisonType.GreaterThan, 6));
filter.add(new ControllerPredicate(TargetController.YOU));
}
private static final NotOfThisWorldCondition fInstance = new NotOfThisWorldCondition();
public static Condition getInstance() {
return fInstance;
}
@Override
public boolean apply(Game game, Ability source) {
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
if (sourceSpell != null && sourceSpell.getStackAbility().getTargets().isChosen()) {
StackObject objectToCounter = game.getStack().getStackObject(sourceSpell.getStackAbility().getTargets().getFirstTarget());
if (objectToCounter != null) {
for (Target target : objectToCounter.getStackAbility().getTargets()) {
for (UUID targetId : target.getTargets()) {
Permanent targetedPermanent = game.getPermanentOrLKIBattlefield(targetId);
if (targetedPermanent != null && filter.match(targetedPermanent, sourceSpell.getSourceId(), sourceSpell.getControllerId(), game)) {
return true;
}
}
}
}
}
return false;
}
@Override
public String toString() {
return "it targets a spell or ability that targets a creature you control with power 7 or greater";
}
}