mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
- little refactor of Ethereal Valkyrie
This commit is contained in:
parent
fb447d7740
commit
1c2f8f4caa
2 changed files with 222 additions and 401 deletions
|
@ -4,13 +4,8 @@ import java.util.UUID;
|
|||
import mage.MageInt;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.Costs;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
|
@ -18,19 +13,11 @@ import mage.abilities.keyword.ForetellAbility;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.ModalDoubleFacesCard;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SpellAbilityCastMode;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -149,176 +136,11 @@ class EtherealValkyrieEffect extends OneShotEffect {
|
|||
foretellAbility.setControllerId(exileCard.getOwnerId());
|
||||
game.getState().addOtherAbility(exileCard, foretellAbility);
|
||||
foretellAbility.activate(game, true);
|
||||
game.addEffect(new ForetellAddCostEffect(new MageObjectReference(exileCard, game)), source);
|
||||
ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game));
|
||||
game.addEffect(effect, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class ForetellAddCostEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final MageObjectReference mor;
|
||||
|
||||
public ForetellAddCostEffect(MageObjectReference mor) {
|
||||
super(Duration.EndOfGame, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
this.mor = mor;
|
||||
staticText = "Foretold card";
|
||||
}
|
||||
|
||||
public ForetellAddCostEffect(final ForetellAddCostEffect effect) {
|
||||
super(effect);
|
||||
this.mor = effect.mor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = mor.getCard(game);
|
||||
if (card != null
|
||||
&& game.getState().getZone(card.getId()) == Zone.EXILED) {
|
||||
String foretellCost = (String) game.getState().getValue(card.getId().toString() + "Foretell Cost");
|
||||
Ability ability = new ForetellCostAbility(foretellCost);
|
||||
ability.setSourceId(card.getId());
|
||||
ability.setControllerId(source.getControllerId());
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
} else {
|
||||
discard();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForetellAddCostEffect copy() {
|
||||
return new ForetellAddCostEffect(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ForetellCostAbility extends SpellAbility {
|
||||
|
||||
private String abilityName;
|
||||
private SpellAbility spellAbilityToResolve;
|
||||
|
||||
public ForetellCostAbility(String foretellCost) {
|
||||
super(null, "Testing", Zone.EXILED, SpellAbilityType.BASE_ALTERNATE, SpellAbilityCastMode.NORMAL);
|
||||
this.setAdditionalCostsRuleVisible(false);
|
||||
this.name = "Foretell " + foretellCost;
|
||||
this.addCost(new ManaCostsImpl(foretellCost));
|
||||
}
|
||||
|
||||
public ForetellCostAbility(final ForetellCostAbility ability) {
|
||||
super(ability);
|
||||
this.spellAbilityType = ability.spellAbilityType;
|
||||
this.abilityName = ability.abilityName;
|
||||
this.spellAbilityToResolve = ability.spellAbilityToResolve;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivatedAbility.ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
if (super.canActivate(playerId, game).canActivate()) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null) {
|
||||
// Card must be in the exile zone
|
||||
if (game.getState().getZone(card.getId()) != Zone.EXILED) {
|
||||
return ActivatedAbility.ActivationStatus.getFalse();
|
||||
}
|
||||
// Card must be Foretold
|
||||
if (game.getState().getValue(card.getId().toString() + "Foretell Turn Number") == null
|
||||
&& game.getState().getValue(card.getId().toString() + "foretellAbility") == null) {
|
||||
return ActivatedAbility.ActivationStatus.getFalse();
|
||||
}
|
||||
// Can't be cast if the turn it was Foretold is the same
|
||||
if ((int) game.getState().getValue(card.getId().toString() + "Foretell Turn Number") == game.getTurnNum()) {
|
||||
return ActivatedAbility.ActivationStatus.getFalse();
|
||||
}
|
||||
// Check that the card is actually in the exile zone (ex: Oblivion Ring exiles it after it was Foretold, etc)
|
||||
UUID exileId = (UUID) game.getState().getValue(card.getId().toString() + "foretellAbility");
|
||||
ExileZone exileZone = game.getState().getExile().getExileZone(exileId);
|
||||
if (exileZone != null
|
||||
&& exileZone.isEmpty()) {
|
||||
return ActivatedAbility.ActivationStatus.getFalse();
|
||||
}
|
||||
if (card instanceof SplitCard) {
|
||||
if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) {
|
||||
return ((SplitCard) card).getLeftHalfCard().getSpellAbility().canActivate(playerId, game);
|
||||
} else if (((SplitCard) card).getRightHalfCard().getName().equals(abilityName)) {
|
||||
return ((SplitCard) card).getRightHalfCard().getSpellAbility().canActivate(playerId, game);
|
||||
}
|
||||
} else if (card instanceof ModalDoubleFacesCard) {
|
||||
if (((ModalDoubleFacesCard) card).getLeftHalfCard().getName().equals(abilityName)) {
|
||||
return ((ModalDoubleFacesCard) card).getLeftHalfCard().getSpellAbility().canActivate(playerId, game);
|
||||
} else if (((ModalDoubleFacesCard) card).getRightHalfCard().getName().equals(abilityName)) {
|
||||
return ((ModalDoubleFacesCard) card).getRightHalfCard().getSpellAbility().canActivate(playerId, game);
|
||||
}
|
||||
}
|
||||
return card.getSpellAbility().canActivate(playerId, game);
|
||||
}
|
||||
}
|
||||
return ActivatedAbility.ActivationStatus.getFalse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellAbility getSpellAbilityToResolve(Game game) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null) {
|
||||
if (spellAbilityToResolve == null) {
|
||||
SpellAbility spellAbilityCopy = null;
|
||||
if (card instanceof SplitCard) {
|
||||
if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) {
|
||||
spellAbilityCopy = ((SplitCard) card).getLeftHalfCard().getSpellAbility().copy();
|
||||
} else if (((SplitCard) card).getRightHalfCard().getName().equals(abilityName)) {
|
||||
spellAbilityCopy = ((SplitCard) card).getRightHalfCard().getSpellAbility().copy();
|
||||
}
|
||||
} else if (card instanceof ModalDoubleFacesCard) {
|
||||
if (((ModalDoubleFacesCard) card).getLeftHalfCard().getName().equals(abilityName)) {
|
||||
spellAbilityCopy = ((ModalDoubleFacesCard) card).getLeftHalfCard().getSpellAbility().copy();
|
||||
} else if (((ModalDoubleFacesCard) card).getRightHalfCard().getName().equals(abilityName)) {
|
||||
spellAbilityCopy = ((ModalDoubleFacesCard) card).getRightHalfCard().getSpellAbility().copy();
|
||||
}
|
||||
} else {
|
||||
spellAbilityCopy = card.getSpellAbility().copy();
|
||||
}
|
||||
if (spellAbilityCopy == null) {
|
||||
return null;
|
||||
}
|
||||
spellAbilityCopy.setId(this.getId());
|
||||
spellAbilityCopy.getManaCosts().clear();
|
||||
spellAbilityCopy.getManaCostsToPay().clear();
|
||||
spellAbilityCopy.getCosts().addAll(this.getCosts().copy());
|
||||
spellAbilityCopy.addCost(this.getManaCosts().copy());
|
||||
spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
|
||||
spellAbilityToResolve = spellAbilityCopy;
|
||||
}
|
||||
}
|
||||
return spellAbilityToResolve;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Costs<Cost> getCosts() {
|
||||
if (spellAbilityToResolve == null) {
|
||||
return super.getCosts();
|
||||
}
|
||||
return spellAbilityToResolve.getCosts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForetellCostAbility copy() {
|
||||
return new ForetellCostAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule(boolean all) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for split card in PlayerImpl method:
|
||||
* getOtherUseableActivatedAbilities
|
||||
*
|
||||
* @param abilityName
|
||||
*/
|
||||
public void setAbilityName(String abilityName) {
|
||||
this.abilityName = abilityName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,13 +74,12 @@ public class ForetellAbility extends SpecialAction {
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Foretell " + foretellCost + " <i>(During your turn, " +
|
||||
"you may pay {2} and exile this card from your hand face down. " +
|
||||
"Cast it on a later turn for its foretell cost.)</i>";
|
||||
return "Foretell " + foretellCost + " <i>(During your turn, "
|
||||
+ "you may pay {2} and exile this card from your hand face down. "
|
||||
+ "Cast it on a later turn for its foretell cost.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class ForetellExileEffect extends OneShotEffect {
|
||||
public class ForetellExileEffect extends OneShotEffect {
|
||||
|
||||
private final Card card;
|
||||
String foretellCost;
|
||||
|
@ -128,9 +127,9 @@ class ForetellExileEffect extends OneShotEffect {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ForetellLookAtCardEffect extends AsThoughEffectImpl {
|
||||
public class ForetellLookAtCardEffect extends AsThoughEffectImpl {
|
||||
|
||||
public ForetellLookAtCardEffect() {
|
||||
super(AsThoughEffectType.LOOK_AT_FACE_DOWN, Duration.EndOfGame, Outcome.AIDontUseIt);
|
||||
|
@ -168,10 +167,9 @@ class ForetellLookAtCardEffect extends AsThoughEffectImpl {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this needed to be a continuousEffect for a card like Dream Devourer...unless someone has a better idea
|
||||
class ForetellAddCostEffect extends ContinuousEffectImpl {
|
||||
public class ForetellAddCostEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final MageObjectReference mor;
|
||||
|
||||
|
@ -206,9 +204,9 @@ class ForetellAddCostEffect extends ContinuousEffectImpl {
|
|||
public ForetellAddCostEffect copy() {
|
||||
return new ForetellAddCostEffect(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ForetellCostAbility extends SpellAbility {
|
||||
public class ForetellCostAbility extends SpellAbility {
|
||||
|
||||
private String abilityName;
|
||||
private SpellAbility spellAbilityToResolve;
|
||||
|
@ -335,4 +333,5 @@ class ForetellCostAbility extends SpellAbility {
|
|||
this.abilityName = abilityName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue