mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
static keyword may be accessed as method of Trigger
triggers are stored as list (unlike array)
This commit is contained in:
@@ -43,6 +43,11 @@ public abstract class AllZoneUtil {
|
||||
*/
|
||||
public static CardList getCardsIn(final Constant.Zone zone) {
|
||||
final CardList cards = new CardList();
|
||||
getCardsIn(zone, cards);
|
||||
return cards;
|
||||
}
|
||||
|
||||
private static void getCardsIn(final Constant.Zone zone, final CardList cards) {
|
||||
if (zone == Zone.Stack) {
|
||||
cards.addAll(AllZone.getStackZone().getCards());
|
||||
} else {
|
||||
@@ -50,32 +55,25 @@ public abstract class AllZoneUtil {
|
||||
cards.addAll(p.getZone(zone).getCards());
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getCardsIn.
|
||||
*
|
||||
* @param zones
|
||||
* a List<Constant.Zone>
|
||||
* @return CardList
|
||||
*/
|
||||
public static CardList getCardsIn(final List<Constant.Zone> zones) {
|
||||
}
|
||||
|
||||
public static CardList getCardsIn(final Iterable<Constant.Zone> zones) {
|
||||
final CardList cards = new CardList();
|
||||
for (final Zone z : zones) {
|
||||
if (z == Zone.Stack) {
|
||||
cards.addAll(AllZone.getStackZone().getCards());
|
||||
continue;
|
||||
}
|
||||
|
||||
for (final Player p : AllZone.getPlayersInGame()) {
|
||||
cards.addAll(p.getZone(z).getCards());
|
||||
}
|
||||
getCardsIn(z, cards);
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
public static CardList getCardsIn(final Constant.Zone[] zones) {
|
||||
final CardList cards = new CardList();
|
||||
for (final Zone z : zones) {
|
||||
getCardsIn(z, cards);
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gets a list of all cards owned by both players that have are currently in
|
||||
* the given zone.
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
@@ -689,7 +690,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final ArrayList<Trigger> getTriggers() {
|
||||
public final List<Trigger> getTriggers() {
|
||||
return this.getCharacteristics().getTriggers();
|
||||
}
|
||||
|
||||
@@ -720,7 +721,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
* @param trigs
|
||||
* a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final void setTriggers(final ArrayList<Trigger> trigs) {
|
||||
public final void setTriggers(final List<Trigger> trigs) {
|
||||
final ArrayList<Trigger> copyList = new ArrayList<Trigger>();
|
||||
for (final Trigger t : trigs) {
|
||||
if (t.getIsIntrinsic()) {
|
||||
@@ -6613,7 +6614,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
if (!shares) {
|
||||
return false;
|
||||
}
|
||||
} else if (restriction.equals("Battlefield")) {
|
||||
} else if (restriction.equals(Constant.Zone.Battlefield.toString())) {
|
||||
final CardList list = AllZoneUtil.getCardsIn(Constant.Zone.Battlefield);
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
|
||||
@@ -151,14 +151,13 @@ public class ComputerAIGeneral implements Computer {
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean hasETBTrigger(final Card card) {
|
||||
final ArrayList<Trigger> triggers = card.getTriggers();
|
||||
for (final Trigger tr : triggers) {
|
||||
for (final Trigger tr : card.getTriggers()) {
|
||||
final HashMap<String, String> params = tr.getMapParams();
|
||||
if (tr.getMode() != TriggerType.ChangesZone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!params.get("Destination").equals("Battlefield")) {
|
||||
if (!params.get("Destination").equals(Zone.Battlefield.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,7 @@ public class ComputerUtilAttack {
|
||||
|
||||
// Cards with triggers should come first (for Battle Cry)
|
||||
for (final Card attacker : in) {
|
||||
final ArrayList<Trigger> registeredTriggers = attacker.getTriggers();
|
||||
for (final Trigger trigger : registeredTriggers) {
|
||||
for (final Trigger trigger : attacker.getTriggers()) {
|
||||
if (trigger.getMode() == TriggerType.Attacks) {
|
||||
list.add(attacker);
|
||||
}
|
||||
|
||||
@@ -204,7 +204,9 @@ public final class Constant {
|
||||
Sideboard(true),
|
||||
/** Ante. */
|
||||
Ante(false);
|
||||
|
||||
|
||||
public static final Zone[] StaticAbilitiesSourceZones = new Zone[]{Battlefield, Graveyard, Exile, Hand};
|
||||
|
||||
private final boolean holdsHiddenInfo;
|
||||
private Zone(boolean holdsHidden) {
|
||||
holdsHiddenInfo = holdsHidden;
|
||||
@@ -254,7 +256,7 @@ public final class Constant {
|
||||
|
||||
public boolean isKnown() {
|
||||
return !holdsHiddenInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1380,6 +1380,15 @@ public abstract class Player extends GameEntity {
|
||||
return result;
|
||||
}
|
||||
|
||||
public final CardList getCardsIn(final Constant.Zone[] zones) {
|
||||
final CardList result = new CardList();
|
||||
for (final Constant.Zone z : zones) {
|
||||
if (this.getZone(z) != null) {
|
||||
result.addAll(this.getZone(z).getCards());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* gets a list of all cards with requested cardName in a given player's
|
||||
* requested zone. This function makes a CardList from Card[].
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.CardColor;
|
||||
import forge.card.replacement.ReplacementEffect;
|
||||
@@ -264,7 +265,7 @@ public class CardCharacteristics {
|
||||
*
|
||||
* @return the triggers
|
||||
*/
|
||||
public final ArrayList<Trigger> getTriggers() {
|
||||
public final List<Trigger> getTriggers() {
|
||||
return this.triggers;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge.card.abilityfactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.AllZone;
|
||||
@@ -627,7 +628,7 @@ public final class AbilityFactoryAnimate {
|
||||
// suppress triggers from the animated card
|
||||
final ArrayList<Trigger> removedTriggers = new ArrayList<Trigger>();
|
||||
if (params.containsKey("OverwriteTriggers") || params.containsKey("RemoveAllAbilities")) {
|
||||
final ArrayList<Trigger> triggersToRemove = c.getTriggers();
|
||||
final List<Trigger> triggersToRemove = c.getTriggers();
|
||||
for (final Trigger trigger : triggersToRemove) {
|
||||
trigger.setSuppressed(true);
|
||||
removedTriggers.add(trigger);
|
||||
@@ -1251,7 +1252,7 @@ public final class AbilityFactoryAnimate {
|
||||
// suppress triggers from the animated card
|
||||
final ArrayList<Trigger> removedTriggers = new ArrayList<Trigger>();
|
||||
if (params.containsKey("OverwriteTriggers") || params.containsKey("RemoveAllAbilities")) {
|
||||
final ArrayList<Trigger> triggersToRemove = c.getTriggers();
|
||||
final List<Trigger> triggersToRemove = c.getTriggers();
|
||||
for (final Trigger trigger : triggersToRemove) {
|
||||
trigger.setSuppressed(true);
|
||||
removedTriggers.add(trigger);
|
||||
|
||||
@@ -428,8 +428,7 @@ public class SpellPermanent extends Spell {
|
||||
}
|
||||
|
||||
// Trigger play improvements
|
||||
final ArrayList<Trigger> triggers = card.getTriggers();
|
||||
for (final Trigger tr : triggers) {
|
||||
for (final Trigger tr : card.getTriggers()) {
|
||||
// These triggers all care for ETB effects
|
||||
|
||||
final HashMap<String, String> params = tr.getMapParams();
|
||||
@@ -437,7 +436,7 @@ public class SpellPermanent extends Spell {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!params.get("Destination").equals("Battlefield")) {
|
||||
if (!params.get("Destination").equals(Zone.Battlefield.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,8 +312,7 @@ public class StaticAbilityContinuous {
|
||||
|
||||
// remove triggers
|
||||
if (params.containsKey("RemoveTriggers") || removeAllAbilities) {
|
||||
final ArrayList<Trigger> triggers = affectedCard.getTriggers();
|
||||
for (final Trigger trigger : triggers) {
|
||||
for (final Trigger trigger : affectedCard.getTriggers()) {
|
||||
trigger.setTemporarilySuppressed(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,4 +725,12 @@ public abstract class Trigger extends TriggerReplacementBase {
|
||||
copy.setID(this.getId());
|
||||
copy.setMode(this.getMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return getMapParams().containsKey("Static"); // && params.get("Static").equals("True") [always true if present]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,13 +341,13 @@ public class TriggerHandler {
|
||||
// This is done to allow the list of triggers to be modified while
|
||||
// triggers are running.
|
||||
final ArrayList<Trigger> delayedTriggersWorkingCopy = new ArrayList<Trigger>(this.delayedTriggers);
|
||||
CardList allCards = AllZoneUtil.getCardsInGame();
|
||||
CardList allCards = AllZoneUtil.getCardsIn(Zone.StaticAbilitiesSourceZones);
|
||||
boolean checkStatics = false;
|
||||
|
||||
// Static triggers
|
||||
for (final Card c : allCards) {
|
||||
for (final Trigger t : c.getTriggers()) {
|
||||
if (t.getMapParams().containsKey("Static")) {
|
||||
if (t.isStatic()) {
|
||||
checkStatics |= this.runSingleTrigger(t, mode, runParams);
|
||||
}
|
||||
}
|
||||
@@ -358,11 +358,11 @@ public class TriggerHandler {
|
||||
}
|
||||
|
||||
// AP
|
||||
allCards = playerAP.getAllCards();
|
||||
allCards = playerAP.getCardsIn(Zone.StaticAbilitiesSourceZones);
|
||||
allCards.addAll(AllZoneUtil.getCardsIn(Constant.Zone.Stack).getController(playerAP));
|
||||
for (final Card c : allCards) {
|
||||
for (final Trigger t : c.getTriggers()) {
|
||||
if (!t.getMapParams().containsKey("Static")) {
|
||||
if (!t.isStatic()) {
|
||||
this.runSingleTrigger(t, mode, runParams);
|
||||
}
|
||||
}
|
||||
@@ -379,11 +379,11 @@ public class TriggerHandler {
|
||||
}
|
||||
|
||||
// NAP
|
||||
allCards = playerAP.getOpponent().getAllCards();
|
||||
allCards = playerAP.getOpponent().getCardsIn(Zone.StaticAbilitiesSourceZones);
|
||||
allCards.addAll(AllZoneUtil.getCardsIn(Constant.Zone.Stack).getController(playerAP.getOpponent()));
|
||||
for (final Card c : allCards) {
|
||||
for (final Trigger t : c.getTriggers()) {
|
||||
if (!t.getMapParams().containsKey("Static")) {
|
||||
if (!t.isStatic()) {
|
||||
this.runSingleTrigger(t, mode, runParams);
|
||||
}
|
||||
}
|
||||
@@ -451,18 +451,12 @@ public class TriggerHandler {
|
||||
// Torpor Orb check
|
||||
final CardList torporOrbs = AllZoneUtil.getCardsIn(Zone.Battlefield, "Torpor Orb");
|
||||
|
||||
if (torporOrbs.size() != 0) {
|
||||
if (params.containsKey("Destination")) {
|
||||
if ((params.get("Destination").equals("Battlefield") || params.get("Destination").equals("Any"))
|
||||
&& mode.equals("ChangesZone")
|
||||
&& ((params.get("ValidCard").contains("Creature")) || (params.get("ValidCard").contains("Self") && regtrig
|
||||
.getHostCard().isCreature()))) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (mode.equals("ChangesZone")
|
||||
&& ((params.get("ValidCard").contains("Creature")) || (params.get("ValidCard").contains("Self") && regtrig
|
||||
.getHostCard().isCreature()))) {
|
||||
if (torporOrbs.size() != 0 && mode == TriggerType.ChangesZone) {
|
||||
String destination = params.get("Destination");
|
||||
// if destination is not set, or set to 'battlefield' or 'any'
|
||||
if (null == destination || Zone.Battlefield.toString().equals(destination) || "Any".equals(destination) ) {
|
||||
if (params.get("ValidCard").contains("Creature")
|
||||
|| (params.get("ValidCard").contains("Self") && regtrig.getHostCard().isCreature())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1074,7 +1068,7 @@ public class TriggerHandler {
|
||||
// Card src = (Card)(sa[0].getSourceCard().getTriggeringObject("Card"));
|
||||
// System.out.println("Trigger going on stack for "+mode+". Card = "+src);
|
||||
|
||||
if (params.containsKey("Static") && params.get("Static").equals("True")) {
|
||||
if (regtrig.isStatic()) {
|
||||
Singletons.getModel().getGameAction().playSpellAbilityNoStack(wrapperAbility, false);
|
||||
} else {
|
||||
AllZone.getStack().addSimultaneousStackEntry(wrapperAbility);
|
||||
|
||||
Reference in New Issue
Block a user