Fixed BecomesBlocked triggered abilities

This commit is contained in:
North 2012-05-25 21:28:58 +03:00
parent 11b692fa47
commit 5d0c7862c6
9 changed files with 208 additions and 43 deletions

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility;
import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
@ -52,7 +52,7 @@ public class AshmouthHound extends CardImpl<AshmouthHound> {
this.toughness = new MageInt(1);
// Whenever Ashmouth Hound blocks or becomes blocked by a creature, Ashmouth Hound deals 1 damage to that creature.
this.addAbility(new BlocksOrBecomesBlockedTriggeredAbility(new DamageTargetEffect(1, true, "that creature"), false));
this.addAbility(new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DamageTargetEffect(1, true, "that creature"), false));
}
public AshmouthHound(final AshmouthHound card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility;
import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
@ -51,7 +51,7 @@ public class InfernoElemental extends CardImpl<InfernoElemental> {
this.toughness = new MageInt(4);
// Whenever Inferno Elemental blocks or becomes blocked by a creature, Inferno Elemental deals 3 damage to that creature.
this.addAbility(new BlocksOrBecomesBlockedTriggeredAbility(new DamageTargetEffect(3, true, "that creature"), false));
this.addAbility(new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DamageTargetEffect(3, true, "that creature"), false));
}
public InfernoElemental(final InfernoElemental card) {

View file

@ -36,10 +36,9 @@ import mage.Constants.Rarity;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility;
import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.players.Player;
@ -57,7 +56,9 @@ public class EngulfingSlagwurm extends CardImpl<EngulfingSlagwurm> {
this.color.setGreen(true);
this.power = new MageInt(7);
this.toughness = new MageInt(7);
Ability ability = new BlocksOrBecomesBlockedTriggeredAbility(new DestroyTargetEffect(), false);
// Whenever Engulfing Slagwurm blocks or becomes blocked by a creature, destroy that creature. You gain life equal to that creature's toughness.
Ability ability = new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DestroyTargetEffect(), false);
ability.addEffect(new EngulfingSlagwurmEffect());
this.addAbility(ability);
}

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.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.target.targetpointer.FixedTarget;
/**
*
* @author North
*/
public class BecomesBlockedByCreatureTriggeredAbility extends TriggeredAbilityImpl<BecomesBlockedByCreatureTriggeredAbility> {
public BecomesBlockedByCreatureTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
}
public BecomesBlockedByCreatureTriggeredAbility(final BecomesBlockedByCreatureTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED && event.getTargetId().equals(this.getSourceId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked by a creature, " + super.getRule();
}
@Override
public BecomesBlockedByCreatureTriggeredAbility copy() {
return new BecomesBlockedByCreatureTriggeredAbility(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.common.TargetCreaturePermanent;
/**
*
@ -43,7 +42,6 @@ public class BecomesBlockedTriggeredAbility extends TriggeredAbilityImpl<Becomes
public BecomesBlockedTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
this.addTarget(new TargetCreaturePermanent());
}
public BecomesBlockedTriggeredAbility(final BecomesBlockedTriggeredAbility ability) {
@ -52,8 +50,7 @@ public class BecomesBlockedTriggeredAbility extends TriggeredAbilityImpl<Becomes
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED && event.getTargetId().equals(this.getSourceId())) {
this.getTargets().get(0).add(event.getSourceId(), game);
if (event.getType() == EventType.CREATURE_BLOCKED && event.getTargetId().equals(this.getSourceId())) {
return true;
}
return false;
@ -68,4 +65,4 @@ public class BecomesBlockedTriggeredAbility extends TriggeredAbilityImpl<Becomes
public BecomesBlockedTriggeredAbility copy() {
return new BecomesBlockedTriggeredAbility(this);
}
}
}

View file

@ -0,0 +1,79 @@
/*
* 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.target.targetpointer.FixedTarget;
/**
*
* @author North
*/
public class BlocksOrBecomesBlockedByCreatureTriggeredAbility extends TriggeredAbilityImpl<BlocksOrBecomesBlockedByCreatureTriggeredAbility> {
public BlocksOrBecomesBlockedByCreatureTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
}
public BlocksOrBecomesBlockedByCreatureTriggeredAbility(final BlocksOrBecomesBlockedByCreatureTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
if (event.getSourceId().equals(this.getSourceId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
if (event.getTargetId().equals(this.getSourceId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} blocks or becomes blocked by a creature, " + super.getRule();
}
@Override
public BlocksOrBecomesBlockedByCreatureTriggeredAbility copy() {
return new BlocksOrBecomesBlockedByCreatureTriggeredAbility(this);
}
}

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,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;
/**
*
@ -28,19 +50,9 @@ public class BlocksOrBecomesBlockedTriggeredAbility extends TriggeredAbilityImpl
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED) {
if (event.getSourceId().equals(this.getSourceId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
if (event.getTargetId().equals(this.getSourceId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
if ((event.getType() == EventType.BLOCKER_DECLARED || event.getType() == EventType.CREATURE_BLOCKED)
&& event.getSourceId().equals(this.getSourceId())) {
return true;
}
return false;
}

View file

@ -364,7 +364,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
lethalDamage = attacker.getToughness().getValue() - attacker.getDamage();
if (lethalDamage >= damage) {
assigned.put(attackerId, damage);
damage = 0;
break;
}
int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + attacker.getName(), game);
@ -518,6 +517,11 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BLOCKER_DECLARED, attackerId, blockerId, players.get(blockerId)));
}
}
if(!blockers.isEmpty()) {
for (UUID attackerId: attackers) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, attackerId, null));
}
}
}
@Override

View file

@ -88,7 +88,7 @@ public class GameEvent {
PLAY_LAND, LAND_PLAYED,
CAST_SPELL, SPELL_CAST,
ACTIVATE_ABILITY, ACTIVATED_ABILITY,
MANA_ADDED, MANA_PAYED,
MANA_ADDED, MANA_PAYED,
LOSES, LOST, WINS,
TARGET, TARGETED,
COUNTER, COUNTERED,
@ -96,9 +96,10 @@ public class GameEvent {
DECLARE_ATTACKER, ATTACKER_DECLARED,
DECLARING_BLOCKERS, DECLARED_BLOCKERS,
DECLARE_BLOCKER, BLOCKER_DECLARED,
CREATURE_BLOCKED,
SEARCH_LIBRARY, LIBRARY_SEARCHED,
SHUFFLE_LIBRARY, LIBRARY_SHUFFLED,
ENCHANT_PLAYER, ENCHANTED_PLAYER,
SHUFFLE_LIBRARY, LIBRARY_SHUFFLED,
ENCHANT_PLAYER, ENCHANTED_PLAYER,
//permanent events
ENTERS_THE_BATTLEFIELD,
@ -121,8 +122,8 @@ public class GameEvent {
COUNTER_REMOVED,
LOSE_CONTROL, LOST_CONTROL,
GAIN_CONTROL, GAINED_CONTROL,
CREATE_TOKEN,
REGENERATE, REGENERATED,
CREATE_TOKEN,
REGENERATE, REGENERATED,
//combat events
COMBAT_DAMAGE_APPLIED,
@ -157,9 +158,9 @@ public class GameEvent {
public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId, String data, int amount) {
GameEvent event = getEvent(type, targetId,playerId);
event.setAmount(amount);
event.setData(data);
return event;
event.setAmount(amount);
event.setData(data);
return event;
}
public EventType getType() {
@ -198,11 +199,11 @@ public class GameEvent {
this.data = data;
}
public Zone getZone() {
return zone;
}
public Zone getZone() {
return zone;
}
public void setZone(Zone zone) {
this.zone = zone;
}
public void setZone(Zone zone) {
this.zone = zone;
}
}