Added and changed some framework classes.

This commit is contained in:
LevelX2 2013-10-28 23:50:08 +01:00
parent 760773e15a
commit 9dce38a0a9
15 changed files with 450 additions and 28 deletions

View file

@ -82,7 +82,7 @@ public class FaithfulSquire extends CardImpl<FaithfulSquire> {
this.addAbility(new ConditionalTriggeredAbility(
new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect()),
new HasCounterCondition(CounterType.KI, 2, Integer.MAX_VALUE),
"At the beginning of the end step, if there are two or more ki counters on Faithful Squire, you may flip it.", true));
"At the beginning of the end step, if there are two or more ki counters on {this}, you may flip it.", true));
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinousEffect(new CopyTokenEffect(new KaisoMemoryOfLoyalty()), FlippedCondition.getInstance(), ""));
ability.setRuleVisible(false);
@ -118,7 +118,7 @@ class KaisoMemoryOfLoyalty extends Token {
Zone.BATTLEFIELD,
new PreventDamageTargetEffect(Duration.EndOfTurn, Integer.MAX_VALUE),
new RemoveCountersSourceCost(CounterType.KI.createInstance()));
ability.addTarget(new TargetCreaturePermanent());
ability.addTarget(new TargetCreaturePermanent(true));
this.addAbility(ability);
}
}

View file

@ -33,7 +33,7 @@ import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.RegenerateSourceEffect;
@ -59,7 +59,7 @@ public class KashiTribeReaver extends CardImpl<KashiTribeReaver> {
// Whenever Kashi-Tribe Reaver deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability;
ability = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability);
// {1}{G}: Regenerate Kashi-Tribe Reaver.

View file

@ -33,7 +33,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
import mage.abilities.effects.common.TapTargetEffect;
import mage.cards.CardImpl;
@ -56,7 +56,7 @@ public class KashiTribeWarriors extends CardImpl<KashiTribeWarriors> {
// Whenever Kashi-Tribe Reaver deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability;
ability = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability);
}

View file

@ -33,7 +33,7 @@ import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.combat.MustBeBlockedByTargetSourceEffect;
@ -64,7 +64,7 @@ public class MatsuTribeDecoy extends CardImpl<MatsuTribeDecoy> {
this.addAbility(ability);
// Whenever Kashi-Tribe Reaver deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability2;
ability2 = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability2 = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability2.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability2);
}

View file

@ -33,7 +33,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
import mage.abilities.effects.common.TapTargetEffect;
import mage.cards.CardImpl;
@ -56,7 +56,7 @@ public class OrochiRanger extends CardImpl<OrochiRanger> {
// Whenever Orochi Ranger deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability;
ability = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability);
}

View file

@ -30,7 +30,7 @@ package mage.sets.legions;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
@ -57,7 +57,7 @@ public class ToxinSliver extends CardImpl<ToxinSliver> {
this.toughness = new MageInt(3);
// Whenever a Sliver deals combat damage to a creature, destroy that creature. It can't be regenerated.
this.addAbility(new DealsCombatDamageToACreatureTriggeredAbility(new DestroyTargetEffect(false), false, true));
this.addAbility(new DealsDamageToACreatureTriggeredAbility(new DestroyTargetEffect(false), true, false, true));
}

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.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.keyword.DredgeAbility;
import mage.abilities.keyword.FlyingAbility;
@ -55,7 +55,7 @@ public class StinkweedImp extends CardImpl<StinkweedImp> {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever Stinkweed Imp deals combat damage to a creature, destroy that creature.
this.addAbility(new DealsCombatDamageToACreatureTriggeredAbility(new DestroyTargetEffect(), false, true));
this.addAbility(new DealsDamageToACreatureTriggeredAbility(new DestroyTargetEffect(), true, false, true));
// Dredge 5
this.addAbility(new DredgeAbility(5));
}

View file

