diff --git a/Mage.Sets/src/mage/cards/b/Blustersquall.java b/Mage.Sets/src/mage/cards/b/Blustersquall.java index 0bfe1d44ba76..435cb5958723 100644 --- a/Mage.Sets/src/mage/cards/b/Blustersquall.java +++ b/Mage.Sets/src/mage/cards/b/Blustersquall.java @@ -1,20 +1,12 @@ package mage.cards.b; -import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.TapTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.filter.StaticFilters; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.target.common.TargetCreaturePermanent; import java.util.UUID; @@ -29,11 +21,10 @@ public Blustersquall(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U}"); // Tap target creature you don't control. - this.getSpellAbility().addTarget(new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL)); - this.getSpellAbility().addEffect(new TapTargetEffect()); // Overload {3}{U} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - this.addAbility(new OverloadAbility(this, new BlustersqallTapAllEffect(), new ManaCostsImpl<>("{3}{U}"))); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{3}{U}"), + new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL), new TapTargetEffect()); } private Blustersquall(final Blustersquall card) { @@ -45,28 +36,3 @@ public Blustersquall copy() { return new Blustersquall(this); } } - -class BlustersqallTapAllEffect extends OneShotEffect { - - BlustersqallTapAllEffect() { - super(Outcome.Tap); - staticText = "Tap each creature you don't control"; - } - - private BlustersqallTapAllEffect(final BlustersqallTapAllEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, source.getControllerId(), source, game)) { - creature.tap(source, game); - } - return true; - } - - @Override - public BlustersqallTapAllEffect copy() { - return new BlustersqallTapAllEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/b/BreakTheIce.java b/Mage.Sets/src/mage/cards/b/BreakTheIce.java index 1339b17b491f..fbc8d2398771 100644 --- a/Mage.Sets/src/mage/cards/b/BreakTheIce.java +++ b/Mage.Sets/src/mage/cards/b/BreakTheIce.java @@ -1,7 +1,6 @@ package mage.cards.b; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.DestroyAllEffect; import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; @@ -34,11 +33,9 @@ public BreakTheIce(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{B}{B}"); // Destroy target land that is snow or could produce {C}. - this.getSpellAbility().addEffect(new DestroyTargetEffect()); - this.getSpellAbility().addTarget(new TargetPermanent(filter)); - // Overload {4}{B}{B} - this.addAbility(new OverloadAbility(this, new DestroyAllEffect(filter), new ManaCostsImpl<>("{4}{B}{B}"))); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{4}{B}{B}"), + new TargetPermanent(filter), new DestroyTargetEffect()); } private BreakTheIce(final BreakTheIce card) { diff --git a/Mage.Sets/src/mage/cards/c/ChemistersTrick.java b/Mage.Sets/src/mage/cards/c/ChemistersTrick.java index 0b350b5185a8..5b1bd778b822 100644 --- a/Mage.Sets/src/mage/cards/c/ChemistersTrick.java +++ b/Mage.Sets/src/mage/cards/c/ChemistersTrick.java @@ -1,23 +1,14 @@ package mage.cards.c; -import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect; -import mage.abilities.effects.common.continuous.BoostAllEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.target.common.TargetCreaturePermanent; -import mage.target.targetpointer.FixedTarget; import java.util.UUID; @@ -33,14 +24,10 @@ public ChemistersTrick(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U}{R}"); // Target creature you don't control gets -2/-0 until end of turn and attacks this turn if able. - this.getSpellAbility().addTarget(new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL)); - this.getSpellAbility().addEffect(new BoostTargetEffect(-2, 0, Duration.EndOfTurn)); - this.getSpellAbility().addEffect(new AttacksIfAbleTargetEffect(Duration.EndOfTurn).setText("and attacks this turn if able")); - // Overload {3}{U}{R} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - OverloadAbility ability = new OverloadAbility(this, new BoostAllEffect(-2, 0, Duration.EndOfTurn, StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, false), new ManaCostsImpl<>("{3}{U}{R}")); - ability.addEffect(new ChemistersTrickEffect()); - this.addAbility(ability); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{3}{U}{R}"), + new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL), new BoostTargetEffect(-2, 0, Duration.EndOfTurn), + new AttacksIfAbleTargetEffect(Duration.EndOfTurn).setText("and attacks this turn if able")); } private ChemistersTrick(final ChemistersTrick card) { @@ -52,31 +39,3 @@ public ChemistersTrick copy() { return new ChemistersTrick(this); } } - -class ChemistersTrickEffect extends OneShotEffect { - - - ChemistersTrickEffect() { - super(Outcome.ReturnToHand); - staticText = "each creature you don't control attacks this turn if able"; - } - - private ChemistersTrickEffect(final ChemistersTrickEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, source.getControllerId(), source, game)) { - AttacksIfAbleTargetEffect effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn); - effect.setTargetPointer(new FixedTarget(creature.getId(), game)); - game.addEffect(effect, source); - } - return true; - } - - @Override - public ChemistersTrickEffect copy() { - return new ChemistersTrickEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/c/CorporealProjection.java b/Mage.Sets/src/mage/cards/c/CorporealProjection.java index e91c44cbe313..161d8bc201dc 100644 --- a/Mage.Sets/src/mage/cards/c/CorporealProjection.java +++ b/Mage.Sets/src/mage/cards/c/CorporealProjection.java @@ -1,15 +1,12 @@ package mage.cards.c; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.continuous.GainAbilityAllEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; import mage.abilities.keyword.MyriadAbility; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Duration; -import mage.filter.StaticFilters; import mage.target.common.TargetControlledCreaturePermanent; import java.util.UUID; @@ -23,17 +20,9 @@ public CorporealProjection(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{U}{R}"); // Target creature you control gains myriad until end of turn. - this.getSpellAbility().addEffect(new GainAbilityTargetEffect(new MyriadAbility(false))); - this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - // Overload {3}{U}{U}{R}{R} - this.addAbility(new OverloadAbility( - this, - new GainAbilityAllEffect( - new MyriadAbility(false), Duration.EndOfTurn, - StaticFilters.FILTER_CONTROLLED_CREATURE - ), new ManaCostsImpl<>("{3}{U}{U}{R}{R}") - )); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{3}{U}{U}{R}{R}"), + new TargetControlledCreaturePermanent(), new GainAbilityTargetEffect(new MyriadAbility(false))); } private CorporealProjection(final CorporealProjection card) { diff --git a/Mage.Sets/src/mage/cards/c/Counterflux.java b/Mage.Sets/src/mage/cards/c/Counterflux.java index cad1aa3ac112..e4b74893e8bf 100644 --- a/Mage.Sets/src/mage/cards/c/Counterflux.java +++ b/Mage.Sets/src/mage/cards/c/Counterflux.java @@ -1,29 +1,23 @@ package mage.cards.c; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CantBeCounteredSourceEffect; import mage.abilities.effects.common.CounterTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.FilterSpell; -import mage.game.Game; -import mage.game.stack.Spell; -import mage.game.stack.StackObject; import mage.target.TargetSpell; +import java.util.UUID; + /** * @@ -49,11 +43,9 @@ public Counterflux(UUID ownerId, CardSetInfo setInfo) { this.addAbility(ability); // Counter target spell you don't control. - this.getSpellAbility().addTarget(new TargetSpell(filter)); - this.getSpellAbility().addEffect(new CounterTargetEffect()); - // Overload {1}{U}{U}{R} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - this.addAbility(new OverloadAbility(this, new CounterfluxEffect(), new ManaCostsImpl<>("{1}{U}{U}{R}"))); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{1}{U}{U}{R}"), + new TargetSpell(filter), new CounterTargetEffect()); } private Counterflux(final Counterflux card) { @@ -65,37 +57,3 @@ public Counterflux copy() { return new Counterflux(this); } } - -class CounterfluxEffect extends OneShotEffect { - - CounterfluxEffect() { - super(Outcome.Detriment); - staticText = "Counter each spell you don't control."; - - } - - private CounterfluxEffect(final CounterfluxEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - - List spellsToCounter = new LinkedList<>(); - for (StackObject stackObject : game.getStack()) { - if (stackObject instanceof Spell && !stackObject.isControlledBy(source.getControllerId())) { - spellsToCounter.add((Spell) stackObject); - } - } - for (Spell spell : spellsToCounter) { - game.getStack().counter(spell.getId(), source, game); - } - return true; - } - - @Override - public CounterfluxEffect copy() { - return new CounterfluxEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/cards/c/CyclonicRift.java b/Mage.Sets/src/mage/cards/c/CyclonicRift.java index 728c94209e33..ed1038ec3601 100644 --- a/Mage.Sets/src/mage/cards/c/CyclonicRift.java +++ b/Mage.Sets/src/mage/cards/c/CyclonicRift.java @@ -1,8 +1,6 @@ package mage.cards.c; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.Effect; -import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; import mage.abilities.effects.common.ReturnToHandTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; @@ -29,13 +27,9 @@ public CyclonicRift(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}"); // Return target nonland permanent you don't control to its owner's hand. - this.getSpellAbility().addTarget(new TargetPermanent(filter)); - this.getSpellAbility().addEffect(new ReturnToHandTargetEffect()); - // Overload {6}{U} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - Effect effect = new ReturnToHandFromBattlefieldAllEffect(filter); - effect.setText("Return each nonland permanent you don't control to its owner's hand"); - this.addAbility(new OverloadAbility(this, effect, new ManaCostsImpl<>("{6}{U}"))); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{6}{U}"), + new TargetPermanent(filter), new ReturnToHandTargetEffect()); } private CyclonicRift(final CyclonicRift card) { diff --git a/Mage.Sets/src/mage/cards/d/Damn.java b/Mage.Sets/src/mage/cards/d/Damn.java index 3f556e82b5ea..9141a7c8355f 100644 --- a/Mage.Sets/src/mage/cards/d/Damn.java +++ b/Mage.Sets/src/mage/cards/d/Damn.java @@ -1,13 +1,11 @@ package mage.cards.d; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.DestroyAllEffect; import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.filter.StaticFilters; import mage.target.common.TargetCreaturePermanent; import java.util.UUID; @@ -22,16 +20,10 @@ public Damn(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{B}{B}"); // Destroy target creature. A creature destroyed this way can’t be regenerated. - this.getSpellAbility().addTarget(new TargetCreaturePermanent()); - this.getSpellAbility().addEffect(new DestroyTargetEffect(true) - .setText("destroy target creature. A creature destroyed this way can't be regenerated")); - // Overload {2}{W}{W} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of “target” with “each.”) - this.addAbility(new OverloadAbility( - this, - new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_CREATURES, true), - new ManaCostsImpl<>("{2}{W}{W}") - )); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{2}{W}{W}"), + new TargetCreaturePermanent(), new DestroyTargetEffect(true) + .setText("destroy target creature. A creature destroyed this way can't be regenerated")); } private Damn(final Damn card) { diff --git a/Mage.Sets/src/mage/cards/d/Downsize.java b/Mage.Sets/src/mage/cards/d/Downsize.java index 96c802234f5d..59334f5d077b 100644 --- a/Mage.Sets/src/mage/cards/d/Downsize.java +++ b/Mage.Sets/src/mage/cards/d/Downsize.java @@ -1,16 +1,13 @@ package mage.cards.d; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.continuous.BoostAllEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.filter.StaticFilters; import mage.target.TargetPermanent; -import mage.target.common.TargetCreaturePermanent; import java.util.UUID; @@ -25,12 +22,9 @@ public Downsize(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U}"); // Target creature you don't control gets -4/-0 until end of turn. - this.getSpellAbility().addTarget(new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL)); - this.getSpellAbility().addEffect(new BoostTargetEffect(-4, 0, Duration.EndOfTurn)); - // Overload {2}{U} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - this.addAbility(new OverloadAbility(this, new BoostAllEffect(-4, 0, Duration.EndOfTurn, StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, false), new ManaCostsImpl<>("{2}{U}"))); - + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{2}{U}"), + new TargetPermanent(FILTER_CREATURE_YOU_DONT_CONTROL), new BoostTargetEffect(-4, 0, Duration.EndOfTurn)); } private Downsize(final Downsize card) { diff --git a/Mage.Sets/src/mage/cards/d/Dragonshift.java b/Mage.Sets/src/mage/cards/d/Dragonshift.java index 625fde9b54f8..bf216ecddb37 100644 --- a/Mage.Sets/src/mage/cards/d/Dragonshift.java +++ b/Mage.Sets/src/mage/cards/d/Dragonshift.java @@ -1,11 +1,8 @@ package mage.cards.d; -import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.continuous.BecomesCreatureAllEffect; import mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect; -import mage.abilities.effects.common.continuous.LoseAllAbilitiesAllEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; @@ -39,18 +36,9 @@ public Dragonshift(UUID ownerId, CardSetInfo setInfo) { true, false, Duration.EndOfTurn) .withDurationRuleAtStart(true); effect.setText("Until end of turn, target creature you control becomes a blue and red Dragon with base power and toughness 4/4, loses all abilities, and gains flying."); - this.getSpellAbility().addEffect(effect); - this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - // Overload {3}{U}{U}{R}{R} - Ability ability = new OverloadAbility(this, new LoseAllAbilitiesAllEffect(new FilterControlledCreaturePermanent(""), Duration.EndOfTurn), new ManaCostsImpl<>("{3}{U}{U}{R}{R}")); - ability.addEffect(new BecomesCreatureAllEffect( - new CreatureToken(4, 4, "blue and red Dragon with base power and toughness 4/4 and with flying") - .withColor("UR") - .withSubType(SubType.DRAGON) - .withAbility(FlyingAbility.getInstance()), - null, filter, Duration.EndOfTurn, true, false, true)); - this.addAbility(ability); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{3}{U}{U}{R}{R}"), + new TargetControlledCreaturePermanent(), effect); } private Dragonshift(final Dragonshift card) { @@ -61,4 +49,4 @@ private Dragonshift(final Dragonshift card) { public Dragonshift copy() { return new Dragonshift(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/d/Dynacharge.java b/Mage.Sets/src/mage/cards/d/Dynacharge.java index 4541d62a8099..54d6c15c2948 100644 --- a/Mage.Sets/src/mage/cards/d/Dynacharge.java +++ b/Mage.Sets/src/mage/cards/d/Dynacharge.java @@ -1,9 +1,7 @@ package mage.cards.d; -import java.util.UUID; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.continuous.BoostControlledEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.abilities.keyword.OverloadAbility; import mage.cards.CardImpl; @@ -12,6 +10,8 @@ import mage.constants.Duration; import mage.target.common.TargetControlledCreaturePermanent; +import java.util.UUID; + /** * * @author LevelX2 @@ -23,11 +23,9 @@ public Dynacharge(UUID ownerId, CardSetInfo setInfo) { // Target creature you control gets +2/+0 until end of turn. - this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - this.getSpellAbility().addEffect(new BoostTargetEffect(2,0, Duration.EndOfTurn)); - // Overload {2}{R} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of "target" with "each.") - this.addAbility(new OverloadAbility(this, new BoostControlledEffect(2,0, Duration.EndOfTurn), new ManaCostsImpl<>("{2}{R}"))); + OverloadAbility.ImplementOverloadAbility(this, new ManaCostsImpl<>("{2}{R}"), + new TargetControlledCreaturePermanent(), new BoostTargetEffect(2,0, Duration.EndOfTurn)); } private Dynacharge(final Dynacharge card) { @@ -38,4 +36,4 @@ private Dynacharge(final Dynacharge card) { public Dynacharge copy() { return new Dynacharge(this); } -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/abilities/keyword/OverloadAbility.java b/Mage/src/main/java/mage/abilities/keyword/OverloadAbility.java index c7300abd7219..5a57a797c8bf 100644 --- a/Mage/src/main/java/mage/abilities/keyword/OverloadAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/OverloadAbility.java @@ -1,11 +1,21 @@ package mage.abilities.keyword; +import mage.MageObjectReference; +import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; import mage.cards.Card; +import mage.constants.Outcome; import mage.constants.SpellAbilityType; import mage.constants.TimingRule; +import mage.game.Game; +import mage.target.Target; +import mage.target.targetpointer.FixedTargets; + +import java.util.stream.Collectors; /** * 702.94. Overload @@ -30,6 +40,26 @@ */ public class OverloadAbility extends SpellAbility { + public static void ImplementOverloadAbility(Card card, ManaCosts costs, Target target, Effect... effects) { + card.getSpellAbility().addTarget(target.copy()); + Ability overload = new OverloadAbility(card, costs); + for (Effect effect : effects) { + card.getSpellAbility().addEffect(effect.copy()); + OverloadedEffect overloadEffect = new OverloadedEffect(effect, target.copy()); + overloadEffect.setText(effect.getText(card.getSpellAbility().getModes().getMode()) + .replace("target", "each")); + overload.addEffect(overloadEffect); + } + card.addAbility(overload); + } + + public OverloadAbility(Card card, ManaCosts costs) { + super(costs, card.getName() + " with overload"); + this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; + this.timing = (card.isSorcery(null) ? TimingRule.SORCERY : TimingRule.INSTANT); + } + + //TODO: Remove once all Overload cards have been converted public OverloadAbility(Card card, Effect effect, ManaCosts costs) { super(costs, card.getName() + " with overload"); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; @@ -57,3 +87,39 @@ public String getRule() { } } + +class OverloadedEffect extends OneShotEffect { + Effect innerEffect; + Target target; + + public OverloadedEffect(Effect innerEffect, Target target) { + super(Outcome.Benefit); + this.innerEffect = innerEffect; + this.target = target.withNotTarget(true); + } + + protected OverloadedEffect(final OverloadedEffect effect) { + super(effect); + this.innerEffect = effect.innerEffect; + this.target = effect.target; + } + + @Override + public boolean apply(Game game, Ability source) { + innerEffect.setTargetPointer(new FixedTargets( + target.possibleTargets(source.getControllerId(), source, game) + .stream().map(id -> new MageObjectReference(id, game)) + .collect(Collectors.toSet()))); + if (innerEffect instanceof OneShotEffect) { + return innerEffect.apply(game, source); + } else { + game.addEffect((ContinuousEffect) innerEffect, source); + return true; + } + } + + @Override + public OverloadedEffect copy() { + return new OverloadedEffect(this); + } +}