Skip to content

Commit

Permalink
Update Thought Gorger and Toothy to use common effects/values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grath committed Dec 18, 2024
1 parent 2f2c7ee commit 1b3d237
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 77 deletions.
38 changes: 6 additions & 32 deletions Mage.Sets/src/mage/cards/t/ThoughtGorger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}

49 changes: 4 additions & 45 deletions Mage.Sets/src/mage/cards/t/ToothyImaginaryFriend.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
*
Expand All @@ -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) {
Expand All @@ -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}";
}
}

0 comments on commit 1b3d237

Please sign in to comment.