mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
[MID] Implemented Disturb mechanic (#8201)
* [MID] Implemented Disturb mechanic Co-authored-by: Oleg Agafonov <jaydi85@gmail.com> Co-authored-by: Evan Kranzler <theelk801@gmail.com>
This commit is contained in:
parent
1195016399
commit
7082b86eb3
33 changed files with 230 additions and 111 deletions
|
|
@ -432,6 +432,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
|
||||
case FLASHBACK:
|
||||
case MADNESS:
|
||||
case DISTURB:
|
||||
// from Snapcaster Mage:
|
||||
// If you cast a spell from a graveyard using its flashback ability, you can’t pay other alternative costs
|
||||
// (such as that of Foil). (2018-12-07)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,129 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.constants.TimingRule;
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author weirddan455
|
||||
* TODO: this is currently implemented in a pull request
|
||||
* 702.146. Disturb
|
||||
* <p>
|
||||
* 702.146a Disturb is an ability found on the front face of some transforming double-faced cards
|
||||
* (see rule 712, “Double-Faced Cards”). “Disturb [cost]” means “You may cast this card
|
||||
* transformed from your graveyard by paying [cost] rather than its mana cost.” See
|
||||
* rule 712.4b.
|
||||
* <p>
|
||||
* 702.146b A resolving transforming double-faced spell that was cast using its disturb
|
||||
* ability enters the battlefield with its back face up.
|
||||
*
|
||||
* @author weirddan455, JayDi85
|
||||
*/
|
||||
public class DisturbAbility extends SpellAbility {
|
||||
|
||||
public DisturbAbility(Cost cost) {
|
||||
this(cost, TimingRule.SORCERY);
|
||||
private final String manaCost;
|
||||
private SpellAbility spellAbilityToResolve;
|
||||
|
||||
public DisturbAbility(Card card, String manaCost) {
|
||||
super(card.getSpellAbility());
|
||||
this.newId();
|
||||
|
||||
// verify check
|
||||
if (card.getSecondCardFace() == null || card.getSecondCardFace().getClass().equals(card.getClass())) {
|
||||
throw new IllegalArgumentException("Wrong code usage. Disturb ability can be added to double faces card only (main side).");
|
||||
}
|
||||
|
||||
this.setCardName(card.getSecondCardFace().getName() + " with Disturb");
|
||||
this.zone = Zone.GRAVEYARD;
|
||||
this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE;
|
||||
this.spellAbilityCastMode = SpellAbilityCastMode.DISTURB;
|
||||
|
||||
this.manaCost = manaCost;
|
||||
this.getManaCosts().clear();
|
||||
this.getManaCostsToPay().clear();
|
||||
this.addManaCost(new ManaCostsImpl(manaCost));
|
||||
this.addSubAbility(new TransformAbility());
|
||||
}
|
||||
|
||||
public DisturbAbility(Cost cost, TimingRule timingRule) {
|
||||
super(null, "", Zone.GRAVEYARD, SpellAbilityType.BASE_ALTERNATE);
|
||||
private DisturbAbility(final DisturbAbility ability) {
|
||||
super(ability);
|
||||
this.manaCost = ability.manaCost;
|
||||
this.spellAbilityToResolve = ability.spellAbilityToResolve;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisturbAbility copy() {
|
||||
return new DisturbAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(Game game, boolean noMana) {
|
||||
if (super.activate(game, noMana)) {
|
||||
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getSourceId(), Boolean.TRUE);
|
||||
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
|
||||
game.addEffect(new DisturbEffect(), this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
if (super.canActivate(playerId, game).canActivate()) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
|
||||
return card.getSpellAbility().canActivate(playerId, game);
|
||||
}
|
||||
}
|
||||
return ActivationStatus.getFalse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule(boolean all) {
|
||||
return this.getRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Disturb " + this.manaCost
|
||||
+ " <i>(You may cast this card transformed from your graveyard for its disturb cost.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class DisturbEffect extends ContinuousEffectImpl {
|
||||
|
||||
public DisturbEffect() {
|
||||
super(Duration.WhileOnStack, Layer.CopyEffects_1, SubLayer.CopyEffects_1a, Outcome.BecomeCreature);
|
||||
staticText = "";
|
||||
}
|
||||
|
||||
private DisturbEffect(final DisturbEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisturbEffect copy() {
|
||||
return new DisturbEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getSpell(source.getSourceId());
|
||||
if (spell == null || spell.getFromZone() != Zone.GRAVEYARD) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (spell.getCard().getSecondCardFace() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// simulate another side as new card (another code part in spell constructor)
|
||||
TransformAbility.transformCardSpellDynamic(spell, spell.getCard().getSecondCardFace(), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,9 @@ import mage.abilities.effects.ContinuousEffectImpl;
|
|||
import mage.cards.Card;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.MageObjectAttribute;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
|
|
@ -35,8 +37,7 @@ public class TransformAbility extends SimpleStaticAbility {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static void transform(Permanent permanent, Card sourceCard, Game game, Ability source) {
|
||||
|
||||
public static void transformPermanent(Permanent permanent, Card sourceCard, Game game, Ability source) {
|
||||
if (sourceCard == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -65,6 +66,48 @@ public class TransformAbility extends SimpleStaticAbility {
|
|||
permanent.getPower().modifyBaseValue(sourceCard.getPower().getValue());
|
||||
permanent.getToughness().modifyBaseValue(sourceCard.getToughness().getValue());
|
||||
}
|
||||
|
||||
public static Card transformCardSpellStatic(Card mainSide, Card otherSide, Game game) {
|
||||
// workaround to simulate transformed card on the stack (example: disturb ability)
|
||||
// prepare static attributes
|
||||
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
|
||||
Card newCard = mainSide.copy();
|
||||
newCard.setName(otherSide.getName());
|
||||
newCard.getSuperType().clear();
|
||||
|
||||
// mana value must be from main side only
|
||||
newCard.getManaCost().clear();
|
||||
newCard.getManaCost().add(mainSide.getManaCost().copy());
|
||||
|
||||
for (SuperType type : otherSide.getSuperType()) {
|
||||
newCard.addSuperType(type);
|
||||
}
|
||||
game.getState().getCardState(newCard.getId()).clearAbilities();
|
||||
for (Ability ability : otherSide.getAbilities()) {
|
||||
game.getState().addOtherAbility(newCard, ability);
|
||||
}
|
||||
newCard.getPower().modifyBaseValue(otherSide.getPower().getValue());
|
||||
newCard.getToughness().modifyBaseValue(otherSide.getToughness().getValue());
|
||||
|
||||
return newCard;
|
||||
}
|
||||
|
||||
public static void transformCardSpellDynamic(Spell spell, Card otherSide, Game game) {
|
||||
// workaround to simulate transformed card on the stack (example: disturb ability)
|
||||
// prepare dynamic attributes
|
||||
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
|
||||
MageObjectAttribute moa = game.getState().getCreateMageObjectAttribute(spell.getCard(), game);
|
||||
moa.getColor().setColor(otherSide.getColor(game));
|
||||
moa.getCardType().clear();
|
||||
moa.getCardType().addAll(otherSide.getCardType(game));
|
||||
moa.getSubtype().clear();
|
||||
moa.getSubtype().addAll(otherSide.getSubtype(game));
|
||||
|
||||
game.getState().getCardState(spell.getCard().getId()).clearAbilities();
|
||||
for (Ability ability : otherSide.getAbilities()) {
|
||||
game.getState().addOtherAbility(spell.getCard(), ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TransformEffect extends ContinuousEffectImpl {
|
||||
|
|
@ -101,7 +144,7 @@ class TransformEffect extends ContinuousEffectImpl {
|
|||
return false;
|
||||
}
|
||||
|
||||
TransformAbility.transform(permanent, card, game, source);
|
||||
TransformAbility.transformPermanent(permanent, card, game, source);
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ public enum SpellAbilityCastMode {
|
|||
NORMAL("Normal"),
|
||||
MADNESS("Madness"),
|
||||
FLASHBACK("Flashback"),
|
||||
BESTOW("Bestow");
|
||||
BESTOW("Bestow"),
|
||||
DISTURB("Disturb");
|
||||
|
||||
private final String text;
|
||||
|
||||
|
|
|
|||
|
|
@ -1889,7 +1889,7 @@ public abstract class GameImpl implements Game {
|
|||
}
|
||||
newBluePrint.assignNewId();
|
||||
if (copyFromPermanent.isTransformed()) {
|
||||
TransformAbility.transform(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
|
||||
TransformAbility.transformPermanent(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
|
||||
}
|
||||
}
|
||||
if (applier != null) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class PermanentCard extends PermanentImpl {
|
|||
|| NightboundAbility.checkCard(this, game)) {
|
||||
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId(), null);
|
||||
setTransformed(true);
|
||||
TransformAbility.transform(this, getSecondCardFace(), game, null);
|
||||
TransformAbility.transformPermanent(this, getSecondCardFace(), game, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import mage.abilities.costs.mana.ManaCost;
|
|||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.keyword.BestowAbility;
|
||||
import mage.abilities.keyword.MorphAbility;
|
||||
import mage.abilities.keyword.TransformAbility;
|
||||
import mage.abilities.text.TextPart;
|
||||
import mage.cards.*;
|
||||
import mage.constants.*;
|
||||
|
|
@ -66,21 +67,29 @@ public class Spell extends StackObjectImpl implements Card {
|
|||
private ActivationManaAbilityStep currentActivatingManaAbilitiesStep = ActivationManaAbilityStep.BEFORE;
|
||||
|
||||
public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone, Game game) {
|
||||
this.card = card;
|
||||
this.color = card.getColor(null).copy();
|
||||
this.frameColor = card.getFrameColor(null).copy();
|
||||
this.frameStyle = card.getFrameStyle();
|
||||
Card affectedCard = card;
|
||||
|
||||
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
|
||||
if (ability.getSpellAbilityCastMode() == SpellAbilityCastMode.DISTURB && affectedCard.getSecondCardFace() != null) {
|
||||
// simulate another side as new card (another code part in continues effect from disturb ability)
|
||||
affectedCard = TransformAbility.transformCardSpellStatic(card, card.getSecondCardFace(), game);
|
||||
}
|
||||
|
||||
this.card = affectedCard;
|
||||
this.color = affectedCard.getColor(null).copy();
|
||||
this.frameColor = affectedCard.getFrameColor(null).copy();
|
||||
this.frameStyle = affectedCard.getFrameStyle();
|
||||
this.id = ability.getId();
|
||||
this.zoneChangeCounter = card.getZoneChangeCounter(game); // sync card's ZCC with spell (copy spell settings)
|
||||
this.zoneChangeCounter = affectedCard.getZoneChangeCounter(game); // sync card's ZCC with spell (copy spell settings)
|
||||
this.ability = ability;
|
||||
this.ability.setControllerId(controllerId);
|
||||
if (ability.getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
spellCards.add(((SplitCard) card).getLeftHalfCard());
|
||||
spellAbilities.add(((SplitCard) card).getLeftHalfCard().getSpellAbility().copy());
|
||||
spellCards.add(((SplitCard) card).getRightHalfCard());
|
||||
spellAbilities.add(((SplitCard) card).getRightHalfCard().getSpellAbility().copy());
|
||||
spellCards.add(((SplitCard) affectedCard).getLeftHalfCard());
|
||||
spellAbilities.add(((SplitCard) affectedCard).getLeftHalfCard().getSpellAbility().copy());
|
||||
spellCards.add(((SplitCard) affectedCard).getRightHalfCard());
|
||||
spellAbilities.add(((SplitCard) affectedCard).getRightHalfCard().getSpellAbility().copy());
|
||||
} else {
|
||||
spellCards.add(card);
|
||||
spellCards.add(affectedCard);
|
||||
spellAbilities.add(ability);
|
||||
}
|
||||
this.controllerId = controllerId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue