mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Combine into one class
This commit is contained in:
@@ -25,6 +25,7 @@ public enum AbilityKey {
|
||||
AttackedTarget("AttackedTarget"),
|
||||
Blocker("Blocker"),
|
||||
Blockers("Blockers"),
|
||||
CastOrCopy("CastOrCopy"),
|
||||
CastSA("CastSA"),
|
||||
CastSACMC("CastSACMC"),
|
||||
Card("Card"),
|
||||
@@ -33,7 +34,6 @@ public enum AbilityKey {
|
||||
Cause("Cause"),
|
||||
Causer("Causer"),
|
||||
Championed("Championed"),
|
||||
CopySA("CopySA"),
|
||||
Cost("Cost"),
|
||||
CostStack("CostStack"),
|
||||
CounterAmount("CounterAmount"),
|
||||
|
||||
@@ -50,7 +50,7 @@ import forge.util.Localizer;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TriggerSpellAbilityCast extends Trigger {
|
||||
public class TriggerSpellAbilityCastOrCopy extends Trigger {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -64,7 +64,7 @@ public class TriggerSpellAbilityCast extends Trigger {
|
||||
* @param intrinsic
|
||||
* the intrinsic
|
||||
*/
|
||||
public TriggerSpellAbilityCast(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
public TriggerSpellAbilityCastOrCopy(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
@@ -80,17 +80,31 @@ public class TriggerSpellAbilityCast extends Trigger {
|
||||
final Card cast = spellAbility.getHostCard();
|
||||
final Game game = cast.getGame();
|
||||
final SpellAbilityStackInstance si = game.getStack().getInstanceFromSpellAbility(spellAbility);
|
||||
String castOrCopy = (String) runParams.get(AbilityKey.CastOrCopy);
|
||||
|
||||
if (this.getMode() == TriggerType.SpellCast) {
|
||||
if (!spellAbility.isSpell()) {
|
||||
// Specific checks for trigger types
|
||||
if (castOrCopy.equals("Copy")) {
|
||||
if (this.getMode().equals(TriggerType.AbilityCast) ||
|
||||
this.getMode().equals(TriggerType.SpellAbilityCast) ||
|
||||
this.getMode().equals(TriggerType.SpellCast)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.getMode() == TriggerType.AbilityCast) {
|
||||
if (!spellAbility.isAbility()) {
|
||||
} else if (castOrCopy.equals("Cast")) {
|
||||
if (this.getMode().equals(TriggerType.SpellAbilityCopy) ||
|
||||
this.getMode().equals(TriggerType.SpellCopy)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (spellAbility.isSpell()) {
|
||||
if (this.getMode().equals(TriggerType.AbilityCast)) {
|
||||
return false;
|
||||
}
|
||||
} else if (spellAbility.isAbility()) {
|
||||
if (this.getMode().equals(TriggerType.SpellCast) ||
|
||||
this.getMode().equals(TriggerType.SpellCopy) ||
|
||||
this.getMode().equals(TriggerType.SpellCastOrCopy)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.getMode() == TriggerType.SpellAbilityCast) {
|
||||
// Empty block for readability.
|
||||
}
|
||||
|
||||
if (hasParam("ActivatedOnly")) {
|
||||
@@ -100,6 +114,10 @@ public class TriggerSpellAbilityCast extends Trigger {
|
||||
}
|
||||
|
||||
|
||||
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Player))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!matchesValidParam("ValidControllingPlayer", cast.getController())) {
|
||||
return false;
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.util.Localizer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Trigger_SpellAbilityCopy class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TriggerSpellAbilityCopy extends Trigger {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Trigger_SpellAbilityCopy.
|
||||
* </p>
|
||||
*
|
||||
* @param params
|
||||
* a {@link java.util.HashMap} object.
|
||||
* @param host
|
||||
* a {@link forge.game.card.Card} object.
|
||||
* @param intrinsic
|
||||
* the intrinsic
|
||||
*/
|
||||
public TriggerSpellAbilityCopy(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* @param runParams*/
|
||||
@Override
|
||||
public final boolean performTest(final Map<AbilityKey, Object> runParams) {
|
||||
final SpellAbility spellAbility = (SpellAbility) runParams.get(AbilityKey.CopySA);
|
||||
if (spellAbility == null) {
|
||||
System.out.println("TriggerSpellAbilityCopy performTest encountered spellAbility == null. runParams2 = " + runParams);
|
||||
return false;
|
||||
}
|
||||
final Card cast = spellAbility.getHostCard();
|
||||
final Game game = cast.getGame();
|
||||
final SpellAbilityStackInstance si = game.getStack().getInstanceFromSpellAbility(spellAbility);
|
||||
|
||||
if (this.getMode() == TriggerType.SpellCopy) {
|
||||
if (!spellAbility.isSpell()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchesValidParam("ValidCard", cast)) {
|
||||
return false;
|
||||
}
|
||||
if (!matchesValidParam("ValidSA", spellAbility)) {
|
||||
return false;
|
||||
}
|
||||
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Player))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasParam("ValidActivatingPlayer")) {
|
||||
if (si == null || !matchesValid(si.getSpellAbility(true).getActivatingPlayer(), getParam("ValidActivatingPlayer").split(","))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa, Map<AbilityKey, Object> runParams) {
|
||||
final SpellAbility copySA = (SpellAbility) runParams.get(AbilityKey.CopySA);
|
||||
final SpellAbilityStackInstance si = sa.getHostCard().getGame().getStack().getInstanceFromSpellAbility(copySA);
|
||||
sa.setTriggeringObject(AbilityKey.Card, copySA.getHostCard());
|
||||
sa.setTriggeringObject(AbilityKey.SpellAbility, copySA);
|
||||
sa.setTriggeringObject(AbilityKey.StackInstance, si);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Localizer.getInstance().getMessage("lblCard")).append(": ").append(sa.getTriggeringObject(AbilityKey.Card)).append(", ");
|
||||
sb.append(Localizer.getInstance().getMessage("lblActivator")).append(": ").append(sa.getTriggeringObject(AbilityKey.Activator)).append(", ");
|
||||
sb.append(Localizer.getInstance().getMessage("lblSpellAbility")).append(": ").append(sa.getTriggeringObject(AbilityKey.SpellAbility));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game.trigger;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.util.Localizer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Trigger_SpellAbilityCopy class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TriggerSpellCastOrCopy extends Trigger {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Trigger_SpellCastOrCopy.
|
||||
* </p>
|
||||
*
|
||||
* @param params
|
||||
* a {@link java.util.HashMap} object.
|
||||
* @param host
|
||||
* a {@link Card} object.
|
||||
* @param intrinsic
|
||||
* the intrinsic
|
||||
*/
|
||||
public TriggerSpellCastOrCopy(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* @param runParams*/
|
||||
@Override
|
||||
public final boolean performTest(final Map<AbilityKey, Object> runParams) {
|
||||
final SpellAbility spellAbility = (SpellAbility) runParams.get(AbilityKey.CastSA);
|
||||
if (spellAbility == null) {
|
||||
System.out.println("TriggerSpellCastOrCopy performTest encountered spellAbility == null. runParams2 = " + runParams);
|
||||
return false;
|
||||
}
|
||||
final Card cast = spellAbility.getHostCard();
|
||||
final Game game = cast.getGame();
|
||||
final SpellAbilityStackInstance si = game.getStack().getInstanceFromSpellAbility(spellAbility);
|
||||
|
||||
if (!matchesValidParam("ValidCard", cast)) {
|
||||
return false;
|
||||
}
|
||||
if (!matchesValidParam("ValidSA", spellAbility)) {
|
||||
return false;
|
||||
}
|
||||
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Player))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasParam("ValidActivatingPlayer")) {
|
||||
if (si == null || !matchesValid(si.getSpellAbility(true).getActivatingPlayer(), getParam("ValidActivatingPlayer").split(","))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa, Map<AbilityKey, Object> runParams) {
|
||||
final SpellAbility castSA = (SpellAbility) runParams.get(AbilityKey.CastSA);
|
||||
final SpellAbilityStackInstance si = sa.getHostCard().getGame().getStack().getInstanceFromSpellAbility(castSA);
|
||||
sa.setTriggeringObject(AbilityKey.Card, castSA.getHostCard());
|
||||
sa.setTriggeringObject(AbilityKey.SpellAbility, castSA);
|
||||
sa.setTriggeringObject(AbilityKey.StackInstance, si);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Localizer.getInstance().getMessage("lblCard")).append(": ").append(sa.getTriggeringObject(AbilityKey.Card)).append(", ");
|
||||
sb.append(Localizer.getInstance().getMessage("lblActivator")).append(": ").append(sa.getTriggeringObject(AbilityKey.Activator)).append(", ");
|
||||
sb.append(Localizer.getInstance().getMessage("lblSpellAbility")).append(": ").append(sa.getTriggeringObject(AbilityKey.SpellAbility));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import forge.game.card.Card;
|
||||
*/
|
||||
public enum TriggerType {
|
||||
Abandoned(TriggerAbandoned.class),
|
||||
AbilityCast(TriggerSpellAbilityCast.class),
|
||||
AbilityCast(TriggerSpellAbilityCastOrCopy.class),
|
||||
Adapt(TriggerAdapt.class),
|
||||
Always(TriggerAlways.class),
|
||||
Attached(TriggerAttached.class),
|
||||
@@ -90,11 +90,11 @@ public enum TriggerType {
|
||||
SearchedLibrary(TriggerSearchedLibrary.class),
|
||||
SetInMotion(TriggerSetInMotion.class),
|
||||
Shuffled(TriggerShuffled.class),
|
||||
SpellAbilityCast(TriggerSpellAbilityCast.class),
|
||||
SpellAbilityCopy(TriggerSpellAbilityCopy.class),
|
||||
SpellCast(TriggerSpellAbilityCast.class),
|
||||
SpellCastOrCopy(TriggerSpellCastOrCopy.class),
|
||||
SpellCopy(TriggerSpellAbilityCopy.class),
|
||||
SpellAbilityCast(TriggerSpellAbilityCastOrCopy.class),
|
||||
SpellAbilityCopy(TriggerSpellAbilityCastOrCopy.class),
|
||||
SpellCast(TriggerSpellAbilityCastOrCopy.class),
|
||||
SpellCastOrCopy(TriggerSpellAbilityCastOrCopy.class),
|
||||
SpellCopy(TriggerSpellAbilityCastOrCopy.class),
|
||||
Surveil(TriggerSurveil.class),
|
||||
Taps(TriggerTaps.class),
|
||||
TapsForMana(TriggerTapsForMana.class),
|
||||
|
||||
@@ -293,15 +293,16 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
|
||||
|
||||
// Copied spells aren't cast per se so triggers shouldn't run for them.
|
||||
Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
||||
runParams.put(AbilityKey.Cost, sp.getPayCosts());
|
||||
runParams.put(AbilityKey.Player, sp.getHostCard().getController());
|
||||
runParams.put(AbilityKey.Activator, sp.getActivatingPlayer());
|
||||
runParams.put(AbilityKey.CastSA, si.getSpellAbility(true));
|
||||
runParams.put(AbilityKey.CastSACMC, si.getSpellAbility(true).getHostCard().getCMC());
|
||||
runParams.put(AbilityKey.CurrentStormCount, thisTurnCast.size());
|
||||
runParams.put(AbilityKey.CurrentCastSpells, Lists.newArrayList(thisTurnCast));
|
||||
if (!sp.isCopied()) {
|
||||
runParams.put(AbilityKey.CastOrCopy, "Cast");
|
||||
// Run SpellAbilityCast triggers
|
||||
runParams.put(AbilityKey.Cost, sp.getPayCosts());
|
||||
runParams.put(AbilityKey.Player, sp.getHostCard().getController());
|
||||
runParams.put(AbilityKey.Activator, sp.getActivatingPlayer());
|
||||
runParams.put(AbilityKey.CastSA, si.getSpellAbility(true));
|
||||
runParams.put(AbilityKey.CastSACMC, si.getSpellAbility(true).getHostCard().getCMC());
|
||||
runParams.put(AbilityKey.CurrentStormCount, thisTurnCast.size());
|
||||
runParams.put(AbilityKey.CurrentCastSpells, Lists.newArrayList(thisTurnCast));
|
||||
game.getTriggerHandler().runTrigger(TriggerType.SpellAbilityCast, runParams, true);
|
||||
|
||||
sp.applyPayingManaEffects();
|
||||
@@ -333,11 +334,8 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
|
||||
game.getTriggerHandler().runTrigger(TriggerType.Crewed, runParams, false);
|
||||
}
|
||||
} else {
|
||||
// Run SpellAbilityCopy triggers
|
||||
runParams.put(AbilityKey.Activator, sp.getActivatingPlayer());
|
||||
runParams.put(AbilityKey.CopySA, si.getSpellAbility(true));
|
||||
runParams.put(AbilityKey.CastSA, si.getSpellAbility(true));
|
||||
// Run SpellCopy triggers
|
||||
runParams.put(AbilityKey.CastOrCopy, "Copy");
|
||||
// Run Copy triggers
|
||||
if (sp.isSpell()) {
|
||||
game.getTriggerHandler().runTrigger(TriggerType.SpellCopy, runParams, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user