mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
Convert AlternativeSourceCostsImpl keywords to using the costs tag system
This commit is contained in:
parent
bea33c7493
commit
f3d5faf199
7 changed files with 26 additions and 44 deletions
|
|
@ -3,7 +3,6 @@ package mage.abilities.condition.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.keyword.DashAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
|
|
@ -15,11 +14,6 @@ public enum DashedCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
return card != null
|
||||
&& CardUtil.castStream(card
|
||||
.getAbilities(game)
|
||||
.stream(), DashAbility.class)
|
||||
.anyMatch(ability -> ability.isActivated(source, game));
|
||||
return CardUtil.checkSourceCostsTagExists(game, source, DashAbility.getActivationKey());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ package mage.abilities.condition.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.keyword.EvokeAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* Checks if a the spell was cast with the alternate evoke costs
|
||||
|
|
@ -20,12 +20,6 @@ public enum EvokedCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
return card.getAbilities(game).stream()
|
||||
.filter(EvokeAbility.class::isInstance)
|
||||
.anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
|
||||
}
|
||||
return false;
|
||||
return CardUtil.checkSourceCostsTagExists(game, source, EvokeAbility.getActivationKey());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package mage.abilities.condition.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.keyword.ProwlAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* Checks if a the spell was cast with the alternate prowl costs
|
||||
|
|
@ -17,17 +17,7 @@ public enum ProwlCostWasPaidCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
for (Ability ability : card.getAbilities(game)) {
|
||||
if (ability instanceof ProwlAbility) {
|
||||
if (((ProwlAbility) ability).isActivated(source, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return CardUtil.checkSourceCostsTagExists(game, source, ProwlAbility.getActivationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import mage.abilities.SpellAbility;
|
|||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
|
@ -20,7 +20,10 @@ public abstract class AlternativeSourceCostsImpl extends StaticAbility implement
|
|||
|
||||
protected final AlternativeCost alternativeCost;
|
||||
protected final String reminderText;
|
||||
private int zoneChangeCounter = 0;
|
||||
protected final String activationKey;
|
||||
protected static String getActivationKey(String name){
|
||||
return name+"ActivationKey";
|
||||
}
|
||||
|
||||
protected AlternativeSourceCostsImpl(String name, String reminderText, String manaString) {
|
||||
this(name, reminderText, new ManaCostsImpl<>(manaString));
|
||||
|
|
@ -31,13 +34,14 @@ public abstract class AlternativeSourceCostsImpl extends StaticAbility implement
|
|||
this.name = name;
|
||||
this.reminderText = reminderText;
|
||||
this.alternativeCost = new AlternativeCostImpl<>(name, reminderText, cost);
|
||||
this.activationKey = getActivationKey(name);
|
||||
}
|
||||
|
||||
protected AlternativeSourceCostsImpl(final AlternativeSourceCostsImpl ability) {
|
||||
super(ability);
|
||||
this.alternativeCost = ability.alternativeCost.copy();
|
||||
this.reminderText = ability.reminderText;
|
||||
this.zoneChangeCounter = ability.zoneChangeCounter;
|
||||
this.activationKey = ability.activationKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -58,15 +62,9 @@ public abstract class AlternativeSourceCostsImpl extends StaticAbility implement
|
|||
|| !player.chooseUse(Outcome.Benefit, "Cast this for its " + this.name + " cost? (" + alternativeCost.getText(true) + ')', ability, game)) {
|
||||
return false;
|
||||
}
|
||||
ability.setCostsTag(activationKey, null);
|
||||
alternativeCost.activate();
|
||||
if (zoneChangeCounter == 0) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null) {
|
||||
zoneChangeCounter = card.getZoneChangeCounter(game);
|
||||
} else {
|
||||
throw new IllegalArgumentException("source card not found");
|
||||
}
|
||||
}
|
||||
|
||||
ability.clearManaCostsToPay();
|
||||
ability.clearCosts();
|
||||
for (Iterator<Cost> it = ((Costs<Cost>) alternativeCost).iterator(); it.hasNext(); ) {
|
||||
|
|
@ -82,11 +80,7 @@ public abstract class AlternativeSourceCostsImpl extends StaticAbility implement
|
|||
|
||||
@Override
|
||||
public boolean isActivated(Ability ability, Game game) {
|
||||
Card card = game.getCard(sourceId);
|
||||
if (card != null && card.getZoneChangeCounter(game) <= zoneChangeCounter + 1) {
|
||||
return alternativeCost.isActivated(game);
|
||||
}
|
||||
return false;
|
||||
return CardUtil.checkSourceCostsTagExists(game, ability, activationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -102,7 +96,6 @@ public abstract class AlternativeSourceCostsImpl extends StaticAbility implement
|
|||
@Override
|
||||
public void resetCost() {
|
||||
alternativeCost.reset();
|
||||
this.zoneChangeCounter = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ public class DashAbility extends AlternativeSourceCostsImpl {
|
|||
public DashAbility copy() {
|
||||
return new DashAbility(this);
|
||||
}
|
||||
public static String getActivationKey(){
|
||||
return getActivationKey(KEYWORD);
|
||||
}
|
||||
}
|
||||
|
||||
class DashAddDelayedTriggeredAbilityEffect extends OneShotEffect {
|
||||
|
|
|
|||
|
|
@ -39,4 +39,8 @@ public class EvokeAbility extends AlternativeSourceCostsImpl {
|
|||
public EvokeAbility copy() {
|
||||
return new EvokeAbility(this);
|
||||
}
|
||||
|
||||
public static String getActivationKey(){
|
||||
return getActivationKey(EVOKE_KEYWORD);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,8 @@ public class ProwlAbility extends AlternativeSourceCostsImpl {
|
|||
public boolean isAvailable(Ability source, Game game) {
|
||||
return ProwlCondition.instance.apply(game, source);
|
||||
}
|
||||
|
||||
public static String getActivationKey(){
|
||||
return getActivationKey(PROWL_KEYWORD);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue