Expanded handling of the ENTERS_THE_BATTLEFIELD event to fix issue #82.

This commit is contained in:
LevelX2 2013-02-17 01:13:15 +01:00
parent 58db10296a
commit 50bb73fa08
20 changed files with 328 additions and 94 deletions

View file

@ -34,7 +34,6 @@ import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
@ -53,12 +52,10 @@ public class AllyEntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.ZONE_CHANGE) {
if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId);
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getToZone() == Zone.BATTLEFIELD
&& permanent.getControllerId().equals(this.controllerId)
if (permanent.getControllerId().equals(this.controllerId)
&& (targetId.equals(this.getSourceId())
|| (permanent.hasSubtype("Ally") && !targetId.equals(this.getSourceId())))) {
return true;

View file

@ -5,7 +5,7 @@ import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
public class AnotherCreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl<AnotherCreatureEntersBattlefieldTriggeredAbility> {
@ -23,11 +23,9 @@ public class AnotherCreatureEntersBattlefieldTriggeredAbility extends TriggeredA
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getToZone() == Constants.Zone.BATTLEFIELD
&& zEvent.getTarget().getCardType().contains(Constants.CardType.CREATURE)
&& zEvent.getTargetId() != this.getSourceId()) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && event.getTargetId() != this.getSourceId()) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.getCardType().contains(Constants.CardType.CREATURE)) {
return true;
}
}

View file

@ -34,7 +34,6 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.TargetPlayer;
@ -77,7 +76,7 @@ public class CreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityI
*/
public CreatureEntersBattlefieldTriggeredAbility(Effect effect, boolean optional, boolean opponentController) {
this(Zone.BATTLEFIELD, effect, optional, opponentController);
this.opponentController = opponentController;
}
/**
@ -88,7 +87,6 @@ public class CreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityI
*/
public CreatureEntersBattlefieldTriggeredAbility(Zone zone, Effect effect, boolean optional, boolean opponentController) {
this(zone, effect, null, optional, opponentController);
}
/**
@ -115,10 +113,9 @@ public class CreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityI
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.ZONE_CHANGE) {
if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD
&& filter.match(permanent, sourceId, controllerId, game)
if (filter.match(permanent, sourceId, controllerId, game)
&& (permanent.getControllerId().equals(this.controllerId) ^ opponentController)) {
if (!this.getTargets().isEmpty()) {
Target target = this.getTargets().get(0);

View file

@ -56,13 +56,10 @@ public class EntersAnotherCreatureYourControlTriggeredAbility extends ZoneChange
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && !event.getTargetId().equals(this.getSourceId())) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getToZone() == Constants.Zone.BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE) && permanent.getControllerId().equals(this.getControllerId())) {
return true;
}
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && !event.getTargetId().equals(this.getSourceId())) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE) && permanent.getControllerId().equals(this.getControllerId())) {
return true;
}
}
return false;

View file

@ -28,27 +28,93 @@
package mage.abilities.common;
import java.util.UUID;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class EntersBattlefieldAllTriggeredAbility extends ZoneChangeAllTriggeredAbility<EntersBattlefieldAllTriggeredAbility> {
public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
protected FilterPermanent filter;
protected String rule;
protected boolean controlled;
/**
* zone = BATTLEFIELD
* optional = false
*
* @param effect
* @param filter
*/
public EntersBattlefieldAllTriggeredAbility(Effect effect, FilterPermanent filter) {
this(Zone.BATTLEFIELD, effect, filter, false);
}
public EntersBattlefieldAllTriggeredAbility(Effect effect, FilterPermanent filter, String rule) {
this(Zone.BATTLEFIELD, effect, filter, false, rule);
}
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional) {
super(zone, Zone.BATTLEFIELD, effect, filter, "Whenever " + filter.getMessage() + " enters the battlefield, ", optional);
this(zone, effect, filter, optional, null);
this.filter = filter;
}
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) {
this(zone, effect, filter, optional, rule, false);
}
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule, boolean controlled) {
super(Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
this.rule = rule;
this.controlled = controlled;
}
public EntersBattlefieldAllTriggeredAbility(EntersBattlefieldAllTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
this.rule = ability.rule;
this.controlled = ability.controlled;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId);
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
return true;
}
}
return false;
}
@Override
public String getRule() {
if (rule != null && !rule.isEmpty()) {
return rule;
}
StringBuilder sb = new StringBuilder("Whenever ").append(filter.getMessage());
sb.append(" enters the battlefield");
if (controlled) {
sb.append("under your control,");
} else {
sb.append(",");
}
sb.append(super.getRule());
return sb.toString();
}
@Override
public EntersBattlefieldAllTriggeredAbility copy() {
return new EntersBattlefieldAllTriggeredAbility(this);
}
}

View file

@ -0,0 +1,92 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import java.util.UUID;
import mage.Constants.Zone;
import mage.abilities.effects.Effect;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class EntersBattlefieldControlledTriggeredAbility extends EntersBattlefieldAllTriggeredAbility {
/**
* zone = BATTLEFIELD
* optional = false
* rule = null
*
* @param effect
* @param filter
*/
public EntersBattlefieldControlledTriggeredAbility(Effect effect, FilterPermanent filter) {
this(Zone.BATTLEFIELD, effect, filter, false);
}
public EntersBattlefieldControlledTriggeredAbility(Effect effect, FilterPermanent filter, String rule) {
this(Zone.BATTLEFIELD, effect, filter, false, rule);
}
public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional) {
this(zone, effect, filter, optional, null);
this.filter = filter;
}
public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) {
super(zone, effect, filter, optional, rule, true);
}
public EntersBattlefieldControlledTriggeredAbility(EntersBattlefieldControlledTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId);
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
return true;
}
}
return false;
}
@Override
public EntersBattlefieldControlledTriggeredAbility copy() {
return new EntersBattlefieldControlledTriggeredAbility(this);
}
}

View file

@ -29,30 +29,45 @@
package mage.abilities.common;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class EntersBattlefieldTriggeredAbility extends ZoneChangeTriggeredAbility<EntersBattlefieldTriggeredAbility> {
public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
public EntersBattlefieldTriggeredAbility(Effect effect) {
this(effect, false);
}
public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, "When {this} enters the battlefield, ", optional);
super(Zone.BATTLEFIELD, effect, optional);
}
public EntersBattlefieldTriggeredAbility(EntersBattlefieldTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
&& event.getTargetId().equals(getSourceId())) {
return true;
}
return false;
}
@Override
public String getRule() {
return "When {this} enters the battlefield, " + super.getRule();
}
@Override
public EntersBattlefieldTriggeredAbility copy() {
return new EntersBattlefieldTriggeredAbility(this);
}
}

View file

@ -58,7 +58,7 @@ public class LandfallAbility extends TriggeredAbilityImpl<LandfallAbility> {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.BATTLEFIELD) {
if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) {
return true;

View file

@ -119,7 +119,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl<AuraReplacement
game.getBattlefield().addPermanent(permanent);
game.setZone(card.getId(), Zone.BATTLEFIELD);
game.applyEffects();
permanent.entersBattlefield(event.getSourceId(), game);
permanent.entersBattlefield(event.getSourceId(), game, fromZone, true);
game.applyEffects();
game.fireEvent(new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD));

View file

