Fixed that creatures or enchantments with triggered abilities that should trigger only once as they or the enhcanted creature blocks (also multiple creatures e.g. Guardian of the Gateless) really only trigger once. They triggered wrongly per blocked creature before.

This commit is contained in:
LevelX2 2014-03-21 14:47:17 +01:00
parent ccd91f0657
commit 63b8890287
15 changed files with 244 additions and 60 deletions

View file

@ -1,6 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* 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;
@ -10,37 +33,21 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author garnold
*/
public class BlocksAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksAttachedTriggeredAbility>{
private boolean setFixedTargetPointer;
private String attachedDescription;
private boolean setFixedTargetPointerToBlocked;
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) {
this(effect, attachedDescription, optional, false);
}
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
}
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean setFixedTargetPointerToBlocked) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
this.setFixedTargetPointerToBlocked = setFixedTargetPointerToBlocked;
}
public BlocksAttachedTriggeredAbility(final BlocksAttachedTriggeredAbility ability) {
super(ability);
this.setFixedTargetPointer = ability.setFixedTargetPointer;
this.attachedDescription = ability.attachedDescription;
}
@ -51,19 +58,9 @@ public class BlocksAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksA
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
Permanent p = game.getPermanent(event.getSourceId());
if (p != null && p.getAttachments().contains(this.getSourceId())) {
if (setFixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
}
if (setFixedTargetPointerToBlocked) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
if (event.getType() == GameEvent.EventType.DECLARED_BLOCKERS) {
Permanent attachment = game.getPermanent(this.getSourceId());
if (attachment != null && attachment.getAttachedTo() != null && game.getCombat().getBlockers().contains(attachment.getAttachedTo())) {
return true;
}
}

View file

@ -0,0 +1,102 @@
/*
* 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 mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class BlocksCreatureAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksCreatureAttachedTriggeredAbility>{
private boolean setFixedTargetPointer;
private String attachedDescription;
private boolean setFixedTargetPointerToBlocked;
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) {
this(effect, attachedDescription, optional, false);
}
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
}
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean setFixedTargetPointerToBlocked) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
this.setFixedTargetPointerToBlocked = setFixedTargetPointerToBlocked;
}
public BlocksCreatureAttachedTriggeredAbility(final BlocksCreatureAttachedTriggeredAbility ability) {
super(ability);
this.setFixedTargetPointer = ability.setFixedTargetPointer;
this.attachedDescription = ability.attachedDescription;
}
@Override
public BlocksCreatureAttachedTriggeredAbility copy() {
return new BlocksCreatureAttachedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
Permanent p = game.getPermanent(event.getSourceId());
if (p != null && p.getAttachments().contains(this.getSourceId())) {
if (setFixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
}
if (setFixedTargetPointerToBlocked) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever " + attachedDescription + " creature blocks a creature, " + super.getRule();
}
}

View file

@ -0,0 +1,82 @@
/*
* 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 mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class BlocksCreatureTriggeredAbility extends TriggeredAbilityImpl<BlocksCreatureTriggeredAbility> {
private boolean setTargetPointer;
public BlocksCreatureTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public BlocksCreatureTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
}
public BlocksCreatureTriggeredAbility(final BlocksCreatureTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED && event.getSourceId().equals(this.getSourceId())) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} blocks a creature, " + super.getRule();
}
@Override
public BlocksCreatureTriggeredAbility copy() {
return new BlocksCreatureTriggeredAbility(this);
}
}

View file

@ -33,7 +33,6 @@ import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -41,7 +40,7 @@ import mage.target.targetpointer.FixedTarget;
*/
public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggeredAbility> {
private boolean fixedTargetPointer;
// private boolean fixedTargetPointer;
public BlocksTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
@ -49,22 +48,17 @@ public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggered
public BlocksTriggeredAbility(Effect effect, boolean optional, boolean fixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.fixedTargetPointer = fixedTargetPointer;
// this.fixedTargetPointer = fixedTargetPointer;
}
public BlocksTriggeredAbility(final BlocksTriggeredAbility ability) {
super(ability);
this.fixedTargetPointer = ability.fixedTargetPointer;
// this.fixedTargetPointer = ability.fixedTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED && event.getSourceId().equals(this.getSourceId())) {
if (fixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
if (event.getType() == EventType.DECLARED_BLOCKERS && game.getCombat().getBlockers().contains(this.getSourceId())) {
return true;
}
return false;
@ -72,7 +66,7 @@ public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggered
@Override
public String getRule() {
return "Whenever {this} blocks" + (fixedTargetPointer ? " a creature" : "") + ", " + super.getRule();
return "Whenever {this} blocks, " + super.getRule();
}
@Override