forked from External/mage
[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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue