mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Condensed "targets a permanent you control" conditions into a single class
This commit is contained in:
parent
993c11f279
commit
8463d693d4
4 changed files with 86 additions and 106 deletions
|
@ -1,36 +1,44 @@
|
|||
package mage.cards.p;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.SourceTargetsPermanentCondition;
|
||||
import mage.abilities.effects.common.DestroyTargetEffect;
|
||||
import mage.abilities.effects.common.cost.SpellCostReductionSourceEffect;
|
||||
import mage.abilities.effects.keyword.SurveilEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SuperType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.SupertypePredicate;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class PriceOfFame extends CardImpl {
|
||||
|
||||
private static final FilterPermanent filter
|
||||
= new FilterControlledCreaturePermanent("a legendary creature");
|
||||
|
||||
static {
|
||||
filter.add(new SupertypePredicate(SuperType.LEGENDARY));
|
||||
}
|
||||
|
||||
private static final Condition condition = new SourceTargetsPermanentCondition(filter);
|
||||
|
||||
public PriceOfFame(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{3}{B}");
|
||||
|
||||
// This spell costs {2} less to cast if it targets a legendary creature.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.STACK,
|
||||
new SpellCostReductionSourceEffect(2, PriceOfFameCondition.instance))
|
||||
.setRuleAtTheTop(true));
|
||||
this.addAbility(new SimpleStaticAbility(
|
||||
Zone.STACK, new SpellCostReductionSourceEffect(2, condition)
|
||||
).setRuleAtTheTop(true));
|
||||
|
||||
// Destroy target creature.
|
||||
this.getSpellAbility().addEffect(new DestroyTargetEffect());
|
||||
|
@ -49,28 +57,3 @@ public final class PriceOfFame extends CardImpl {
|
|||
return new PriceOfFame(this);
|
||||
}
|
||||
}
|
||||
|
||||
enum PriceOfFameCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
|
||||
if (sourceSpell != null) {
|
||||
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
|
||||
while (targets.hasNext()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
|
||||
if (permanent != null && permanent.isCreature() && permanent.isLegendary()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "it targets a legendary creature";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
package mage.cards.s;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.SourceTargetsPermanentCondition;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.FightTargetsEffect;
|
||||
import mage.abilities.effects.common.cost.SpellCostReductionSourceEffect;
|
||||
|
@ -15,16 +15,14 @@ import mage.constants.SubType;
|
|||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -34,18 +32,22 @@ public final class SavageStomp extends CardImpl {
|
|||
|
||||
private static final FilterCreaturePermanent filter
|
||||
= new FilterCreaturePermanent("creature you don't control");
|
||||
private static final FilterPermanent filter2
|
||||
= new FilterControlledCreaturePermanent(SubType.DINOSAUR, "a Dinosaur you control");
|
||||
|
||||
static {
|
||||
filter.add(new ControllerPredicate(TargetController.NOT_YOU));
|
||||
}
|
||||
|
||||
private static final Condition condition = new SourceTargetsPermanentCondition(filter2);
|
||||
|
||||
public SavageStomp(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{G}");
|
||||
|
||||
// Savage Stomp costs {2} less to cast if it targets a Dinosaur you control.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.STACK,
|
||||
new SpellCostReductionSourceEffect(2, SavageStompCondition.instance))
|
||||
.setRuleAtTheTop(true));
|
||||
this.addAbility(new SimpleStaticAbility(
|
||||
Zone.STACK, new SpellCostReductionSourceEffect(2, condition)
|
||||
).setRuleAtTheTop(true));
|
||||
|
||||
// Put a +1/+1 counter on target creature you control. Then that creature fights target creature you don't control.
|
||||
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance());
|
||||
|
@ -67,29 +69,3 @@ public final class SavageStomp extends CardImpl {
|
|||
return new SavageStomp(this);
|
||||
}
|
||||
}
|
||||
|
||||
enum SavageStompCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
|
||||
if (sourceSpell == null) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
|
||||
while (targets.hasNext()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
|
||||
if (permanent != null && permanent.hasSubtype(SubType.DINOSAUR, game)
|
||||
&& permanent.isControlledBy(source.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "it targets a Dinosaur you control";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package mage.cards.t;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.SourceTargetsPermanentCondition;
|
||||
import mage.abilities.effects.common.FightTargetsEffect;
|
||||
import mage.abilities.effects.common.cost.SpellCostReductionSourceEffect;
|
||||
import mage.cards.CardImpl;
|
||||
|
@ -11,16 +11,14 @@ import mage.constants.CardType;
|
|||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
import mage.filter.predicate.permanent.CounterPredicate;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -30,18 +28,23 @@ public final class TitanicBrawl extends CardImpl {
|
|||
|
||||
private static final FilterCreaturePermanent filter
|
||||
= new FilterCreaturePermanent("creature you don't control");
|
||||
private static final FilterPermanent filter2
|
||||
= new FilterControlledCreaturePermanent("a creature you control with a +1/+1 counter on it");
|
||||
|
||||
static {
|
||||
filter.add(new ControllerPredicate(TargetController.NOT_YOU));
|
||||
filter2.add(new CounterPredicate(CounterType.P1P1));
|
||||
}
|
||||
|
||||
private static final Condition condition = new SourceTargetsPermanentCondition(filter2);
|
||||
|
||||
public TitanicBrawl(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{G}");
|
||||
|
||||
// This spell costs {1} less to cast if it targets a creature you control with a +1/+1 counter on it.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.STACK,
|
||||
new SpellCostReductionSourceEffect(1, TitanicBrawlCondition.instance))
|
||||
.setRuleAtTheTop(true));
|
||||
this.addAbility(new SimpleStaticAbility(
|
||||
Zone.STACK, new SpellCostReductionSourceEffect(1, condition)
|
||||
).setRuleAtTheTop(true));
|
||||
|
||||
// Target creature you control fights target creature you don't control.
|
||||
this.getSpellAbility().addEffect(new FightTargetsEffect());
|
||||
|
@ -58,30 +61,3 @@ public final class TitanicBrawl extends CardImpl {
|
|||
return new TitanicBrawl(this);
|
||||
}
|
||||
}
|
||||
|
||||
enum TitanicBrawlCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
|
||||
if (sourceSpell == null) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
|
||||
while (targets.hasNext()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
|
||||
if (permanent != null && permanent.getCounters(game).containsKey(CounterType.P1P1)
|
||||
&& permanent.isControlledBy(source.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "it targets a creature you control with a +1/+1 counter on it";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class SourceTargetsPermanentCondition implements Condition {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public SourceTargetsPermanentCondition(FilterPermanent filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
|
||||
if (sourceSpell == null) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
|
||||
while (targets.hasNext()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
|
||||
if (permanent != null && filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "it targets " + filter.getMessage();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue