* Fixed a problem with "put into the graveyard from anywhere triggers" that checked wrongly the state of the source object on the battlefield if went to graveyard itself.

This commit is contained in:
LevelX2 2015-12-24 17:58:04 +01:00
parent d40afd9ef5
commit eb0ae55257
16 changed files with 229 additions and 128 deletions

View file

@ -41,8 +41,6 @@ import mage.cards.Card;
import mage.constants.Zone;
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.game.stack.Spell;
@ -97,9 +95,11 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
boolean controllerSet = false;
if (!ability.getZone().equals(Zone.COMMAND) && event != null
&& event.getTargetId() != null // && event.getTargetId().equals(ability.getSourceId())
&& ((event.getType().equals(EventType.ZONE_CHANGE) && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD))
|| event.getType().equals(EventType.DESTROYED_PERMANENT)
|| event.getType().equals(EventType.SACRIFICED_PERMANENT))
&& ability.isLeavesTheBattlefieldTrigger()
// && ((event.getType().equals(EventType.ZONE_CHANGE)
// && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD))
// || event.getType().equals(EventType.DESTROYED_PERMANENT)
// || event.getType().equals(EventType.SACRIFICED_PERMANENT))
&& game.getLKI().get(Zone.BATTLEFIELD) != null && game.getLKI().get(Zone.BATTLEFIELD).containsKey(ability.getSourceId())) {
// need to check if object was face down for dies and destroy events because the ability triggers in the new zone, zone counter -1 is used
Permanent permanent = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD, ability.getSourceObjectZoneChangeCounter() - 1);

View file