@ -60,22 +60,22 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
for (UUID id : targetPointer.getTargets(game, source)) {
switch (game.getState().getZone(id)) {
for (UUID targetId : targetPointer.getTargets(game, source)) {
switch (game.getState().getZone(targetId)) {
case BATTLEFIELD:
Permanent permanent = game.getPermanent(id);
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
result |= permanent.moveToZone(Zone.HAND, source.getId(), game, false);
}
break;
case GRAVEYARD:
Card card = game.getCard(id);
Card card = game.getCard(targetId);
if (card != null) {
result |= card.moveToZone(Zone.HAND, source.getId(), game, true);
}
break;
case EXILED:
card = game.getCard(id);
card = game.getCard(targetId);
if (card != null) {
result |= card.moveToZone(Zone.HAND, source.getId(), game, true);
}

View file

@ -72,10 +72,9 @@ public class EchoAbility extends TriggeredAbilityImpl<EchoAbility> {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
if(zEvent.getToZone() != null && zEvent.getToZone() == Constants.Zone.BATTLEFIELD &&
zEvent.getFromZone() == null && this.echoPaid) {
if(zEvent.getFromZone() == null && this.echoPaid) {
this.echoPaid = false;
}
}

View file

@ -69,10 +69,9 @@ public class EvolveAbility extends TriggeredAbilityImpl<EvolveAbility> {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent triggeringCreature = game.getPermanent(event.getTargetId());
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD
&& triggeringCreature != null
if (triggeringCreature != null
&& triggeringCreature.getCardType().contains(CardType.CREATURE)
&& triggeringCreature.getControllerId().equals(this.controllerId)) {
Permanent sourceCreature = game.getPermanent(sourceId);

View file

@ -318,7 +318,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
game.addPermanent(permanent);
game.setZone(objectId, Zone.BATTLEFIELD);
game.applyEffects();
permanent.entersBattlefield(sourceId, game);
permanent.entersBattlefield(sourceId, game, event.getFromZone(), true);
game.applyEffects();
if (flag) {
permanent.setTapped(true);
@ -444,7 +444,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
game.addPermanent(permanent);
game.setZone(objectId, Zone.BATTLEFIELD);
//game.applyEffects(); // magenoxx: this causes bugs
permanent.entersBattlefield(sourceId, game);
permanent.entersBattlefield(sourceId, game, event.getFromZone(), true);
game.applyEffects();
game.fireEvent(new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD));
return true;

View file

@ -1614,7 +1614,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
card.setOwnerId(ownerId);
PermanentCard permanent = new PermanentCard(card.getCard(), ownerId);
getBattlefield().addPermanent(permanent);
permanent.entersBattlefield(permanent.getId(), this);
permanent.entersBattlefield(permanent.getId(), this, Zone.OUTSIDE, false);
((PermanentImpl)permanent).removeSummoningSickness();
if (card.isTapped()) {
permanent.setTapped(true);

View file

@ -0,0 +1,71 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.events;
import java.util.ArrayList;
import java.util.UUID;
import mage.Constants.Zone;
import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class EntersTheBattlefieldEvent extends GameEvent {
private Zone fromZone;
private Permanent target;
public EntersTheBattlefieldEvent(Permanent target, UUID sourceId, UUID playerId, Zone fromZone) {
super(EventType.ENTERS_THE_BATTLEFIELD, target.getId(), sourceId, playerId);
this.fromZone = fromZone;
this.target = target;
}
public EntersTheBattlefieldEvent(Permanent target, UUID sourceId, UUID playerId, Zone fromZone, ArrayList<UUID> appliedEffects) {
super(EventType.ENTERS_THE_BATTLEFIELD, target.getId(), sourceId, playerId);
this.fromZone = fromZone;
if (appliedEffects != null) {
this.appliedEffects = appliedEffects;
}
}
public Zone getFromZone() {
return fromZone;
}
public Permanent getTarget() {
return target;
}
public void setTarget(Permanent target) {
this.target = target;
}
}

View file

@ -32,13 +32,12 @@ import java.util.ArrayList;
import mage.MageObject;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.Controllable;
import mage.game.Game;
import java.util.List;
import java.util.UUID;
import mage.Constants.Zone;
public interface Permanent extends Card, Controllable {
@ -107,7 +106,7 @@ public interface Permanent extends Card, Controllable {
boolean destroy(UUID sourceId, Game game, boolean noRegen);
boolean sacrifice(UUID sourceId, Game game);
boolean regenerate(UUID sourceId, Game game);
void entersBattlefield(UUID sourceId, Game game);
void entersBattlefield(UUID sourceId, Game game, Zone fromZone, boolean fireEvent);
String getValue();
@Deprecated

View file

@ -61,6 +61,7 @@ import mage.game.events.DamageCreatureEvent;
import mage.game.events.DamagePlaneswalkerEvent;
import mage.game.events.DamagedCreatureEvent;
import mage.game.events.DamagedPlaneswalkerEvent;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.players.Player;
@ -733,10 +734,16 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
markedDamage.add(counter);
}
@Override
public void entersBattlefield(UUID sourceId, Game game) {
public void entersBattlefield(UUID sourceId, Game game, Zone fromZone, boolean fireEvent) {
controlledFromStartOfControllerTurn = false;
game.replaceEvent(GameEvent.getEvent(EventType.ENTERS_THE_BATTLEFIELD, objectId, sourceId, controllerId));
EntersTheBattlefieldEvent event = new EntersTheBattlefieldEvent(this, sourceId, getControllerId(), fromZone);
if (!game.replaceEvent(event)) {
if (fireEvent) {
game.fireEvent(event);
}
}
}
@Override

View file

@ -117,7 +117,7 @@ public class Token extends MageObjectImpl<Token> {
game.getState().addCard(permanent);
game.addPermanent(permanent);
this.lastAddedTokenId = permanent.getId();
permanent.entersBattlefield(sourceId, game);
permanent.entersBattlefield(sourceId, game, Zone.OUTSIDE, true);
game.applyEffects();
game.fireEvent(new ZoneChangeEvent(permanent, controllerId, Zone.OUTSIDE, Zone.BATTLEFIELD));
}

View file

@ -3,7 +3,6 @@ package mage.watchers.common;
import mage.Constants;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.watchers.WatcherImpl;
@ -28,9 +27,10 @@ public class LandfallWatcher extends WatcherImpl<LandfallWatcher> {
@Override
public void watch(GameEvent event, Game game) {
if (condition == true) //no need to check - condition has already occured
if (condition == true) { //no need to check - condition has already occured
return;
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Constants.Zone.BATTLEFIELD) {
}
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.getCardType().contains(Constants.CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) {
condition = true;

View file

@ -69,51 +69,48 @@ public class SoulbondWatcher extends WatcherImpl<SoulbondWatcher> {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getToZone() == Constants.Zone.BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE)) {
if (permanent.getAbilities().contains(SoulbondAbility.getInstance())) {
Player controller = game.getPlayer(permanent.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(Constants.Zone.PICK);
cards.add(permanent);
controller.lookAtCards("Soulbond", cards, game);
if (controller.chooseUse(Constants.Outcome.Benefit, "Use Soulbond?", game)) {
TargetControlledPermanent target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(permanent.getId(), controller.getId(), game)) {
if (controller.choose(Constants.Outcome.Benefit, target, permanent.getId(), game)) {
Permanent chosen = game.getPermanent(target.getFirstTarget());
if (chosen != null) {
chosen.setPairedCard(permanent.getId());
permanent.setPairedCard(chosen.getId());
}
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE)) {
if (permanent.getAbilities().contains(SoulbondAbility.getInstance())) {
Player controller = game.getPlayer(permanent.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(Constants.Zone.PICK);
cards.add(permanent);
controller.lookAtCards("Soulbond", cards, game);
if (controller.chooseUse(Constants.Outcome.Benefit, "Use Soulbond?", game)) {
TargetControlledPermanent target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(permanent.getId(), controller.getId(), game)) {
if (controller.choose(Constants.Outcome.Benefit, target, permanent.getId(), game)) {
Permanent chosen = game.getPermanent(target.getFirstTarget());
if (chosen != null) {
chosen.setPairedCard(permanent.getId());
permanent.setPairedCard(chosen.getId());
}
}
}
}
}
}
// if still unpaired
if (permanent.getPairedCard() == null) {
// try to find creature with Soulbond and unpaired
Player controller = null;
for (Permanent chosen : game.getBattlefield().getActivePermanents(filter, permanent.getControllerId(), permanent.getId(), game)) {
if (!chosen.getId().equals(permanent.getId()) && chosen.getAbilities().contains(SoulbondAbility.getInstance()) && chosen.getPairedCard() == null) {
if (controller == null) {
controller = game.getPlayer(permanent.getControllerId());
}
if (controller != null) {
Cards cards = new CardsImpl(Constants.Zone.PICK);
cards.add(chosen);
controller.lookAtCards("Soulbond", cards, game);
if (controller.chooseUse(Constants.Outcome.Benefit, "Use Soulbond for recent " + permanent.getName() + "?", game)) {
chosen.setPairedCard(permanent.getId());
permanent.setPairedCard(chosen.getId());
break;
}
// if still unpaired
if (permanent.getPairedCard() == null) {
// try to find creature with Soulbond and unpaired
Player controller = null;
for (Permanent chosen : game.getBattlefield().getActivePermanents(filter, permanent.getControllerId(), permanent.getId(), game)) {
if (!chosen.getId().equals(permanent.getId()) && chosen.getAbilities().contains(SoulbondAbility.getInstance()) && chosen.getPairedCard() == null) {
if (controller == null) {
controller = game.getPlayer(permanent.getControllerId());
}
if (controller != null) {
Cards cards = new CardsImpl(Constants.Zone.PICK);
cards.add(chosen);
controller.lookAtCards("Soulbond", cards, game);
if (controller.chooseUse(Constants.Outcome.Benefit, "Use Soulbond for recent " + permanent.getName() + "?", game)) {
chosen.setPairedCard(permanent.getId());
permanent.setPairedCard(chosen.getId());
break;
}
}
}