diff --git a/Mage.Sets/src/mage/cards/t/ThoughtGorger.java b/Mage.Sets/src/mage/cards/t/ThoughtGorger.java index dd9aa9f18011..ddb2e2a6bd2a 100644 --- a/Mage.Sets/src/mage/cards/t/ThoughtGorger.java +++ b/Mage.Sets/src/mage/cards/t/ThoughtGorger.java @@ -4,14 +4,15 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; +import mage.abilities.dynamicvalue.common.CountersSourceCount; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; -import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.Permanent; @@ -37,7 +38,10 @@ public ThoughtGorger(UUID ownerId, CardSetInfo setInfo) { this.addAbility(new EntersBattlefieldTriggeredAbility(new ThoughtGorgerEffectEnters())); // When Thought Gorger leaves the battlefield, draw a card for each +1/+1 counter on it. - this.addAbility(new LeavesBattlefieldTriggeredAbility(new ThoughtGorgerEffectLeaves(), false)); + this.addAbility(new LeavesBattlefieldTriggeredAbility( + new DrawCardSourceControllerEffect(new CountersSourceCount(CounterType.P1P1)) + .setText("draw a card for each +1/+1 counter on it"), false + )); } private ThoughtGorger(final ThoughtGorger card) { @@ -83,33 +87,3 @@ public boolean apply(Game game, Ability source) { return true; } } - -class ThoughtGorgerEffectLeaves extends OneShotEffect { - - ThoughtGorgerEffectLeaves() { - super(Outcome.Neutral); - this.staticText = "draw a card for each +1/+1 counter on it."; - } - - private ThoughtGorgerEffectLeaves(final ThoughtGorgerEffectLeaves effect) { - super(effect); - } - - @Override - public ThoughtGorgerEffectLeaves copy() { - return new ThoughtGorgerEffectLeaves(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - Permanent thoughtGorgerLastState = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - int numberCounters = thoughtGorgerLastState.getCounters(game).getCount(CounterType.P1P1); - if (player != null) { - player.drawCards(numberCounters, source, game); - return true; - } - return false; - } -} - diff --git a/Mage.Sets/src/mage/cards/t/ToothyImaginaryFriend.java b/Mage.Sets/src/mage/cards/t/ToothyImaginaryFriend.java index 02a45c84c73e..aa448f995795 100644 --- a/Mage.Sets/src/mage/cards/t/ToothyImaginaryFriend.java +++ b/Mage.Sets/src/mage/cards/t/ToothyImaginaryFriend.java @@ -2,11 +2,9 @@ import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.CountersSourceCount; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.PartnerWithAbility; @@ -15,10 +13,7 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.SuperType; -import mage.constants.Zone; import mage.counters.CounterType; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -42,8 +37,9 @@ public ToothyImaginaryFriend(UUID ownerId, CardSetInfo setInfo) { // When Toothy leaves the battlefield, draw a card for each +1/+1 counter on it. this.addAbility(new LeavesBattlefieldTriggeredAbility( - new DrawCardSourceControllerEffect(new ToothyImaginaryFriendCountersCount(CounterType.P1P1)) - .setText("draw a card for each +1/+1 counter on it"), false)); + new DrawCardSourceControllerEffect(new CountersSourceCount(CounterType.P1P1)) + .setText("draw a card for each +1/+1 counter on it"), false + )); } private ToothyImaginaryFriend(final ToothyImaginaryFriend card) { @@ -55,40 +51,3 @@ public ToothyImaginaryFriend copy() { return new ToothyImaginaryFriend(this); } } - -class ToothyImaginaryFriendCountersCount implements DynamicValue { - - private final String counterName; - - public ToothyImaginaryFriendCountersCount(CounterType counter) { - this.counterName = counter.getName(); - } - - private ToothyImaginaryFriendCountersCount(final ToothyImaginaryFriendCountersCount countersCount) { - this.counterName = countersCount.counterName; - } - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Permanent permanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); - if (permanent != null) { - return permanent.getCounters(game).getCount(counterName); - } - return 0; - } - - @Override - public ToothyImaginaryFriendCountersCount copy() { - return new ToothyImaginaryFriendCountersCount(this); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return counterName + " counter on {this}"; - } -}