* Starfield of Nyx - Fixed that the continuous effect's dependancy to continuousEffects that add subtype aura was not checked. Reworked the dependency check to be a bit more generic (#1259).

This commit is contained in:
LevelX2 2015-09-12 19:35:02 +02:00
parent daea667cbf
commit 0ca991c4ba
22 changed files with 408 additions and 185 deletions

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 java.util.UUID;
@ -42,6 +41,7 @@ import mage.abilities.effects.common.CreateSpecialActionEffect;
import mage.abilities.effects.common.RemoveSpecialActionEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.constants.CardType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
@ -76,25 +76,25 @@ public class LicidAbility extends ActivatedAbilityImpl {
}
class LicidEffect extends OneShotEffect {
private final ManaCost specialActionCost;
LicidEffect(ManaCost specialActionCost) {
super(Outcome.Neutral);
this.specialActionCost = specialActionCost;
this.staticText = "{this} loses this ability and becomes an Aura enchantment with enchant creature. Attach it to target creature. You may pay " + specialActionCost.getText() + " to end this effect";
}
LicidEffect(final LicidEffect effect) {
super(effect);
this.specialActionCost = effect.specialActionCost;
}
@Override
public LicidEffect copy() {
return new LicidEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
@ -113,15 +113,16 @@ class LicidEffect extends OneShotEffect {
}
class LicidContinuousEffect extends ContinuousEffectImpl {
private final UUID messageId;
LicidContinuousEffect(UUID messageId) {
super(Duration.Custom, Outcome.Neutral);
this.messageId = messageId;
dependencyTypes.add(DependencyType.AuraAddingRemoving);
}
LicidContinuousEffect(LicidContinuousEffect ability) {
LicidContinuousEffect(final LicidContinuousEffect ability) {
super(ability);
this.messageId = ability.messageId;
}
@ -201,28 +202,28 @@ class LicidSpecialAction extends SpecialAction {
}
class LicidSpecialActionEffect extends OneShotEffect {
private final UUID messageId;
private final UUID generatingSpecialActionId;
LicidSpecialActionEffect(UUID messageId, UUID generatingSpecialActionId, String licidName) {
super(Outcome.Neutral);
this.messageId = messageId;
this.generatingSpecialActionId = generatingSpecialActionId;
this.staticText = "End " + licidName + " Effect";
}
LicidSpecialActionEffect(final LicidSpecialActionEffect effect) {
super(effect);
this.messageId = effect.messageId;
this.generatingSpecialActionId = effect.generatingSpecialActionId;
}
@Override
public LicidSpecialActionEffect copy() {
return new LicidSpecialActionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
new RemoveSpecialActionEffect(this.generatingSpecialActionId).apply(game, source);

View file

@ -1,5 +1,8 @@
package mage.abilities.decorator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.condition.Condition;
@ -25,7 +28,6 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
protected Condition condition;
protected boolean initDone = false;
public ConditionalContinuousEffect(ContinuousEffect effect, Condition condition, String text) {
this(effect, null, condition, text);
}
@ -61,7 +63,7 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
public boolean isDiscarded() {
return this.discarded || effect.isDiscarded() || (otherwiseEffect != null && otherwiseEffect.isDiscarded());
}
@Override
public void init(Ability source, Game game) {
if (baseCondition instanceof LockedInCondition) {
@ -70,7 +72,7 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.init(source, game);
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.init(source, game);
@ -134,4 +136,13 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
public ConditionalContinuousEffect copy() {
return new ConditionalContinuousEffect(this);
}
@Override
public Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer) {
if (effect != null) {
return effect.isDependentTo(allEffectsInLayer);
}
return super.isDependentTo(allEffectsInLayer);
}
}

View file

@ -32,6 +32,7 @@ import java.util.Set;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.SubLayer;
@ -73,6 +74,8 @@ public interface ContinuousEffect extends Effect {
Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer);
Set<DependencyType> getDependencyTypes();
@Override
void newId();

View file

@ -28,6 +28,7 @@
package mage.abilities.effects;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -39,6 +40,7 @@ import mage.abilities.dynamicvalue.common.DomainValue;
import mage.abilities.dynamicvalue.common.SignInversionDynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.constants.AbilityType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.EffectType;
import mage.constants.Layer;
@ -69,6 +71,7 @@ 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;
// until your next turn
protected int startingTurn;
@ -79,6 +82,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
this.duration = duration;
this.order = 0;
this.effectType = EffectType.CONTINUOUS;
this.dependencyTypes = EnumSet.noneOf(DependencyType.class);
}
public ContinuousEffectImpl(Duration duration, Layer layer, SubLayer sublayer, Outcome outcome) {
@ -100,6 +104,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
this.temporary = effect.temporary;
this.startingTurn = effect.startingTurn;
this.startingControllerId = effect.startingControllerId;
this.dependencyTypes = effect.dependencyTypes;
}
@Override
@ -256,4 +261,9 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
return null;
}
@Override
public EnumSet<DependencyType> getDependencyTypes() {
return dependencyTypes;
}
}

View file

@ -25,14 +25,18 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common.continuous;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.*;
import mage.constants.CardType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -40,12 +44,15 @@ import mage.game.permanent.Permanent;
* @author nantuko
*/
public class AddCardTypeTargetEffect extends ContinuousEffectImpl {
private final CardType addedCardType;
public AddCardTypeTargetEffect(CardType addedCardType, Duration duration) {
super(duration, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit);
this.addedCardType = addedCardType;
if (addedCardType.equals(CardType.ENCHANTMENT)) {
dependencyTypes.add(DependencyType.EnchantmentAddingRemoving);
}
}
public AddCardTypeTargetEffect(final AddCardTypeTargetEffect effect) {
@ -56,7 +63,7 @@ public class AddCardTypeTargetEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
for (UUID targetId :targetPointer.getTargets(game, source)) {
for (UUID targetId : targetPointer.getTargets(game, source)) {
Permanent target = game.getPermanent(targetId);
if (target != null) {
if (!target.getCardType().contains(addedCardType)) {

View file

@ -31,6 +31,7 @@ import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.EnchantAbility;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import static mage.constants.Layer.AbilityAddingRemovingEffects_6;
@ -56,10 +57,10 @@ public class BecomesAuraSourceEffect extends ContinuousEffectImpl implements Sou
newAbility = new EnchantAbility(target.getTargetName());
newAbility.setRuleAtTheTop(true);
staticText = "it becomes an Aura with enchant " + target.getTargetName();
dependencyTypes.add(DependencyType.AuraAddingRemoving);
}
public BecomesAuraSourceEffect(final BecomesAuraSourceEffect effect) {
super(effect);
this.target = effect.target;
@ -112,4 +113,4 @@ public class BecomesAuraSourceEffect extends ContinuousEffectImpl implements Sou
return Layer.AbilityAddingRemovingEffects_6.equals(layer) || Layer.TypeChangingEffects_4.equals(layer);
}
}
}

View file

@ -40,6 +40,7 @@ import mage.abilities.mana.WhiteManaAbility;
import mage.choices.Choice;
import mage.choices.ChoiceBasicLandType;
import mage.constants.CardType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
@ -73,6 +74,21 @@ public class BecomesBasicLandTargetEffect extends ContinuousEffectImpl {
public BecomesBasicLandTargetEffect(Duration duration, boolean chooseLandType, boolean loseOther, String... landNames) {
super(duration, Outcome.Detriment);
this.landTypes.addAll(Arrays.asList(landNames));
if (landTypes.contains("Mountain")) {
dependencyTypes.add(DependencyType.BecomeMountain);
}
if (landTypes.contains("Forest")) {
dependencyTypes.add(DependencyType.BecomeForest);
}
if (landTypes.contains("Swamp")) {
dependencyTypes.add(DependencyType.BecomeSwamp);
}
if (landTypes.contains("Island")) {
dependencyTypes.add(DependencyType.BecomeIsland);
}
if (landTypes.contains("Plains")) {
dependencyTypes.add(DependencyType.BecomePlains);
}
this.chooseLandType = chooseLandType;
this.staticText = setText();
this.loseOther = loseOther;

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import mage.abilities.Ability;
@ -37,6 +36,7 @@ import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.SourceEffect;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import static mage.constants.Layer.TypeChangingEffects_4;
@ -54,57 +54,66 @@ import mage.target.common.TargetCreaturePermanent;
*
* 702.102. Bestow
*
* 702.102a Bestow represents two static abilities, one that functions while the card with bestow is
* on the stack and another that functions both while its on stack and while its on the battlefield.
* Bestow [cost] means You may cast this card by paying [cost] rather than its mana cost. and If
* you chose to pay this spells bestow cost, it becomes an Aura enchantment and gains enchant creature.
* These effects last until one of two things happens: this spell has an illegal target as it resolves
* and or the permanent this spell becomes, becomes unattached. Paying a cards bestow cost follows the
* rules for paying alternative costs in rules 601.2b and 601.2eg.
* 702.102a Bestow represents two static abilities, one that functions while the
* card with bestow is on the stack and another that functions both while its
* on stack and while its on the battlefield. Bestow [cost] means You may
* cast this card by paying [cost] rather than its mana cost. and If you chose
* to pay this spells bestow cost, it becomes an Aura enchantment and gains
* enchant creature. These effects last until one of two things happens: this
* spell has an illegal target as it resolves and or the permanent this spell
* becomes, becomes unattached. Paying a cards bestow cost follows the rules
* for paying alternative costs in rules 601.2b and 601.2eg.
*
* 702.102b If a spells controller chooses to pay its bestow cost, that player chooses a legal target
* for that Aura spell as defined by its enchant creature ability and rule 601.2c. See also rule 303.4.
* 702.102b If a spells controller chooses to pay its bestow cost, that player
* chooses a legal target for that Aura spell as defined by its enchant creature
* ability and rule 601.2c. See also rule 303.4.
*
* 702.102c A spells controller cant choose to pay its bestow cost unless that player can choose a legal
* target for that spell after it becomes an Aura spell.
* 702.102c A spells controller cant choose to pay its bestow cost unless that
* player can choose a legal target for that spell after it becomes an Aura
* spell.
*
* 702.102d As an Aura spell with bestow begins resolving, if its target is illegal, the effect making
* it an Aura spell ends. It continues resolving as a creature spell and will be put onto the battlefield
* under the control of the spells controller. This is an exception to rule 608.3a.
* 702.102d As an Aura spell with bestow begins resolving, if its target is
* illegal, the effect making it an Aura spell ends. It continues resolving as a
* creature spell and will be put onto the battlefield under the control of the
* spells controller. This is an exception to rule 608.3a.
*
* 702.102e If an Aura with bestow is attached to an illegal object or player, it becomes unattached.
* This is an exception to rule 704.5n.
*
* You dont choose whether the spell is going to be an Aura spell or not until the spell is already on
* the stack. Abilities that affect when you can cast a spell, such as flash, will apply to the creature
* card in whatever zone youre casting it from. For example, an effect that said you can cast creature
* spells as though they have flash will allow you to cast a creature card with bestow as an Aura spell
* anytime you could cast an instant.
* 702.102e If an Aura with bestow is attached to an illegal object or player,
* it becomes unattached. This is an exception to rule 704.5n.
*
* On the stack, a spell with bestow is either a creature spell or an Aura spell. Its never both.
* You dont choose whether the spell is going to be an Aura spell or not until
* the spell is already on the stack. Abilities that affect when you can cast a
* spell, such as flash, will apply to the creature card in whatever zone youre
* casting it from. For example, an effect that said you can cast creature
* spells as though they have flash will allow you to cast a creature card with
* bestow as an Aura spell anytime you could cast an instant.
*
* Unlike other Aura spells, an Aura spell with bestow isnt countered if its target is illegal as it
* begins to resolve. Rather, the effect making it an Aura spell ends, it loses enchant creature, it
* returns to being an enchantment creature spell, and it resolves and enters the battlefield as an
* On the stack, a spell with bestow is either a creature spell or an Aura
* spell. Its never both.
*
* Unlike other Aura spells, an Aura spell with bestow isnt countered if its
* target is illegal as it begins to resolve. Rather, the effect making it an
* Aura spell ends, it loses enchant creature, it returns to being an
* enchantment creature spell, and it resolves and enters the battlefield as an
* enchantment creature.
*
* Unlike other Auras, an Aura with bestow isnt put into its owners graveyard if it becomes unattached.
* Rather, the effect making it an Aura ends, it loses enchant creature, and it remains on the
* battlefield as an enchantment creature. It can attack (and its {T} abilities can be activated,
* if it has any) on the turn it becomes unattached if its been under your control continuously,
* even as an Aura, since your most recent turn began.
* Unlike other Auras, an Aura with bestow isnt put into its owners graveyard
* if it becomes unattached. Rather, the effect making it an Aura ends, it loses
* enchant creature, and it remains on the battlefield as an enchantment
* creature. It can attack (and its {T} abilities can be activated, if it has
* any) on the turn it becomes unattached if its been under your control
* continuously, even as an Aura, since your most recent turn began.
*
* If a permanent with bestow enters the battlefield by any method other than being cast, it will be
* an enchantment creature. You cant choose to pay the bestow cost and have it become an Aura.
* If a permanent with bestow enters the battlefield by any method other than
* being cast, it will be an enchantment creature. You cant choose to pay the
* bestow cost and have it become an Aura.
*
* Auras attached to a creature dont become tapped when the creature becomes tapped. Except in some
* rare cases, an Aura with bestow remains untapped when it becomes unattached and becomes a creature.
* Auras attached to a creature dont become tapped when the creature becomes
* tapped. Except in some rare cases, an Aura with bestow remains untapped when
* it becomes unattached and becomes a creature.
*
*
* @author LevelX2
*/
public class BestowAbility extends SpellAbility {
public BestowAbility(Card card, String manaString) {
@ -135,67 +144,67 @@ public class BestowAbility extends SpellAbility {
@Override
public String getRule() {
return "Bestow " + getManaCostsToPay().getText()+ " <i>(If you cast this card for its bestow cost, it's an Aura spell with enchant creature. It becomes a creature again if it's not attached to a creature.)</i>";
return "Bestow " + getManaCostsToPay().getText() + " <i>(If you cast this card for its bestow cost, it's an Aura spell with enchant creature. It becomes a creature again if it's not attached to a creature.)</i>";
}
}
class BestowTypeChangingEffect extends ContinuousEffectImpl implements SourceEffect {
class BestowTypeChangingEffect extends ContinuousEffectImpl implements SourceEffect {
private boolean wasAttached;
private boolean wasAttached;
public BestowTypeChangingEffect() {
super(Duration.WhileOnBattlefield, Outcome.BoostCreature);
wasAttached = false;
}
public BestowTypeChangingEffect(final BestowTypeChangingEffect effect) {
super(effect);
this.wasAttached = effect.wasAttached;
}
@Override
public BestowTypeChangingEffect copy() {
return new BestowTypeChangingEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
switch (layer) {
case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
if (permanent.getAttachedTo() == null) {
if (wasAttached && permanent.getSubtype().contains("Aura")) {
permanent.getSubtype().remove("Aura");
wasAttached = false;
}
} else {
permanent.getCardType().remove(CardType.CREATURE);
permanent.getSubtype().clear();
if (!permanent.getSubtype().contains("Aura")) {
permanent.getSubtype().add("Aura");
}
wasAttached = true;
}
}
break;
}
return true;
public BestowTypeChangingEffect() {
super(Duration.WhileOnBattlefield, Outcome.BoostCreature);
wasAttached = false;
dependencyTypes.add(DependencyType.AuraAddingRemoving);
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
public BestowTypeChangingEffect(final BestowTypeChangingEffect effect) {
super(effect);
this.wasAttached = effect.wasAttached;
}
@Override
public BestowTypeChangingEffect copy() {
return new BestowTypeChangingEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
switch (layer) {
case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
if (permanent.getAttachedTo() == null) {
if (wasAttached && permanent.getSubtype().contains("Aura")) {
permanent.getSubtype().remove("Aura");
wasAttached = false;
}
} else {
permanent.getCardType().remove(CardType.CREATURE);
permanent.getSubtype().clear();
if (!permanent.getSubtype().contains("Aura")) {
permanent.getSubtype().add("Aura");
}
wasAttached = true;
}
}
break;
}
return true;
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.TypeChangingEffects_4;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.TypeChangingEffects_4;
}
}

View file

@ -0,0 +1,50 @@
/*
* 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.constants;
/**
* Dependency types are a part of a workaround solution to handle dependencies
* of continuous effects.
*
* http://magiccards.info/rule/613-interaction-of-continuous-effects.html
*
* https://github.com/magefree/mage/issues/1259
*
*
* @author LevelX2
*/
public enum DependencyType {
AuraAddingRemoving,
BecomeForest,
BecomeIsland,
BecomeMountain,
BecomePlains,
BecomeSwamp,
EnchantmentAddingRemoving;
}