* Manor Gargoyle - Fixed that the lose of defender ability did not stop it having indestructibility.

This commit is contained in:
LevelX2 2016-03-12 10:31:12 +01:00
parent f9d88cfb24
commit 436c82d25a
5 changed files with 117 additions and 28 deletions

View file

@ -28,10 +28,6 @@
package mage.sets.innistrad;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -40,13 +36,18 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.effects.common.continuous.LoseAbilitySourceEffect;
import mage.abilities.keyword.DefenderAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -67,32 +68,33 @@ public class ManorGargoyle extends CardImpl {
this.toughness = new MageInt(4);
this.addAbility(DefenderAbility.getInstance());
/*
TODO: Implement the dependency rule
613.7. Within a layer or sublayer, determining which order effects are applied in is sometimes done using a dependency system.
/*
613.7. Within a layer or sublayer, determining which order effects are applied in is sometimes done using a dependency system.
If a dependency exists, it will override the timestamp system.
613.7a An effect is said to depend on another if
(a) its applied in the same layer (and, if applicable, sublayer) as the other effect (see rules 613.1 and 613.3);
(b) applying the other would change the text or the existence of the first effect, what it applies to, or what
it does to any of the things it applies to; and
(c) neither effect is from a characteristic-defining ability or both effects are from characteristic-defining
613.7a An effect is said to depend on another if
(a) its applied in the same layer (and, if applicable, sublayer) as the other effect (see rules 613.1 and 613.3);
(b) applying the other would change the text or the existence of the first effect, what it applies to, or what
it does to any of the things it applies to; and
(c) neither effect is from a characteristic-defining ability or both effects are from characteristic-defining
abilities. Otherwise, the effect is considered to be independent of the other effect.
613.7b An effect dependent on one or more other effects waits to apply until just after all of those effects have been applied.
If multiple dependent effects would apply simultaneously in this way, theyre applied in timestamp order relative to each
other. If several dependent effects form a dependency loop, then this rule is ignored and the effects in the dependency
other. If several dependent effects form a dependency loop, then this rule is ignored and the effects in the dependency
loop are applied in timestamp order.
613.7c After each effect is applied, the order of remaining effects is reevaluated and may change if an effect that has not yet
been applied becomes dependent on or independent of one or more other effects that have not yet been applied.
*/
// Manor Gargoyle has indestructible as long as it has defender.
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance()), HasDefenderCondition.getInstance(), rule);
GainAbilitySourceEffect gainEffect = new GainAbilitySourceEffect(IndestructibleAbility.getInstance());
gainEffect.setDependedToType(DependencyType.LooseDefenderEffect);
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(gainEffect, HasDefenderCondition.getInstance(), rule);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
// {1}: Until end of turn, Manor Gargoyle loses defender and gains flying.
Effect effect2 = new LoseAbilitySourceEffect(DefenderAbility.getInstance(), Duration.EndOfTurn);
ContinuousEffect effect2 = new LoseAbilitySourceEffect(DefenderAbility.getInstance(), Duration.EndOfTurn);
effect2.addDependencyType(DependencyType.LooseDefenderEffect);
effect2.setText("Until end of turn, {this} loses defender");
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect2, new ManaCostsImpl("{1}"));
effect2 = new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.EndOfTurn);

View file

@ -0,0 +1,58 @@
/*
* 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 org.mage.test.cards.conditional;
import mage.abilities.keyword.DefenderAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class ConditionalContinuousEffectTest extends CardTestPlayerBase {
@Test
public void testManorGargoyle() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
addCard(Zone.BATTLEFIELD, playerA, "Manor Gargoyle");
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{1}: Until end of turn");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertTapped("Mountain", true);
assertAbility(playerA, "Manor Gargoyle", DefenderAbility.getInstance(), false);
assertAbility(playerA, "Manor Gargoyle", IndestructibleAbility.getInstance(), false);
}
}

View file

@ -76,6 +76,10 @@ public interface ContinuousEffect extends Effect {
Set<DependencyType> getDependencyTypes();
void addDependencyType(DependencyType dependencyType);
void setDependedToType(DependencyType dependencyType);
@Override
void newId();

View file

@ -29,6 +29,7 @@ package mage.abilities.effects;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -71,7 +72,8 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
protected boolean affectedObjectsSet = false;
protected List<MageObjectReference> affectedObjectList = new ArrayList<>();
protected boolean temporary = false;
protected EnumSet<DependencyType> dependencyTypes;
protected EnumSet<DependencyType> dependencyTypes; // this effect has the dependencyTypes defined here
protected DependencyType dependendToType; // this effect is dependent to this type
/*
A Characteristic Defining Ability (CDA) is an ability that defines a characteristic of a card or token.
There are 3 specific rules that distinguish a CDA from other abilities.
@ -91,6 +93,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
this.order = 0;
this.effectType = EffectType.CONTINUOUS;
this.dependencyTypes = EnumSet.noneOf(DependencyType.class);
this.dependendToType = null;
}
public ContinuousEffectImpl(Duration duration, Layer layer, SubLayer sublayer, Outcome outcome) {
@ -188,12 +191,10 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
case PTChangingEffects_7:
this.affectedObjectsSet = true;
}
} else {
if (hasLayer(Layer.CopyEffects_1) || hasLayer(Layer.ControlChangingEffects_2) || hasLayer(Layer.TextChangingEffects_3)
|| hasLayer(Layer.TypeChangingEffects_4) || hasLayer(Layer.ColorChangingEffects_5) || hasLayer(Layer.AbilityAddingRemovingEffects_6)
|| hasLayer(Layer.PTChangingEffects_7)) {
this.affectedObjectsSet = true;
}
} else if (hasLayer(Layer.CopyEffects_1) || hasLayer(Layer.ControlChangingEffects_2) || hasLayer(Layer.TextChangingEffects_3)
|| hasLayer(Layer.TypeChangingEffects_4) || hasLayer(Layer.ColorChangingEffects_5) || hasLayer(Layer.AbilityAddingRemovingEffects_6)
|| hasLayer(Layer.PTChangingEffects_7)) {
this.affectedObjectsSet = true;
}
}
startingTurn = game.getTurnNum();
@ -275,6 +276,19 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
@Override
public Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer) {
if (dependendToType != null) {
// the dependent classes needs to be an enclosed class for dependent check of continuous effects
Set<UUID> dependentTo = null;
for (ContinuousEffect effect : allEffectsInLayer) {
if (effect.getDependencyTypes().contains(dependendToType)) {
if (dependentTo == null) {
dependentTo = new HashSet<>();
}
dependentTo.add(effect.getId());
}
}
return dependentTo;
}
return null;
}
@ -283,4 +297,14 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
return dependencyTypes;
}
@Override
public void addDependencyType(DependencyType dependencyType) {
dependencyTypes.add(dependencyType);
}
@Override
public void setDependedToType(DependencyType dependencyType) {
dependendToType = dependencyType;
}
}

View file

@ -46,5 +46,6 @@ public enum DependencyType {
BecomeMountain,
BecomePlains,
BecomeSwamp,
EnchantmentAddingRemoving;
EnchantmentAddingRemoving,
LooseDefenderEffect;
}