mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
StaticAbilityCastWithFlash: refactor that it can be checked before targets
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package forge.game.spellability;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import forge.card.CardStateName;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.Game;
|
||||
@@ -100,7 +102,9 @@ public abstract class Spell extends SpellAbility implements java.io.Serializable
|
||||
card.setController(activator, 0);
|
||||
}
|
||||
|
||||
if (!this.getRestrictions().canPlay(getHostCard(), this)) {
|
||||
card = ObjectUtils.firstNonNull(getAlternateHost(card), card);
|
||||
|
||||
if (!this.getRestrictions().canPlay(card, this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ import forge.game.player.Player;
|
||||
import forge.game.player.PlayerCollection;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.staticability.StaticAbilityCastWithFlash;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
@@ -2059,17 +2060,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final Game game = activator.getGame();
|
||||
final CardCollection allp = new CardCollection(game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES));
|
||||
allp.add(host);
|
||||
for (final Card ca : allp) {
|
||||
for (final StaticAbility stAb : ca.getStaticAbilities()) {
|
||||
if (stAb.applyAbility("CastWithFlash", host, this, activator)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return StaticAbilityCastWithFlash.anyWithFlash(this, host, activator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import forge.game.card.*;
|
||||
import forge.game.cost.IndividualCostPaymentInstance;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.staticability.StaticAbilityCastWithFlash;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Expressions;
|
||||
@@ -503,6 +504,12 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
||||
System.out.println(c.getName() + " Did not have activator set in SpellAbilityRestriction.canPlay()");
|
||||
}
|
||||
|
||||
if (!StaticAbilityCastWithFlash.anyWithFlashNeedsTargeting(sa, c, activator)) {
|
||||
if (!sa.canCastTiming(c, activator)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sa.hasSVar("IsCastFromPlayEffect")) {
|
||||
if (!checkTimingRestrictions(c, sa)) {
|
||||
return false;
|
||||
|
||||
@@ -403,24 +403,6 @@ public class StaticAbility extends CardTraitBase implements IIdentifiable, Clone
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean applyAbility(final String mode, final Card card, final SpellAbility spellAbility, final Player player) {
|
||||
|
||||
// don't apply the ability if it hasn't got the right mode
|
||||
if (!getParam("Mode").equals(mode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isSuppressed() || !this.checkConditions()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode.equals("CastWithFlash")) {
|
||||
return StaticAbilityCastWithFlash.applyWithFlashAbility(this, spellAbility, card, player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean applyAbility(String mode, Card card, CounterType type) {
|
||||
|
||||
// don't apply the ability if it hasn't got the right mode
|
||||
|
||||
@@ -1,15 +1,57 @@
|
||||
package forge.game.staticability;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.game.GameObject;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObjectPredicates;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
public class StaticAbilityCastWithFlash {
|
||||
public static boolean applyWithFlashAbility(final StaticAbility stAb, final SpellAbility sa, final Card card, final Player activator) {
|
||||
|
||||
static String MODE = "CastWithFlash";
|
||||
|
||||
public static boolean anyWithFlashNeedsTargeting(final SpellAbility sa, final Card card, final Player activator) {
|
||||
final Game game = activator.getGame();
|
||||
final CardCollection allp = new CardCollection(game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES));
|
||||
allp.add(card);
|
||||
for (final Card ca : allp) {
|
||||
for (final StaticAbility stAb : ca.getStaticAbilities()) {
|
||||
if (!stAb.getParam("Mode").equals(MODE) || stAb.isSuppressed() || !stAb.checkConditions()) {
|
||||
continue;
|
||||
}
|
||||
if (applyWithFlashNeedsTargeting(stAb, sa, card, activator)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean anyWithFlash(final SpellAbility sa, final Card card, final Player activator) {
|
||||
final Game game = activator.getGame();
|
||||
final CardCollection allp = new CardCollection(game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES));
|
||||
allp.add(card);
|
||||
for (final Card ca : allp) {
|
||||
for (final StaticAbility stAb : ca.getStaticAbilities()) {
|
||||
if (!stAb.getParam("Mode").equals(MODE) || stAb.isSuppressed() || !stAb.checkConditions()) {
|
||||
continue;
|
||||
}
|
||||
if (applyWithFlashAbility(stAb, sa, card, activator)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean commonParts(final StaticAbility stAb, final SpellAbility sa, final Card card, final Player activator) {
|
||||
final Card hostCard = stAb.getHostCard();
|
||||
|
||||
if (stAb.hasParam("ValidCard")
|
||||
@@ -26,27 +68,31 @@ public class StaticAbilityCastWithFlash {
|
||||
&& !activator.isValid(stAb.getParam("Caster"), hostCard.getController(), hostCard, null)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean applyWithFlashNeedsTargeting(final StaticAbility stAb, final SpellAbility sa, final Card card, final Player activator) {
|
||||
if (!commonParts(stAb, sa, card, activator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stAb.hasParam("Targeting");
|
||||
}
|
||||
|
||||
public static boolean applyWithFlashAbility(final StaticAbility stAb, final SpellAbility sa, final Card card, final Player activator) {
|
||||
final Card hostCard = stAb.getHostCard();
|
||||
|
||||
if (!commonParts(stAb, sa, card, activator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stAb.hasParam("Targeting")) {
|
||||
if (!sa.usesTargeting()) {
|
||||
return false;
|
||||
}
|
||||
boolean found = false;
|
||||
String[] valids = stAb.getParam("Targeting").split(",");
|
||||
for (GameObject ga : sa.getTargets()) {
|
||||
if (ga.isValid(valids, hostCard.getController(), hostCard, null)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (stAb.hasParam("Origin")) {
|
||||
List<ZoneType> src = ZoneType.listValueOf(stAb.getParam("Origin"));
|
||||
if (!src.contains(hostCard.getGame().getZoneOf(card).getZoneType())) {
|
||||
String[] valids = stAb.getParam("Targeting").split(",");
|
||||
if (!Iterables.any(sa.getTargets(), GameObjectPredicates.restriction(valids, hostCard.getController(), hostCard, null))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user