@ -33,7 +33,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
import mage.abilities.effects.common.TapTargetEffect;
@ -74,7 +74,7 @@ public class KashiTribeElite extends CardImpl<KashiTribeElite> {
// Whenever Kashi-Tribe Elite deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability;
ability = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability);

View file

@ -33,7 +33,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility;
import mage.abilities.common.DealsDamageToACreatureTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
@ -62,7 +62,7 @@ public class MatsuTribeBirdstalker extends CardImpl<MatsuTribeBirdstalker> {
// Whenever Kashi-Tribe Elite deals combat damage to a creature, tap that creature and it doesn't untap during its controller's next untap step.
Ability ability;
ability = new DealsCombatDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), false, true);
ability = new DealsDamageToACreatureTriggeredAbility(new TapTargetEffect("that creature"), true, false, true);
ability.addEffect(new SkipNextUntapTargetEffect("and it"));
this.addAbility(ability);

View file

@ -111,7 +111,14 @@ public abstract class TriggeredAbilityImpl<T extends TriggeredAbilityImpl<T>> ex
StringBuilder sb = new StringBuilder();
if (!superRule.isEmpty()) {
String ruleLow = superRule.toLowerCase();
if (optional && !ruleLow.startsWith("you ")) {
if (optional) {
if (ruleLow.startsWith("you ")) {
if (!ruleLow.startsWith("you may")) {
StringBuilder newRule = new StringBuilder(superRule);
newRule.insert(4, "may ");
superRule = newRule.toString();
}
} else {
if (this.getTargets().isEmpty()
|| ruleLow.startsWith("exile")
|| ruleLow.startsWith("destroy")
@ -122,6 +129,7 @@ public abstract class TriggeredAbilityImpl<T extends TriggeredAbilityImpl<T>> ex
} else {
sb.append("you may have ");
}
}
}
sb.append(superRule.substring(0, 1).toLowerCase());

View file

@ -0,0 +1,100 @@
/*
* 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.DamagedCreatureEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX
*/
public class DealsDamageToACreatureAttachedTriggeredAbility extends TriggeredAbilityImpl<DealsDamageToACreatureAttachedTriggeredAbility> {
private boolean combatOnly;
private boolean setTargetPointer;
private String attachedDescription;
public DealsDamageToACreatureAttachedTriggeredAbility(Effect effect, boolean combatOnly, String attachedDescription, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
this.attachedDescription = attachedDescription;
}
public DealsDamageToACreatureAttachedTriggeredAbility(final DealsDamageToACreatureAttachedTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
this.combatOnly = ability.combatOnly;
this.attachedDescription = ability.attachedDescription;
}
@Override
public DealsDamageToACreatureAttachedTriggeredAbility copy() {
return new DealsDamageToACreatureAttachedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_CREATURE
&& (!combatOnly || ((DamagedCreatureEvent) event).isCombatDamage())) {
Permanent attachment = game.getPermanent(this.getSourceId());
if (attachment != null
&& attachment.getAttachedTo() != null
&& event.getSourceId().equals(attachment.getAttachedTo())
) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
effect.setValue("damage", event.getAmount());
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return new StringBuilder("Whenever ").append(attachedDescription)
.append(" deals ")
.append(combatOnly ? "combat ":"")
.append("damage to a creature, ")
.append(super.getRule()).toString();
}
}

View file

@ -0,0 +1,88 @@
/*
* 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.DamagedCreatureEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX
*/
public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl<DealsDamageToACreatureTriggeredAbility> {
private boolean combatOnly;
private boolean setTargetPointer;
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
}
public DealsDamageToACreatureTriggeredAbility(final DealsDamageToACreatureTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
this.combatOnly = ability.combatOnly;
}
@Override
public DealsDamageToACreatureTriggeredAbility copy() {
return new DealsDamageToACreatureTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_CREATURE) {
if (event.getSourceId().equals(this.sourceId)
&& (!combatOnly || ((DamagedCreatureEvent) event).isCombatDamage())) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
effect.setValue("damage", event.getAmount());
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return new StringBuilder("Whenever {this} deals ").append(combatOnly ? "combat ":"").append("damage to a creature, ").append(super.getRule()).toString();
}
}

View file

@ -64,7 +64,7 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili
@Override
public String getRule() {
StringBuilder sb = new StringBuilder("Whenever ").append(attachedDescription);
sb.append(" creature deals");
sb.append(" deals");
if (!onlyCombat) {
sb.append(" combat");
}

View file

@ -0,0 +1,122 @@
/*
* 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.decorator;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.condition.FixedCondition;
import mage.abilities.effects.ReplacementEffect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* @author LevelX2
*/
public class ConditionalReplacementEffect extends ReplacementEffectImpl<ConditionalReplacementEffect> {
protected ReplacementEffect effect;
protected ReplacementEffect otherwiseEffect;
protected Condition condition;
protected boolean lockedInCondition;
protected boolean conditionState;
public ConditionalReplacementEffect(ReplacementEffect effect, Condition condition, boolean lockedInCondition) {
this(effect, condition, null, lockedInCondition);
}
public ConditionalReplacementEffect(ReplacementEffect effect, Condition condition, ReplacementEffect otherwiseEffect, boolean lockedInCondition) {
super(effect.getDuration(), effect.getOutcome());
this.effect = effect;
this.condition = condition;
this.otherwiseEffect = otherwiseEffect;
this.lockedInCondition = lockedInCondition;
}
public ConditionalReplacementEffect(final ConditionalReplacementEffect effect) {
super(effect);
this.effect = (ReplacementEffect) effect.effect.copy();
if (effect.otherwiseEffect != null) {
this.otherwiseEffect = (ReplacementEffect) effect.otherwiseEffect.copy();
}
this.condition = effect.condition;
this.lockedInCondition = effect.lockedInCondition;
this.conditionState = effect.conditionState;
}
@Override
public boolean isDiscarded() {
return effect.isDiscarded() || (otherwiseEffect != null && otherwiseEffect.isDiscarded());
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
return effect.replaceEvent(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.replaceEvent(event, source, game);
}
if (!conditionState && effect.getDuration() == Duration.OneUse) {
used = true;
}
if (!conditionState && effect.getDuration() == Duration.Custom) {
this.discard();
}
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (lockedInCondition && !(condition instanceof FixedCondition)) {
condition = new FixedCondition(condition.apply(game, source));
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
return effect.applies(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.applies(event, source, game);
}
return false;
}
@Override
public ConditionalReplacementEffect copy() {
return new ConditionalReplacementEffect(this);
}
}

View file

@ -0,0 +1,104 @@
/*
* 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.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class PreventAllDamageAttachedEffect extends PreventionEffectImpl<PreventAllDamageAttachedEffect> {
private String attachedDescription;
private boolean combatOnly;
public PreventAllDamageAttachedEffect(Duration duration, String attachedDescription, boolean combatOnly) {
super(duration);
this.attachedDescription = attachedDescription;
this.combatOnly = combatOnly;
staticText = setText();
}
public PreventAllDamageAttachedEffect(final PreventAllDamageAttachedEffect effect) {
super(effect);
this.attachedDescription = effect.attachedDescription;
this.combatOnly = effect.combatOnly;
}
@Override
public PreventAllDamageAttachedEffect copy() {
return new PreventAllDamageAttachedEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), damage));
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment != null
&& attachment.getAttachedTo() != null) {
if (event.getTargetId().equals(attachment.getAttachedTo())) {
return true;
}
}
}
return false;
}
private String setText() {
StringBuilder sb = new StringBuilder("Prevent all ");
if (combatOnly) {
sb.append("combat ");
}
sb.append("damage that would be dealt to ");
sb.append(attachedDescription);
return sb.toString();
}
}