* Bioshift - Fixed that always all counters were moved, the remove counter event was not fired and that the two targetes were handled as one target definition.

This commit is contained in:
LevelX2 2015-06-18 13:39:49 +02:00
parent 7ee6e13913
commit ae1f726f56
4 changed files with 164 additions and 73 deletions

View file

@ -40,6 +40,7 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
/**
@ -54,8 +55,10 @@ public class Bioshift extends CardImpl {
// Move any number of +1/+1 counters from target creature onto another target creature with the same controller.
getSpellAbility().addEffect(new MoveCounterFromTargetToTargetEffect());
getSpellAbility().addTarget(new TargetCreaturePermanentSameController(2,2,new FilterCreaturePermanent(),false));
getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature (you take counters from)")));
getSpellAbility().addTarget(new BioshiftSecondTargetPermanent());
}
public Bioshift(final Bioshift card) {
super(card);
@ -67,37 +70,6 @@ public class Bioshift extends CardImpl {
}
}
class TargetCreaturePermanentSameController extends TargetCreaturePermanent {
public TargetCreaturePermanentSameController(int minNumTargets, int maxNumTargets, FilterCreaturePermanent filter, boolean notTarget) {
super(minNumTargets, maxNumTargets, filter, notTarget);
this.targetName = filter.getMessage();
}
public TargetCreaturePermanentSameController(final TargetCreaturePermanentSameController target) {
super(target);
}
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
UUID firstTarget = this.getFirstTarget();
if (firstTarget != null) {
Permanent permanent = game.getPermanent(firstTarget);
Permanent targetPermanent = game.getPermanent(id);
if (permanent == null || targetPermanent == null
|| !permanent.getControllerId().equals(targetPermanent.getOwnerId())) {
return false;
}
}
return super.canTarget(id, source, game);
}
@Override
public TargetCreaturePermanentSameController copy() {
return new TargetCreaturePermanentSameController(this);
}
}
class MoveCounterFromTargetToTargetEffect extends OneShotEffect {
public MoveCounterFromTargetToTargetEffect() {
@ -116,22 +88,56 @@ class MoveCounterFromTargetToTargetEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent fromPermanent = game.getPermanent(targetPointer.getFirst(game, source));
Permanent toPermanent = null;
if (targetPointer.getTargets(game, source).size() > 1) {
toPermanent = game.getPermanent(targetPointer.getTargets(game, source).get(1));
}
if (fromPermanent == null || toPermanent == null || !fromPermanent.getControllerId().equals(toPermanent.getControllerId())) {
return false;
}
int amountCounters = fromPermanent.getCounters().getCount(CounterType.P1P1);
if (amountCounters > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller.getAmount(0, amountCounters, "How many counters do you want to move?", game) > 0){
fromPermanent.getCounters().removeCounter(CounterType.P1P1, amountCounters);
toPermanent.addCounters(CounterType.P1P1.createInstance(amountCounters), game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent fromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
Permanent toPermanent = null;
if (source.getTargets().size() > 1) {
toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
}
if (fromPermanent == null || toPermanent == null || !fromPermanent.getControllerId().equals(toPermanent.getControllerId())) {
return false;
}
int amountCounters = fromPermanent.getCounters().getCount(CounterType.P1P1);
if (amountCounters > 0) {
int amountToMove = controller.getAmount(0, amountCounters, "How many counters do you want to move?", game);
if (amountToMove > 0) {
fromPermanent.removeCounters(CounterType.P1P1.createInstance(amountToMove), game);
toPermanent.addCounters(CounterType.P1P1.createInstance(amountToMove), game);
}
}
return true;
}
return true;
return false;
}
}
class BioshiftSecondTargetPermanent extends TargetPermanent {
BioshiftSecondTargetPermanent() {
super();
this.filter = new FilterCreaturePermanent("another target creature with the same controller (counters go to)");
}
BioshiftSecondTargetPermanent(final BioshiftSecondTargetPermanent target) {
super(target);
}
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
Permanent firstPermanent = game.getPermanent(source.getTargets().getFirstTarget());
Permanent secondPermanent = game.getPermanent(id);
if (firstPermanent != null && secondPermanent != null) {
if (!firstPermanent.getId().equals(id) && firstPermanent.getControllerId().equals(secondPermanent.getControllerId())) {
return super.canTarget(controllerId, id, source, game);
}
}
return false;
}
@Override
public BioshiftSecondTargetPermanent copy() {
return new BioshiftSecondTargetPermanent(this);
}
}

View file

@ -49,6 +49,7 @@ import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import java.util.UUID;
import mage.abilities.effects.PreventionEffectData;
/**
*
@ -121,7 +122,7 @@ public class ProteanHydra extends CardImpl {
class ProteanHydraEffect2 extends PreventionEffectImpl {
public ProteanHydraEffect2() {
super(Duration.WhileOnBattlefield);
super(Duration.WhileOnBattlefield, Integer.MAX_VALUE, false, false);
staticText = "If damage would be dealt to {this}, prevent that damage and remove that many +1/+1 counters from it";
}
@ -141,19 +142,14 @@ public class ProteanHydra extends CardImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
boolean retValue = false;
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false);
int damage = event.getAmount();
if (!game.replaceEvent(preventEvent)) {
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), damage));
retValue = true;
PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
if (preventionEffectData.getPreventedDamage() > 0) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.removeCounters(CounterType.P1P1.createInstance(preventionEffectData.getPreventedDamage()), game);
}
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.removeCounters(CounterType.P1P1.createInstance(damage), game);
}
return retValue;
return false;
}
@Override
@ -183,9 +179,14 @@ public class ProteanHydra extends CardImpl {
return new ProteanHydraAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTER_REMOVED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.COUNTER_REMOVED && event.getData().equals("+1/+1") && event.getTargetId().equals(this.getSourceId())) {
if (event.getData().equals("+1/+1") && event.getTargetId().equals(this.getSourceId())) {
return true;
}
return false;
@ -213,12 +214,14 @@ public class ProteanHydra extends CardImpl {
return new ProteanHydraDelayedTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.END_TURN_STEP_PRE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.END_TURN_STEP_PRE) {
return true;
}
return false;
return true;
}
@Override

View file

@ -111,10 +111,11 @@ class GlamerSpinnersEffect extends OneShotEffect {
5/1/2008 You may target a permanent that has no Auras enchanting it.
5/1/2008 When the ability resolves, you choose the permanent that will be receiving the Auras. It can't be the targeted permanent, it must have the same controller as the targeted permanent, and it must be able to be enchanted by all the Auras attached to the targeted permanent. If you can't choose a permanent that meets all those criteria, the Auras won't move.
*/
Boolean passed = true;
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (targetPermanent != null) {
Permanent sourcePermanent = (Permanent) source.getSourceObject(game);
if (targetPermanent != null && controller != null && sourcePermanent != null) {
Boolean passed = true;
FilterPermanent filterChoice = new FilterPermanent("a different permanent with the same controller as the target to attach the enchantments to");
filterChoice.add(new ControllerIdPredicate(targetPermanent.getControllerId()));
filterChoice.add(Predicates.not(new PermanentIdPredicate(targetPermanent.getId())));
@ -122,11 +123,10 @@ class GlamerSpinnersEffect extends OneShotEffect {
Target chosenPermanentToAttachAuras = new TargetPermanent(filterChoice);
chosenPermanentToAttachAuras.setNotTarget(true);
LinkedList<UUID> auras = new LinkedList();
LinkedList<UUID> auras = new LinkedList<>();
auras.addAll(targetPermanent.getAttachments());
if (controller != null
&& controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) {
if (controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) {
Permanent permanentToAttachAuras = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
if (permanentToAttachAuras != null) {
for (UUID auraId : auras) {
@ -148,7 +148,7 @@ class GlamerSpinnersEffect extends OneShotEffect {
}
}
if (passed) {
LinkedList<UUID> aurasToAttach = new LinkedList();
LinkedList<UUID> aurasToAttach = new LinkedList<>();
aurasToAttach.addAll(auras);
for (UUID auraId : aurasToAttach) {
@ -158,10 +158,12 @@ class GlamerSpinnersEffect extends OneShotEffect {
}
return true;
}
game.informPlayers(sourcePermanent.getLogName() + ": No enchantments were moved from the target permanent.");
}
}
return true;
}
game.informPlayers("Glamer Spinners: No enchantments were moved from the target permanent.");
return false;
}
}