magarena/release/Magarena/scripts/Woodland_Sleuth.groovy

28 lines
1.3 KiB
Groovy

[
new MagicWhenComesIntoPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicPayedCost payedCost) {
return (game.getCreatureDiedThisTurn()) ?
new MagicEvent(
permanent,
this,
"Return a creature card at random from your graveyard to your hand."
) :
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
final MagicPlayer player = event.getPlayer();
final List<MagicCard> targets = game.filterCards(player,MagicTargetFilter.TARGET_CREATURE_CARD_FROM_GRAVEYARD);
if (targets.size() > 0) {
final MagicPermanent permanent = event.getPermanent();
final MagicRandom rng = new MagicRandom(player.getGraveyard().getStateId());
final int index = rng.nextInt(targets.size());
final MagicCard card = targets.get(index);
game.doAction(new MagicRemoveCardAction(card,MagicLocationType.Graveyard));
game.doAction(new MagicMoveCardAction(card,MagicLocationType.Graveyard,MagicLocationType.OwnersHand));
}
}
}
]