@ -56,6 +56,10 @@ public interface TriggeredAbility extends Ability {
boolean isOptional();
boolean isLeavesTheBattlefieldTrigger();
void setLeavesTheBattlefieldTrigger(boolean leavesTheBattlefieldTrigger);
@Override
TriggeredAbility copy();

View file

@ -45,6 +45,7 @@ import mage.players.Player;
public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility {
protected boolean optional;
protected boolean leavesTheBattlefieldTrigger;
public TriggeredAbilityImpl(Zone zone, Effect effect) {
this(zone, effect, false);
@ -52,6 +53,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
public TriggeredAbilityImpl(Zone zone, Effect effect, boolean optional) {
super(AbilityType.TRIGGERED, zone);
setLeavesTheBattlefieldTrigger(false);
if (effect != null) {
addEffect(effect);
}
@ -61,6 +63,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
public TriggeredAbilityImpl(final TriggeredAbilityImpl ability) {
super(ability);
this.optional = ability.optional;
this.leavesTheBattlefieldTrigger = ability.leavesTheBattlefieldTrigger;
}
@Override
@ -169,18 +172,31 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
* again before the ability resolves.) The most common zone-change
* triggers are enters-the-battlefield triggers and
* leaves-the-battlefield triggers.
*
* from:
* http://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/537065-ixidron-and-kozilek
* There are two types of triggers that involve the graveyard: dies
* triggers (which are a subset of leave-the-battlefield triggers) and
* put into the graveyard from anywhere triggers.
*
* The former triggers trigger based on the game state prior to the move
* where the Kozilek permanent is face down and has no abilities. The
* latter triggers trigger from the game state after the move where the
* Kozilek card is itself and has the ability.
*/
if (event != null && event.getTargetId() != null && event.getTargetId().equals(getSourceId())) {
switch (event.getType()) {
case ZONE_CHANGE:
case DESTROYED_PERMANENT:
if (event.getType().equals(EventType.DESTROYED_PERMANENT)) {
source = game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
} else {
if (((ZoneChangeEvent) event).getTarget() != null) {
source = ((ZoneChangeEvent) event).getTarget();
if (isLeavesTheBattlefieldTrigger()) {
if (event.getType().equals(EventType.DESTROYED_PERMANENT)) {
source = game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
} else {
source = game.getLastKnownInformation(getSourceId(), ((ZoneChangeEvent) event).getZone());
if (((ZoneChangeEvent) event).getTarget() != null) {
source = ((ZoneChangeEvent) event).getTarget();
} else {
source = game.getLastKnownInformation(getSourceId(), ((ZoneChangeEvent) event).getZone());
}
}
}
@ -194,6 +210,23 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return super.isInUseableZone(game, source, event);
}
/*
603.6c,603.6d
*/
@Override
public boolean isLeavesTheBattlefieldTrigger() {
return leavesTheBattlefieldTrigger;
}
/*
603.6c,603.6d
This has to be set, if the triggered ability has to check back in time if the permanent the ability is connected to had the ability on the battlefeild while the trigger is checked
*/
@Override
public final void setLeavesTheBattlefieldTrigger(boolean leavesTheBattlefieldTrigger) {
this.leavesTheBattlefieldTrigger = leavesTheBattlefieldTrigger;
}
@Override
public boolean isOptional() {
return optional;

View file

@ -74,7 +74,7 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent = game.getPermanent(getSourceId());
} else {
if (game.getShortLivingLKI(sourceId, Zone.BATTLEFIELD)) {
if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
}
}
@ -97,7 +97,7 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(zEvent.getTarget(), sourceId, controllerId, game)) {
if (filter.match(zEvent.getTarget(), getSourceId(), getControllerId(), game)) {
return true;
}
}

View file

@ -39,11 +39,11 @@ import mage.game.events.ZoneChangeEvent;
*
* @author LevelX2
*/
public class EntersOrLeavesTheBattlefieldSourceTriggeredAbility extends TriggeredAbilityImpl {
public EntersOrLeavesTheBattlefieldSourceTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
setLeavesTheBattlefieldTrigger(true);
}
public EntersOrLeavesTheBattlefieldSourceTriggeredAbility(final EntersOrLeavesTheBattlefieldSourceTriggeredAbility ability) {
@ -67,7 +67,7 @@ public class EntersOrLeavesTheBattlefieldSourceTriggeredAbility extends Triggere
return true;
}
if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId())) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone().equals(Zone.BATTLEFIELD)) {
return true;
}

View file

@ -19,6 +19,34 @@ public class PutIntoGraveFromAnywhereSourceTriggeredAbility extends ZoneChangeTr
public PutIntoGraveFromAnywhereSourceTriggeredAbility(final PutIntoGraveFromAnywhereSourceTriggeredAbility ability) {
super(ability);
}
//
// /**
// *
// * There are two types of triggers that involve the graveyard: dies triggers
// * (which are a subset of leave-the-battlefield triggers) and put into the
// * graveyard from anywhere triggers.
// *
// * The former triggers trigger based on the game state prior to the move
// * where the Kozilek permanent is face down and has no abilities. The latter
// * triggers trigger from the game state after the move where the Kozilek
// * card is itself and has the ability.
// *
// * The trigger on Kozilek will trigger and he and the graveyard will be
// * shuffled into the library.
// * http://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/537065-ixidron-and-kozilek
// *
// * @param game
// * @param source
// * @param event
// * @return
// */
// @Override
// public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
// if (game.getState().getZone(source.getId()).equals(Zone.GRAVEYARD)) {
// return this.hasSourceObjectAbility(game, source, event);
// }
// return false;
// }
@Override
public PutIntoGraveFromAnywhereSourceTriggeredAbility copy() {

View file

@ -50,8 +50,10 @@ public class PutIntoGraveFromBattlefieldAllTriggeredAbility extends TriggeredAbi
public PutIntoGraveFromBattlefieldAllTriggeredAbility(Effect effect, boolean optional, FilterPermanent filter, boolean setTargetPointer) {
this(effect, optional, filter, setTargetPointer, false);
}
public PutIntoGraveFromBattlefieldAllTriggeredAbility(Effect effect, boolean optional, FilterPermanent filter, boolean setTargetPointer, boolean onlyToControllerGraveyard) {
super(Zone.BATTLEFIELD, effect, optional);
this.setLeavesTheBattlefieldTrigger(true);
this.filter = filter;
this.onlyToControllerGraveyard = onlyToControllerGraveyard;
this.setTargetPointer = setTargetPointer;
@ -75,11 +77,11 @@ public class PutIntoGraveFromBattlefieldAllTriggeredAbility extends TriggeredAbi
if (zEvent.getFromZone() == Zone.BATTLEFIELD
&& zEvent.getToZone() == Zone.GRAVEYARD) {
if (filter.match(zEvent.getTarget(), this.getSourceId(), this.getControllerId(), game)) {
if(onlyToControllerGraveyard && !this.getControllerId().equals(game.getOwnerId(zEvent.getTargetId()))) {
if (onlyToControllerGraveyard && !this.getControllerId().equals(game.getOwnerId(zEvent.getTargetId()))) {
return false;
}
if (setTargetPointer) {
for (Effect effect :this.getEffects()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
@ -91,8 +93,8 @@ public class PutIntoGraveFromBattlefieldAllTriggeredAbility extends TriggeredAbi
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " is put into " + (onlyToControllerGraveyard ? "your":"a") +
" graveyard from the battlefield, " + super.getRule();
return "Whenever " + filter.getMessage() + " is put into " + (onlyToControllerGraveyard ? "your" : "a")
+ " graveyard from the battlefield, " + super.getRule();
}
@Override

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,12 +20,11 @@
* 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 mage.abilities.TriggeredAbilityImpl;
@ -38,8 +37,9 @@ import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
* Is applied when the {@link Permanent} with this ability instance changes zones.
*
* Is applied when the {@link Permanent} with this ability instance changes
* zones.
*
* @author BetaSteward_at_googlemail.com
*/
public class ZoneChangeTriggeredAbility extends TriggeredAbilityImpl {
@ -51,14 +51,17 @@ public class ZoneChangeTriggeredAbility extends TriggeredAbilityImpl {
public ZoneChangeTriggeredAbility(Zone fromZone, Zone toZone, Effect effect, String rule, boolean optional) {
this(toZone == null ? Zone.ALL : toZone, fromZone, toZone, effect, rule, optional);
}
public ZoneChangeTriggeredAbility(Zone worksInZone, Zone fromZone, Zone toZone, Effect effect, String rule, boolean optional) {
super(worksInZone, effect, optional);
if (fromZone.equals(Zone.BATTLEFIELD)) {
setLeavesTheBattlefieldTrigger(true);
}
this.fromZone = fromZone;
this.toZone = toZone;
this.rule = rule;
}
public ZoneChangeTriggeredAbility(Zone toZone, Effect effect, String rule, boolean optional) {
super(toZone, effect, optional);
this.fromZone = null;
@ -81,7 +84,7 @@ public class ZoneChangeTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(this.getSourceId())) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if ((fromZone == null || zEvent.getFromZone() == fromZone) && (toZone == null || zEvent.getToZone() == toZone)) {
return true;
}

View file

@ -1,36 +1,34 @@
/*
* 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.
*/
* 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.counters;
import org.apache.log4j.Logger;
import java.io.Serializable;
import org.apache.log4j.Logger;
/**
* @author BetaSteward_at_googlemail.com
@ -42,9 +40,9 @@ public class Counter implements Serializable {
protected final String name;
protected int count;
/**
* Creates a {@link Counter} with the provided {@code name} and a default value of 1
* Creates a {@link Counter} with the provided {@code name} and a default
* value of 1
*
* @param name the name of this counter.
*/
@ -53,11 +51,11 @@ public class Counter implements Serializable {
this.count = 1;
}
/**
* Creates a {@link Counter} with the provided {@code name} and {@code count}
* Creates a {@link Counter} with the provided {@code name} and
* {@code count}
*
* @param name the name of this counter.
* @param name the name of this counter.
* @param count the value of this counter.
*/
public Counter(final String name, final int count) {
@ -65,7 +63,6 @@ public class Counter implements Serializable {
this.count = count;
}
/**
* Creates a {@link Counter} from an existing {@link Counter} object.
*
@ -92,36 +89,37 @@ public class Counter implements Serializable {
count += amount;
}
/**
* Decreases the {@code count} by one. Will not allow the count to be less than 0.
* If an attempt is made to make the count be less than zero, the call will be logged.
* Decreases the {@code count} by one. Will not allow the count to be less
* than 0. If an attempt is made to make the count be less than zero, the
* call will be logged.
*/
public void decrease() {
if (count > 0) {
count--;
} else {
logger.warn("An attempt was made to set the counter '" + name +
"' to less than 0. Setting to 0.");
logger.warn("An attempt was made to set the counter '" + name
+ "' to less than 0. Setting to 0.");
}
}
/**
* Decreases the {@code count} by tne passed in {@code amount}. Will not allow the count
* to be less than 0. If an attempt is made to make the count be less than zero, the call will be logged.
* Decreases the {@code count} by the passed in {@code amount}. Will not
* allow the count to be less than 0. If an attempt is made to make the
* count be less than zero, the call will be logged.
*
* @param amount
*/
public void remove(int amount) {
if (count >= amount) {
count -= amount;
} else {
logger.warn("An attempt was made to set the counter '" + name +
"' to less than 0. Setting to 0.");
logger.warn("An attempt was made to set the counter '" + name
+ "' to less than 0. Setting to 0.");
count = 0;
}
}
/**
* Returns the name of this {@link Counter}
*
@ -149,20 +147,24 @@ public class Counter implements Serializable {
return new Counter(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Counter counter = (Counter) o;
if (count != counter.count) return false;
if (count != counter.count) {
return false;
}
return !(name != null ? !name.equals(counter.name) : counter.name != null);
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;