From 79b7d49e8369a43139e89862c7bbd02c691a045e Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sat, 10 Apr 2021 21:55:32 -0400 Subject: [PATCH] [STX] Implemented Show of Confidence --- .../src/mage/cards/s/ShowOfConfidence.java | 90 +++++++++++++++++++ .../mage/sets/StrixhavenSchoolOfMages.java | 1 + .../watchers/common/SpellsCastWatcher.java | 11 +-- 3 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/s/ShowOfConfidence.java diff --git a/Mage.Sets/src/mage/cards/s/ShowOfConfidence.java b/Mage.Sets/src/mage/cards/s/ShowOfConfidence.java new file mode 100644 index 0000000000..cb6ee9a83b --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/ShowOfConfidence.java @@ -0,0 +1,90 @@ +package mage.cards.s; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CastSourceTriggeredAbility; +import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.abilities.keyword.VigilanceAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.stack.Spell; +import mage.target.common.TargetCreaturePermanent; +import mage.watchers.common.SpellsCastWatcher; + +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ShowOfConfidence extends CardImpl { + + public ShowOfConfidence(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); + + // When you cast this spell, copy it for each other instant or sorcery spell you've cast this turn. You may choose new targets for the copies. + this.addAbility(new CastSourceTriggeredAbility(new ShowOfConfidenceEffect()), new SpellsCastWatcher()); + + // Put a +1/+1 counter on target creature. It gains vigilance until end of turn. + this.getSpellAbility().addEffect(new AddCountersTargetEffect(CounterType.P1P1.createInstance())); + this.getSpellAbility().addEffect(new GainAbilityTargetEffect( + VigilanceAbility.getInstance(), Duration.EndOfTurn + ).setText("It gains vigilance until end of turn")); + this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + } + + private ShowOfConfidence(final ShowOfConfidence card) { + super(card); + } + + @Override + public ShowOfConfidence copy() { + return new ShowOfConfidence(this); + } +} + +class ShowOfConfidenceEffect extends OneShotEffect { + + ShowOfConfidenceEffect() { + super(Outcome.Benefit); + staticText = "copy it for each other instant or sorcery spell you've cast this turn. " + + "You may choose new targets for the copies"; + } + + private ShowOfConfidenceEffect(final ShowOfConfidenceEffect effect) { + super(effect); + } + + @Override + public ShowOfConfidenceEffect copy() { + return new ShowOfConfidenceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = (Spell) getValue("spellCast"); + SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class); + if (spell == null || watcher == null) { + return false; + } + int copies = watcher.getSpellsCastThisTurn(source.getControllerId()) + .stream() + .filter(Objects::nonNull) + .filter(MageObject::isInstantOrSorcery) + .filter(s -> !s.getSourceId().equals(source.getSourceId()) + || s.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()) + .mapToInt(x -> 1) + .sum(); + if (copies > 0) { + spell.createCopyOnStack(game, source, source.getControllerId(), true, copies); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index 0ba6abc575..4ce4c18b35 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -232,6 +232,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Shadewing Laureate", 229, Rarity.UNCOMMON, mage.cards.s.ShadewingLaureate.class)); cards.add(new SetCardInfo("Shaile, Dean of Radiance", 158, Rarity.RARE, mage.cards.s.ShaileDeanOfRadiance.class)); cards.add(new SetCardInfo("Shineshadow Snarl", 272, Rarity.RARE, mage.cards.s.ShineshadowSnarl.class)); + cards.add(new SetCardInfo("Show of Confidence", 28, Rarity.UNCOMMON, mage.cards.s.ShowOfConfidence.class)); cards.add(new SetCardInfo("Silverquill Apprentice", 231, Rarity.UNCOMMON, mage.cards.s.SilverquillApprentice.class)); cards.add(new SetCardInfo("Silverquill Campus", 273, Rarity.COMMON, mage.cards.s.SilverquillCampus.class)); cards.add(new SetCardInfo("Silverquill Command", 232, Rarity.RARE, mage.cards.s.SilverquillCommand.class)); diff --git a/Mage/src/main/java/mage/watchers/common/SpellsCastWatcher.java b/Mage/src/main/java/mage/watchers/common/SpellsCastWatcher.java index a6f9cb854c..a074640a1f 100644 --- a/Mage/src/main/java/mage/watchers/common/SpellsCastWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/SpellsCastWatcher.java @@ -10,14 +10,9 @@ import mage.game.events.GameEvent.EventType; import mage.game.stack.Spell; import mage.watchers.Watcher; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** - * * @author LevelX2 */ public class SpellsCastWatcher extends Watcher { @@ -73,11 +68,11 @@ public class SpellsCastWatcher extends Watcher { } public List getSpellsCastThisTurn(UUID playerId) { - return spellsCast.get(playerId); + return spellsCast.computeIfAbsent(playerId, x -> new ArrayList<>()); } public List getSpellsCastFromGraveyardThisTurn(UUID playerId) { - return spellsCastFromGraveyard.get(playerId); + return spellsCastFromGraveyard.computeIfAbsent(playerId, x -> new ArrayList<>()); } public int getNumberOfNonCreatureSpells() {