* Updated enters battlefield replacement effects for new handling.

This commit is contained in:
LevelX2 2015-10-16 00:32:55 +02:00
parent d264dd83e1
commit 6dfbcab5ab
9 changed files with 201 additions and 119 deletions

View file

@ -27,6 +27,8 @@
*/
package mage.sets.riseoftheeldrazi;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -39,17 +41,17 @@ import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.FilterSpell;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.PowerPredicate;
import mage.filter.predicate.other.TargetsPermanentPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
import mage.game.stack.StackObject;
import mage.target.Target;
import mage.target.TargetSpell;
import mage.target.TargetObject;
import mage.target.Targets;
/**
*
@ -57,19 +59,14 @@ import mage.target.TargetSpell;
*/
public class NotOfThisWorld extends CardImpl {
private final static FilterSpell filter = new FilterSpell("spell that targets a permanent you control");
static {
filter.add(new TargetsPermanentPredicate(new FilterControlledPermanent()));
}
public NotOfThisWorld(UUID ownerId) {
super(ownerId, 8, "Not of This World", Rarity.UNCOMMON, new CardType[]{CardType.TRIBAL, CardType.INSTANT}, "{7}");
this.expansionSetCode = "ROE";
this.subtype.add("Eldrazi");
// Counter target spell or ability that targets a permanent you control.
this.getSpellAbility().addTarget(new TargetSpell(filter));
this.getSpellAbility().addTarget(
new TargetStackObjectTargetingControlledPermanent());
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.
this.addAbility(new SimpleStaticAbility(Zone.STACK, new SpellCostReductionSourceEffect(7, NotOfThisWorldCondition.getInstance())));
@ -85,6 +82,92 @@ public class NotOfThisWorld extends CardImpl {
}
}
class TargetStackObjectTargetingControlledPermanent extends TargetObject {
public TargetStackObjectTargetingControlledPermanent() {
this.minNumberOfTargets = 1;
this.maxNumberOfTargets = 1;
this.zone = Zone.STACK;
this.targetName = "spell or ability that targets a permanent you control";
}
public TargetStackObjectTargetingControlledPermanent(final TargetStackObjectTargetingControlledPermanent target) {
super(target);
}
@Override
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) {
StackObject stackObject = game.getStack().getStackObject(id);
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
return true;
}
return false;
}
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
return canChoose(sourceControllerId, game);
}
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
for (StackObject stackObject : game.getStack()) {
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
Targets objectTargets = stackObject.getStackAbility().getTargets();
if (!objectTargets.isEmpty()) {
for (Target target : objectTargets) {
for (UUID targetId : target.getTargets()) {
Permanent targetedPermanent = game.getPermanentOrLKIBattlefield(targetId);
if (targetedPermanent != null && targetedPermanent.getControllerId().equals(sourceControllerId)) {
return true;
}
}
}
}
}
}
return false;
}
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId,
Game game) {
return possibleTargets(sourceControllerId, game);
}
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
for (StackObject stackObject : game.getStack()) {
if ((stackObject instanceof Spell) || (stackObject instanceof StackAbility)) {
Targets objectTargets = stackObject.getStackAbility().getTargets();
if (!objectTargets.isEmpty()) {
for (Target target : objectTargets) {
for (UUID targetId : target.getTargets()) {
Permanent targetedPermanent = game.getPermanentOrLKIBattlefield(targetId);
if (targetedPermanent != null && targetedPermanent.getControllerId().equals(sourceControllerId)) {
possibleTargets.add(stackObject.getId());
}
}
}
}
}
}
return possibleTargets;
}
@Override
public TargetStackObjectTargetingControlledPermanent copy() {
return new TargetStackObjectTargetingControlledPermanent(this);
}
}
class NotOfThisWorldCondition implements Condition {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control with power 7 or greater");

View file

@ -25,13 +25,12 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.constants.Zone;
import mage.abilities.StaticAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.common.TapSourceEffect;
import mage.constants.Zone;
/**
*
@ -42,7 +41,7 @@ public class EntersBattlefieldTappedAbility extends StaticAbility {
private String ruleText;
public EntersBattlefieldTappedAbility() {
super(Zone.BATTLEFIELD, new EntersBattlefieldEffect(new TapSourceEffect(true)));
super(Zone.ALL, new EntersBattlefieldEffect(new TapSourceEffect(true)));
}
public EntersBattlefieldTappedAbility(String ruleText) {

View file

@ -59,6 +59,9 @@ public class EntersBattlefieldWithXCountersEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
}
if (permanent != null) {
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility != null

View file

@ -25,12 +25,12 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -39,6 +39,7 @@ import mage.game.permanent.Permanent;
* @author BetaSteward_at_googlemail.com
*/
public class TapSourceEffect extends OneShotEffect {
private boolean withoutTrigger;
public TapSourceEffect() {
@ -64,6 +65,9 @@ public class TapSourceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
}
if (permanent != null) {
if (withoutTrigger) {
permanent.setTapped(true);

View file

@ -30,6 +30,7 @@ package mage.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.cards.Card;
import mage.constants.Duration;
import mage.constants.Layer;
@ -93,9 +94,14 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl implements Sou
public void init(Ability source, Game game) {
super.init(source, game);
if (affectedObjectsSet) {
Permanent permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
if (permanent != null) {
affectedObjectList.add(new MageObjectReference(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()) + 1, game));
} else {
affectedObjectList.add(new MageObjectReference(source.getSourceId(), game));
}
}
}
@Override
public boolean apply(Game game, Ability source) {

View file

@ -2,6 +2,7 @@ package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
@ -16,6 +17,7 @@ import mage.watchers.common.BloodthirstWatcher;
* @author Loki
*/
public class BloodthirstAbility extends EntersBattlefieldAbility {
private int amount;
public BloodthirstAbility(int amount) {
@ -48,6 +50,7 @@ public class BloodthirstAbility extends EntersBattlefieldAbility {
}
class BloodthirstEffect extends OneShotEffect {
private final int amount;
BloodthirstEffect(int amount) {
@ -67,9 +70,9 @@ class BloodthirstEffect extends OneShotEffect {
if (player != null) {
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get("DamagedOpponents", source.getControllerId());
if (watcher != null && watcher.conditionMet()) {
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.P1P1.createInstance(amount), game);
Permanent permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(amount), game);
}
}
@ -83,4 +86,3 @@ class BloodthirstEffect extends OneShotEffect {
return new BloodthirstEffect(this);
}
}

View file

@ -3,6 +3,7 @@ package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
@ -18,10 +19,8 @@ import mage.game.permanent.Permanent;
* 702.31a Fading is a keyword that represents two abilities. Fading N means This permanent enters the battlefield with N fade counters on it and At the beginning of your upkeep, remove a fade counter from this permanent. If you cant, sacrifice the permanent.
*
*/
public class FadingAbility extends EntersBattlefieldAbility {
private String ruleText;
public FadingAbility(int fadeCounter, Card card) {
@ -29,14 +28,8 @@ public class FadingAbility extends EntersBattlefieldAbility {
Ability ability = new BeginningOfUpkeepTriggeredAbility(new FadingEffect(), TargetController.YOU, false);
ability.setRuleVisible(false);
addSubAbility(ability);
StringBuilder sb = new StringBuilder("Fading ");
sb.append(fadeCounter);
sb.append(" <i>(This permanent enters the battlefield with ")
.append(fadeCounter)
.append(" fade counters on it. ")
.append(" At the beginning of your upkeep, remove a fade counter from this permanent. If you cant, sacrifice the permanent.")
.append(")</i>");
ruleText = sb.toString();
ruleText = "Fading " + fadeCounter + " <i>(This permanent enters the battlefield with " + fadeCounter + " fade counters on it."
+ " At the beginning of your upkeep, remove a fade counter from this permanent. If you cant, sacrifice the permanent.</i>";
}
public FadingAbility(final FadingAbility ability) {
@ -54,7 +47,9 @@ public class FadingAbility extends EntersBattlefieldAbility {
return ruleText;
}
}
class FadingEffect extends OneShotEffect {
FadingEffect() {
super(Outcome.Sacrifice);
staticText = "remove a fade counter from this permanent. If you cant, sacrifice the permanent";
@ -64,18 +59,15 @@ class FadingEffect extends OneShotEffect {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
int amount = p.getCounters().getCount(CounterType.FADE);
Permanent permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
if (permanent != null) {
int amount = permanent.getCounters().getCount(CounterType.FADE);
if (amount > 0) {
p.removeCounters(CounterType.FADE.createInstance(), game);
}
else
{
p.sacrifice(source.getSourceId(), game);
permanent.removeCounters(CounterType.FADE.createInstance(), game);
} else {
permanent.sacrifice(source.getSourceId(), game);
}
return true;
}

View file

@ -25,13 +25,13 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.SunburstCount;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.CardType;
@ -46,8 +46,6 @@ import mage.players.Player;
*
* @author Plopman
*/
public class SunburstAbility extends EntersBattlefieldAbility {
private final static String ruleCreature = "Sunburst <i>(This enters the battlefield with a +1/+1 counter on it for each color of mana spent to cast it.)</i>";
@ -64,7 +62,6 @@ public class SunburstAbility extends EntersBattlefieldAbility{
this.isCreature = ability.isCreature;
}
@Override
public EntersBattlefieldAbility copy() {
return new SunburstAbility(this);
@ -75,14 +72,12 @@ public class SunburstAbility extends EntersBattlefieldAbility{
return isCreature ? ruleCreature : ruleNonCreature;
}
}
class SunburstEffect extends OneShotEffect {
private static final DynamicValue amount = new SunburstCount();
public SunburstEffect() {
super(Outcome.Benefit);
staticText = "Sunburst";
@ -94,13 +89,12 @@ class SunburstEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
if (permanent != null) {
Counter counter;
if (permanent.getCardType().contains(CardType.CREATURE)) {
counter = CounterType.P1P1.createInstance(amount.calculate(game, source, this));
}
else{
} else {
counter = CounterType.CHARGE.createInstance(amount.calculate(game, source, this));
}
if (counter != null) {

View file

@ -25,12 +25,12 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.constants.Outcome;
@ -46,8 +46,6 @@ import mage.util.CardUtil;
*
* @author LevelX2
*/
public class TributeAbility extends EntersBattlefieldAbility {
private int tributeValue;
@ -62,7 +60,6 @@ public class TributeAbility extends EntersBattlefieldAbility{
this.tributeValue = ability.tributeValue;
}
@Override
public EntersBattlefieldAbility copy() {
return new TributeAbility(this);
@ -81,7 +78,7 @@ public class TributeAbility extends EntersBattlefieldAbility{
class TributeEffect extends OneShotEffect {
private int tributeValue;
private final int tributeValue;
public TributeEffect(int tributeValue) {
super(Outcome.Detriment);
@ -101,7 +98,7 @@ class TributeEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Permanent sourcePermanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT);
if (controller != null && sourcePermanent != null) {
UUID opponentId;
if (game.getOpponents(controller.getId()).size() == 1) {
@ -119,13 +116,15 @@ class TributeEffect extends OneShotEffect {
sb.append(" (add ").append(CardUtil.numberToText(tributeValue)).append(" +1/+1 counter");
sb.append(tributeValue > 1 ? "s" : "").append(" to it)?");
if (opponent.chooseUse(outcome, sb.toString(), source, game)) {
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(opponent.getLogName() + " pays tribute to " + sourcePermanent.getLogName());
}
game.getState().setValue("tributeValue" + source.getSourceId(), "yes");
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(tributeValue), true).apply(game, source);
} else {
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(opponent.getLogName() + " does not pay tribute to " + sourcePermanent.getLogName());
}
game.getState().setValue("tributeValue" + source.getSourceId(), "no");
}
return true;