1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-03 09:18:59 -09:00

Cleaned up ReturnToHandChosenControllesPermanentEffect.

This commit is contained in:
LevelX2 2015-06-07 01:07:49 +02:00
parent 76a7aeb957
commit f2cf08d5b2
3 changed files with 14 additions and 34 deletions
Mage.Sets/src/mage/sets/planarchaos
Mage/src/mage/abilities/effects/common

View file

@ -29,7 +29,6 @@ package mage.sets.planarchaos;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.ReturnToHandChosenControlledPermanentEffect;
import mage.abilities.keyword.FlashAbility;
@ -38,12 +37,7 @@ import mage.abilities.keyword.FearAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
/**
*
@ -65,8 +59,9 @@ public class DustElemental extends CardImpl {
// Flying; fear
this.addAbility(FlyingAbility.getInstance());
this.addAbility(FearAbility.getInstance());
// When Dust Elemental enters the battlefield, return three creatures you control to their owner's hand.
this.addAbility(new EntersBattlefieldTriggeredAbility(new ReturnToHandChosenControlledPermanentEffect(filter,1,3)));
this.addAbility(new EntersBattlefieldTriggeredAbility(new ReturnToHandChosenControlledPermanentEffect(filter, 3)));
}
public DustElemental(final DustElemental card) {

View file

@ -68,7 +68,7 @@ public class StormfrontRiders extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// When Stormfront Riders enters the battlefield, return two creatures you control to their owner's hand.
this.addAbility(new EntersBattlefieldTriggeredAbility(new ReturnToHandChosenControlledPermanentEffect(new FilterControlledCreaturePermanent("creatures you control"),1,2)));
this.addAbility(new EntersBattlefieldTriggeredAbility(new ReturnToHandChosenControlledPermanentEffect(new FilterControlledCreaturePermanent("creatures you control"), 2)));
// Whenever Stormfront Riders or another creature is returned to your hand from the battlefield, put a 1/1 white Soldier creature token onto the battlefield.
this.addAbility(new ZoneChangeAllTriggeredAbility(Zone.BATTLEFIELD, Zone.BATTLEFIELD, Zone.HAND, new CreateTokenEffect(new SoldierToken()),
filter,"Whenever {this} or another creature is returned to your hand from the battlefield, ", false));

View file

@ -27,14 +27,13 @@
*/
package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;
@ -44,27 +43,18 @@ import mage.util.CardUtil;
* @author Plopmans
*/
public class ReturnToHandChosenControlledPermanentEffect extends OneShotEffect {
private final FilterControlledPermanent filter;
private int number;
private int minNumber;
public ReturnToHandChosenControlledPermanentEffect(FilterControlledPermanent filter) {
this(filter, 1);
}
public ReturnToHandChosenControlledPermanentEffect(FilterControlledPermanent filter, int number) {
super(Outcome.ReturnToHand);
this.filter = filter;
this.number = number;
this.minNumber = number;
this.staticText = getText();
}
public ReturnToHandChosenControlledPermanentEffect(FilterControlledPermanent filter, int minNumber, int maxNumber) {
super(Outcome.ReturnToHand);
this.filter = filter;
this.number = maxNumber;
this.minNumber = minNumber;
this.staticText = getText();
}
@ -72,10 +62,7 @@ public class ReturnToHandChosenControlledPermanentEffect extends OneShotEffect {
super(effect);
this.filter = effect.filter;
this.number = effect.number;
this.minNumber = this.minNumber;
}
@Override
public ReturnToHandChosenControlledPermanentEffect copy() {
@ -84,15 +71,13 @@ public class ReturnToHandChosenControlledPermanentEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetControlledPermanent target = new TargetControlledPermanent(minNumber, number, filter, true);
if (player.choose(this.outcome, target, source.getSourceId(), game)) {
for (UUID targetCreatureId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetCreatureId);
if (permanent != null) {
player.moveCardToHandWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD);
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int available = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
if (available > 0) {
TargetControlledPermanent target = new TargetControlledPermanent(Math.min(number, available), number, filter, true);
if (controller.chooseTarget(this.outcome, target, source, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, Zone.HAND, source, game);
}
}
return true;