From a0e4791ad63f08ca70cfd0d848c4c4bd085df83c Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 12 Nov 2018 04:17:04 +0400 Subject: [PATCH] [GNT] implemented Avatar of Growth --- .../src/mage/cards/a/AvatarOfGrowth.java | 93 +++++++++++++++++++ Mage.Sets/src/mage/sets/GameNight.java | 2 +- ...CostReductionSourceForOpponentsEffect.java | 52 +++++++++++ .../abilities/keyword/UndauntedAbility.java | 53 +---------- 4 files changed, 149 insertions(+), 51 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/a/AvatarOfGrowth.java create mode 100644 Mage/src/main/java/mage/abilities/effects/common/cost/SpellCostReductionSourceForOpponentsEffect.java diff --git a/Mage.Sets/src/mage/cards/a/AvatarOfGrowth.java b/Mage.Sets/src/mage/cards/a/AvatarOfGrowth.java new file mode 100644 index 0000000000..41cb467003 --- /dev/null +++ b/Mage.Sets/src/mage/cards/a/AvatarOfGrowth.java @@ -0,0 +1,93 @@ +package mage.cards.a; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.cost.SpellCostReductionSourceForOpponentsEffect; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; + +import java.util.UUID; + +/** + * @author JayDi85 + */ +public final class AvatarOfGrowth extends CardImpl { + + public AvatarOfGrowth(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{G}{G}"); + this.subtype.add(SubType.ELEMENTAL); + this.subtype.add(SubType.AVATAR); + + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // This spell costs {1} less to cast for each opponent you have. + this.addAbility(new SimpleStaticAbility(Zone.ALL, new SpellCostReductionSourceForOpponentsEffect("This spell costs {1} less to cast for each opponent you have"))); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // When Avatar of Growth enters the battlefield, each player searches their library for up to two basic land cards, puts them onto the battlefield, then shuffles their library. + this.addAbility(new EntersBattlefieldTriggeredAbility(new AvatarOfGrowthSearchEffect())); + } + + public AvatarOfGrowth(final AvatarOfGrowth card) { + super(card); + } + + @Override + public AvatarOfGrowth copy() { + return new AvatarOfGrowth(this); + } +} + +class AvatarOfGrowthSearchEffect extends OneShotEffect { + + public AvatarOfGrowthSearchEffect() { + super(Outcome.Detriment); + this.staticText = "each player searches their library for up to two basic land cards, puts them onto the battlefield, then shuffles their libarary"; + } + + public AvatarOfGrowthSearchEffect(final AvatarOfGrowthSearchEffect effect) { + super(effect); + } + + @Override + public AvatarOfGrowthSearchEffect copy() { + return new AvatarOfGrowthSearchEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND); + if (player.searchLibrary(target, game)) { + if (!target.getTargets().isEmpty()) { + player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game); + } + } + player.shuffleLibrary(source, game); + } + } + return true; + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/GameNight.java b/Mage.Sets/src/mage/sets/GameNight.java index 076c056be1..3669229792 100644 --- a/Mage.Sets/src/mage/sets/GameNight.java +++ b/Mage.Sets/src/mage/sets/GameNight.java @@ -24,7 +24,7 @@ public final class GameNight extends ExpansionSet { cards.add(new SetCardInfo("Aerial Responder", 6, Rarity.UNCOMMON, mage.cards.a.AerialResponder.class)); cards.add(new SetCardInfo("Air Elemental", 19, Rarity.UNCOMMON, mage.cards.a.AirElemental.class)); cards.add(new SetCardInfo("Always Watching", 7, Rarity.RARE, mage.cards.a.AlwaysWatching.class)); - // TODO: cards.add(new SetCardInfo("Avatar of Growth", 5, Rarity.MYTHIC, mage.cards.a.AvatarOfGrowth.class)); + cards.add(new SetCardInfo("Avatar of Growth", 5, Rarity.MYTHIC, mage.cards.a.AvatarOfGrowth.class)); cards.add(new SetCardInfo("Benalish Marshal", 8, Rarity.RARE, mage.cards.b.BenalishMarshal.class)); cards.add(new SetCardInfo("Bombard", 37, Rarity.COMMON, mage.cards.b.Bombard.class)); cards.add(new SetCardInfo("Bone Splinters", 27, Rarity.COMMON, mage.cards.b.BoneSplinters.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/cost/SpellCostReductionSourceForOpponentsEffect.java b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellCostReductionSourceForOpponentsEffect.java new file mode 100644 index 0000000000..4391755fa3 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellCostReductionSourceForOpponentsEffect.java @@ -0,0 +1,52 @@ +package mage.abilities.effects.common.cost; + +import mage.Mana; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.constants.CostModificationType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.game.Game; + +public class SpellCostReductionSourceForOpponentsEffect extends CostModificationEffectImpl { + + public SpellCostReductionSourceForOpponentsEffect() { + this("undaunted (This spell costs {1} less to cast for each opponent.)"); + } + + public SpellCostReductionSourceForOpponentsEffect(String newStaticText) { + super(Duration.Custom, Outcome.Benefit, CostModificationType.REDUCE_COST); + staticText = newStaticText; + } + + public SpellCostReductionSourceForOpponentsEffect(final SpellCostReductionSourceForOpponentsEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source, Ability abilityToModify) { + SpellAbility spellAbility = (SpellAbility) abilityToModify; + Mana mana = spellAbility.getManaCostsToPay().getMana(); + if (mana.getGeneric() > 0) { + int count = game.getOpponents(source.getControllerId()).size(); + int newCount = mana.getGeneric() - count; + if (newCount < 0) { + newCount = 0; + } + mana.setGeneric(newCount); + spellAbility.getManaCostsToPay().load(mana.toString()); + return true; + } + return false; + } + + @Override + public boolean applies(Ability abilityToModify, Ability source, Game game) { + return abilityToModify instanceof SpellAbility && abilityToModify.getSourceId().equals(source.getSourceId()); + } + + @Override + public SpellCostReductionSourceForOpponentsEffect copy() { + return new SpellCostReductionSourceForOpponentsEffect(this); + } +} diff --git a/Mage/src/main/java/mage/abilities/keyword/UndauntedAbility.java b/Mage/src/main/java/mage/abilities/keyword/UndauntedAbility.java index 857d47133b..52061608d3 100644 --- a/Mage/src/main/java/mage/abilities/keyword/UndauntedAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/UndauntedAbility.java @@ -5,25 +5,17 @@ */ package mage.abilities.keyword; -import mage.Mana; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.CostModificationEffectImpl; -import mage.constants.CostModificationType; -import mage.constants.Duration; -import mage.constants.Outcome; +import mage.abilities.effects.common.cost.SpellCostReductionSourceForOpponentsEffect; import mage.constants.Zone; -import mage.game.Game; /** - * * @author LevelX2 */ public class UndauntedAbility extends SimpleStaticAbility { public UndauntedAbility() { - super(Zone.ALL, new UndauntedEffect()); + super(Zone.ALL, new SpellCostReductionSourceForOpponentsEffect("undaunted (This spell costs {1} less to cast for each opponent.)")); setRuleAtTheTop(true); } @@ -36,43 +28,4 @@ public class UndauntedAbility extends SimpleStaticAbility { return new UndauntedAbility(this); } -} - -class UndauntedEffect extends CostModificationEffectImpl { - - public UndauntedEffect() { - super(Duration.Custom, Outcome.Benefit, CostModificationType.REDUCE_COST); - staticText = "undaunted (This spell costs {1} less to cast for each opponent.)"; - } - - public UndauntedEffect(final UndauntedEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - Mana mana = spellAbility.getManaCostsToPay().getMana(); - if (mana.getGeneric() > 0) { - int count = game.getOpponents(source.getControllerId()).size(); - int newCount = mana.getGeneric() - count; - if (newCount < 0) { - newCount = 0; - } - mana.setGeneric(newCount); - spellAbility.getManaCostsToPay().load(mana.toString()); - return true; - } - return false; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - return abilityToModify instanceof SpellAbility && abilityToModify.getSourceId().equals(source.getSourceId()); - } - - @Override - public UndauntedEffect copy() { - return new UndauntedEffect(this); - } -} +} \ No newline at end of file