diff --git a/Mage.Sets/src/mage/sets/darksteel/TearsOfRage.java b/Mage.Sets/src/mage/sets/darksteel/TearsOfRage.java new file mode 100644 index 0000000000..15e9c98986 --- /dev/null +++ b/Mage.Sets/src/mage/sets/darksteel/TearsOfRage.java @@ -0,0 +1,113 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.sets.darksteel; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility; +import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; +import mage.abilities.dynamicvalue.common.AttackingCreatureCount; +import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.SacrificeTargetEffect; +import mage.abilities.effects.common.continuous.BoostControlledEffect; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.PhaseStep; +import mage.constants.Rarity; +import mage.filter.common.FilterAttackingCreature; +import mage.game.Game; +import mage.players.Player; +import mage.target.targetpointer.FixedTargets; + +/** + * + * @author LevelX2 + */ +public class TearsOfRage extends CardImpl { + + public TearsOfRage(UUID ownerId) { + super(ownerId, 70, "Tears of Rage", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{R}{R}"); + this.expansionSetCode = "DST"; + + // Cast Tears of Rage only during the declare attackers step. + this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(PhaseStep.DECLARE_ATTACKERS)); + + // Attacking creatures you control get +X/+0 until end of turn, where X is the number of attacking creatures. Sacrifice those creatures at the beginning of the next end step. + getSpellAbility().addEffect(new BoostControlledEffect(new AttackingCreatureCount("the number of attacking creatures"), new StaticValue(0), + Duration.EndOfTurn, new FilterAttackingCreature("Attacking creatures"), false)); + getSpellAbility().addEffect(new TearsOfRageEffect()); + } + + public TearsOfRage(final TearsOfRage card) { + super(card); + } + + @Override + public TearsOfRage copy() { + return new TearsOfRage(this); + } +} + +class TearsOfRageEffect extends OneShotEffect { + + public TearsOfRageEffect() { + super(Outcome.Sacrifice); + this.staticText = "Sacrifice those creatures at the beginning of the next end step"; + } + + public TearsOfRageEffect(final TearsOfRageEffect effect) { + super(effect); + } + + @Override + public TearsOfRageEffect copy() { + return new TearsOfRageEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Effect effect = new SacrificeTargetEffect("Sacrifice those creatures at the beginning of the next end step", source.getControllerId()); + effect.setTargetPointer(new FixedTargets(game.getBattlefield().getAllActivePermanents(new FilterAttackingCreature(), controller.getId(), game), game)); + DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect); + delayedAbility.setSourceId(source.getSourceId()); + delayedAbility.setControllerId(source.getControllerId()); + delayedAbility.setSourceObject(source.getSourceObject(game), game); + game.addDelayedTriggeredAbility(delayedAbility); + return true; + } + return false; + } + +} diff --git a/Mage/src/main/java/mage/MageObjectReference.java b/Mage/src/main/java/mage/MageObjectReference.java index b2516798d2..d44226ce0d 100644 --- a/Mage/src/main/java/mage/MageObjectReference.java +++ b/Mage/src/main/java/mage/MageObjectReference.java @@ -47,7 +47,7 @@ public class MageObjectReference implements Comparable, Ser private static final Logger logger = Logger.getLogger(MageObjectReference.class); private final UUID sourceId; - private final int zoneChangeCounter; + private int zoneChangeCounter; public MageObjectReference(MageObject mageObject, Game game) { this.sourceId = mageObject.getId(); @@ -67,6 +67,11 @@ public class MageObjectReference implements Comparable, Ser this.zoneChangeCounter = zoneChangeCounter; } + public MageObjectReference(UUID sourceId) { + this.sourceId = sourceId; + this.zoneChangeCounter = -1; + } + public MageObjectReference(UUID sourceId, Game game) { this.sourceId = sourceId; MageObject mageObject = game.getObject(sourceId); @@ -163,4 +168,7 @@ public class MageObjectReference implements Comparable, Ser return null; } + public void setZoneChangeCounter(int zoneChangeCounter) { + this.zoneChangeCounter = zoneChangeCounter; + } } diff --git a/Mage/src/main/java/mage/abilities/common/CastOnlyDuringPhaseStepSourceAbility.java b/Mage/src/main/java/mage/abilities/common/CastOnlyDuringPhaseStepSourceAbility.java index d7c1a2ea89..66794eb59d 100644 --- a/Mage/src/main/java/mage/abilities/common/CastOnlyDuringPhaseStepSourceAbility.java +++ b/Mage/src/main/java/mage/abilities/common/CastOnlyDuringPhaseStepSourceAbility.java @@ -38,7 +38,7 @@ public class CastOnlyDuringPhaseStepSourceAbility extends SimpleStaticAbility { } public CastOnlyDuringPhaseStepSourceAbility(TurnPhase turnPhase, PhaseStep phaseStep, Condition condition, String effectText) { - super(Zone.BATTLEFIELD, new CastOnlyDuringPhaseStepSourceEffect(turnPhase, phaseStep, condition)); + super(Zone.ALL, new CastOnlyDuringPhaseStepSourceEffect(turnPhase, phaseStep, condition)); this.setRuleAtTheTop(true); if (effectText != null) { getEffects().get(0).setText(effectText); diff --git a/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java index 4491195a01..04a5308816 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java @@ -30,7 +30,7 @@ public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifying this.turnPhase = turnPhase; this.phaseStep = phaseStep; this.condition = condition; - setText(); + staticText = setText(); } private CastOnlyDuringPhaseStepSourceEffect(final CastOnlyDuringPhaseStepSourceEffect effect) { diff --git a/Mage/src/main/java/mage/target/targetpointer/FixedTargets.java b/Mage/src/main/java/mage/target/targetpointer/FixedTargets.java new file mode 100644 index 0000000000..224433f396 --- /dev/null +++ b/Mage/src/main/java/mage/target/targetpointer/FixedTargets.java @@ -0,0 +1,90 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.target.targetpointer; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.cards.Cards; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ +public class FixedTargets implements TargetPointer { + + final ArrayList targets = new ArrayList<>(); + private boolean initialized; + + public FixedTargets(UUID targetId) { + targets.add(new MageObjectReference(targetId)); + this.initialized = false; + } + + public FixedTargets(Cards cards, Game game) { + for (UUID targetId : cards) { + MageObjectReference mor = new MageObjectReference(targetId, game); + targets.add(mor); + } + this.initialized = true; + } + + public FixedTargets(List permanents, Game game) { + for (Permanent permanent : permanents) { + MageObjectReference mor = new MageObjectReference(permanent.getId(), permanent.getZoneChangeCounter(game), game); + targets.add(mor); + } + this.initialized = true; + } + + private FixedTargets(final FixedTargets fixedTargets) { + this.targets.addAll(fixedTargets.targets); + this.initialized = fixedTargets.initialized; + } + + @Override + public void init(Game game, Ability source) { + if (!initialized) { + initialized = true; + for (MageObjectReference mor : targets) { + mor.setZoneChangeCounter(game.getState().getZoneChangeCounter(mor.getSourceId())); + } + } + } + + @Override + public List getTargets(Game game, Ability source) { + // check target not changed zone + ArrayList list = new ArrayList<>(1); + for (MageObjectReference mor : targets) { + if (game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) { + list.add(mor.getSourceId()); + } + } + return list; + } + + @Override + public UUID getFirst(Game game, Ability source) { + // check target not changed zone + for (MageObjectReference mor : targets) { + if (game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) { + return mor.getSourceId(); + } + } + return null; + } + + @Override + public TargetPointer copy() { + return new FixedTargets(this); + } + +}