From 6a7253d22fb87fc0601c215ed2a9791ad84abc55 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 5 Feb 2019 23:12:42 +0400 Subject: [PATCH] Added delirium hint as enum --- .../src/mage/cards/i/IshkanahGrafwidow.java | 12 ++--- .../condition/common/DeliriumCondition.java | 18 +------ .../common/CardTypesInGraveyardCount.java | 47 +++++++++++++++++++ .../mage/abilities/hint/DeliriumHint.java | 25 ++++++++++ 4 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/CardTypesInGraveyardCount.java create mode 100644 Mage/src/main/java/mage/abilities/hint/DeliriumHint.java diff --git a/Mage.Sets/src/mage/cards/i/IshkanahGrafwidow.java b/Mage.Sets/src/mage/cards/i/IshkanahGrafwidow.java index c130b759ab..a58da28f30 100644 --- a/Mage.Sets/src/mage/cards/i/IshkanahGrafwidow.java +++ b/Mage.Sets/src/mage/cards/i/IshkanahGrafwidow.java @@ -1,7 +1,5 @@ - package mage.cards.i; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; @@ -12,6 +10,7 @@ import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.abilities.hint.DeliriumHint; import mage.abilities.keyword.ReachAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -24,8 +23,9 @@ import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.permanent.token.SpiderToken; import mage.target.common.TargetOpponent; +import java.util.UUID; + /** - * * @author fireshoes */ public final class IshkanahGrafwidow extends CardImpl { @@ -37,7 +37,7 @@ public final class IshkanahGrafwidow extends CardImpl { } public IshkanahGrafwidow(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{G}"); addSuperType(SuperType.LEGENDARY); this.subtype.add(SubType.SPIDER); this.power = new MageInt(3); @@ -52,8 +52,8 @@ public final class IshkanahGrafwidow extends CardImpl { new EntersBattlefieldTriggeredAbility(new CreateTokenEffect(new SpiderToken(), 3), false), DeliriumCondition.instance, "Delirium — When {this} enters the battlefield, if there are four or more card types among cards in your graveyard, " - + "create three 1/2 green Spider creature tokens with reach."); - this.addAbility(ability); + + "create three 1/2 green Spider creature tokens with reach."); + this.addAbility(ability.addHint(DeliriumHint.instance)); // {5}{B}: Target opponent loses 1 life for each Spider you control. PermanentsOnBattlefieldCount count = new PermanentsOnBattlefieldCount(filter); diff --git a/Mage/src/main/java/mage/abilities/condition/common/DeliriumCondition.java b/Mage/src/main/java/mage/abilities/condition/common/DeliriumCondition.java index 3d05017d79..370a2a3020 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/DeliriumCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/DeliriumCondition.java @@ -1,17 +1,11 @@ - package mage.abilities.condition.common; -import java.util.EnumSet; import mage.abilities.Ability; import mage.abilities.condition.Condition; -import mage.cards.Card; -import mage.constants.CardType; +import mage.abilities.dynamicvalue.common.CardTypesInGraveyardCount; import mage.game.Game; -import mage.players.Player; /** - * - * * @author fireshoes */ public enum DeliriumCondition implements Condition { @@ -20,15 +14,7 @@ public enum DeliriumCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - EnumSet foundCardTypes = EnumSet.noneOf(CardType.class); - for (Card card : controller.getGraveyard().getCards(game)) { - foundCardTypes.addAll(card.getCardType()); - } - return foundCardTypes.size() >= 4; - } - return false; + return CardTypesInGraveyardCount.instance.calculate(game, source, null) >= 4; } @Override diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardTypesInGraveyardCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardTypesInGraveyardCount.java new file mode 100644 index 0000000000..32b2d55318 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardTypesInGraveyardCount.java @@ -0,0 +1,47 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.cards.Card; +import mage.constants.CardType; +import mage.game.Game; +import mage.players.Player; + +import java.util.EnumSet; + +/** + * @author JayDi85 + */ +public enum CardTypesInGraveyardCount implements DynamicValue { + + instance; + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + Player controller = game.getPlayer(sourceAbility.getControllerId()); + if (controller != null) { + EnumSet foundCardTypes = EnumSet.noneOf(CardType.class); + for (Card card : controller.getGraveyard().getCards(game)) { + foundCardTypes.addAll(card.getCardType()); + } + return foundCardTypes.size(); + } + return 0; + } + + @Override + public CardTypesInGraveyardCount copy() { + return instance; + } + + @Override + public String toString() { + return "1"; + } + + @Override + public String getMessage() { + return "the number of opponents you attacked this turn"; + } +} diff --git a/Mage/src/main/java/mage/abilities/hint/DeliriumHint.java b/Mage/src/main/java/mage/abilities/hint/DeliriumHint.java new file mode 100644 index 0000000000..f756b1938a --- /dev/null +++ b/Mage/src/main/java/mage/abilities/hint/DeliriumHint.java @@ -0,0 +1,25 @@ +package mage.abilities.hint; + +import mage.abilities.Ability; +import mage.abilities.condition.common.DeliriumCondition; +import mage.abilities.dynamicvalue.common.CardTypesInGraveyardCount; +import mage.game.Game; + +/** + * @author JayDi85 + */ +public enum DeliriumHint implements Hint { + + instance; + private static final ConditionHint hint = new ConditionHint(DeliriumCondition.instance, "4+ card types in the graveyard"); + + @Override + public String getText(Game game, Ability ability) { + return hint.getText(game, ability) + " (current: " + CardTypesInGraveyardCount.instance.calculate(game, ability, null) + ")"; + } + + @Override + public Hint copy() { + return instance; + } +}