diff --git a/Mage.Sets/src/mage/sets/onslaught/Aurification.java b/Mage.Sets/src/mage/sets/onslaught/Aurification.java new file mode 100644 index 00000000000..92479ceca51 --- /dev/null +++ b/Mage.Sets/src/mage/sets/onslaught/Aurification.java @@ -0,0 +1,164 @@ +/* + * 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.onslaught; + +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.LeavesBattlefieldTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.BecomesSubtypeAllEffect; +import mage.abilities.effects.common.continuous.GainAbilityAllEffect; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.abilities.keyword.DefenderAbility; +import mage.cards.CardImpl; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.CounterPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTarget; + +import java.util.ArrayList; +import java.util.UUID; + +/** + * + * @author andyfries + */ + +public class Aurification extends CardImpl { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Each creature with a gold counter on it"); + + static { + filter.add(new CounterPredicate(CounterType.GOLD)); + } + + final String rule = "Each creature with a gold counter on it is a Wall in addition to its other creature types and has defender."; + + public Aurification(UUID ownerId) { + super(ownerId, 6, "Aurification", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{W}"); + this.expansionSetCode = "ONS"; + + // Whenever a creature deals damage to you, put a gold counter on it. + this.addAbility(new AddGoldCountersAbility()); + + // Each creature with a gold counter on it is a Wall in addition to its other creature types and has defender. + ArrayList subtypes = new ArrayList<>(1); + subtypes.add("Wall"); + + BecomesSubtypeAllEffect becomesSubtypeAllEffect = new BecomesSubtypeAllEffect(Duration.WhileOnBattlefield, subtypes, filter, false); + becomesSubtypeAllEffect.setText(""); + + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, becomesSubtypeAllEffect)); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAllEffect(DefenderAbility.getInstance(), Duration.WhileOnBattlefield, filter, rule))); + + // When Aurification leaves the battlefield, remove all gold counters from all creatures. + this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllGoldCountersEffect(), false)); + } + + public Aurification(final Aurification card) { + super(card); + } + + @Override + public Aurification copy() { + return new Aurification(this); + } + + public class AddGoldCountersAbility extends TriggeredAbilityImpl { + + public AddGoldCountersAbility() { + super(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.GOLD.createInstance())); + } + + public AddGoldCountersAbility(final AddGoldCountersAbility ability) { + super(ability); + } + + @Override + public AddGoldCountersAbility copy() { + return new AddGoldCountersAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getPlayerId().equals(this.getControllerId())) { + Permanent permanent = game.getPermanent(event.getSourceId()); + if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { + for (Effect effect : this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getSourceId())); + } + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever a creature deals damage to you, put a gold counter on it."; + } + + } + + public class RemoveAllGoldCountersEffect extends OneShotEffect { + public RemoveAllGoldCountersEffect() { + super(Outcome.Neutral); + this.staticText = "remove all gold counters from all creatures"; + } + + public RemoveAllGoldCountersEffect(final RemoveAllGoldCountersEffect effect) { + super(effect); + } + + @Override + public RemoveAllGoldCountersEffect copy() { + return new RemoveAllGoldCountersEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + for (Permanent permanent : game.getBattlefield().getAllActivePermanents(CardType.CREATURE)) { + if (permanent != null){ + permanent.getCounters().removeAllCounters(CounterType.GOLD); + } + } + return true; + } + } +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/continuous/BecomesSubtypeAllEffect.java b/Mage/src/mage/abilities/effects/common/continuous/BecomesSubtypeAllEffect.java index 36c62e51adb..80e7bcdb69b 100644 --- a/Mage/src/mage/abilities/effects/common/continuous/BecomesSubtypeAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continuous/BecomesSubtypeAllEffect.java @@ -6,8 +6,11 @@ package mage.abilities.effects.common.continuous; import java.util.ArrayList; +import java.util.Iterator; +import mage.MageObjectReference; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.ContinuousEffectImpl; import mage.constants.Duration; import mage.constants.Layer; @@ -25,21 +28,23 @@ public class BecomesSubtypeAllEffect extends ContinuousEffectImpl { protected ArrayList subtypes = new ArrayList(); protected boolean loseOther; // loses other subtypes + protected FilterCreaturePermanent filter; - public BecomesSubtypeAllEffect(Duration duration, String subtype) { + public BecomesSubtypeAllEffect(Duration duration, String subtype) { this(duration, createArrayList(subtype)); } public BecomesSubtypeAllEffect(Duration duration, ArrayList subtypes) { - this(duration, subtypes, true); + this(duration, subtypes, new FilterCreaturePermanent("All creatures"), true); } public BecomesSubtypeAllEffect(Duration duration, - ArrayList subtypes, boolean loseOther) { + ArrayList subtypes, FilterCreaturePermanent filter, boolean loseOther) { super(duration, Outcome.Detriment); this.subtypes = subtypes; this.staticText = setText(); this.loseOther = loseOther; + this.filter = filter; } private static ArrayList createArrayList(String subtype) { @@ -52,7 +57,7 @@ public class BecomesSubtypeAllEffect extends ContinuousEffectImpl { super(effect); this.subtypes.addAll(effect.subtypes); this.loseOther = effect.loseOther; - this.loseOther = effect.loseOther; + this.filter = effect.filter; } @Override @@ -68,9 +73,7 @@ public class BecomesSubtypeAllEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - - for (Permanent permanent : game.getBattlefield() - .getAllActivePermanents(new FilterCreaturePermanent(), game)) { + for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) { if (permanent != null) { switch (layer) { case TypeChangingEffects_4: diff --git a/Mage/src/mage/counters/CounterType.java b/Mage/src/mage/counters/CounterType.java index 2f0aa49ad8d..569afd3b645 100644 --- a/Mage/src/mage/counters/CounterType.java +++ b/Mage/src/mage/counters/CounterType.java @@ -55,6 +55,7 @@ public enum CounterType { FEATHER("feather"), FLOOD("flood"), FUSE("fuse"), + GOLD("gold"), HATCHLING("hatchling"), HOOFPRINT("hoofprint"), ICE("ice"), diff --git a/Mage/src/mage/counters/Counters.java b/Mage/src/mage/counters/Counters.java index 6b1aca15edf..473106f081f 100644 --- a/Mage/src/mage/counters/Counters.java +++ b/Mage/src/mage/counters/Counters.java @@ -96,6 +96,16 @@ public class Counters extends HashMap implements Serializable { } } + public void removeAllCounters(CounterType counterType){ + removeAllCounters(counterType.getName()); + } + + public void removeAllCounters(String name){ + if (this.containsKey(name)){ + this.remove(name); + } + } + public int getCount(String name) { if (this.containsKey(name)) { return this.get(name).getCount();