This commit is contained in:
jeffwadsworth 2020-06-29 15:07:47 -05:00
parent b01a1ac3aa
commit fa5cf8b412

View file

@ -1,11 +1,11 @@
package mage.cards.l;
import java.util.HashMap;
import java.util.Map;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesSourceTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -14,7 +14,6 @@ import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.token.SquirrelToken;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
import mage.util.ManaUtil;
import java.util.UUID;
@ -32,7 +31,8 @@ public final class LiegeOfTheHollows extends CardImpl {
this.toughness = new MageInt(4);
// When Liege of the Hollows dies, each player may pay any amount of mana.
// Then each player creates a number of 1/1 green Squirrel creature tokens equal to the amount of mana they paid this way.
// Then each player creates a number of 1/1 green Squirrel creature tokens
// equal to the amount of mana they paid this way.
this.addAbility(new DiesSourceTriggeredAbility(new LiegeOfTheHollowsEffect()));
}
@ -66,18 +66,25 @@ class LiegeOfTheHollowsEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Map<UUID, Integer> paidMana = new HashMap<>();
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int numSquirrels = ManaUtil.playerPaysXGenericMana(false, "Liege of the Hollows", player, source, game);
if (numSquirrels > 0) {
Effect effect = new CreateTokenTargetEffect(new SquirrelToken(), numSquirrels);
effect.setTargetPointer(new FixedTarget(playerId));
effect.apply(game, source);
paidMana.put(player.getId(), ManaUtil.playerPaysXGenericMana(false,
"Liege of the Hollows", player, source, game));
}
}
// create tokens
SquirrelToken token = new SquirrelToken();
for (Map.Entry<UUID, Integer> entry
: paidMana.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
token.putOntoBattlefield(entry.getValue(), game, source.getSourceId(), player.getId());
}
}
game.getState().processAction(game);
// prevent undo
controller.resetStoredBookmark(game);