diff --git a/Mage.Sets/src/mage/cards/f/FlameDischarge.java b/Mage.Sets/src/mage/cards/f/FlameDischarge.java new file mode 100644 index 00000000000..c3d4c4e762b --- /dev/null +++ b/Mage.Sets/src/mage/cards/f/FlameDischarge.java @@ -0,0 +1,71 @@ +package mage.cards.f; + +import java.util.UUID; + +import mage.abilities.Ability; +import mage.abilities.condition.common.ControlledModifiedCreatureAsSpellCastCondition; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.common.TargetCreatureOrPlaneswalker; +import mage.watchers.common.ControlledModifiedCreatureAsSpellCastWatcher; + +/** + * + * @author weirddan455 + */ +public final class FlameDischarge extends CardImpl { + + public FlameDischarge(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{R}"); + + // Flame Discharge deals X damage to target creature or planeswalker. If you controlled a modified creature as you cast this spell, it deals X plus 2 damage instead. + this.getSpellAbility().addEffect(new FlameDischargeEffect()); + this.getSpellAbility().addTarget(new TargetCreatureOrPlaneswalker()); + this.getSpellAbility().addWatcher(new ControlledModifiedCreatureAsSpellCastWatcher()); + } + + private FlameDischarge(final FlameDischarge card) { + super(card); + } + + @Override + public FlameDischarge copy() { + return new FlameDischarge(this); + } +} + +class FlameDischargeEffect extends OneShotEffect { + + public FlameDischargeEffect() { + super(Outcome.Damage); + this.staticText = "{this} deals X damage to target creature or planeswalker. If you controlled a modified creature as you cast this spell, it deals X plus 2 damage instead"; + } + + private FlameDischargeEffect(final FlameDischargeEffect effect) { + super(effect); + } + + @Override + public FlameDischargeEffect copy() { + return new FlameDischargeEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getFirstTarget()); + if (permanent == null) { + return false; + } + int damageAmount = source.getManaCostsToPay().getX(); + if (ControlledModifiedCreatureAsSpellCastCondition.instance.apply(game, source)) { + damageAmount += 2; + } + permanent.damage(damageAmount, source, game); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/KamigawaNeonDynasty.java b/Mage.Sets/src/mage/sets/KamigawaNeonDynasty.java index c4944923520..6a4bcf6f1a2 100644 --- a/Mage.Sets/src/mage/sets/KamigawaNeonDynasty.java +++ b/Mage.Sets/src/mage/sets/KamigawaNeonDynasty.java @@ -89,6 +89,7 @@ public final class KamigawaNeonDynasty extends ExpansionSet { cards.add(new SetCardInfo("Fang of Shigeki", 183, Rarity.COMMON, mage.cards.f.FangOfShigeki.class)); cards.add(new SetCardInfo("Farewell", 13, Rarity.RARE, mage.cards.f.Farewell.class)); cards.add(new SetCardInfo("Favor of Jukai", 184, Rarity.COMMON, mage.cards.f.FavorOfJukai.class)); + cards.add(new SetCardInfo("Flame Discharge", 142, Rarity.UNCOMMON, mage.cards.f.FlameDischarge.class)); cards.add(new SetCardInfo("Forest", 291, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Fragment of Konda", 12, Rarity.UNCOMMON, mage.cards.f.FragmentOfKonda.class)); cards.add(new SetCardInfo("Futurist Operative", 53, Rarity.UNCOMMON, mage.cards.f.FuturistOperative.class)); diff --git a/Mage/src/main/java/mage/abilities/condition/common/ControlledModifiedCreatureAsSpellCastCondition.java b/Mage/src/main/java/mage/abilities/condition/common/ControlledModifiedCreatureAsSpellCastCondition.java new file mode 100644 index 00000000000..5000cbb92a9 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/ControlledModifiedCreatureAsSpellCastCondition.java @@ -0,0 +1,31 @@ +package mage.abilities.condition.common; + +import mage.MageObject; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.watchers.common.ControlledModifiedCreatureAsSpellCastWatcher; + +/** + * + * @author weirddan455 + */ +public enum ControlledModifiedCreatureAsSpellCastCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + MageObject sourceObject = source.getSourceObject(game); + ControlledModifiedCreatureAsSpellCastWatcher watcher = game.getState().getWatcher(ControlledModifiedCreatureAsSpellCastWatcher.class); + if (sourceObject == null || watcher == null) { + return false; + } + return watcher.checkModifiedCondition(new MageObjectReference(sourceObject, game)); + } + + @Override + public String toString() { + return "you controlled a modified creature as you cast this spell"; + } +} diff --git a/Mage/src/main/java/mage/watchers/common/ControlledModifiedCreatureAsSpellCastWatcher.java b/Mage/src/main/java/mage/watchers/common/ControlledModifiedCreatureAsSpellCastWatcher.java new file mode 100644 index 00000000000..4ec8368da0f --- /dev/null +++ b/Mage/src/main/java/mage/watchers/common/ControlledModifiedCreatureAsSpellCastWatcher.java @@ -0,0 +1,53 @@ +package mage.watchers.common; + +import mage.MageObjectReference; +import mage.constants.WatcherScope; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.ModifiedPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; +import mage.watchers.Watcher; + +import java.util.HashMap; + +/** + * + * @author weirddan455 + */ +public class ControlledModifiedCreatureAsSpellCastWatcher extends Watcher { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); + + static { + filter.add(ModifiedPredicate.instance); + } + + public ControlledModifiedCreatureAsSpellCastWatcher() { + super(WatcherScope.GAME); + } + + private final HashMap spellsCastCondition = new HashMap<>(); + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SPELL_CAST) { + Spell spell = game.getSpell(event.getTargetId()); + if (spell != null) { + MageObjectReference mor = new MageObjectReference(spell, game); + Boolean condition = !game.getBattlefield().getAllActivePermanents(filter, spell.getControllerId(), game).isEmpty(); + spellsCastCondition.put(mor, condition); + } + } + } + + @Override + public void reset() { + super.reset(); + spellsCastCondition.clear(); + } + + public boolean checkModifiedCondition(MageObjectReference mor) { + return spellsCastCondition.getOrDefault(mor, false); + } +}