removed FModel.getGame method.

please retrieve the GameState instance from nearby players
This commit is contained in:
Maxmtg
2013-04-23 13:18:58 +00:00
parent 01fb283285
commit 3b4f1dbb05
186 changed files with 1246 additions and 1291 deletions

View File

@@ -61,6 +61,7 @@ import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
import forge.card.trigger.ZCTrigger; import forge.card.trigger.ZCTrigger;
import forge.game.GameActionUtil; import forge.game.GameActionUtil;
import forge.game.GameState;
import forge.game.GlobalRuleChange; import forge.game.GlobalRuleChange;
import forge.game.event.CardEquippedEvent; import forge.game.event.CardEquippedEvent;
import forge.game.event.CounterAddedEvent; import forge.game.event.CounterAddedEvent;
@@ -264,7 +265,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|| (cur == CardCharacteristicName.Transformed && state == CardCharacteristicName.Original)) { || (cur == CardCharacteristicName.Transformed && state == CardCharacteristicName.Original)) {
HashMap<String, Object> runParams = new HashMap<String, Object>(); HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Transformer", this); runParams.put("Transformer", this);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Transformed, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.Transformed, runParams, false);
} }
return true; return true;
@@ -369,12 +370,12 @@ public class Card extends GameEntity implements Comparable<Card> {
HashMap<String, Object> repParams = new HashMap<String, Object>(); HashMap<String, Object> repParams = new HashMap<String, Object>();
repParams.put("Event", "TurnFaceUp"); repParams.put("Event", "TurnFaceUp");
repParams.put("Affected", this); repParams.put("Affected", this);
Singletons.getModel().getGame().getReplacementHandler().run(repParams); getGame().getReplacementHandler().run(repParams);
// Run triggers // Run triggers
final Map<String, Object> runParams = new TreeMap<String, Object>(); final Map<String, Object> runParams = new TreeMap<String, Object>();
runParams.put("Card", this); runParams.put("Card", this);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.TurnFaceUp, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.TurnFaceUp, runParams, false);
} }
return result; return result;
} }
@@ -1193,11 +1194,11 @@ public class Card extends GameEntity implements Comparable<Card> {
runParams.put("Card", this); runParams.put("Card", this);
runParams.put("CounterType", counterType); runParams.put("CounterType", counterType);
for (int i = 0; i < addAmount; i++) { for (int i = 0; i < addAmount; i++) {
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.CounterAdded, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.CounterAdded, runParams, false);
} }
// play the Add Counter sound // play the Add Counter sound
Singletons.getModel().getGame().getEvents().post(new CounterAddedEvent(addAmount)); getGame().getEvents().post(new CounterAddedEvent(addAmount));
this.updateObservers(); this.updateObservers();
} }
@@ -1264,23 +1265,23 @@ public class Card extends GameEntity implements Comparable<Card> {
runParams.put("Card", this); runParams.put("Card", this);
runParams.put("CounterType", counterName); runParams.put("CounterType", counterName);
for (int i = 0; i < delta; i++) { for (int i = 0; i < delta; i++) {
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.CounterRemoved, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.CounterRemoved, runParams, false);
} }
if (counterName.equals(CounterType.TIME) && (newValue == 0)) { if (counterName.equals(CounterType.TIME) && (newValue == 0)) {
final boolean hasVanish = CardFactoryUtil.hasKeyword(this, "Vanishing") != -1; final boolean hasVanish = CardFactoryUtil.hasKeyword(this, "Vanishing") != -1;
if (hasVanish && this.isInPlay()) { if (hasVanish && this.isInPlay()) {
Singletons.getModel().getGame().getAction().sacrifice(this, null); getGame().getAction().sacrifice(this, null);
} }
if (this.hasSuspend() && Singletons.getModel().getGame().isCardExiled(this)) { if (this.hasSuspend() && getGame().isCardExiled(this)) {
getOwner().getController().playFromSuspend(this); getOwner().getController().playFromSuspend(this);
} }
} }
// Play the Subtract Counter sound // Play the Subtract Counter sound
Singletons.getModel().getGame().getEvents().post(new CounterRemovedEvent(delta)); getGame().getEvents().post(new CounterRemovedEvent(delta));
this.updateObservers(); this.updateObservers();
} }
@@ -3171,7 +3172,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/ */
public final void addEquipping(final Card c) { public final void addEquipping(final Card c) {
this.equipping.add(c); this.equipping.add(c);
this.setTimestamp(Singletons.getModel().getGame().getNextTimestamp()); this.setTimestamp(getGame().getNextTimestamp());
this.updateObservers(); this.updateObservers();
} }
@@ -3199,7 +3200,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/ */
public final void equipCard(final Card c) { public final void equipCard(final Card c) {
if (c.hasKeyword("CARDNAME can't be equipped.")) { if (c.hasKeyword("CARDNAME can't be equipped.")) {
Singletons.getModel().getGame().getGameLog().add("ResolveStack", "Trying to equip " + c.getName() getGame().getGameLog().add("ResolveStack", "Trying to equip " + c.getName()
+ " but it can't be equipped.", 2); + " but it can't be equipped.", 2);
return; return;
} }
@@ -3209,7 +3210,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final String[] k = parse.split(" ", 2); final String[] k = parse.split(" ", 2);
final String[] restrictions = k[1].split(","); final String[] restrictions = k[1].split(",");
if (c.isValid(restrictions, this.getController(), this)) { if (c.isValid(restrictions, this.getController(), this)) {
Singletons.getModel().getGame().getGameLog().add("ResolveStack", "Trying to equip " + c.getName() getGame().getGameLog().add("ResolveStack", "Trying to equip " + c.getName()
+ " but it can't be equipped.", 2); + " but it can't be equipped.", 2);
return; return;
} }
@@ -3221,7 +3222,7 @@ public class Card extends GameEntity implements Comparable<Card> {
c.addEquippedBy(this); c.addEquippedBy(this);
// Play the Equip sound // Play the Equip sound
Singletons.getModel().getGame().getEvents().post(new CardEquippedEvent()); getGame().getEvents().post(new CardEquippedEvent());
// run trigger // run trigger
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("AttachSource", this); runParams.put("AttachSource", this);
@@ -3246,7 +3247,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final Map<String, Object> runParams = new TreeMap<String, Object>(); final Map<String, Object> runParams = new TreeMap<String, Object>();
runParams.put("Equipment", this); runParams.put("Equipment", this);
runParams.put("Card", c); runParams.put("Card", c);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Unequip, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.Unequip, runParams, false);
} }
/** /**
@@ -3373,7 +3374,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/ */
public final void addEnchanting(final GameEntity e) { public final void addEnchanting(final GameEntity e) {
this.enchanting = e; this.enchanting = e;
this.setTimestamp(Singletons.getModel().getGame().getNextTimestamp()); this.setTimestamp(getGame().getNextTimestamp());
this.updateObservers(); this.updateObservers();
} }
@@ -3402,7 +3403,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/ */
public final void enchantEntity(final GameEntity entity) { public final void enchantEntity(final GameEntity entity) {
if (entity.hasKeyword("CARDNAME can't be enchanted.")) { if (entity.hasKeyword("CARDNAME can't be enchanted.")) {
Singletons.getModel().getGame().getGameLog().add("ResolveStack", "Trying to enchant " + entity.getName() getGame().getGameLog().add("ResolveStack", "Trying to enchant " + entity.getName()
+ " but it can't be enchanted.", 2); + " but it can't be enchanted.", 2);
return; return;
} }
@@ -3895,7 +3896,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return 0; return 0;
} }
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.toughnessAssignsDamage)) { if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.toughnessAssignsDamage)) {
return this.getNetDefense(); return this.getNetDefense();
} }
return this.getNetAttack(); return this.getNetAttack();
@@ -4133,12 +4134,12 @@ public class Card extends GameEntity implements Comparable<Card> {
// Run triggers // Run triggers
final Map<String, Object> runParams = new TreeMap<String, Object>(); final Map<String, Object> runParams = new TreeMap<String, Object>();
runParams.put("Card", this); runParams.put("Card", this);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Taps, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.Taps, runParams, false);
} }
this.setTapped(true); this.setTapped(true);
// Play the Tap sound // Play the Tap sound
Singletons.getModel().getGame().getEvents().post(new SetTappedEvent(true)); getGame().getEvents().post(new SetTappedEvent(true));
} }
/** /**
@@ -4151,10 +4152,10 @@ public class Card extends GameEntity implements Comparable<Card> {
// Run triggers // Run triggers
final Map<String, Object> runParams = new TreeMap<String, Object>(); final Map<String, Object> runParams = new TreeMap<String, Object>();
runParams.put("Card", this); runParams.put("Card", this);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Untaps, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.Untaps, runParams, false);
// Play the Untap sound // Play the Untap sound
Singletons.getModel().getGame().getEvents().post(new SetTappedEvent(false)); getGame().getEvents().post(new SetTappedEvent(false));
} }
for (final Command var : this.untapCommandList) { for (final Command var : this.untapCommandList) {
@@ -4884,9 +4885,9 @@ public class Card extends GameEntity implements Comparable<Card> {
// Suppressed Exiling is as close as we can get to // Suppressed Exiling is as close as we can get to
// "ceasing to exist" // "ceasing to exist"
Singletons.getModel().getGame().getTriggerHandler().suppressMode(TriggerType.ChangesZone); getGame().getTriggerHandler().suppressMode(TriggerType.ChangesZone);
Singletons.getModel().getGame().getAction().exile(this); getGame().getAction().exile(this);
Singletons.getModel().getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone); getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
} }
return true; return true;
} }
@@ -5278,10 +5279,10 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("DefenderCtrl")) { } else if (property.startsWith("DefenderCtrl")) {
if (!Singletons.getModel().getGame().getPhaseHandler().inCombat()) { if (!getGame().getPhaseHandler().inCombat()) {
return false; return false;
} }
if (!Singletons.getModel().getGame().getCombat().getDefendingPlayerRelatedTo(source).contains(this.getController())) { if (!getGame().getCombat().getDefendingPlayerRelatedTo(source).contains(this.getController())) {
return false; return false;
} }
} else if (property.startsWith("EnchantedPlayerCtrl")) { } else if (property.startsWith("EnchantedPlayerCtrl")) {
@@ -5295,7 +5296,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else if (property.startsWith("RememberedPlayerCtrl")) { } else if (property.startsWith("RememberedPlayerCtrl")) {
if (source.getRemembered().isEmpty()) { if (source.getRemembered().isEmpty()) {
final Card newCard = Singletons.getModel().getGame().getCardState(source); final Card newCard = getGame().getCardState(source);
for (final Object o : newCard.getRemembered()) { for (final Object o : newCard.getRemembered()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!this.getController().equals(o)) { if (!this.getController().equals(o)) {
@@ -5341,11 +5342,11 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} }
} else if (property.startsWith("ActivePlayerCtrl")) { } else if (property.startsWith("ActivePlayerCtrl")) {
if (!Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(this.getController())) { if (!getGame().getPhaseHandler().isPlayerTurn(this.getController())) {
return false; return false;
} }
} else if (property.startsWith("NonActivePlayerCtrl")) { } else if (property.startsWith("NonActivePlayerCtrl")) {
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(this.getController())) { if (getGame().getPhaseHandler().isPlayerTurn(this.getController())) {
return false; return false;
} }
} else if (property.startsWith("YouOwn")) { } else if (property.startsWith("YouOwn")) {
@@ -5655,7 +5656,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else if (restriction.equals("MostProminentColor")) { } else if (restriction.equals("MostProminentColor")) {
for (final String color : CardUtil.getColors(this)) { for (final String color : CardUtil.getColors(this)) {
if (CardFactoryUtil.isMostProminentColor(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), color)) { if (CardFactoryUtil.isMostProminentColor(getGame().getCardsIn(ZoneType.Battlefield), color)) {
return true; return true;
} }
} }
@@ -5679,7 +5680,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
String color = props[1]; String color = props[1];
return CardFactoryUtil.isMostProminentColor(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), color); return CardFactoryUtil.isMostProminentColor(getGame().getCardsIn(ZoneType.Battlefield), color);
} else if (property.startsWith("notSharesColorWith")) { } else if (property.startsWith("notSharesColorWith")) {
if (property.equals("notSharesColorWith")) { if (property.equals("notSharesColorWith")) {
if (this.sharesColorWith(source)) { if (this.sharesColorWith(source)) {
@@ -5777,7 +5778,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} else if (restriction.equals("EachTopLibrary")) { } else if (restriction.equals("EachTopLibrary")) {
final List<Card> list = new ArrayList<Card>(); final List<Card> list = new ArrayList<Card>();
for (Player p : Singletons.getModel().getGame().getPlayers()) { for (Player p : getGame().getPlayers()) {
final Card top = p.getCardsIn(ZoneType.Library).get(0); final Card top = p.getCardsIn(ZoneType.Library).get(0);
list.add(top); list.add(top);
} }
@@ -5804,14 +5805,14 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
return false; return false;
} else if (restriction.equals(ZoneType.Graveyard.toString())) { } else if (restriction.equals(ZoneType.Graveyard.toString())) {
for (final Card card : Singletons.getModel().getGame().getCardsIn(ZoneType.Graveyard)) { for (final Card card : getGame().getCardsIn(ZoneType.Graveyard)) {
if (this.getName().equals(card.getName())) { if (this.getName().equals(card.getName())) {
return true; return true;
} }
} }
return false; return false;
} else if (restriction.equals(ZoneType.Battlefield.toString())) { } else if (restriction.equals(ZoneType.Battlefield.toString())) {
for (final Card card : Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)) { for (final Card card : getGame().getCardsIn(ZoneType.Battlefield)) {
if (this.getName().equals(card.getName())) { if (this.getName().equals(card.getName())) {
return true; return true;
} }
@@ -5842,7 +5843,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
return false; return false;
} else if (restriction.equals("NonToken")) { } else if (restriction.equals("NonToken")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), final List<Card> list = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield),
Presets.NON_TOKEN); Presets.NON_TOKEN);
for (final Card card : list) { for (final Card card : list) {
if (this.getName().equals(card.getName())) { if (this.getName().equals(card.getName())) {
@@ -5959,11 +5960,11 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("enteredBattlefieldThisTurn")) { } else if (property.startsWith("enteredBattlefieldThisTurn")) {
if (!(this.getTurnInZone() == Singletons.getModel().getGame().getPhaseHandler().getTurn())) { if (!(this.getTurnInZone() == getGame().getPhaseHandler().getTurn())) {
return false; return false;
} }
} else if (property.startsWith("notEnteredBattlefieldThisTurn")) { } else if (property.startsWith("notEnteredBattlefieldThisTurn")) {
if (this.getTurnInZone() == Singletons.getModel().getGame().getPhaseHandler().getTurn()) { if (this.getTurnInZone() == getGame().getPhaseHandler().getTurn()) {
return false; return false;
} }
} else if (property.startsWith("firstTurnControlled")) { } else if (property.startsWith("firstTurnControlled")) {
@@ -6039,7 +6040,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("greatestPower")) { } else if (property.startsWith("greatestPower")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final List<Card> list = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES);
for (final Card crd : list) { for (final Card crd : list) {
if (crd.getNetAttack() > this.getNetAttack()) { if (crd.getNetAttack() > this.getNetAttack()) {
return false; return false;
@@ -6053,21 +6054,21 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} }
} else if (property.startsWith("leastPower")) { } else if (property.startsWith("leastPower")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final List<Card> list = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES);
for (final Card crd : list) { for (final Card crd : list) {
if (crd.getNetAttack() < this.getNetAttack()) { if (crd.getNetAttack() < this.getNetAttack()) {
return false; return false;
} }
} }
} else if (property.startsWith("leastToughness")) { } else if (property.startsWith("leastToughness")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final List<Card> list = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES);
for (final Card crd : list) { for (final Card crd : list) {
if (crd.getNetDefense() < this.getNetDefense()) { if (crd.getNetDefense() < this.getNetDefense()) {
return false; return false;
} }
} }
} else if (property.startsWith("greatestCMC")) { } else if (property.startsWith("greatestCMC")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final List<Card> list = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES);
for (final Card crd : list) { for (final Card crd : list) {
if (crd.isSplitCard()) { if (crd.isSplitCard()) {
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > this.getCMC()) { if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > this.getCMC()) {
@@ -6083,7 +6084,7 @@ public class Card extends GameEntity implements Comparable<Card> {
List<Card> list = new ArrayList<Card>(); List<Card> list = new ArrayList<Card>();
for (final Object o : source.getRemembered()) { for (final Object o : source.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
list.add(Singletons.getModel().getGame().getCardState((Card) o)); list.add(getGame().getCardState((Card) o));
} }
} }
if (!list.contains(this)) { if (!list.contains(this)) {
@@ -6094,7 +6095,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("lowestCMC")) { } else if (property.startsWith("lowestCMC")) {
final List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final List<Card> list = getGame().getCardsIn(ZoneType.Battlefield);
for (final Card crd : list) { for (final Card crd : list) {
if (!crd.isLand() && !crd.isImmutable()) { if (!crd.isLand() && !crd.isImmutable()) {
if (crd.isSplitCard()) { if (crd.isSplitCard()) {
@@ -6146,7 +6147,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("suspended")) { } else if (property.startsWith("suspended")) {
if (!this.hasSuspend() || !Singletons.getModel().getGame().isCardExiled(this) if (!this.hasSuspend() || !getGame().isCardExiled(this)
|| !(this.getCounters(CounterType.getType("TIME")) >= 1)) { || !(this.getCounters(CounterType.getType("TIME")) >= 1)) {
return false; return false;
} }
@@ -6244,7 +6245,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.equals("attackedBySourceThisCombat")) { } else if (property.equals("attackedBySourceThisCombat")) {
final GameEntity defender = Singletons.getModel().getGame().getCombat().getDefenderByAttacker(source); final GameEntity defender = getGame().getCombat().getDefenderByAttacker(source);
if (defender instanceof Card) { if (defender instanceof Card) {
if (!this.equals((Card) defender)) { if (!this.equals((Card) defender)) {
return false; return false;
@@ -6319,7 +6320,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("unblocked")) { } else if (property.startsWith("unblocked")) {
if (!Singletons.getModel().getGame().getCombat().isUnblocked(this)) { if (!getGame().getCombat().isUnblocked(this)) {
return false; return false;
} }
} else if (property.startsWith("kicked")) { } else if (property.startsWith("kicked")) {
@@ -6704,7 +6705,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isAttacking() { public final boolean isAttacking() {
return Singletons.getModel().getGame().getCombat().isAttacking(this); return getGame().getCombat().isAttacking(this);
} }
/** /**
@@ -6715,7 +6716,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isAttacking(GameEntity ge) { public final boolean isAttacking(GameEntity ge) {
Combat combat = Singletons.getModel().getGame().getCombat(); Combat combat = getGame().getCombat();
if (!combat.isAttacking(this)) { if (!combat.isAttacking(this)) {
return false; return false;
} }
@@ -6730,7 +6731,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isBlocking() { public final boolean isBlocking() {
final List<Card> blockers = Singletons.getModel().getGame().getCombat().getAllBlockers(); final List<Card> blockers = getGame().getCombat().getAllBlockers();
return blockers.contains(this); return blockers.contains(this);
} }
@@ -6742,7 +6743,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isBlocked() { public final boolean isBlocked() {
return Singletons.getModel().getGame().getCombat().isBlocked(this); return getGame().getCombat().isBlocked(this);
} }
/** /**
@@ -6755,7 +6756,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isBlocking(final Card attacker) { public final boolean isBlocking(final Card attacker) {
return Singletons.getModel().getGame().getCombat().getAttackersBlockedBy(this).contains(attacker); return getGame().getCombat().getAttackersBlockedBy(this).contains(attacker);
} }
/** /**
@@ -6768,7 +6769,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isBlockedBy(final Card blocker) { public final boolean isBlockedBy(final Card blocker) {
return Singletons.getModel().getGame().getCombat().getAttackersBlockedBy(blocker).contains(this); return getGame().getCombat().getAttackersBlockedBy(blocker).contains(this);
} }
// ///////////////////////// // /////////////////////////
@@ -6778,7 +6779,7 @@ public class Card extends GameEntity implements Comparable<Card> {
// //////////////////////// // ////////////////////////
// all damage to cards is now handled in Card.java, no longer // all damage to cards is now handled in Card.java, no longer
// Singletons.getModel().getGameAction()... // getGameAction()...
/** /**
* <p> * <p>
* addReceivedDamageFromThisTurn. * addReceivedDamageFromThisTurn.
@@ -7089,11 +7090,11 @@ public class Card extends GameEntity implements Comparable<Card> {
public final int staticDamagePrevention(final int damage, final int possiblePrevention, final Card source, public final int staticDamagePrevention(final int damage, final int possiblePrevention, final Card source,
final boolean isCombat) { final boolean isCombat) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) { if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
return damage; return damage;
} }
for (final Card ca : Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)) { for (final Card ca : getGame().getCardsIn(ZoneType.Battlefield)) {
for (final ReplacementEffect re : ca.getReplacementEffects()) { for (final ReplacementEffect re : ca.getReplacementEffects()) {
Map<String, String> params = re.getMapParams(); Map<String, String> params = re.getMapParams();
if (!"DamageDone".equals(params.get("Event")) || !params.containsKey("PreventionEffect")) { if (!"DamageDone".equals(params.get("Event")) || !params.containsKey("PreventionEffect")) {
@@ -7148,11 +7149,11 @@ public class Card extends GameEntity implements Comparable<Card> {
@Override @Override
public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat, final boolean isTest) { public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat, final boolean isTest) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) { if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
return damageIn; return damageIn;
} }
if (isCombat && Singletons.getModel().getGame().getPhaseHandler().isPreventCombatDamageThisTurn()) { if (isCombat && getGame().getPhaseHandler().isPreventCombatDamageThisTurn()) {
return 0; return 0;
} }
@@ -7211,7 +7212,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
// Prevent Damage static abilities // Prevent Damage static abilities
for (final Card ca : Singletons.getModel().getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) { for (final Card ca : getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities(); final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities();
for (final StaticAbility stAb : staticAbilities) { for (final StaticAbility stAb : staticAbilities) {
restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat, isTest); restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat, isTest);
@@ -7224,7 +7225,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return 0; return 0;
} }
if (source.isCreature() && Singletons.getModel().getGame().isCardInPlay("Well-Laid Plans") if (source.isCreature() && getGame().isCardInPlay("Well-Laid Plans")
&& source.sharesColorWith(this)) { && source.sharesColorWith(this)) {
return 0; return 0;
} }
@@ -7250,7 +7251,7 @@ public class Card extends GameEntity implements Comparable<Card> {
@Override @Override
public final int preventDamage(final int damage, final Card source, final boolean isCombat) { public final int preventDamage(final int damage, final Card source, final boolean isCombat) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention) if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)
|| source.hasKeyword("Damage that would be dealt by CARDNAME can't be prevented.")) { || source.hasKeyword("Damage that would be dealt by CARDNAME can't be prevented.")) {
return damage; return damage;
} }
@@ -7270,7 +7271,7 @@ public class Card extends GameEntity implements Comparable<Card> {
repParams.put("IsCombat", isCombat); repParams.put("IsCombat", isCombat);
repParams.put("Prevention", true); repParams.put("Prevention", true);
if (Singletons.getModel().getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) { if (getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) {
return 0; return 0;
} }
@@ -7316,7 +7317,7 @@ public class Card extends GameEntity implements Comparable<Card> {
public final int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) { public final int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) {
int restDamage = damage; int restDamage = damage;
for (Card c : Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)) { for (Card c : getGame().getCardsIn(ZoneType.Battlefield)) {
if (c.getName().equals("Sulfuric Vapors")) { if (c.getName().equals("Sulfuric Vapors")) {
if (source.isSpell() && source.isRed()) { if (source.isSpell() && source.isRed()) {
restDamage += 1; restDamage += 1;
@@ -7397,7 +7398,7 @@ public class Card extends GameEntity implements Comparable<Card> {
repParams.put("DamageAmount", damageIn); repParams.put("DamageAmount", damageIn);
repParams.put("IsCombat", isCombat); repParams.put("IsCombat", isCombat);
if (Singletons.getModel().getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) { if (getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) {
return 0; return 0;
} }
@@ -7460,14 +7461,14 @@ public class Card extends GameEntity implements Comparable<Card> {
runParams.put("DamageTarget", this); runParams.put("DamageTarget", this);
runParams.put("DamageAmount", damageToAdd); runParams.put("DamageAmount", damageToAdd);
runParams.put("IsCombatDamage", isCombat); runParams.put("IsCombatDamage", isCombat);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.DamageDone, runParams, false); getGame().getTriggerHandler().runTrigger(TriggerType.DamageDone, runParams, false);
String additionalLog = ""; String additionalLog = "";
if (this.isPlaneswalker()) { if (this.isPlaneswalker()) {
this.subtractCounter(CounterType.LOYALTY, damageToAdd); this.subtractCounter(CounterType.LOYALTY, damageToAdd);
additionalLog = String.format("(Removing %d Loyalty Counters)", damageToAdd); additionalLog = String.format("(Removing %d Loyalty Counters)", damageToAdd);
} else { } else {
boolean wither = (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.alwaysWither) boolean wither = (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.alwaysWither)
|| source.hasKeyword("Wither") || source.hasKeyword("Infect")); || source.hasKeyword("Wither") || source.hasKeyword("Infect"));
GameActionUtil.executeDamageToCreatureEffects(source, this, damageToAdd); GameActionUtil.executeDamageToCreatureEffects(source, this, damageToAdd);
@@ -7477,14 +7478,14 @@ public class Card extends GameEntity implements Comparable<Card> {
additionalLog = "(As -1/-1 Counters)"; additionalLog = "(As -1/-1 Counters)";
} }
if (source.hasKeyword("Deathtouch") && this.isCreature()) { if (source.hasKeyword("Deathtouch") && this.isCreature()) {
Singletons.getModel().getGame().getAction().destroy(this, null); getGame().getAction().destroy(this, null);
additionalLog = "(Deathtouch)"; additionalLog = "(Deathtouch)";
} else if (this.isInPlay() && !wither) { } else if (this.isInPlay() && !wither) {
this.damage += damageToAdd; this.damage += damageToAdd;
} }
} }
Singletons.getModel().getGame().getGameLog().add("Damage", String.format("Dealing %d damage to %s. %s", getGame().getGameLog().add("Damage", String.format("Dealing %d damage to %s. %s",
damageToAdd, this.getName(), additionalLog), 3); damageToAdd, this.getName(), additionalLog), 3);
return true; return true;
} }
@@ -7859,7 +7860,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return boolean * @return boolean
*/ */
public boolean isInZone(final ZoneType zone) { public boolean isInZone(final ZoneType zone) {
return Singletons.getModel().getGame().isCardInZone(this, zone); return getGame().isCardInZone(this, zone);
} }
public final boolean canBeDestroyed() { public final boolean canBeDestroyed() {
@@ -7881,7 +7882,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
// CantTarget static abilities // CantTarget static abilities
for (final Card ca : Singletons.getModel().getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) { for (final Card ca : getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities(); final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities();
for (final StaticAbility stAb : staticAbilities) { for (final StaticAbility stAb : staticAbilities) {
if (stAb.applyAbility("CantTarget", this, sa)) { if (stAb.applyAbility("CantTarget", this, sa)) {
@@ -8203,7 +8204,7 @@ public class Card extends GameEntity implements Comparable<Card> {
int xPaid = 0; int xPaid = 0;
// 2012-07-22 - If a card is on the stack, count the xManaCost in with it's CMC // 2012-07-22 - If a card is on the stack, count the xManaCost in with it's CMC
if (Singletons.getModel().getGame().getCardsIn(ZoneType.Stack).contains(this) && getManaCost() != null) { if (getGame().getCardsIn(ZoneType.Stack).contains(this) && getManaCost() != null) {
xPaid = getXManaCostPaid() * getManaCost().countX(); xPaid = getXManaCostPaid() * getManaCost().countX();
} }
@@ -8296,4 +8297,20 @@ public class Card extends GameEntity implements Comparable<Card> {
public Iterable<OptionalCost> getOptionalCostsPaid() { return costsPaid; } public Iterable<OptionalCost> getOptionalCostsPaid() { return costsPaid; }
public boolean isOptionalCostPaid(OptionalCost cost) { return costsPaid.contains(cost); } public boolean isOptionalCostPaid(OptionalCost cost) { return costsPaid.contains(cost); }
/**
* Fetch GameState for this card from references to players who may own or control this card.
*/
public GameState getGame() {
Player controller = getController();
if (null != controller)
return controller.getGame();
Player owner = getOwner();
if (null != owner)
return owner.getGame();
throw new IllegalStateException("Card " + toString() + " has no means to determine the game it belongs to!");
}
} // end Card class } // end Card class

View File

@@ -30,6 +30,7 @@ import forge.card.ability.ApiType;
import forge.card.spellability.AbilityManaPart; import forge.card.spellability.AbilityManaPart;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -88,15 +89,15 @@ public final class CardUtil {
* @param src a Card object * @param src a Card object
* @return a List<Card> that matches the given criteria * @return a List<Card> that matches the given criteria
*/ */
public static List<Card> getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid, public static List<Card> getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src) {
final Card src) {
List<Card> res = new ArrayList<Card>(); List<Card> res = new ArrayList<Card>();
final GameState game = src.getGame();
if (to != ZoneType.Stack) { if (to != ZoneType.Stack) {
for (Player p : Singletons.getModel().getGame().getPlayers()) { for (Player p : game.getPlayers()) {
res.addAll(p.getZone(to).getCardsAddedThisTurn(from)); res.addAll(p.getZone(to).getCardsAddedThisTurn(from));
} }
} else { } else {
res.addAll(Singletons.getModel().getGame().getStackZone().getCardsAddedThisTurn(from)); res.addAll(game.getStackZone().getCardsAddedThisTurn(from));
} }
res = CardLists.getValidCards(res, valid, src.getController(), src); res = CardLists.getValidCards(res, valid, src.getController(), src);
@@ -106,8 +107,8 @@ public final class CardUtil {
public static List<Card> getThisTurnCast(final String valid, final Card src) { public static List<Card> getThisTurnCast(final String valid, final Card src) {
List<Card> res = new ArrayList<Card>(); List<Card> res = new ArrayList<Card>();
final GameState game = src.getGame();
res.addAll(Singletons.getModel().getGame().getStack().getCardsCastThisTurn()); res.addAll(game.getStack().getCardsCastThisTurn());
res = CardLists.getValidCards(res, valid, src.getController(), src); res = CardLists.getValidCards(res, valid, src.getController(), src);
@@ -116,8 +117,8 @@ public final class CardUtil {
public static List<Card> getLastTurnCast(final String valid, final Card src) { public static List<Card> getLastTurnCast(final String valid, final Card src) {
List<Card> res = new ArrayList<Card>(); List<Card> res = new ArrayList<Card>();
final GameState game = src.getGame();
res.addAll(Singletons.getModel().getGame().getStack().getCardsCastLastTurn()); res.addAll(game.getStack().getCardsCastLastTurn());
res = CardLists.getValidCards(res, valid, src.getController(), src); res = CardLists.getValidCards(res, valid, src.getController(), src);
@@ -181,12 +182,13 @@ public final class CardUtil {
public static List<Card> getRadiance(final Card source, final Card origin, final String[] valid) { public static List<Card> getRadiance(final Card source, final Card origin, final String[] valid) {
final List<Card> res = new ArrayList<Card>(); final List<Card> res = new ArrayList<Card>();
final GameState game = source.getGame();
for (final CardColor col : origin.getColor()) { for (final CardColor col : origin.getColor()) {
for (final String strCol : col.toStringList()) { for (final String strCol : col.toStringList()) {
if (strCol.equalsIgnoreCase("Colorless")) { if (strCol.equalsIgnoreCase("Colorless")) {
continue; continue;
} }
for (final Card c : Singletons.getModel().getGame().getColoredCardsInPlay(strCol)) { for (final Card c : game.getColoredCardsInPlay(strCol)) {
if (!res.contains(c) && c.isValid(valid, source.getController(), source) && !c.equals(origin)) { if (!res.contains(c) && c.isValid(valid, source.getController(), source) && !c.equals(origin)) {
res.add(c); res.add(c);
} }
@@ -248,7 +250,8 @@ public final class CardUtil {
if (validCard.startsWith("Defined.")) { if (validCard.startsWith("Defined.")) {
cards = AbilityUtils.getDefinedCards(card, validCard.replace("Defined.", ""), abMana); cards = AbilityUtils.getDefinedCards(card, validCard.replace("Defined.", ""), abMana);
} else { } else {
cards = CardLists.getValidCards(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card); final GameState game = sa.getActivatingPlayer().getGame();
cards = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card);
} }
// remove anything cards that is already in parents // remove anything cards that is already in parents

View File

@@ -289,4 +289,12 @@ public enum CounterType {
final String replacedName = name.replace("/", "").replaceAll("\\+", "p").replaceAll("\\-", "m").toUpperCase(); final String replacedName = name.replace("/", "").replaceAll("\\+", "p").replaceAll("\\-", "m").toUpperCase();
return Enum.valueOf(CounterType.class, replacedName); return Enum.valueOf(CounterType.class, replacedName);
} }
// although this should be in AI's code
public boolean isNegativeCounter() {
CounterType c = this;
return (c == CounterType.AGE) || (c == CounterType.BLAZE) || (c == CounterType.BRIBERY) || (c == CounterType.DOOM)
|| (c == CounterType.ICE) || (c == CounterType.M1M1) || (c == CounterType.M0M2) || (c == CounterType.M0M1)
|| (c == CounterType.TIME);
}
} }

View File

@@ -29,6 +29,7 @@ import forge.card.TriggerReplacementBase;
import forge.card.replacement.ReplacementEffect; import forge.card.replacement.ReplacementEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
import forge.game.GameState;
import forge.game.GlobalRuleChange; import forge.game.GlobalRuleChange;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -63,8 +64,6 @@ public class StaticEffects {
this.removeStaticEffect(this.staticEffects.get(i)); this.removeStaticEffect(this.staticEffects.get(i));
} }
this.staticEffects = new ArrayList<StaticEffect>(); this.staticEffects = new ArrayList<StaticEffect>();
Singletons.getModel().getGame().getTriggerHandler().cleanUpTemporaryTriggers();
} }
public void setGlobalRuleChange(GlobalRuleChange change) { public void setGlobalRuleChange(GlobalRuleChange change) {
@@ -374,11 +373,12 @@ public class StaticEffects {
* <p> * <p>
* rePopulateStateBasedList. * rePopulateStateBasedList.
* </p> * </p>
* @param game
*/ */
public final void rePopulateStateBasedList() { public final void rePopulateStateBasedList(GameState game) {
this.reset(); this.reset();
final List<Card> cards = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final List<Card> cards = game.getCardsIn(ZoneType.Battlefield);
Log.debug("== Start add state effects =="); Log.debug("== Start add state effects ==");
for (Card c : cards) { for (Card c : cards) {

View File

@@ -9,10 +9,10 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardUtil; import forge.CardUtil;
import forge.GameEntity; import forge.GameEntity;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.Zone; import forge.game.zone.Zone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -155,8 +155,8 @@ public abstract class TriggerReplacementBase {
} }
protected boolean meetsCommonRequirements(Map<String, String> params) { protected boolean meetsCommonRequirements(Map<String, String> params) {
final Player hostController = this.getHostCard().getController();
Player hostController = this.getHostCard().getController(); final GameState game = hostController.getGame();
if ("True".equalsIgnoreCase(params.get("Metalcraft")) && !hostController.hasMetalcraft()) return false; if ("True".equalsIgnoreCase(params.get("Metalcraft")) && !hostController.hasMetalcraft()) return false;
if ("True".equalsIgnoreCase(params.get("Threshold")) && !hostController.hasThreshold()) return false; if ("True".equalsIgnoreCase(params.get("Threshold")) && !hostController.hasThreshold()) return false;
@@ -167,7 +167,7 @@ public abstract class TriggerReplacementBase {
if ("You".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getPoisonCounters() == 0) return false; if ("You".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getPoisonCounters() == 0) return false;
if ("Opponent".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getOpponent().getPoisonCounters() == 0) return false; if ("Opponent".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getOpponent().getPoisonCounters() == 0) return false;
if ("Each".equalsIgnoreCase(params.get("PlayersPoisoned"))) { if ("Each".equalsIgnoreCase(params.get("PlayersPoisoned"))) {
for( Player p : Singletons.getModel().getGame().getPlayers()) for( Player p : game.getPlayers())
if( p.getPoisonCounters() == 0 ) if( p.getPoisonCounters() == 0 )
return false; return false;
} }
@@ -281,14 +281,14 @@ public abstract class TriggerReplacementBase {
} }
if (params.containsKey("CheckSVar")) { if (params.containsKey("CheckSVar")) {
final int sVar = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), params.get("CheckSVar"), null); final int sVar = AbilityUtils.calculateAmount(game.getCardState(this.getHostCard()), params.get("CheckSVar"), null);
String comparator = "GE1"; String comparator = "GE1";
if (params.containsKey("SVarCompare")) { if (params.containsKey("SVarCompare")) {
comparator = params.get("SVarCompare"); comparator = params.get("SVarCompare");
} }
final String svarOperator = comparator.substring(0, 2); final String svarOperator = comparator.substring(0, 2);
final String svarOperand = comparator.substring(2); final String svarOperand = comparator.substring(2);
final int operandValue = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), final int operandValue = AbilityUtils.calculateAmount(game.getCardState(this.getHostCard()),
svarOperand, null); svarOperand, null);
if (!Expressions.compare(sVar, svarOperator, operandValue)) { if (!Expressions.compare(sVar, svarOperator, operandValue)) {
return false; return false;

View File

@@ -12,7 +12,6 @@ import forge.CardLists;
import forge.CardUtil; import forge.CardUtil;
import forge.Constant; import forge.Constant;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.mana.ManaCostBeingPaid; import forge.card.mana.ManaCostBeingPaid;
@@ -79,7 +78,8 @@ public class AbilityUtils {
public static List<Card> getDefinedCards(final Card hostCard, final String def, final SpellAbility sa) { public static List<Card> getDefinedCards(final Card hostCard, final String def, final SpellAbility sa) {
final List<Card> cards = new ArrayList<Card>(); final List<Card> cards = new ArrayList<Card>();
final String defined = (def == null) ? "Self" : def; // default to Self final String defined = (def == null) ? "Self" : def; // default to Self
final GameState game = sa.getActivatingPlayer().getGame();
Card c = null; Card c = null;
if (defined.equals("Self")) { if (defined.equals("Self")) {
@@ -142,7 +142,7 @@ public class AbilityUtils {
else { else {
final Object crd = root.getTriggeringObject(defined.substring(9)); final Object crd = root.getTriggeringObject(defined.substring(9));
if (crd instanceof Card) { if (crd instanceof Card) {
c = Singletons.getModel().getGame().getCardState((Card) crd); c = game.getCardState((Card) crd);
} else if (crd instanceof List<?>) { } else if (crd instanceof List<?>) {
for (final Card cardItem : (List<Card>) crd) { for (final Card cardItem : (List<Card>) crd) {
cards.add(cardItem); cards.add(cardItem);
@@ -153,7 +153,7 @@ public class AbilityUtils {
final SpellAbility root = sa.getRootAbility(); final SpellAbility root = sa.getRootAbility();
final Object crd = root.getReplacingObject(defined.substring(8)); final Object crd = root.getReplacingObject(defined.substring(8));
if (crd instanceof Card) { if (crd instanceof Card) {
c = Singletons.getModel().getGame().getCardState((Card) crd); c = game.getCardState((Card) crd);
} else if (crd instanceof List<?>) { } else if (crd instanceof List<?>) {
for (final Card cardItem : (List<Card>) crd) { for (final Card cardItem : (List<Card>) crd) {
cards.add(cardItem); cards.add(cardItem);
@@ -161,26 +161,26 @@ public class AbilityUtils {
} }
} else if (defined.equals("Remembered")) { } else if (defined.equals("Remembered")) {
if (hostCard.getRemembered().isEmpty()) { if (hostCard.getRemembered().isEmpty()) {
final Card newCard = Singletons.getModel().getGame().getCardState(hostCard); final Card newCard = game.getCardState(hostCard);
for (final Object o : newCard.getRemembered()) { for (final Object o : newCard.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
cards.add(Singletons.getModel().getGame().getCardState((Card) o)); cards.add(game.getCardState((Card) o));
} }
} }
} }
for (final Object o : hostCard.getRemembered()) { for (final Object o : hostCard.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
cards.add(Singletons.getModel().getGame().getCardState((Card) o)); cards.add(game.getCardState((Card) o));
} }
} }
} else if (defined.equals("Clones")) { } else if (defined.equals("Clones")) {
for (final Card clone : hostCard.getClones()) { for (final Card clone : hostCard.getClones()) {
cards.add(Singletons.getModel().getGame().getCardState(clone)); cards.add(game.getCardState(clone));
} }
} else if (defined.equals("Imprinted")) { } else if (defined.equals("Imprinted")) {
for (final Card imprint : hostCard.getImprinted()) { for (final Card imprint : hostCard.getImprinted()) {
cards.add(Singletons.getModel().getGame().getCardState(imprint)); cards.add(game.getCardState(imprint));
} }
} else if (defined.startsWith("ThisTurnEntered")) { } else if (defined.startsWith("ThisTurnEntered")) {
final String[] workingCopy = defined.split("_"); final String[] workingCopy = defined.split("_");
@@ -196,11 +196,11 @@ public class AbilityUtils {
validFilter = workingCopy[2]; validFilter = workingCopy[2];
} }
for (final Card cl : CardUtil.getThisTurnEntered(destination, origin, validFilter, hostCard)) { for (final Card cl : CardUtil.getThisTurnEntered(destination, origin, validFilter, hostCard)) {
cards.add(Singletons.getModel().getGame().getCardState(cl)); cards.add(game.getCardState(cl));
} }
} else if (defined.equals("ChosenCard")) { } else if (defined.equals("ChosenCard")) {
for (final Card chosen : hostCard.getChosenCard()) { for (final Card chosen : hostCard.getChosenCard()) {
cards.add(Singletons.getModel().getGame().getCardState(chosen)); cards.add(game.getCardState(chosen));
} }
} else { } else {
List<Card> list = null; List<Card> list = null;
@@ -226,22 +226,16 @@ public class AbilityUtils {
else if (defined.startsWith("Valid ")) { else if (defined.startsWith("Valid ")) {
String validDefined = defined.substring("Valid ".length()); String validDefined = defined.substring("Valid ".length());
GameState game = Singletons.getModel().getGame();
list = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validDefined.split(","), hostCard.getController(), hostCard); list = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validDefined.split(","), hostCard.getController(), hostCard);
} }
else if (defined.startsWith("ValidHand ")) { else if (defined.startsWith("ValidHand ")) {
String validDefined = defined.substring("ValidHand ".length()); String validDefined = defined.substring("ValidHand ".length());
GameState game = Singletons.getModel().getGame();
list = CardLists.getValidCards(game.getCardsIn(ZoneType.Hand), validDefined.split(","), hostCard.getController(), hostCard); list = CardLists.getValidCards(game.getCardsIn(ZoneType.Hand), validDefined.split(","), hostCard.getController(), hostCard);
} }
else if (defined.startsWith("ValidAll ")) { else if (defined.startsWith("ValidAll ")) {
String validDefined = defined.substring("ValidAll ".length()); String validDefined = defined.substring("ValidAll ".length());
GameState game = Singletons.getModel().getGame();
list = CardLists.getValidCards(game.getCardsInGame(), validDefined.split(","), hostCard.getController(), hostCard); list = CardLists.getValidCards(game.getCardsInGame(), validDefined.split(","), hostCard.getController(), hostCard);
} }
@@ -292,6 +286,7 @@ public class AbilityUtils {
public static int calculateAmount(final Card card, String amount, final SpellAbility ability) { public static int calculateAmount(final Card card, String amount, final SpellAbility ability) {
// return empty strings and constants // return empty strings and constants
if (StringUtils.isBlank(amount)) { return 0; } if (StringUtils.isBlank(amount)) { return 0; }
final GameState game = card.getController().getGame();
// Strip and save sign for calculations // Strip and save sign for calculations
final boolean startsWithPlus = amount.charAt(0) == '+'; final boolean startsWithPlus = amount.charAt(0) == '+';
@@ -366,7 +361,7 @@ public class AbilityUtils {
final String hType = calcX[0].substring(11); final String hType = calcX[0].substring(11);
final ArrayList<Player> players = new ArrayList<Player>(); final ArrayList<Player> players = new ArrayList<Player>();
if (hType.equals("Players") || hType.equals("")) { if (hType.equals("Players") || hType.equals("")) {
players.addAll(Singletons.getModel().getGame().getPlayers()); players.addAll(game.getPlayers());
return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier; return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier;
} else if (hType.equals("Opponents")) { } else if (hType.equals("Opponents")) {
players.addAll(card.getController().getOpponents()); players.addAll(card.getController().getOpponents());
@@ -382,8 +377,8 @@ public class AbilityUtils {
} }
return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier; return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier;
} else if (hType.equals("NonActive")) { } else if (hType.equals("NonActive")) {
players.addAll(Singletons.getModel().getGame().getPlayers()); players.addAll(game.getPlayers());
players.remove(Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn()); players.remove(game.getPhaseHandler().getPlayerTurn());
return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier; return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier;
} }
return 0; return 0;
@@ -393,10 +388,10 @@ public class AbilityUtils {
// Add whole Remembered list to handlePaid // Add whole Remembered list to handlePaid
final List<Card> list = new ArrayList<Card>(); final List<Card> list = new ArrayList<Card>();
if (card.getRemembered().isEmpty()) { if (card.getRemembered().isEmpty()) {
final Card newCard = Singletons.getModel().getGame().getCardState(card); final Card newCard = game.getCardState(card);
for (final Object o : newCard.getRemembered()) { for (final Object o : newCard.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
list.add(Singletons.getModel().getGame().getCardState((Card) o)); list.add(game.getCardState((Card) o));
} }
} }
} }
@@ -410,7 +405,7 @@ public class AbilityUtils {
} else { } else {
for (final Object o : card.getRemembered()) { for (final Object o : card.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
list.add(Singletons.getModel().getGame().getCardState((Card) o)); list.add(game.getCardState((Card) o));
} }
} }
} }
@@ -422,7 +417,7 @@ public class AbilityUtils {
// Add whole Imprinted list to handlePaid // Add whole Imprinted list to handlePaid
final List<Card> list = new ArrayList<Card>(); final List<Card> list = new ArrayList<Card>();
for (final Card c : card.getImprinted()) { for (final Card c : card.getImprinted()) {
list.add(Singletons.getModel().getGame().getCardState(c)); list.add(game.getCardState(c));
} }
return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier; return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier;
@@ -434,7 +429,7 @@ public class AbilityUtils {
if (card.isEnchanting()) { if (card.isEnchanting()) {
Object o = card.getEnchanting(); Object o = card.getEnchanting();
if (o instanceof Card) { if (o instanceof Card) {
list.add(Singletons.getModel().getGame().getCardState((Card) o)); list.add(game.getCardState((Card) o));
} }
} }
return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier; return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier;
@@ -704,6 +699,7 @@ public class AbilityUtils {
public static List<Player> getDefinedPlayers(final Card card, final String def, final SpellAbility sa) { public static List<Player> getDefinedPlayers(final Card card, final String def, final SpellAbility sa) {
final List<Player> players = new ArrayList<Player>(); final List<Player> players = new ArrayList<Player>();
final String defined = (def == null) ? "You" : def; final String defined = (def == null) ? "You" : def;
final GameState game = sa.getActivatingPlayer().getGame();
if (defined.equals("Targeted")) { if (defined.equals("Targeted")) {
final SpellAbility saTargeting = sa.getSATargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
@@ -893,12 +889,12 @@ public class AbilityUtils {
} }
} }
} else if (defined.equals("AttackingPlayer")) { } else if (defined.equals("AttackingPlayer")) {
final Player p = Singletons.getModel().getGame().getCombat().getAttackingPlayer(); final Player p = game.getCombat().getAttackingPlayer();
if (!players.contains(p)) { if (!players.contains(p)) {
players.add(p); players.add(p);
} }
} else if (defined.equals("DefendingPlayer")) { } else if (defined.equals("DefendingPlayer")) {
players.addAll(Singletons.getModel().getGame().getCombat().getDefendingPlayerRelatedTo(card)); players.addAll(game.getCombat().getDefendingPlayerRelatedTo(card));
} else if (defined.equals("ChosenPlayer")) { } else if (defined.equals("ChosenPlayer")) {
final Player p = card.getChosenPlayer(); final Player p = card.getChosenPlayer();
if (!players.contains(p)) { if (!players.contains(p)) {
@@ -910,7 +906,7 @@ public class AbilityUtils {
players.add(p); players.add(p);
} }
} else if (defined.startsWith("Flipped")) { } else if (defined.startsWith("Flipped")) {
for (Player p : Singletons.getModel().getGame().getPlayers()) { for (Player p : game.getPlayers()) {
if (null != sa.getSourceCard().getFlipResult(p)) { if (null != sa.getSourceCard().getFlipResult(p)) {
if (sa.getSourceCard().getFlipResult(p).equals(defined.substring(7))) { if (sa.getSourceCard().getFlipResult(p).equals(defined.substring(7))) {
players.add(p); players.add(p);
@@ -920,11 +916,11 @@ public class AbilityUtils {
} else if (defined.equals("You")) { } else if (defined.equals("You")) {
players.add(sa.getActivatingPlayer()); players.add(sa.getActivatingPlayer());
} else if (defined.equals("Each")) { } else if (defined.equals("Each")) {
players.addAll(Singletons.getModel().getGame().getPlayers()); players.addAll(game.getPlayers());
} else if (defined.equals("Opponent")) { } else if (defined.equals("Opponent")) {
players.add(sa.getActivatingPlayer().getOpponent()); players.add(sa.getActivatingPlayer().getOpponent());
} else { } else {
for (Player p : Singletons.getModel().getGame().getPlayers()) { for (Player p : game.getPlayers()) {
if (p.isValid(defined, sa.getActivatingPlayer(), sa.getSourceCard())) { if (p.isValid(defined, sa.getActivatingPlayer(), sa.getSourceCard())) {
players.add(p); players.add(p);
} }
@@ -950,7 +946,8 @@ public class AbilityUtils {
final SpellAbility sa) { final SpellAbility sa) {
final ArrayList<SpellAbility> sas = new ArrayList<SpellAbility>(); final ArrayList<SpellAbility> sas = new ArrayList<SpellAbility>();
final String defined = (def == null) ? "Self" : def; // default to Self final String defined = (def == null) ? "Self" : def; // default to Self
final GameState game = sa.getActivatingPlayer().getGame();
SpellAbility s = null; SpellAbility s = null;
// TODO - this probably needs to be fleshed out a bit, but the basics // TODO - this probably needs to be fleshed out a bit, but the basics
@@ -974,7 +971,7 @@ public class AbilityUtils {
for (final Object o : card.getRemembered()) { for (final Object o : card.getRemembered()) {
if (o instanceof Card) { if (o instanceof Card) {
final Card rem = (Card) o; final Card rem = (Card) o;
sas.addAll(Singletons.getModel().getGame().getCardState(rem).getSpellAbilities()); sas.addAll(game.getCardState(rem).getSpellAbilities());
} }
} }
} else if (defined.equals("Imprinted")) { } else if (defined.equals("Imprinted")) {
@@ -995,7 +992,7 @@ public class AbilityUtils {
final SpellAbility root = sa.getRootAbility(); final SpellAbility root = sa.getRootAbility();
final Object crd = root.getTriggeringObject("Card"); final Object crd = root.getTriggeringObject("Card");
if (crd instanceof Card) { if (crd instanceof Card) {
triggeredCard = Singletons.getModel().getGame().getCardState((Card) crd); triggeredCard = game.getCardState((Card) crd);
} //find the imprinted card that does not share a name with the triggered card } //find the imprinted card that does not share a name with the triggered card
for (final SpellAbility spell : imprintedCards) { for (final SpellAbility spell : imprintedCards) {
if (!spell.getSourceCard().getName().equals(triggeredCard.getName())) { if (!spell.getSourceCard().getName().equals(triggeredCard.getName())) {
@@ -1057,8 +1054,7 @@ public class AbilityUtils {
return; return;
} }
final GameState game = Singletons.getModel().getGame(); AbilityUtils.resolveApiAbility(sa, usedStack, sa.getActivatingPlayer().getGame());
AbilityUtils.resolveApiAbility(sa, usedStack, game);
} }
private static void resolveSubAbilities(final SpellAbility sa, boolean usedStack, final GameState game) { private static void resolveSubAbilities(final SpellAbility sa, boolean usedStack, final GameState game) {

View File

@@ -1,7 +1,6 @@
package forge.card.ability; package forge.card.ability;
import forge.Singletons;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
@@ -81,7 +80,7 @@ public abstract class SpellAbilityAi {
return false; return false;
} }
if (sa.getRestrictions().getPlaneswalker() && Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.MAIN2)) { if (sa.getRestrictions().getPlaneswalker() && ai.getGame().getPhaseHandler().is(PhaseType.MAIN2)) {
return true; return true;
} }
if (sa.isTrigger()) { if (sa.isTrigger()) {
@@ -91,7 +90,7 @@ public abstract class SpellAbilityAi {
return false; return false;
} }
PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler phase = ai.getGame().getPhaseHandler();
return phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai); return phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai);
} }

View File

@@ -6,11 +6,11 @@ import com.google.common.collect.Iterables;
import forge.Card; import forge.Card;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.player.Player; import forge.game.player.Player;
@@ -34,7 +34,8 @@ public class AnimateAi extends SpellAbilityAi {
protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) { protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = aiPlayer.getGame();
// TODO - add some kind of check to answer // TODO - add some kind of check to answer
// "Am I going to attack with this?" // "Am I going to attack with this?"
// TODO - add some kind of check for during human turn to answer // TODO - add some kind of check for during human turn to answer
@@ -42,8 +43,8 @@ public class AnimateAi extends SpellAbilityAi {
// don't use instant speed animate abilities outside computers // don't use instant speed animate abilities outside computers
// Combat_Begin step // Combat_Begin step
if (!Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_BEGIN) if (!game.getPhaseHandler().is(PhaseType.COMBAT_BEGIN)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(aiPlayer) && game.getPhaseHandler().isPlayerTurn(aiPlayer)
&& !SpellAbilityAi.isSorcerySpeed(sa) && !SpellAbilityAi.isSorcerySpeed(sa)
&& !sa.hasParam("ActivationPhases") && !sa.hasParam("Permanent")) { && !sa.hasParam("ActivationPhases") && !sa.hasParam("Permanent")) {
return false; return false;
@@ -51,7 +52,7 @@ public class AnimateAi extends SpellAbilityAi {
Player opponent = aiPlayer.getWeakestOpponent(); Player opponent = aiPlayer.getWeakestOpponent();
// don't animate if the AI won't attack anyway // don't animate if the AI won't attack anyway
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(aiPlayer) if (game.getPhaseHandler().isPlayerTurn(aiPlayer)
&& aiPlayer.getLife() < 6 && aiPlayer.getLife() < 6
&& opponent.getLife() > 6 && opponent.getLife() > 6
&& Iterables.any(opponent.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES)) { && Iterables.any(opponent.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES)) {
@@ -60,14 +61,14 @@ public class AnimateAi extends SpellAbilityAi {
// don't use instant speed animate abilities outside humans // don't use instant speed animate abilities outside humans
// Combat_Declare_Attackers_InstantAbility step // Combat_Declare_Attackers_InstantAbility step
if ((!Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) if ((!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
|| (Singletons.getModel().getGame().getCombat().getAttackers().isEmpty())) || (game.getCombat().getAttackers().isEmpty()))
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(opponent)) { && game.getPhaseHandler().isPlayerTurn(opponent)) {
return false; return false;
} }
// don't activate during main2 unless this effect is permanent // don't activate during main2 unless this effect is permanent
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.MAIN2) && !sa.hasParam("Permanent")) { if (game.getPhaseHandler().is(PhaseType.MAIN2) && !sa.hasParam("Permanent")) {
return false; return false;
} }
@@ -77,7 +78,7 @@ public class AnimateAi extends SpellAbilityAi {
boolean bFlag = false; boolean bFlag = false;
for (final Card c : defined) { for (final Card c : defined) {
bFlag |= (!c.isCreature() && !c.isTapped() bFlag |= (!c.isCreature() && !c.isTapped()
&& !(c.getTurnInZone() == Singletons.getModel().getGame().getPhaseHandler().getTurn()) && !(c.getTurnInZone() == game.getPhaseHandler().getTurn())
&& !c.isEquipping()); && !c.isEquipping());
// for creatures that could be improved (like Figure of Destiny) // for creatures that could be improved (like Figure of Destiny)

View File

@@ -14,7 +14,6 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.CardUtil; import forge.CardUtil;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType; import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
@@ -79,7 +78,7 @@ public class AttachAi extends SpellAbilityAi {
source.setSVar("PayX", Integer.toString(xPay)); source.setSVar("PayX", Integer.toString(xPay));
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
&& !"Curse".equals(sa.getParam("AILogic"))) { && !"Curse".equals(sa.getParam("AILogic"))) {
return false; return false;
} }
@@ -264,7 +263,7 @@ public class AttachAi extends SpellAbilityAi {
private static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa, private static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa,
final boolean mandatory) { final boolean mandatory) {
List<Player> targetable = new ArrayList<Player>(); List<Player> targetable = new ArrayList<Player>();
for (final Player player : Singletons.getModel().getGame().getPlayers()) { for (final Player player : aiPlayer.getGame().getPlayers()) {
if (sa.canTarget(player)) { if (sa.canTarget(player)) {
targetable.add(player); targetable.add(player);
} }
@@ -880,7 +879,7 @@ public class AttachAi extends SpellAbilityAi {
return null; return null;
} }
List<Card> list = Singletons.getModel().getGame().getCardsIn(tgt.getZone()); List<Card> list = aiPlayer.getGame().getCardsIn(tgt.getZone());
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource);
// TODO If Attaching without casting, don't need to actually target. // TODO If Attaching without casting, don't need to actually target.
@@ -1023,7 +1022,7 @@ public class AttachAi extends SpellAbilityAi {
* @return true, if is useful keyword * @return true, if is useful keyword
*/ */
private static boolean isUsefulAttachKeyword(final String keyword, final Card card, final SpellAbility sa, final int powerBonus) { private static boolean isUsefulAttachKeyword(final String keyword, final Card card, final SpellAbility sa, final int powerBonus) {
final PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); final PhaseHandler ph = sa.getActivatingPlayer().getGame().getPhaseHandler();
if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) { if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) {
return false; return false;
} }

View File

@@ -5,7 +5,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -20,7 +19,7 @@ public class BecomesBlockedAi extends SpellAbilityAi {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = aiPlayer.getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source);
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);

View File

@@ -5,7 +5,6 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -101,7 +100,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
} }
// Don't cast during main1? // Don't cast during main1?
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.MAIN1, ai)) { if (ai.getGame().getPhaseHandler().is(PhaseType.MAIN1, ai)) {
return false; return false;
} }
} else if (origin.equals(ZoneType.Graveyard)) { } else if (origin.equals(ZoneType.Graveyard)) {

View File

@@ -4,7 +4,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -34,7 +33,7 @@ public class ChooseCardAi extends SpellAbilityAi {
if (sa.hasParam("ChoiceZone")) { if (sa.hasParam("ChoiceZone")) {
choiceZone = ZoneType.smartValueOf(sa.getParam("ChoiceZone")); choiceZone = ZoneType.smartValueOf(sa.getParam("ChoiceZone"));
} }
List<Card> choices = Singletons.getModel().getGame().getCardsIn(choiceZone); List<Card> choices = ai.getGame().getCardsIn(choiceZone);
if (sa.hasParam("Choices")) { if (sa.hasParam("Choices")) {
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host); choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host);
} }

View File

@@ -7,13 +7,13 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType; import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
@@ -65,9 +65,10 @@ public class ChooseSourceAi extends SpellAbilityAi {
} }
} }
if (sa.hasParam("AILogic")) { if (sa.hasParam("AILogic")) {
final GameState game = ai.getGame();
if (sa.getParam("AILogic").equals("NeedsPrevention")) { if (sa.getParam("AILogic").equals("NeedsPrevention")) {
if (!Singletons.getModel().getGame().getStack().isEmpty()) { if (!game.getStack().isEmpty()) {
final SpellAbility topStack = Singletons.getModel().getGame().getStack().peekAbility(); final SpellAbility topStack = game.getStack().peekAbility();
if (sa.hasParam("Choices") && !topStack.getSourceCard().isValid(sa.getParam("Choices"), ai, source)) { if (sa.hasParam("Choices") && !topStack.getSourceCard().isValid(sa.getParam("Choices"), ai, source)) {
return false; return false;
} }
@@ -98,21 +99,21 @@ public class ChooseSourceAi extends SpellAbilityAi {
} }
return true; return true;
} }
if (!Singletons.getModel().getGame().getPhaseHandler().getPhase() if (!game.getPhaseHandler().getPhase()
.equals(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { .equals(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
return false; return false;
} }
List<Card> choices = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> choices = game.getCardsIn(ZoneType.Battlefield);
if (sa.hasParam("Choices")) { if (sa.hasParam("Choices")) {
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host); choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host);
} }
choices = CardLists.filter(choices, new Predicate<Card>() { choices = CardLists.filter(choices, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (!c.isAttacking(ai) || !Singletons.getModel().getGame().getCombat().isUnblocked(c)) { if (!c.isAttacking(ai) || !game.getCombat().isUnblocked(c)) {
return false; return false;
} }
return ComputerUtilCombat.damageIfUnblocked(c, ai, Singletons.getModel().getGame().getCombat()) > 0; return ComputerUtilCombat.damageIfUnblocked(c, ai, game.getCombat()) > 0;
} }
}); });
if (choices.isEmpty()) { if (choices.isEmpty()) {

View File

@@ -3,11 +3,11 @@ package forge.card.ability.ai;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseHandler;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -18,6 +18,7 @@ public class CloneAi extends SpellAbilityAi {
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = source.getGame();
boolean useAbility = true; boolean useAbility = true;
@@ -33,7 +34,7 @@ public class CloneAi extends SpellAbilityAi {
// TODO - add some kind of check for during human turn to answer // TODO - add some kind of check for during human turn to answer
// "Can I use this to block something?" // "Can I use this to block something?"
PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler phase = game.getPhaseHandler();
// don't use instant speed clone abilities outside computers // don't use instant speed clone abilities outside computers
// Combat_Begin step // Combat_Begin step
if (!phase.is(PhaseType.COMBAT_BEGIN) if (!phase.is(PhaseType.COMBAT_BEGIN)
@@ -45,7 +46,7 @@ public class CloneAi extends SpellAbilityAi {
// don't use instant speed clone abilities outside humans // don't use instant speed clone abilities outside humans
// Combat_Declare_Attackers_InstantAbility step // Combat_Declare_Attackers_InstantAbility step
if ((!phase.is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) if ((!phase.is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
|| Singletons.getModel().getGame().getCombat().getAttackers().isEmpty()) || game.getCombat().getAttackers().isEmpty())
&& !phase.isPlayerTurn(ai)) { && !phase.isPlayerTurn(ai)) {
return false; return false;
} }

View File

@@ -25,11 +25,11 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -113,7 +113,7 @@ public class ControlGainAi extends SpellAbilityAi {
// Don't steal something if I can't Attack without, or prevent it from // Don't steal something if I can't Attack without, or prevent it from
// blocking at least // blocking at least
if ((lose != null) && lose.contains("EOT") if ((lose != null) && lose.contains("EOT")
&& Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) { && ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
return false; return false;
} }
@@ -184,9 +184,10 @@ public class ControlGainAi extends SpellAbilityAi {
@Override @Override
public boolean chkAIDrawback(SpellAbility sa, final AIPlayer ai) { public boolean chkAIDrawback(SpellAbility sa, final AIPlayer ai) {
final GameState game = ai.getGame();
if ((sa.getTarget() == null) || !sa.getTarget().doesTarget()) { if ((sa.getTarget() == null) || !sa.getTarget().doesTarget()) {
if (sa.hasParam("AllValid")) { if (sa.hasParam("AllValid")) {
List<Card> tgtCards = CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), ai.getOpponent()); List<Card> tgtCards = CardLists.filterControlledBy(game.getCardsIn(ZoneType.Battlefield), ai.getOpponent());
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa); tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
if (tgtCards.isEmpty()) { if (tgtCards.isEmpty()) {
return false; return false;
@@ -195,7 +196,7 @@ public class ControlGainAi extends SpellAbilityAi {
final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null; final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null;
if ((lose != null) && lose.contains("EOT") if ((lose != null) && lose.contains("EOT")
&& Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) { && game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
return false; return false;
} }
} else { } else {

View File

@@ -9,7 +9,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -29,7 +28,7 @@ public class CopyPermanentAi extends SpellAbilityAi {
// Card source = sa.getSourceCard(); // Card source = sa.getSourceCard();
// TODO - I'm sure someone can do this AI better // TODO - I'm sure someone can do this AI better
if (sa.hasParam("AtEOT") && !Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.MAIN1)) { if (sa.hasParam("AtEOT") && !aiPlayer.getGame().getPhaseHandler().is(PhaseType.MAIN1)) {
return false; return false;
} else { } else {
double chance = .4; // 40 percent chance with instant speed stuff double chance = .4; // 40 percent chance with instant speed stuff
@@ -56,7 +55,7 @@ public class CopyPermanentAi extends SpellAbilityAi {
final Target abTgt = sa.getTarget(); final Target abTgt = sa.getTarget();
if (abTgt != null) { if (abTgt != null) {
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = aiPlayer.getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source); list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source);
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);
list = CardLists.filter(list, new Predicate<Card>() { list = CardLists.filter(list, new Predicate<Card>() {

View File

@@ -1,13 +1,13 @@
package forge.card.ability.ai; package forge.card.ability.ai;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
import forge.game.ai.ComputerUtilMana; import forge.game.ai.ComputerUtilMana;
@@ -21,7 +21,8 @@ public class CounterAi extends SpellAbilityAi {
boolean toReturn = true; boolean toReturn = true;
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
if (Singletons.getModel().getGame().getStack().isEmpty()) { final GameState game = ai.getGame();
if (game.getStack().isEmpty()) {
return false; return false;
} }
@@ -38,7 +39,7 @@ public class CounterAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
if (tgt != null) { if (tgt != null) {
final SpellAbility topSA = Singletons.getModel().getGame().getStack().peekAbility(); final SpellAbility topSA = game.getStack().peekAbility();
if (!CardFactoryUtil.isCounterableBy(topSA.getSourceCard(), sa) || topSA.getActivatingPlayer() == ai) { if (!CardFactoryUtil.isCounterableBy(topSA.getSourceCard(), sa) || topSA.getActivatingPlayer() == ai) {
// might as well check for player's friendliness // might as well check for player's friendliness
return false; return false;
@@ -110,10 +111,11 @@ public class CounterAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
if (tgt != null) { if (tgt != null) {
if (Singletons.getModel().getGame().getStack().isEmpty()) { final GameState game = ai.getGame();
if (game.getStack().isEmpty()) {
return false; return false;
} }
final SpellAbility topSA = Singletons.getModel().getGame().getStack().peekAbility(); final SpellAbility topSA = game.getStack().peekAbility();
if (!CardFactoryUtil.isCounterableBy(topSA.getSourceCard(), sa) || topSA.getActivatingPlayer() == ai) { if (!CardFactoryUtil.isCounterableBy(topSA.getSourceCard(), sa) || topSA.getActivatingPlayer() == ai) {
return false; return false;
} }

View File

@@ -8,7 +8,6 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -23,7 +22,7 @@ public class CountersProliferateAi extends SpellAbilityAi {
@Override @Override
public boolean apply(final Card crd) { public boolean apply(final Card crd) {
for (final CounterType c1 : CounterType.values()) { for (final CounterType c1 : CounterType.values()) {
if (crd.getCounters(c1) != 0 && !CardFactoryUtil.isNegativeCounter(c1)) { if (crd.getCounters(c1) != 0 && !c1.isNegativeCounter()) {
return true; return true;
} }
} }
@@ -35,7 +34,7 @@ public class CountersProliferateAi extends SpellAbilityAi {
@Override @Override
public boolean apply(final Card crd) { public boolean apply(final Card crd) {
for (final CounterType c1 : CounterType.values()) { for (final CounterType c1 : CounterType.values()) {
if (crd.getCounters(c1) != 0 && CardFactoryUtil.isNegativeCounter(c1)) { if (crd.getCounters(c1) != 0 && c1.isNegativeCounter()) {
return true; return true;
} }
} }

View File

@@ -9,7 +9,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -151,7 +150,7 @@ public class CountersPutAi extends SpellAbilityAi {
} }
// Don't use non P1P1/M1M1 counters before main 2 if possible // Don't use non P1P1/M1M1 counters before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases") && !sa.hasParam("ActivationPhases")
&& !(type.equals("P1P1") || type.equals("M1M1"))) { && !(type.equals("P1P1") || type.equals("M1M1"))) {
return false; return false;

View File

@@ -7,7 +7,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -105,7 +104,7 @@ public class CountersPutAllAi extends SpellAbilityAi {
} }
//Check for cards that could profit from the ability //Check for cards that could profit from the ability
PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler phase = ai.getGame().getPhaseHandler();
if (type.equals("P1P1") && sa.isAbility() && source.isCreature() if (type.equals("P1P1") && sa.isAbility() && source.isCreature()
&& sa.getPayCosts() != null && sa.getPayCosts().hasTapCost() && sa.getPayCosts() != null && sa.getPayCosts().hasTapCost()
&& sa instanceof AbilitySub && sa instanceof AbilitySub

View File

@@ -4,7 +4,6 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -66,7 +65,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
return false; return false;
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases") && !sa.hasParam("ActivationPhases")
&& !type.equals("M1M1")) { && !type.equals("M1M1")) {
return false; return false;

View File

@@ -6,9 +6,9 @@ import com.google.common.collect.Iterables;
import forge.Card; import forge.Card;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
@@ -17,6 +17,7 @@ import forge.game.zone.ZoneType;
public abstract class DamageAiBase extends SpellAbilityAi { public abstract class DamageAiBase extends SpellAbilityAi {
protected boolean shouldTgtP(final Player comp, final SpellAbility sa, final int d, final boolean noPrevention) { protected boolean shouldTgtP(final Player comp, final SpellAbility sa, final int d, final boolean noPrevention) {
int restDamage = d; int restDamage = d;
final GameState game = comp.getGame();
final Player enemy = comp.getOpponent(); final Player enemy = comp.getOpponent();
if (!sa.canTarget(enemy)) { if (!sa.canTarget(enemy)) {
return false; return false;
@@ -44,8 +45,8 @@ public abstract class DamageAiBase extends SpellAbilityAi {
if (sa.isSpell()) { if (sa.isSpell()) {
// If this is a spell, cast it instead of discarding // If this is a spell, cast it instead of discarding
if ((Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) || Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.MAIN2)) if ((game.getPhaseHandler().is(PhaseType.END_OF_TURN) || game.getPhaseHandler().is(PhaseType.MAIN2))
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(comp) && (hand.size() > comp.getMaxHandSize())) { && game.getPhaseHandler().isPlayerTurn(comp) && (hand.size() > comp.getMaxHandSize())) {
return true; return true;
} }
} }

View File

@@ -8,7 +8,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -86,7 +85,7 @@ public class DamageAllAi extends SpellAbilityAi {
} }
// wait until stack is empty (prevents duplicate kills) // wait until stack is empty (prevents duplicate kills)
if (!Singletons.getModel().getGame().getStack().isEmpty()) { if (!ai.getGame().getStack().isEmpty()) {
return false; return false;
} }

View File

@@ -8,13 +8,13 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
@@ -81,7 +81,7 @@ public class DamageDealAi extends DamageAiBase {
if (source.getName().equals("Stuffy Doll")) { if (source.getName().equals("Stuffy Doll")) {
// Now stuffy sits around for blocking // Now stuffy sits around for blocking
// TODO(sol): this should also happen if Stuffy is going to die // TODO(sol): this should also happen if Stuffy is going to die
return Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai.getOpponent()); return ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai.getOpponent());
} }
if (sa.isAbility()) { if (sa.isAbility()) {
@@ -133,7 +133,7 @@ public class DamageDealAi extends DamageAiBase {
final Player pl, final boolean mandatory) { final Player pl, final boolean mandatory) {
// wait until stack is empty (prevents duplicate kills) // wait until stack is empty (prevents duplicate kills)
if (!saMe.isTrigger() && !Singletons.getModel().getGame().getStack().isEmpty()) { if (!saMe.isTrigger() && !ai.getGame().getStack().isEmpty()) {
return null; return null;
} }
final Target tgt = saMe.getTarget(); final Target tgt = saMe.getTarget();
@@ -226,7 +226,8 @@ public class DamageDealAi extends DamageAiBase {
final boolean isTrigger, final boolean mandatory) { final boolean isTrigger, final boolean mandatory) {
final Card source = saMe.getSourceCard(); final Card source = saMe.getSourceCard();
final boolean noPrevention = saMe.hasParam("NoPrevention"); final boolean noPrevention = saMe.hasParam("NoPrevention");
final PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); final GameState game = source.getGame();
final PhaseHandler phase = game.getPhaseHandler();
final boolean divided = saMe.hasParam("DividedAsYouChoose"); final boolean divided = saMe.hasParam("DividedAsYouChoose");
// target loop // target loop

View File

@@ -6,12 +6,12 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
@@ -27,6 +27,7 @@ public class DamagePreventAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final GameState game = ai.getGame();
boolean chance = false; boolean chance = false;
final Cost cost = sa.getPayCosts(); final Cost cost = sa.getPayCosts();
@@ -56,7 +57,7 @@ public class DamagePreventAi extends SpellAbilityAi {
sa.getParam("Defined"), sa); sa.getParam("Defined"), sa);
// react to threats on the stack // react to threats on the stack
if (Singletons.getModel().getGame().getStack().size() > 0) { if (game.getStack().size() > 0) {
final ArrayList<Object> threatenedObjects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa); final ArrayList<Object> threatenedObjects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa);
for (final Object o : objects) { for (final Object o : objects) {
if (threatenedObjects.contains(o)) { if (threatenedObjects.contains(o)) {
@@ -64,7 +65,7 @@ public class DamagePreventAi extends SpellAbilityAi {
} }
} }
} else { } else {
PhaseHandler handler = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler handler = game.getPhaseHandler();
if (handler.is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (handler.is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
boolean flag = false; boolean flag = false;
for (final Object o : objects) { for (final Object o : objects) {
@@ -75,8 +76,8 @@ public class DamagePreventAi extends SpellAbilityAi {
// Don't need to worry about Combat Damage during AI's turn // Don't need to worry about Combat Damage during AI's turn
final Player p = (Player) o; final Player p = (Player) o;
if (!handler.isPlayerTurn(p)) { if (!handler.isPlayerTurn(p)) {
flag |= (p == ai && ((ComputerUtilCombat.wouldLoseLife(ai, Singletons.getModel().getGame().getCombat()) && sa flag |= (p == ai && ((ComputerUtilCombat.wouldLoseLife(ai, game.getCombat()) && sa
.isAbility()) || ComputerUtilCombat.lifeInDanger(ai, Singletons.getModel().getGame().getCombat()))); .isAbility()) || ComputerUtilCombat.lifeInDanger(ai, game.getCombat())));
} }
} }
} }
@@ -90,7 +91,7 @@ public class DamagePreventAi extends SpellAbilityAi {
} // targeted } // targeted
// react to threats on the stack // react to threats on the stack
else if (Singletons.getModel().getGame().getStack().size() > 0) { else if (game.getStack().size() > 0) {
tgt.resetTargets(); tgt.resetTargets();
// check stack for something on the stack will kill anything i // check stack for something on the stack will kill anything i
// control // control
@@ -118,10 +119,10 @@ public class DamagePreventAi extends SpellAbilityAi {
} }
} // Protect combatants } // Protect combatants
else if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { else if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
if (sa.canTarget(ai) && ComputerUtilCombat.wouldLoseLife(ai, Singletons.getModel().getGame().getCombat()) if (sa.canTarget(ai) && ComputerUtilCombat.wouldLoseLife(ai, game.getCombat())
&& (ComputerUtilCombat.lifeInDanger(ai, Singletons.getModel().getGame().getCombat()) || sa.isAbility()) && (ComputerUtilCombat.lifeInDanger(ai, game.getCombat()) || sa.isAbility())
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai.getOpponent())) { && game.getPhaseHandler().isPlayerTurn(ai.getOpponent())) {
tgt.addTarget(ai); tgt.addTarget(ai);
chance = true; chance = true;
} else { } else {
@@ -180,7 +181,8 @@ public class DamagePreventAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
tgt.resetTargets(); tgt.resetTargets();
// filter AIs battlefield by what I can target // filter AIs battlefield by what I can target
List<Card> targetables = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final GameState game = ai.getGame();
List<Card> targetables = game.getCardsIn(ZoneType.Battlefield);
targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, sa.getSourceCard()); targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, sa.getSourceCard());
final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai); final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai);
@@ -195,7 +197,7 @@ public class DamagePreventAi extends SpellAbilityAi {
if (compTargetables.size() > 0) { if (compTargetables.size() > 0) {
final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES); final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES);
CardLists.sortByEvaluateCreature(combatants); CardLists.sortByEvaluateCreature(combatants);
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
for (final Card c : combatants) { for (final Card c : combatants) {
if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c)) { if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c)) {
tgt.addTarget(c); tgt.addTarget(c);

View File

@@ -2,7 +2,6 @@ package forge.card.ability.ai;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -39,12 +38,12 @@ public class DamagePreventAllAi extends SpellAbilityAi {
return false; return false;
} }
if (Singletons.getModel().getGame().getStack().size() > 0) { if (ai.getGame().getStack().size() > 0) {
// TODO check stack for something on the stack will kill anything i // TODO check stack for something on the stack will kill anything i
// control // control
} // Protect combatants } // Protect combatants
else if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { else if (ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
// TODO // TODO
} }

View File

@@ -8,7 +8,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -52,12 +51,12 @@ public class DebuffAi extends SpellAbilityAi {
} }
final SpellAbilityRestriction restrict = sa.getRestrictions(); final SpellAbilityRestriction restrict = sa.getRestrictions();
final PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); final PhaseHandler ph = ai.getGame().getPhaseHandler();
// Phase Restrictions // Phase Restrictions
if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
|| !Singletons.getModel().getGame().getStack().isEmpty()) { || !ai.getGame().getStack().isEmpty()) {
// Instant-speed pumps should not be cast outside of combat when the // Instant-speed pumps should not be cast outside of combat when the
// stack is empty // stack is empty
if (!SpellAbilityAi.isSorcerySpeed(sa)) { if (!SpellAbilityAi.isSorcerySpeed(sa)) {
@@ -126,7 +125,7 @@ public class DebuffAi extends SpellAbilityAi {
*/ */
private boolean debuffTgtAI(final Player ai, final SpellAbility sa, final List<String> kws, final boolean mandatory) { private boolean debuffTgtAI(final Player ai, final SpellAbility sa, final List<String> kws, final boolean mandatory) {
// this would be for evasive things like Flying, Unblockable, etc // this would be for evasive things like Flying, Unblockable, etc
if (!mandatory && Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (!mandatory && ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
return false; return false;
} }
@@ -217,7 +216,7 @@ public class DebuffAi extends SpellAbilityAi {
* @return a boolean. * @return a boolean.
*/ */
private boolean debuffMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) { private boolean debuffMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) {
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = ai.getGame().getCardsIn(ZoneType.Battlefield);
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());

View File

@@ -7,7 +7,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.phase.CombatUtil; import forge.game.phase.CombatUtil;
@@ -49,7 +48,7 @@ public class DebuffAllAi extends SpellAbilityAi {
}); });
// don't use DebuffAll after Combat_Begin until AI is improved // don't use DebuffAll after Combat_Begin until AI is improved
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_BEGIN)) { if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_BEGIN)) {
return false; return false;
} }

View File

@@ -9,7 +9,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -172,7 +171,7 @@ public class DestroyAi extends SpellAbilityAi {
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();
if (tgt != null) { if (tgt != null) {
List<Card> list; List<Card> list;
list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); list = ai.getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);
list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source);

View File

@@ -2,7 +2,6 @@ package forge.card.ability.ai;
import java.util.Random; import java.util.Random;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -47,7 +46,7 @@ public class DigAi extends SpellAbilityAi {
} }
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases") if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
&& !sa.hasParam("DestinationZone")) { && !sa.hasParam("DestinationZone")) {
return false; return false;
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -95,7 +94,7 @@ public class DiscardAi extends SpellAbilityAi {
// TODO: Implement support for Discard AI for cards with AnyNumber set to true. // TODO: Implement support for Discard AI for cards with AnyNumber set to true.
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }

View File

@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -32,6 +31,7 @@ import forge.card.cost.PaymentDecision;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
import forge.game.ai.ComputerUtilMana; import forge.game.ai.ComputerUtilMana;
@@ -56,6 +56,7 @@ public class DrawAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final GameState game = ai.getGame();
if (abCost != null) { if (abCost != null) {
// AI currently disabled for these costs // AI currently disabled for these costs
@@ -103,12 +104,12 @@ public class DrawAi extends SpellAbilityAi {
} }
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
if ((!Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai) if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|| Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN)) || game.getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN))
&& !sa.hasParam("PlayerTurn") && !SpellAbilityAi.isSorcerySpeed(sa) && !sa.hasParam("PlayerTurn") && !SpellAbilityAi.isSorcerySpeed(sa)
&& ai.getCardsIn(ZoneType.Hand).size() > 1) { && ai.getCardsIn(ZoneType.Hand).size() > 1) {
return false; return false;
@@ -126,8 +127,8 @@ public class DrawAi extends SpellAbilityAi {
if (SpellAbilityAi.isSorcerySpeed(sa)) { if (SpellAbilityAi.isSorcerySpeed(sa)) {
randomReturn = true; randomReturn = true;
} }
if ((Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) if ((game.getPhaseHandler().is(PhaseType.END_OF_TURN)
&& Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai))) { && game.getPhaseHandler().getNextTurn().equals(ai))) {
randomReturn = true; randomReturn = true;
} }
@@ -142,6 +143,7 @@ public class DrawAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final boolean drawback = (sa instanceof AbilitySub); final boolean drawback = (sa instanceof AbilitySub);
final GameState game = ai.getGame();
Player opp = ai.getOpponent(); Player opp = ai.getOpponent();
int computerHandSize = ai.getCardsIn(ZoneType.Hand).size(); int computerHandSize = ai.getCardsIn(ZoneType.Hand).size();
@@ -209,7 +211,7 @@ public class DrawAi extends SpellAbilityAi {
} }
if (((computerHandSize + numCards) > computerMaxHandSize) if (((computerHandSize + numCards) > computerMaxHandSize)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai)) { && game.getPhaseHandler().isPlayerTurn(ai)) {
if (xPaid) { if (xPaid) {
numCards = computerMaxHandSize - computerHandSize; numCards = computerMaxHandSize - computerHandSize;
source.setSVar("PayX", Integer.toString(numCards)); source.setSVar("PayX", Integer.toString(numCards));
@@ -247,7 +249,7 @@ public class DrawAi extends SpellAbilityAi {
} }
if ((computerHandSize + numCards > computerMaxHandSize) if ((computerHandSize + numCards > computerMaxHandSize)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai) && game.getPhaseHandler().isPlayerTurn(ai)
&& !sa.isTrigger()) { && !sa.isTrigger()) {
// Don't draw too many cards and then risk discarding cards at // Don't draw too many cards and then risk discarding cards at
// EOT // EOT

View File

@@ -7,7 +7,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -25,7 +24,7 @@ import forge.util.MyRandom;
public class EffectAi extends SpellAbilityAi { public class EffectAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final GameState game = Singletons.getModel().getGame(); final GameState game = ai.getGame();
final Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
boolean randomReturn = r.nextFloat() <= .6667; boolean randomReturn = r.nextFloat() <= .6667;
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();

View File

@@ -1,9 +1,9 @@
package forge.card.ability.ai; package forge.card.ability.ai;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -15,38 +15,40 @@ public class FogAi extends SpellAbilityAi {
*/ */
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final GameState game = ai.getGame();
// AI should only activate this during Human's Declare Blockers phase // AI should only activate this during Human's Declare Blockers phase
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())) { if (game.getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())) {
return false; return false;
} }
if (!Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
return false; return false;
} }
// Only cast when Stack is empty, so Human uses spells/abilities first // Only cast when Stack is empty, so Human uses spells/abilities first
if (!Singletons.getModel().getGame().getStack().isEmpty()) { if (!game.getStack().isEmpty()) {
return false; return false;
} }
// Don't cast it, if the effect is already in place // Don't cast it, if the effect is already in place
if (Singletons.getModel().getGame().getPhaseHandler().isPreventCombatDamageThisTurn()) { if (game.getPhaseHandler().isPreventCombatDamageThisTurn()) {
return false; return false;
} }
// Cast it if life is in danger // Cast it if life is in danger
return ComputerUtilCombat.lifeInDanger(ai, Singletons.getModel().getGame().getCombat()); return ComputerUtilCombat.lifeInDanger(ai, game.getCombat());
} }
@Override @Override
public boolean chkAIDrawback(SpellAbility sa, AIPlayer ai) { public boolean chkAIDrawback(SpellAbility sa, AIPlayer ai) {
// AI should only activate this during Human's turn // AI should only activate this during Human's turn
boolean chance; boolean chance;
final GameState game = ai.getGame();
// should really check if other player is attacking this player // should really check if other player is attacking this player
if (ai.isOpponentOf(Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn())) { if (ai.isOpponentOf(game.getPhaseHandler().getPlayerTurn())) {
chance = Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE); chance = game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE);
} else { } else {
chance = Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE); chance = game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE);
} }
return chance; return chance;
@@ -54,11 +56,12 @@ public class FogAi extends SpellAbilityAi {
@Override @Override
protected boolean doTriggerAINoCost(AIPlayer aiPlayer, SpellAbility sa, boolean mandatory) { protected boolean doTriggerAINoCost(AIPlayer aiPlayer, SpellAbility sa, boolean mandatory) {
final GameState game = aiPlayer.getGame();
boolean chance; boolean chance;
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer().getOpponent())) { if (game.getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer().getOpponent())) {
chance = Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE); chance = game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE);
} else { } else {
chance = Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE); chance = game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE);
} }
return chance; return chance;

View File

@@ -3,13 +3,13 @@ package forge.card.ability.ai;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
@@ -34,6 +34,7 @@ public class LifeGainAi extends SpellAbilityAi {
final Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = source.getGame();
final int life = ai.getLife(); final int life = ai.getLife();
final String amountStr = sa.getParam("LifeAmount"); final String amountStr = sa.getParam("LifeAmount");
int lifeAmount = 0; int lifeAmount = 0;
@@ -62,13 +63,13 @@ public class LifeGainAi extends SpellAbilityAi {
return false; return false;
} }
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
boolean lifeCritical = life <= 5; boolean lifeCritical = life <= 5;
lifeCritical |= (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DAMAGE) && ComputerUtilCombat lifeCritical |= (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DAMAGE) && ComputerUtilCombat
.lifeInDanger(ai, Singletons.getModel().getGame().getCombat())); .lifeInDanger(ai, game.getCombat()));
if (abCost != null && !lifeCritical) { if (abCost != null && !lifeCritical) {
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, false)) { if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, false)) {
@@ -93,13 +94,13 @@ public class LifeGainAi extends SpellAbilityAi {
} }
// Don't use lifegain before main 2 if possible // Don't use lifegain before main 2 if possible
if (!lifeCritical && Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (!lifeCritical && game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
// Don't use lifegain before main 2 if possible // Don't use lifegain before main 2 if possible
if (!lifeCritical && (!Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai) if (!lifeCritical && (!game.getPhaseHandler().getNextTurn().equals(ai)
|| Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN)) || game.getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN))
&& !sa.hasParam("PlayerTurn") && !SpellAbilityAi.isSorcerySpeed(sa)) { && !sa.hasParam("PlayerTurn") && !SpellAbilityAi.isSorcerySpeed(sa)) {
return false; return false;
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -110,7 +109,7 @@ public class LifeLoseAi extends SpellAbilityAi {
} }
// Don't use loselife before main 2 if possible // Don't use loselife before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases") && !priority) { && !sa.hasParam("ActivationPhases") && !priority) {
return false; return false;
} }

View File

@@ -4,7 +4,6 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -32,7 +31,7 @@ public class LifeSetAi extends SpellAbilityAi {
} }
// Don't use setLife before main 2 if possible // Don't use setLife before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -53,7 +52,7 @@ public class MillAi extends SpellAbilityAi {
final Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")) { if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
@@ -68,8 +67,7 @@ public class MillAi extends SpellAbilityAi {
chance = .667; // 66.7% chance for sorcery speed chance = .667; // 66.7% chance for sorcery speed
} }
if ((Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) if ((ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) && ai.getGame().getPhaseHandler().getNextTurn().equals(ai))) {
&& Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai))) {
chance = .9; // 90% for end of opponents turn chance = .9; // 90% for end of opponents turn
} }

View File

@@ -7,7 +7,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -39,7 +38,7 @@ public class MustBlockAi extends SpellAbilityAi {
final Target abTgt = sa.getTarget(); final Target abTgt = sa.getTarget();
// only use on creatures that can attack // only use on creatures that can attack
if (!Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) { if (!ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) {
return false; return false;
} }

View File

@@ -7,7 +7,6 @@ import com.google.common.collect.Iterables;
import forge.Card; import forge.Card;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState; import forge.game.GameState;
@@ -28,7 +27,7 @@ public class PermanentCreatureAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) { protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) {
String logic = sa.getParam("AILogic"); String logic = sa.getParam("AILogic");
GameState game = Singletons.getModel().getGame(); GameState game = aiPlayer.getGame();
if ("ZeroToughness".equals(logic)) { if ("ZeroToughness".equals(logic)) {
// If Creature has Zero Toughness, make sure some static ability is in play // If Creature has Zero Toughness, make sure some static ability is in play

View File

@@ -1,9 +1,7 @@
package forge.card.ability.ai; package forge.card.ability.ai;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -20,7 +18,6 @@ public class PermanentNoncreatureAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) { protected boolean canPlayAI(AIPlayer aiPlayer, SpellAbility sa) {
String logic = sa.getParam("AILogic"); String logic = sa.getParam("AILogic");
GameState game = Singletons.getModel().getGame();
if ("DontCast".equals(logic)) { if ("DontCast".equals(logic)) {
return false; return false;
@@ -29,7 +26,7 @@ public class PermanentNoncreatureAi extends SpellAbilityAi {
} }
// Wait for Main2 if possible // Wait for Main2 if possible
if (game.getPhaseHandler().is(PhaseType.MAIN1) if (aiPlayer.getGame().getPhaseHandler().is(PhaseType.MAIN1)
&& !ComputerUtil.castPermanentInMain1(aiPlayer, sa)) { && !ComputerUtil.castPermanentInMain1(aiPlayer, sa)) {
return false; return false;
} }

View File

@@ -5,11 +5,11 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.util.MyRandom; import forge.util.MyRandom;
@@ -61,7 +61,7 @@ public class PhasesAi extends SpellAbilityAi {
return true; return true;
} else if (mandatory) { } else if (mandatory) {
// not enough preferred targets, but mandatory so keep going: // not enough preferred targets, but mandatory so keep going:
return phasesUnpreferredTargeting(sa, mandatory); return phasesUnpreferredTargeting(aiPlayer.getGame(), sa, mandatory);
} }
return false; return false;
@@ -133,12 +133,11 @@ public class PhasesAi extends SpellAbilityAi {
* a boolean. * a boolean.
* @return a boolean. * @return a boolean.
*/ */
private boolean phasesUnpreferredTargeting(final SpellAbility sa, private boolean phasesUnpreferredTargeting(final GameState game, final SpellAbility sa, final boolean mandatory) {
final boolean mandatory) {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = game.getCardsIn(ZoneType.Battlefield);
list = CardLists.getTargetableCards(CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source), sa); list = CardLists.getTargetableCards(CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source), sa);
return false; return false;

View File

@@ -6,7 +6,6 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -47,7 +46,7 @@ public class PlayAi extends SpellAbilityAi {
} }
// don't use this as a response // don't use this as a response
if (!Singletons.getModel().getGame().getStack().isEmpty()) { if (!ai.getGame().getStack().isEmpty()) {
return false; return false;
} }
@@ -58,7 +57,7 @@ public class PlayAi extends SpellAbilityAi {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
if (tgt != null) { if (tgt != null) {
ZoneType zone = tgt.getZone().get(0); ZoneType zone = tgt.getZone().get(0);
cards = CardLists.getValidCards(Singletons.getModel().getGame().getCardsIn(zone), tgt.getValidTgts(), ai, source); cards = CardLists.getValidCards(ai.getGame().getCardsIn(zone), tgt.getValidTgts(), ai, source);
if (cards.isEmpty()) { if (cards.isEmpty()) {
return false; return false;
} }

View File

@@ -3,7 +3,6 @@ package forge.card.ability.ai;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -51,7 +50,7 @@ public class PoisonAi extends SpellAbilityAi {
} }
// Don't use poison before main 2 if possible // Don't use poison before main 2 if possible
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }

View File

@@ -8,7 +8,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Constant; import forge.Constant;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -68,7 +67,7 @@ public class ProtectAi extends SpellAbilityAi {
*/ */
private static List<Card> getProtectCreatures(final Player ai, final SpellAbility sa) { private static List<Card> getProtectCreatures(final Player ai, final SpellAbility sa) {
final ArrayList<String> gains = AbilityUtils.getProtectionList(sa); final ArrayList<String> gains = AbilityUtils.getProtectionList(sa);
final GameState game = Singletons.getModel().getGame(); final GameState game = ai.getGame();
List<Card> list = ai.getCreaturesInPlay(); List<Card> list = ai.getCreaturesInPlay();
list = CardLists.filter(list, new Predicate<Card>() { list = CardLists.filter(list, new Predicate<Card>() {
@@ -113,6 +112,7 @@ public class ProtectAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final GameState game = ai.getGame();
// if there is no target and host card isn't in play, don't activate // if there is no target and host card isn't in play, don't activate
if ((sa.getTarget() == null) && !hostCard.isInPlay()) { if ((sa.getTarget() == null) && !hostCard.isInPlay()) {
return false; return false;
@@ -138,13 +138,13 @@ public class ProtectAi extends SpellAbilityAi {
} }
// Phase Restrictions // Phase Restrictions
if ((Singletons.getModel().getGame().getStack().size() == 0) && Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE)) { if ((game.getStack().size() == 0) && game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE)) {
// Instant-speed protections should not be cast outside of combat // Instant-speed protections should not be cast outside of combat
// when the stack is empty // when the stack is empty
if (!SpellAbilityAi.isSorcerySpeed(sa)) { if (!SpellAbilityAi.isSorcerySpeed(sa)) {
return false; return false;
} }
} else if (Singletons.getModel().getGame().getStack().size() > 0) { } else if (game.getStack().size() > 0) {
// TODO protection something only if the top thing on the stack will // TODO protection something only if the top thing on the stack will
// kill it via damage or destroy // kill it via damage or destroy
return false; return false;
@@ -172,7 +172,8 @@ public class ProtectAi extends SpellAbilityAi {
} // protectPlayAI() } // protectPlayAI()
private boolean protectTgtAI(final Player ai, final SpellAbility sa, final boolean mandatory) { private boolean protectTgtAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
if (!mandatory && Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { final GameState game = ai.getGame();
if (!mandatory && game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
return false; return false;
} }
@@ -195,16 +196,16 @@ public class ProtectAi extends SpellAbilityAi {
* Or, add protection (to make it unblockable) when Compy is attacking. * Or, add protection (to make it unblockable) when Compy is attacking.
*/ */
if (Singletons.getModel().getGame().getStack().isEmpty()) { if (game.getStack().isEmpty()) {
// If the cost is tapping, don't activate before declare // If the cost is tapping, don't activate before declare
// attack/block // attack/block
if ((sa.getPayCosts() != null) && sa.getPayCosts().hasTapCost()) { if ((sa.getPayCosts() != null) && sa.getPayCosts().hasTapCost()) {
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai)) { && game.getPhaseHandler().isPlayerTurn(ai)) {
list.remove(sa.getSourceCard()); list.remove(sa.getSourceCard());
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai)) { && game.getPhaseHandler().isPlayerTurn(ai)) {
list.remove(sa.getSourceCard()); list.remove(sa.getSourceCard());
} }
} }
@@ -250,9 +251,9 @@ public class ProtectAi extends SpellAbilityAi {
} // protectTgtAI() } // protectTgtAI()
private static boolean protectMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) { private static boolean protectMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) {
final GameState game = ai.getGame();
List<Card> list = game.getCardsIn(ZoneType.Battlefield);
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield);
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());

View File

@@ -9,7 +9,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -18,6 +17,7 @@ import forge.card.cost.CostTapType;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.SpellAbilityRestriction;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
@@ -49,7 +49,8 @@ public class PumpAi extends PumpAiBase {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Cost cost = sa.getPayCosts(); final Cost cost = sa.getPayCosts();
final PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); final GameState game = ai.getGame();
final PhaseHandler ph = game.getPhaseHandler();
final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>(); final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>();
final String numDefense = sa.hasParam("NumDef") ? sa.getParam("NumDef") : ""; final String numDefense = sa.hasParam("NumDef") ? sa.getParam("NumDef") : "";
final String numAttack = sa.hasParam("NumAtt") ? sa.getParam("NumAtt") : ""; final String numAttack = sa.hasParam("NumAtt") ? sa.getParam("NumAtt") : "";
@@ -70,7 +71,7 @@ public class PumpAi extends PumpAiBase {
return false; return false;
} }
if (Singletons.getModel().getGame().getStack().isEmpty() && hasTapCost(cost, sa.getSourceCard())) { if (game.getStack().isEmpty() && hasTapCost(cost, sa.getSourceCard())) {
if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && ph.isPlayerTurn(ai)) { if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && ph.isPlayerTurn(ai)) {
return false; return false;
} }
@@ -83,13 +84,13 @@ public class PumpAi extends PumpAiBase {
} }
// Phase Restrictions // Phase Restrictions
if ((Singletons.getModel().getGame().getStack().size() == 0) && ph.getPhase().isBefore(PhaseType.COMBAT_BEGIN)) { if ((game.getStack().size() == 0) && ph.getPhase().isBefore(PhaseType.COMBAT_BEGIN)) {
// Instant-speed pumps should not be cast outside of combat when the // Instant-speed pumps should not be cast outside of combat when the
// stack is empty // stack is empty
if (!sa.isCurse() && !SpellAbilityAi.isSorcerySpeed(sa)) { if (!sa.isCurse() && !SpellAbilityAi.isSorcerySpeed(sa)) {
return false; return false;
} }
} else if (Singletons.getModel().getGame().getStack().size() > 0) { } else if (game.getStack().size() > 0) {
if (!keywords.contains("Shroud") && !keywords.contains("Hexproof")) { if (!keywords.contains("Shroud") && !keywords.contains("Hexproof")) {
return false; return false;
} }
@@ -181,10 +182,11 @@ public class PumpAi extends PumpAiBase {
private boolean pumpTgtAI(final Player ai, final SpellAbility sa, final int defense, final int attack, final boolean mandatory) { private boolean pumpTgtAI(final Player ai, final SpellAbility sa, final int defense, final int attack, final boolean mandatory) {
final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>(); final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>();
final GameState game = ai.getGame();
if (!mandatory if (!mandatory
&& !sa.isTrigger() && !sa.isTrigger()
&& Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) && game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
&& !(sa.isCurse() && (defense < 0)) && !(sa.isCurse() && (defense < 0))
&& !this.containsNonCombatKeyword(keywords) && !this.containsNonCombatKeyword(keywords)
&& !sa.hasParam("UntilYourNextTurn")) { && !sa.hasParam("UntilYourNextTurn")) {
@@ -197,7 +199,7 @@ public class PumpAi extends PumpAiBase {
List<Card> list = new ArrayList<Card>(); List<Card> list = new ArrayList<Card>();
if (sa.hasParam("AILogic")) { if (sa.hasParam("AILogic")) {
if (sa.getParam("AILogic").equals("HighestPower")) { if (sa.getParam("AILogic").equals("HighestPower")) {
list = CardLists.getValidCards(CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); list = CardLists.getValidCards(CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Presets.CREATURES), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);
CardLists.sortByPowerDesc(list); CardLists.sortByPowerDesc(list);
if (!list.isEmpty()) { if (!list.isEmpty()) {
@@ -216,7 +218,7 @@ public class PumpAi extends PumpAiBase {
} else { } else {
if (!tgt.canTgtCreature()) { if (!tgt.canTgtCreature()) {
ZoneType zone = tgt.getZone().get(0); ZoneType zone = tgt.getZone().get(0);
list = Singletons.getModel().getGame().getCardsIn(zone); list = game.getCardsIn(zone);
} else { } else {
list = this.getPumpCreatures(ai, sa, defense, attack, keywords); list = this.getPumpCreatures(ai, sa, defense, attack, keywords);
} }
@@ -227,16 +229,16 @@ public class PumpAi extends PumpAiBase {
} }
list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, sa.getSourceCard()); list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, sa.getSourceCard());
if (Singletons.getModel().getGame().getStack().size() == 0) { if (game.getStack().size() == 0) {
// If the cost is tapping, don't activate before declare // If the cost is tapping, don't activate before declare
// attack/block // attack/block
if ((sa.getPayCosts() != null) && sa.getPayCosts().hasTapCost()) { if ((sa.getPayCosts() != null) && sa.getPayCosts().hasTapCost()) {
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai)) { && game.getPhaseHandler().isPlayerTurn(ai)) {
list.remove(sa.getSourceCard()); list.remove(sa.getSourceCard());
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
&& Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(opp)) { && game.getPhaseHandler().isPlayerTurn(opp)) {
list.remove(sa.getSourceCard()); list.remove(sa.getSourceCard());
} }
} }
@@ -283,7 +285,8 @@ public class PumpAi extends PumpAiBase {
} // pumpTgtAI() } // pumpTgtAI()
private boolean pumpMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) { private boolean pumpMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) {
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final GameState game = ai.getGame();
List<Card> list = game.getCardsIn(ZoneType.Battlefield);
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());

View File

@@ -11,7 +11,6 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.CardUtil; import forge.CardUtil;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState; import forge.game.GameState;
@@ -52,7 +51,8 @@ public abstract class PumpAiBase extends SpellAbilityAi {
* @return true, if is useful keyword * @return true, if is useful keyword
*/ */
public boolean isUsefulCurseKeyword(final Player ai, final String keyword, final Card card, final SpellAbility sa) { public boolean isUsefulCurseKeyword(final Player ai, final String keyword, final Card card, final SpellAbility sa) {
final PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); final GameState game = ai.getGame();
final PhaseHandler ph = game.getPhaseHandler();
final Player human = ai.getOpponent(); final Player human = ai.getOpponent();
//int attack = getNumAttack(sa); //int attack = getNumAttack(sa);
//int defense = getNumDefense(sa); //int defense = getNumDefense(sa);
@@ -157,7 +157,8 @@ public abstract class PumpAiBase extends SpellAbilityAi {
* @return true, if is useful keyword * @return true, if is useful keyword
*/ */
public boolean isUsefulPumpKeyword(final Player ai, final String keyword, final Card card, final SpellAbility sa, final int attack) { public boolean isUsefulPumpKeyword(final Player ai, final String keyword, final Card card, final SpellAbility sa, final int attack) {
final PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); final GameState game = ai.getGame();
final PhaseHandler ph = game.getPhaseHandler();
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();
//int defense = getNumDefense(sa); //int defense = getNumDefense(sa);
if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) { if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) {
@@ -179,10 +180,10 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} else if (keyword.endsWith("Flying")) { } else if (keyword.endsWith("Flying")) {
if (ph.isPlayerTurn(opp) if (ph.isPlayerTurn(opp)
&& ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
&& !CardLists.getKeyword(Singletons.getModel().getGame().getCombat().getAttackers(), "Flying").isEmpty() && !CardLists.getKeyword(game.getCombat().getAttackers(), "Flying").isEmpty()
&& !card.hasKeyword("Reach") && !card.hasKeyword("Reach")
&& CombatUtil.canBlock(card) && CombatUtil.canBlock(card)
&& ComputerUtilCombat.lifeInDanger(ai, Singletons.getModel().getGame().getCombat())) { && ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) {
return true; return true;
} }
Predicate<Card> flyingOrReach = Predicates.or(CardPredicates.hasKeyword("Flying"), CardPredicates.hasKeyword("Reach")); Predicate<Card> flyingOrReach = Predicates.or(CardPredicates.hasKeyword("Flying"), CardPredicates.hasKeyword("Reach"));
@@ -196,9 +197,9 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} else if (keyword.endsWith("Horsemanship")) { } else if (keyword.endsWith("Horsemanship")) {
if (ph.isPlayerTurn(opp) if (ph.isPlayerTurn(opp)
&& ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
&& !CardLists.getKeyword(Singletons.getModel().getGame().getCombat().getAttackers(), "Horsemanship").isEmpty() && !CardLists.getKeyword(game.getCombat().getAttackers(), "Horsemanship").isEmpty()
&& CombatUtil.canBlock(card) && CombatUtil.canBlock(card)
&& ComputerUtilCombat.lifeInDanger(ai, Singletons.getModel().getGame().getCombat())) { && ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) {
return true; return true;
} }
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || card.isAttacking()) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || card.isAttacking())
@@ -219,7 +220,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} else if (keyword.endsWith("Indestructible")) { } else if (keyword.endsWith("Indestructible")) {
return true; return true;
} else if (keyword.endsWith("Deathtouch")) { } else if (keyword.endsWith("Deathtouch")) {
Combat combat = Singletons.getModel().getGame().getCombat(); Combat combat = game.getCombat();
if (ph.isPlayerTurn(opp) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)) { if (ph.isPlayerTurn(opp) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)) {
List<Card> attackers = combat.getAttackers(); List<Card> attackers = combat.getAttackers();
for (Card attacker : attackers) { for (Card attacker : attackers) {
@@ -312,7 +313,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} else if (keyword.equals("Reach")) { } else if (keyword.equals("Reach")) {
if (ph.isPlayerTurn(ai) if (ph.isPlayerTurn(ai)
|| !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
|| CardLists.getKeyword(Singletons.getModel().getGame().getCombat().getAttackers(), "Flying").isEmpty() || CardLists.getKeyword(game.getCombat().getAttackers(), "Flying").isEmpty()
|| card.hasKeyword("Flying") || card.hasKeyword("Flying")
|| !CombatUtil.canBlock(card)) { || !CombatUtil.canBlock(card)) {
return false; return false;
@@ -324,7 +325,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} }
int canBlockNum = 1 + card.getKeywordAmount("CARDNAME can block an additional creature."); int canBlockNum = 1 + card.getKeywordAmount("CARDNAME can block an additional creature.");
int possibleBlockNum = 0; int possibleBlockNum = 0;
for (Card attacker : Singletons.getModel().getGame().getCombat().getAttackers()) { for (Card attacker : game.getCombat().getAttackers()) {
if (CombatUtil.canBlock(attacker, card)) { if (CombatUtil.canBlock(attacker, card)) {
possibleBlockNum++; possibleBlockNum++;
if (possibleBlockNum > canBlockNum) { if (possibleBlockNum > canBlockNum) {
@@ -383,7 +384,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
protected boolean shouldPumpCard(final Player ai, final SpellAbility sa, final Card c, final int defense, final int attack, protected boolean shouldPumpCard(final Player ai, final SpellAbility sa, final Card c, final int defense, final int attack,
final List<String> keywords) { final List<String> keywords) {
final GameState game = Singletons.getModel().getGame(); final GameState game = ai.getGame();
PhaseHandler phase = game.getPhaseHandler(); PhaseHandler phase = game.getPhaseHandler();
if (!c.canBeTargetedBy(sa)) { if (!c.canBeTargetedBy(sa)) {
@@ -413,7 +414,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
if (defense > 0 && ComputerUtilCombat.blockerWouldBeDestroyed(ai, c)) { if (defense > 0 && ComputerUtilCombat.blockerWouldBeDestroyed(ai, c)) {
return true; return true;
} }
List<Card> blockedBy = Singletons.getModel().getGame().getCombat().getAttackersBlockedBy(c); List<Card> blockedBy = game.getCombat().getAttackersBlockedBy(c);
// For now, Only care the first creature blocked by a card. // For now, Only care the first creature blocked by a card.
// TODO Add in better BlockAdditional support // TODO Add in better BlockAdditional support
if (!blockedBy.isEmpty() && attack > 0 && !ComputerUtilCombat.attackerWouldBeDestroyed(ai, blockedBy.get(0))) { if (!blockedBy.isEmpty() && attack > 0 && !ComputerUtilCombat.attackerWouldBeDestroyed(ai, blockedBy.get(0))) {
@@ -490,6 +491,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
*/ */
protected List<Card> getCurseCreatures(final Player ai, final SpellAbility sa, final int defense, final int attack, final List<String> keywords) { protected List<Card> getCurseCreatures(final Player ai, final SpellAbility sa, final int defense, final int attack, final List<String> keywords) {
List<Card> list = ai.getOpponent().getCreaturesInPlay(); List<Card> list = ai.getOpponent().getCreaturesInPlay();
final GameState game = ai.getGame();
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);
if (list.isEmpty()) { if (list.isEmpty()) {
@@ -507,11 +509,11 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} }
}); // leaves all creatures that will be destroyed }); // leaves all creatures that will be destroyed
} // -X/-X end } // -X/-X end
else if (attack < 0 && !Singletons.getModel().getGame().getPhaseHandler().isPreventCombatDamageThisTurn()) { else if (attack < 0 && !game.getPhaseHandler().isPreventCombatDamageThisTurn()) {
// spells that give -X/0 // spells that give -X/0
boolean isMyTurn = Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai); boolean isMyTurn = game.getPhaseHandler().isPlayerTurn(ai);
if (isMyTurn) { if (isMyTurn) {
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_BEGIN)) { if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_BEGIN)) {
// TODO: Curse creatures that will block AI's creatures, if AI is going to attack. // TODO: Curse creatures that will block AI's creatures, if AI is going to attack.
list = new ArrayList<Card>(); list = new ArrayList<Card>();
} else { } else {
@@ -519,7 +521,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} }
} else { } else {
// Human active, only curse attacking creatures // Human active, only curse attacking creatures
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) { if (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
list = CardLists.filter(list, new Predicate<Card>() { list = CardLists.filter(list, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {

View File

@@ -8,10 +8,10 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
@@ -30,12 +30,13 @@ public class PumpAllAi extends PumpAiBase {
protected boolean canPlayAI(final AIPlayer ai, final SpellAbility sa) { protected boolean canPlayAI(final AIPlayer ai, final SpellAbility sa) {
String valid = ""; String valid = "";
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = ai.getGame();
final int power = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumAtt"), sa); final int power = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumAtt"), sa);
final int defense = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumDef"), sa); final int defense = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumDef"), sa);
final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>(); final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>();
final PhaseType phase = Singletons.getModel().getGame().getPhaseHandler().getPhase(); final PhaseType phase = game.getPhaseHandler().getPhase();
if (ComputerUtil.preventRunAwayActivations(sa)) { if (ComputerUtil.preventRunAwayActivations(sa)) {
return false; return false;
@@ -80,8 +81,8 @@ public class PumpAllAi extends PumpAiBase {
else if (power < 0) { // -X/-0 else if (power < 0) { // -X/-0
if (phase.isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) if (phase.isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
|| phase.isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || phase.isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)
|| Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer()) || game.getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())
|| Singletons.getModel().getGame().getPhaseHandler().isPreventCombatDamageThisTurn()) { || game.getPhaseHandler().isPreventCombatDamageThisTurn()) {
return false; return false;
} }
int totalPower = 0; int totalPower = 0;
@@ -91,8 +92,8 @@ public class PumpAllAi extends PumpAiBase {
} }
totalPower += Math.min(c.getNetAttack(), power * -1); totalPower += Math.min(c.getNetAttack(), power * -1);
if (phase == PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY if (phase == PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY
&& Singletons.getModel().getGame().getCombat().getUnblockedAttackers().contains(c)) { && game.getCombat().getUnblockedAttackers().contains(c)) {
if (ComputerUtilCombat.lifeInDanger(sa.getActivatingPlayer(), Singletons.getModel().getGame().getCombat())) { if (ComputerUtilCombat.lifeInDanger(sa.getActivatingPlayer(), game.getCombat())) {
return true; return true;
} }
totalPower += Math.min(c.getNetAttack(), power * -1); totalPower += Math.min(c.getNetAttack(), power * -1);

View File

@@ -23,12 +23,12 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
@@ -59,8 +59,10 @@ public class RegenerateAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
boolean chance = false;
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final GameState game = ai.getGame();
boolean chance = false;
if (abCost != null) { if (abCost != null) {
// AI currently disabled for these costs // AI currently disabled for these costs
if (!ComputerUtilCost.checkLifeCost(ai, abCost, hostCard, 4, null)) { if (!ComputerUtilCost.checkLifeCost(ai, abCost, hostCard, 4, null)) {
@@ -82,7 +84,7 @@ public class RegenerateAi extends SpellAbilityAi {
// them // them
final List<Card> list = AbilityUtils.getDefinedCards(hostCard, sa.getParam("Defined"), sa); final List<Card> list = AbilityUtils.getDefinedCards(hostCard, sa.getParam("Defined"), sa);
if (Singletons.getModel().getGame().getStack().size() > 0) { if (game.getStack().size() > 0) {
final List<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa); final List<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa);
for (final Card c : list) { for (final Card c : list) {
@@ -91,7 +93,7 @@ public class RegenerateAi extends SpellAbilityAi {
} }
} }
} else { } else {
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
boolean flag = false; boolean flag = false;
for (final Card c : list) { for (final Card c : list) {
@@ -116,7 +118,7 @@ public class RegenerateAi extends SpellAbilityAi {
return false; return false;
} }
if (Singletons.getModel().getGame().getStack().size() > 0) { if (game.getStack().size() > 0) {
// check stack for something on the stack will kill anything i // check stack for something on the stack will kill anything i
// control // control
final ArrayList<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa); final ArrayList<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa);
@@ -135,7 +137,7 @@ public class RegenerateAi extends SpellAbilityAi {
chance = true; chance = true;
} }
} else { } else {
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
final List<Card> combatants = CardLists.filter(targetables, CardPredicates.Presets.CREATURES); final List<Card> combatants = CardLists.filter(targetables, CardPredicates.Presets.CREATURES);
CardLists.sortByEvaluateCreature(combatants); CardLists.sortByEvaluateCreature(combatants);
@@ -173,10 +175,11 @@ public class RegenerateAi extends SpellAbilityAi {
private static boolean regenMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) { private static boolean regenMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final GameState game = ai.getGame();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
tgt.resetTargets(); tgt.resetTargets();
// filter AIs battlefield by what I can target // filter AIs battlefield by what I can target
List<Card> targetables = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> targetables = game.getCardsIn(ZoneType.Battlefield);
targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, hostCard); targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, hostCard);
targetables = CardLists.getTargetableCards(targetables, sa); targetables = CardLists.getTargetableCards(targetables, sa);
final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai); final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai);
@@ -192,7 +195,7 @@ public class RegenerateAi extends SpellAbilityAi {
if (compTargetables.size() > 0) { if (compTargetables.size() > 0) {
final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES); final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES);
CardLists.sortByEvaluateCreature(combatants); CardLists.sortByEvaluateCreature(combatants);
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
for (final Card c : combatants) { for (final Card c : combatants) {
if ((c.getShield() == 0) && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c)) { if ((c.getShield() == 0) && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c)) {
tgt.addTarget(c); tgt.addTarget(c);

View File

@@ -6,10 +6,10 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
@@ -24,6 +24,7 @@ public class RegenerateAllAi extends SpellAbilityAi {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
boolean chance = false; boolean chance = false;
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final GameState game = ai.getGame();
if (abCost != null) { if (abCost != null) {
// AI currently disabled for these costs // AI currently disabled for these costs
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, hostCard)) { if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, hostCard)) {
@@ -46,7 +47,7 @@ public class RegenerateAllAi extends SpellAbilityAi {
valid = sa.getParam("ValidCards"); valid = sa.getParam("ValidCards");
} }
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = game.getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard); list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard);
list = CardLists.filter(list, CardPredicates.isController(ai)); list = CardLists.filter(list, CardPredicates.isController(ai));
@@ -55,7 +56,7 @@ public class RegenerateAllAi extends SpellAbilityAi {
} }
int numSaved = 0; int numSaved = 0;
if (Singletons.getModel().getGame().getStack().size() > 0) { if (game.getStack().size() > 0) {
final ArrayList<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa); final ArrayList<Object> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa);
for (final Card c : list) { for (final Card c : list) {
@@ -64,7 +65,7 @@ public class RegenerateAllAi extends SpellAbilityAi {
} }
} }
} else { } else {
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
final List<Card> combatants = CardLists.filter(list, CardPredicates.Presets.CREATURES); final List<Card> combatants = CardLists.filter(list, CardPredicates.Presets.CREATURES);
for (final Card c : combatants) { for (final Card c : combatants) {

View File

@@ -1,7 +1,6 @@
package forge.card.ability.ai; package forge.card.ability.ai;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
@@ -16,7 +15,7 @@ public class StoreSVarAi extends SpellAbilityAi {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
if (ComputerUtil.waitForBlocking(sa) || ai.getLife() + 1 >= source.getNetDefense() if (ComputerUtil.waitForBlocking(sa) || ai.getLife() + 1 >= source.getNetDefense()
|| (ai.getLife() > 5 && !ComputerUtilCombat.lifeInSeriousDanger(ai, Singletons.getModel().getGame().getCombat()))) { || (ai.getLife() > 5 && !ComputerUtilCombat.lifeInSeriousDanger(ai, ai.getGame().getCombat()))) {
return false; return false;
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -19,7 +18,7 @@ public class TapAi extends TapAiBase {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); final PhaseHandler phase = ai.getGame().getPhaseHandler();
final Player turn = phase.getPlayerTurn(); final Player turn = phase.getPlayerTurn();
if (turn.isOpponentOf(ai) && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) { if (turn.isOpponentOf(ai) && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) {

View File

@@ -9,10 +9,10 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.phase.CombatUtil; import forge.game.phase.CombatUtil;
@@ -115,6 +115,7 @@ public abstract class TapAiBase extends SpellAbilityAi {
*/ */
protected boolean tapPrefTargeting(final Player ai, final Card source, final Target tgt, final SpellAbility sa, final boolean mandatory) { protected boolean tapPrefTargeting(final Player ai, final Card source, final Target tgt, final SpellAbility sa, final boolean mandatory) {
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();
final GameState game = ai.getGame();
List<Card> tapList = opp.getCardsIn(ZoneType.Battlefield); List<Card> tapList = opp.getCardsIn(ZoneType.Battlefield);
tapList = CardLists.filter(tapList, Presets.UNTAPPED); tapList = CardLists.filter(tapList, Presets.UNTAPPED);
tapList = CardLists.getValidCards(tapList, tgt.getValidTgts(), source.getController(), source); tapList = CardLists.getValidCards(tapList, tgt.getValidTgts(), source.getController(), source);
@@ -159,7 +160,7 @@ public abstract class TapAiBase extends SpellAbilityAi {
} }
} }
PhaseHandler phase = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler phase = game.getPhaseHandler();
if (phase.isPlayerTurn(ai) if (phase.isPlayerTurn(ai)
&& phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) { && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
// Tap creatures possible blockers before combat during AI's turn. // Tap creatures possible blockers before combat during AI's turn.
@@ -167,7 +168,7 @@ public abstract class TapAiBase extends SpellAbilityAi {
List<Card> attackers; List<Card> attackers;
if (phase.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) { if (phase.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
//Combat has already started //Combat has already started
attackers = Singletons.getModel().getGame().getCombat().getAttackers(); attackers = game.getCombat().getAttackers();
} else { } else {
attackers = CardLists.filter(ai.getCreaturesInPlay(), new Predicate<Card>() { attackers = CardLists.filter(ai.getCreaturesInPlay(), new Predicate<Card>() {
@Override @Override
@@ -240,8 +241,9 @@ public abstract class TapAiBase extends SpellAbilityAi {
protected boolean tapUnpreferredTargeting(final Player ai, final SpellAbility sa, final boolean mandatory) { protected boolean tapUnpreferredTargeting(final Player ai, final SpellAbility sa, final boolean mandatory) {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final GameState game = ai.getGame();
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = game.getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source);
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);

View File

@@ -9,10 +9,10 @@ import com.google.common.collect.Iterables;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.phase.CombatUtil; import forge.game.phase.CombatUtil;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -33,8 +33,9 @@ public class TapAllAi extends SpellAbilityAi {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Player opp = ai.getOpponent(); final Player opp = ai.getOpponent();
final GameState game = ai.getGame();
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_BEGIN)) { if (game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_BEGIN)) {
return false; return false;
} }
@@ -43,7 +44,7 @@ public class TapAllAi extends SpellAbilityAi {
valid = sa.getParam("ValidCards"); valid = sa.getParam("ValidCards");
} }
List<Card> validTappables = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> validTappables = game.getCardsIn(ZoneType.Battlefield);
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
@@ -81,7 +82,7 @@ public class TapAllAi extends SpellAbilityAi {
return false; return false;
} }
// in AI's turn, check if there are possible attackers, before tapping blockers // in AI's turn, check if there are possible attackers, before tapping blockers
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai) && !SpellAbilityAi.isSorcerySpeed(sa)) { if (game.getPhaseHandler().isPlayerTurn(ai) && !SpellAbilityAi.isSorcerySpeed(sa)) {
validTappables = ai.getCardsIn(ZoneType.Battlefield); validTappables = ai.getCardsIn(ZoneType.Battlefield);
final boolean any = Iterables.any(validTappables, new Predicate<Card>() { final boolean any = Iterables.any(validTappables, new Predicate<Card>() {
@Override @Override
@@ -108,7 +109,8 @@ public class TapAllAi extends SpellAbilityAi {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private List<Card> getTapAllTargets(final String valid, final Card source) { private List<Card> getTapAllTargets(final String valid, final Card source) {
List<Card> tmpList = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final GameState game = source.getGame();
List<Card> tmpList = game.getCardsIn(ZoneType.Battlefield);
tmpList = CardLists.getValidCards(tmpList, valid, source.getController(), source); tmpList = CardLists.getValidCards(tmpList, valid, source.getController(), source);
tmpList = CardLists.filter(tmpList, Presets.UNTAPPED); tmpList = CardLists.filter(tmpList, Presets.UNTAPPED);
return tmpList; return tmpList;

View File

@@ -3,12 +3,12 @@ package forge.card.ability.ai;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCost; import forge.game.ai.ComputerUtilCost;
import forge.game.ai.ComputerUtilMana; import forge.game.ai.ComputerUtilMana;
@@ -67,6 +67,7 @@ public class TokenAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) { protected boolean canPlayAI(AIPlayer ai, SpellAbility sa) {
final Cost cost = sa.getPayCosts(); final Cost cost = sa.getPayCosts();
final GameState game = ai.getGame();
readParameters(sa); readParameters(sa);
if (ComputerUtil.preventRunAwayActivations(sa)) { if (ComputerUtil.preventRunAwayActivations(sa)) {
@@ -95,7 +96,7 @@ public class TokenAi extends SpellAbilityAi {
} }
} }
PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler ph = game.getPhaseHandler();
// Don't generate tokens without haste before main 2 if possible // Don't generate tokens without haste before main 2 if possible
if (ph.getPhase().isBefore(PhaseType.MAIN2) if (ph.getPhase().isBefore(PhaseType.MAIN2)
&& ph.isPlayerTurn(ai) && !haste && ph.isPlayerTurn(ai) && !haste
@@ -109,7 +110,7 @@ public class TokenAi extends SpellAbilityAi {
&& !SpellAbilityAi.isSorcerySpeed(sa) && !haste) { && !SpellAbilityAi.isSorcerySpeed(sa) && !haste) {
return false; return false;
} }
if ((ph.getPhase().isAfter(PhaseType.COMBAT_BEGIN) || Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn( if ((ph.getPhase().isAfter(PhaseType.COMBAT_BEGIN) || game.getPhaseHandler().isPlayerTurn(
opp)) opp))
&& oneShot) { && oneShot) {
return false; return false;
@@ -163,7 +164,7 @@ public class TokenAi extends SpellAbilityAi {
return true; return true;
} }
if (Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)) { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)) {
return true; return true;
} }
if (sa.isAbility()) { if (sa.isAbility()) {

View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -51,7 +50,7 @@ public class UnattachAllAi extends SpellAbilityAi {
source.setSVar("PayX", Integer.toString(xPay)); source.setSVar("PayX", Integer.toString(xPay));
} }
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
&& !"Curse".equals(sa.getParam("AILogic"))) { && !"Curse".equals(sa.getParam("AILogic"))) {
return false; return false;
} }

View File

@@ -6,7 +6,6 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.cost.Cost; import forge.card.cost.Cost;
@@ -187,12 +186,11 @@ public class UntapAi extends SpellAbilityAi {
* a boolean. * a boolean.
* @return a boolean. * @return a boolean.
*/ */
private boolean untapUnpreferredTargeting(final SpellAbility sa, private boolean untapUnpreferredTargeting(final SpellAbility sa, final boolean mandatory) {
final boolean mandatory) {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = sa.getActivatingPlayer().getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source);
list = CardLists.getTargetableCards(list, sa); list = CardLists.getTargetableCards(list, sa);

View File

@@ -4,7 +4,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.AbilitySub; import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -20,7 +19,7 @@ public class UntapAllAi extends SpellAbilityAi {
final AbilitySub abSub = sa.getSubAbility(); final AbilitySub abSub = sa.getSubAbility();
if (abSub != null) { if (abSub != null) {
String valid = ""; String valid = "";
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = aiPlayer.getGame().getCardsIn(ZoneType.Battlefield);
if (sa.hasParam("ValidCards")) { if (sa.hasParam("ValidCards")) {
valid = sa.getParam("ValidCards"); valid = sa.getParam("ValidCards");
} }

View File

@@ -1,8 +1,6 @@
package forge.card.ability.effects; package forge.card.ability.effects;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
@@ -12,7 +10,6 @@ import forge.game.zone.ZoneType;
public class AbandonEffect extends SpellAbilityEffect { public class AbandonEffect extends SpellAbilityEffect {
private GameState game = Singletons.getModel().getGame();
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility) * @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
@@ -22,6 +19,8 @@ public class AbandonEffect extends SpellAbilityEffect {
Card source = sa.getSourceCard(); Card source = sa.getSourceCard();
Player controller = source.getController(); Player controller = source.getController();
final GameState game = controller.getGame();
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone); game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
controller.getZone(ZoneType.Command).remove(source); controller.getZone(ZoneType.Command).remove(source);
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);

View File

@@ -1,6 +1,5 @@
package forge.card.ability.effects; package forge.card.ability.effects;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseHandler;
@@ -14,7 +13,7 @@ public class AddPhaseEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
PhaseHandler phaseHandler = Singletons.getModel().getGame().getPhaseHandler(); PhaseHandler phaseHandler = sa.getActivatingPlayer().getGame().getPhaseHandler();
PhaseType extra = PhaseType.smartValueOf(sa.getParam("ExtraPhase")); PhaseType extra = PhaseType.smartValueOf(sa.getParam("ExtraPhase"));
PhaseType after; PhaseType after;

View File

@@ -2,7 +2,6 @@ package forge.card.ability.effects;
import java.util.List; import java.util.List;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -52,7 +51,7 @@ public class AddTurnEffect extends SpellAbilityEffect {
for (final Player p : tgtPlayers) { for (final Player p : tgtPlayers) {
if ((tgt == null) || p.canBeTargetedBy(sa)) { if ((tgt == null) || p.canBeTargetedBy(sa)) {
for (int i = 0; i < numTurns; i++) { for (int i = 0; i < numTurns; i++) {
ExtraTurn extra = Singletons.getModel().getGame().getPhaseHandler().addExtraTurn(p); ExtraTurn extra = p.getGame().getPhaseHandler().addExtraTurn(p);
if (sa.hasParam("LoseAtEndStep")) { if (sa.hasParam("LoseAtEndStep")) {
extra.setLoseAtEndStep(true); extra.setLoseAtEndStep(true);
} }

View File

@@ -9,7 +9,6 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardUtil; import forge.CardUtil;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.TriggerReplacementBase; import forge.card.TriggerReplacementBase;
import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
@@ -19,6 +18,7 @@ import forge.card.spellability.Target;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -33,7 +33,6 @@ public class AnimateAllEffect extends AnimateEffectBase {
public void resolve(final SpellAbility sa) { public void resolve(final SpellAbility sa) {
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final Map<String, String> svars = host.getSVars(); final Map<String, String> svars = host.getSVars();
long timest = -1;
// AF specific sa // AF specific sa
int power = -1; int power = -1;
@@ -44,11 +43,10 @@ public class AnimateAllEffect extends AnimateEffectBase {
if (sa.hasParam("Toughness")) { if (sa.hasParam("Toughness")) {
toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa); toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa);
} }
final GameState game = sa.getActivatingPlayer().getGame();
// Every Animate event needs a unique time stamp // Every Animate event needs a unique time stamp
timest = Singletons.getModel().getGame().getNextTimestamp(); final long timestamp = game.getNextTimestamp();
final long timestamp = timest;
final boolean permanent = sa.hasParam("Permanent"); final boolean permanent = sa.hasParam("Permanent");
@@ -134,7 +132,7 @@ public class AnimateAllEffect extends AnimateEffectBase {
} }
if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { if ((tgtPlayers == null) || tgtPlayers.isEmpty()) {
list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); list = game.getCardsIn(ZoneType.Battlefield);
} else { } else {
list = new ArrayList<Card>(tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield)); list = new ArrayList<Card>(tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield));
} }
@@ -243,9 +241,9 @@ public class AnimateAllEffect extends AnimateEffectBase {
if (!permanent) { if (!permanent) {
if (sa.hasParam("UntilEndOfCombat")) { if (sa.hasParam("UntilEndOfCombat")) {
Singletons.getModel().getGame().getEndOfCombat().addUntil(unanimate); game.getEndOfCombat().addUntil(unanimate);
} else { } else {
Singletons.getModel().getGame().getEndOfTurn().addUntil(unanimate); game.getEndOfTurn().addUntil(unanimate);
} }
} }
} }

View File

@@ -8,7 +8,6 @@ import java.util.Map;
import forge.Card; import forge.Card;
import forge.CardUtil; import forge.CardUtil;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.TriggerReplacementBase; import forge.card.TriggerReplacementBase;
import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
@@ -18,6 +17,7 @@ import forge.card.spellability.Target;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.game.GameState;
public class AnimateEffect extends AnimateEffectBase { public class AnimateEffect extends AnimateEffectBase {
@@ -29,7 +29,7 @@ public class AnimateEffect extends AnimateEffectBase {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final Map<String, String> svars = host.getSVars(); final Map<String, String> svars = host.getSVars();
long timest = -1;
String animateRemembered = null; String animateRemembered = null;
//if host is not on the battlefield don't apply //if host is not on the battlefield don't apply
@@ -53,10 +53,11 @@ public class AnimateEffect extends AnimateEffectBase {
toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa); toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa);
} }
final GameState game = sa.getActivatingPlayer().getGame();
// Every Animate event needs a unique time stamp // Every Animate event needs a unique time stamp
timest = Singletons.getModel().getGame().getNextTimestamp(); final long timestamp = game.getNextTimestamp();
final long timestamp = timest;
final boolean permanent = sa.hasParam("Permanent"); final boolean permanent = sa.hasParam("Permanent");
@@ -264,17 +265,17 @@ public class AnimateEffect extends AnimateEffectBase {
if (!permanent) { if (!permanent) {
if (sa.hasParam("UntilEndOfCombat")) { if (sa.hasParam("UntilEndOfCombat")) {
Singletons.getModel().getGame().getEndOfCombat().addUntil(unanimate); game.getEndOfCombat().addUntil(unanimate);
} else if (sa.hasParam("UntilHostLeavesPlay")) { } else if (sa.hasParam("UntilHostLeavesPlay")) {
host.addLeavesPlayCommand(unanimate); host.addLeavesPlayCommand(unanimate);
} else if (sa.hasParam("UntilYourNextUpkeep")) { } else if (sa.hasParam("UntilYourNextUpkeep")) {
Singletons.getModel().getGame().getUpkeep().addUntil(host.getController(), unanimate); game.getUpkeep().addUntil(host.getController(), unanimate);
} else if (sa.hasParam("UntilControllerNextUntap")) { } else if (sa.hasParam("UntilControllerNextUntap")) {
Singletons.getModel().getGame().getUntap().addUntil(c.getController(), unanimate); game.getUntap().addUntil(c.getController(), unanimate);
} else if (sa.hasParam("UntilYourNextTurn")) { } else if (sa.hasParam("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntil(host.getController(), unanimate); game.getCleanup().addUntil(host.getController(), unanimate);
} else { } else {
Singletons.getModel().getGame().getEndOfTurn().addUntil(unanimate); game.getEndOfTurn().addUntil(unanimate);
} }
} }
} }

View File

@@ -7,13 +7,13 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Command; import forge.Command;
import forge.GameEntity; import forge.GameEntity;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType; import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.ability.ai.AttachAi; import forge.card.ability.ai.AttachAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
@@ -28,10 +28,12 @@ public class AttachEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
if (sa.getSourceCard().isAura() && sa.isSpell()) { if (sa.getSourceCard().isAura() && sa.isSpell()) {
final Player ap = sa.getActivatingPlayer();
// The Spell_Permanent (Auras) version of this AF needs to // The Spell_Permanent (Auras) version of this AF needs to
// move the card into play before Attaching // move the card into play before Attaching
sa.getSourceCard().setController(sa.getActivatingPlayer(), 0);
final Card c = Singletons.getModel().getGame().getAction().moveTo(sa.getActivatingPlayer().getZone(ZoneType.Battlefield), sa.getSourceCard()); sa.getSourceCard().setController(ap, 0);
final Card c = ap.getGame().getAction().moveTo(ap.getZone(ZoneType.Battlefield), sa.getSourceCard());
sa.setSourceCard(c); sa.setSourceCard(c);
} }
@@ -182,13 +184,14 @@ public class AttachEffect extends SpellAbilityEffect {
return false; return false;
} }
aura.setActivatingPlayer(source.getController()); aura.setActivatingPlayer(source.getController());
final GameState game = source.getGame();
final Target tgt = aura.getTarget(); final Target tgt = aura.getTarget();
if (source.getController().isHuman()) { if (source.getController().isHuman()) {
if (tgt.canTgtPlayer()) { if (tgt.canTgtPlayer()) {
final ArrayList<Player> players = new ArrayList<Player>(); final ArrayList<Player> players = new ArrayList<Player>();
for (Player player : Singletons.getModel().getGame().getPlayers()) { for (Player player : game.getPlayers()) {
if (player.isValid(tgt.getValidTgts(), aura.getActivatingPlayer(), source)) { if (player.isValid(tgt.getValidTgts(), aura.getActivatingPlayer(), source)) {
players.add(player); players.add(player);
} }
@@ -200,7 +203,7 @@ public class AttachEffect extends SpellAbilityEffect {
return true; return true;
} }
} else { } else {
List<Card> list = Singletons.getModel().getGame().getCardsIn(tgt.getZone()); List<Card> list = game.getCardsIn(tgt.getZone());
list = CardLists.getValidCards(list, tgt.getValidTgts(), aura.getActivatingPlayer(), source); list = CardLists.getValidCards(list, tgt.getValidTgts(), aura.getActivatingPlayer(), source);
if (list.isEmpty()) { if (list.isEmpty()) {
return false; return false;

View File

@@ -6,13 +6,13 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
import forge.game.GameState;
public class BecomesBlockedEffect extends SpellAbilityEffect { public class BecomesBlockedEffect extends SpellAbilityEffect {
@@ -31,20 +31,21 @@ public class BecomesBlockedEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final GameState game = sa.getActivatingPlayer().getGame();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
for (final Card c : getTargetCards(sa)) { for (final Card c : getTargetCards(sa)) {
if ((tgt == null) || c.canBeTargetedBy(sa)) { if ((tgt == null) || c.canBeTargetedBy(sa)) {
Singletons.getModel().getGame().getCombat().setBlocked(c); game.getCombat().setBlocked(c);
if (!c.getDamageHistory().getCreatureGotBlockedThisCombat()) { if (!c.getDamageHistory().getCreatureGotBlockedThisCombat()) {
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Attacker", c); runParams.put("Attacker", c);
runParams.put("Blocker", null); runParams.put("Blocker", null);
runParams.put("NumBlockers", 0); runParams.put("NumBlockers", 0);
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.AttackerBlocked, runParams, false); game.getTriggerHandler().runTrigger(TriggerType.AttackerBlocked, runParams, false);
// Bushido // Bushido
for (final Ability ab : CardFactoryUtil.getBushidoEffects(c)) { for (final Ability ab : CardFactoryUtil.getBushidoEffects(c)) {
Singletons.getModel().getGame().getStack().add(ab); game.getStack().add(ab);
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package forge.card.ability.effects;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -21,7 +20,7 @@ public class BondEffect extends SpellAbilityEffect {
} }
// find list of valid cards to pair with // find list of valid cards to pair with
List<Card> cards = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> cards = sa.getActivatingPlayer().getGame().getCardsIn(ZoneType.Battlefield);
cards = AbilityUtils.filterListByType(cards, sa.getParam("ValidCards"), sa); cards = AbilityUtils.filterListByType(cards, sa.getParam("ValidCards"), sa);
if (cards.isEmpty()) { if (cards.isEmpty()) {
return; return;

View File

@@ -8,10 +8,10 @@ import com.google.common.collect.Iterables;
import forge.Card; import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
@@ -40,9 +40,10 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
List<Card> cards = new ArrayList<Card>(); List<Card> cards = new ArrayList<Card>();
List<Player> tgtPlayers = getTargetPlayersEmptyAsDefault(sa); List<Player> tgtPlayers = getTargetPlayersEmptyAsDefault(sa);
final GameState game = sa.getActivatingPlayer().getGame();
if ((tgtPlayers == null) || tgtPlayers.isEmpty() || sa.hasParam("UseAllOriginZones")) { if ((tgtPlayers == null) || tgtPlayers.isEmpty() || sa.hasParam("UseAllOriginZones")) {
cards = Singletons.getModel().getGame().getCardsIn(origin); cards = game.getCardsIn(origin);
} else { } else {
for (final Player p : tgtPlayers) { for (final Player p : tgtPlayers) {
cards.addAll(p.getCardsIn(origin)); cards.addAll(p.getCardsIn(origin));
@@ -81,10 +82,10 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
} }
if (sa.hasParam("GainControl")) { if (sa.hasParam("GainControl")) {
c.setController(sa.getActivatingPlayer(), Singletons.getModel().getGame().getNextTimestamp()); c.setController(sa.getActivatingPlayer(), game.getNextTimestamp());
Singletons.getModel().getGame().getAction().moveToPlay(c, sa.getActivatingPlayer()); game.getAction().moveToPlay(c, sa.getActivatingPlayer());
} else { } else {
final Card movedCard = Singletons.getModel().getGame().getAction().moveTo(destination, c, libraryPos); final Card movedCard = game.getAction().moveTo(destination, c, libraryPos);
if (sa.hasParam("ExileFaceDown")) { if (sa.hasParam("ExileFaceDown")) {
movedCard.setState(CardCharacteristicName.FaceDown); movedCard.setState(CardCharacteristicName.FaceDown);
} }
@@ -94,20 +95,20 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
} }
if (remember != null) { if (remember != null) {
Singletons.getModel().getGame().getCardState(sa.getSourceCard()).addRemembered(c); game.getCardState(sa.getSourceCard()).addRemembered(c);
} }
if (forget != null) { if (forget != null) {
Singletons.getModel().getGame().getCardState(sa.getSourceCard()).removeRemembered(c); game.getCardState(sa.getSourceCard()).removeRemembered(c);
} }
if (imprint != null) { if (imprint != null) {
Singletons.getModel().getGame().getCardState(sa.getSourceCard()).addImprinted(c); game.getCardState(sa.getSourceCard()).addImprinted(c);
} }
} }
// if Shuffle parameter exists, and any amount of cards were owned by // if Shuffle parameter exists, and any amount of cards were owned by
// that player, then shuffle that library // that player, then shuffle that library
if (sa.hasParam("Shuffle")) { if (sa.hasParam("Shuffle")) {
for (Player p : Singletons.getModel().getGame().getPlayers()) { for (Player p : game.getPlayers()) {
if (Iterables.any(cards, CardPredicates.isOwner(p))) { if (Iterables.any(cards, CardPredicates.isOwner(p))) {
p.shuffle(); p.shuffle();
} }

View File

@@ -8,12 +8,12 @@ import org.apache.commons.lang3.StringUtils;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.CardType; import forge.card.CardType;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.util.Aggregates; import forge.util.Aggregates;
@@ -34,6 +34,7 @@ public class ChooseCardEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final GameState game = sa.getActivatingPlayer().getGame();
final ArrayList<Card> chosen = new ArrayList<Card>(); final ArrayList<Card> chosen = new ArrayList<Card>();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
@@ -43,7 +44,7 @@ public class ChooseCardEffect extends SpellAbilityEffect {
if (sa.hasParam("ChoiceZone")) { if (sa.hasParam("ChoiceZone")) {
choiceZone = ZoneType.smartValueOf(sa.getParam("ChoiceZone")); choiceZone = ZoneType.smartValueOf(sa.getParam("ChoiceZone"));
} }
List<Card> choices = Singletons.getModel().getGame().getCardsIn(choiceZone); List<Card> choices = game.getCardsIn(choiceZone);
if (sa.hasParam("Choices")) { if (sa.hasParam("Choices")) {
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host); choices = CardLists.getValidCards(choices, sa.getParam("Choices"), host.getController(), host);
} }
@@ -57,7 +58,7 @@ public class ChooseCardEffect extends SpellAbilityEffect {
for (final Player p : tgtPlayers) { for (final Player p : tgtPlayers) {
if (sa.hasParam("EachBasicType")) { if (sa.hasParam("EachBasicType")) {
// Get all lands, // Get all lands,
List<Card> land = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.LANDS); List<Card> land = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Presets.LANDS);
String eachBasic = sa.getParam("EachBasicType"); String eachBasic = sa.getParam("EachBasicType");
if (eachBasic.equals("Controlled")) { if (eachBasic.equals("Controlled")) {
land = CardLists.filterControlledBy(land, p); land = CardLists.filterControlledBy(land, p);

View File

@@ -13,7 +13,6 @@ import com.google.common.collect.Lists;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.CardRulesPredicates; import forge.card.CardRulesPredicates;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -100,7 +99,7 @@ public class ChooseCardNameEffect extends SpellAbilityEffect {
chosen = ComputerUtilCard.getMostProminentCardName(p.getOpponent().getCardsIn(ZoneType.Library)); chosen = ComputerUtilCard.getMostProminentCardName(p.getOpponent().getCardsIn(ZoneType.Library));
} }
} else { } else {
List<Card> list = CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), p.getOpponent()); List<Card> list = CardLists.filterControlledBy(p.getGame().getCardsInGame(), p.getOpponent());
list = CardLists.filter(list, Predicates.not(Presets.LANDS)); list = CardLists.filter(list, Predicates.not(Presets.LANDS));
if (!list.isEmpty()) { if (!list.isEmpty()) {
chosen = list.get(0).getName(); chosen = list.get(0).getName();

View File

@@ -9,10 +9,10 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Constant; import forge.Constant;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -67,25 +67,26 @@ public class ChooseColorEffect extends SpellAbilityEffect {
} else { } else {
List<String> chosen = new ArrayList<String>(); List<String> chosen = new ArrayList<String>();
Player ai = sa.getActivatingPlayer(); Player ai = sa.getActivatingPlayer();
final GameState game = ai.getGame();
Player opp = ai.getOpponent(); Player opp = ai.getOpponent();
if (sa.hasParam("AILogic")) { if (sa.hasParam("AILogic")) {
final String logic = sa.getParam("AILogic"); final String logic = sa.getParam("AILogic");
if (logic.equals("MostProminentInHumanDeck")) { if (logic.equals("MostProminentInHumanDeck")) {
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), opp))); chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(), opp)));
} else if (logic.equals("MostProminentInComputerDeck")) { } else if (logic.equals("MostProminentInComputerDeck")) {
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), ai))); chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(), ai)));
} else if (logic.equals("MostProminentDualInComputerDeck")) { } else if (logic.equals("MostProminentDualInComputerDeck")) {
List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), ai)); List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(game.getCardsInGame(), ai));
chosen.add(prominence.get(0)); chosen.add(prominence.get(0));
chosen.add(prominence.get(1)); chosen.add(prominence.get(1));
} }
else if (logic.equals("MostProminentInGame")) { else if (logic.equals("MostProminentInGame")) {
chosen.add(ComputerUtilCard.getMostProminentColor(Singletons.getModel().getGame().getCardsInGame())); chosen.add(ComputerUtilCard.getMostProminentColor(game.getCardsInGame()));
} }
else if (logic.equals("MostProminentHumanCreatures")) { else if (logic.equals("MostProminentHumanCreatures")) {
List<Card> list = opp.getCreaturesInPlay(); List<Card> list = opp.getCreaturesInPlay();
if (list.isEmpty()) { if (list.isEmpty()) {
list = CardLists.filter(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), opp), CardPredicates.Presets.CREATURES); list = CardLists.filter(CardLists.filterControlledBy(game.getCardsInGame(), opp), CardPredicates.Presets.CREATURES);
} }
chosen.add(ComputerUtilCard.getMostProminentColor(list)); chosen.add(ComputerUtilCard.getMostProminentColor(list));
} }
@@ -96,11 +97,11 @@ public class ChooseColorEffect extends SpellAbilityEffect {
chosen.add(ComputerUtilCard.getMostProminentColor(ai.getOpponent().getCardsIn(ZoneType.Battlefield))); chosen.add(ComputerUtilCard.getMostProminentColor(ai.getOpponent().getCardsIn(ZoneType.Battlefield)));
} }
else if (logic.equals("MostProminentPermanent")) { else if (logic.equals("MostProminentPermanent")) {
final List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final List<Card> list = game.getCardsIn(ZoneType.Battlefield);
chosen.add(ComputerUtilCard.getMostProminentColor(list)); chosen.add(ComputerUtilCard.getMostProminentColor(list));
} }
else if (logic.equals("MostProminentAttackers")) { else if (logic.equals("MostProminentAttackers")) {
chosen.add(ComputerUtilCard.getMostProminentColor(Singletons.getModel().getGame().getCombat().getAttackers())); chosen.add(ComputerUtilCard.getMostProminentColor(game.getCombat().getAttackers()));
} }
else if (logic.equals("MostProminentKeywordInComputerDeck")) { else if (logic.equals("MostProminentKeywordInComputerDeck")) {
List<Card> list = ai.getAllCards(); List<Card> list = ai.getAllCards();

View File

@@ -3,7 +3,6 @@ package forge.card.ability.effects;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -34,7 +33,7 @@ public class ChoosePlayerEffect extends SpellAbilityEffect {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final List<Player> choices = sa.hasParam("Choices") ? AbilityUtils.getDefinedPlayers( final List<Player> choices = sa.hasParam("Choices") ? AbilityUtils.getDefinedPlayers(
sa.getSourceCard(), sa.getParam("Choices"), sa) : Singletons.getModel().getGame().getPlayers(); sa.getSourceCard(), sa.getParam("Choices"), sa) : sa.getActivatingPlayer().getGame().getPlayers();
final String choiceDesc = sa.hasParam("ChoiceTitle") ? sa.getParam("ChoiceTitle") : "Choose a player"; final String choiceDesc = sa.hasParam("ChoiceTitle") ? sa.getParam("ChoiceTitle") : "Choose a player";

View File

@@ -10,7 +10,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType; import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -18,6 +17,7 @@ import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityStackInstance; import forge.card.spellability.SpellAbilityStackInstance;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat; import forge.game.ai.ComputerUtilCombat;
import forge.game.player.Player; import forge.game.player.Player;
@@ -41,11 +41,12 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final ArrayList<Card> chosen = new ArrayList<Card>(); final ArrayList<Card> chosen = new ArrayList<Card>();
final GameState game = sa.getActivatingPlayer().getGame();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final List<Player> tgtPlayers = getTargetPlayers(sa); final List<Player> tgtPlayers = getTargetPlayers(sa);
Stack<SpellAbilityStackInstance> stack = Singletons.getModel().getGame().getStack().getStack(); Stack<SpellAbilityStackInstance> stack = game.getStack().getStack();
List<Card> permanentSources = new ArrayList<Card>(); List<Card> permanentSources = new ArrayList<Card>();
List<Card> stackSources = new ArrayList<Card>(); List<Card> stackSources = new ArrayList<Card>();
@@ -54,7 +55,7 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
List<Card> sourcesToChooseFrom = new ArrayList<Card>(); List<Card> sourcesToChooseFrom = new ArrayList<Card>();
// Get the list of permanent cards // Get the list of permanent cards
permanentSources = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); permanentSources = game.getCardsIn(ZoneType.Battlefield);
// Get the list of cards that produce effects on the stack // Get the list of cards that produce effects on the stack
if (stack != null) { if (stack != null) {
@@ -142,8 +143,8 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
} else { } else {
if (sa.hasParam("AILogic") && sa.getParam("AILogic").equals("NeedsPrevention")) { if (sa.hasParam("AILogic") && sa.getParam("AILogic").equals("NeedsPrevention")) {
final Player ai = sa.getActivatingPlayer(); final Player ai = sa.getActivatingPlayer();
if (!Singletons.getModel().getGame().getStack().isEmpty()) { if (!game.getStack().isEmpty()) {
final SpellAbility topStack = Singletons.getModel().getGame().getStack().peekAbility(); final SpellAbility topStack = game.getStack().peekAbility();
if (sa.hasParam("Choices") && !topStack.getSourceCard().isValid(sa.getParam("Choices"), ai, host)) { if (sa.hasParam("Choices") && !topStack.getSourceCard().isValid(sa.getParam("Choices"), ai, host)) {
break; break;
} }
@@ -177,10 +178,10 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
sourcesToChooseFrom = CardLists.filter(sourcesToChooseFrom, new Predicate<Card>() { sourcesToChooseFrom = CardLists.filter(sourcesToChooseFrom, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (!c.isAttacking(ai) || !Singletons.getModel().getGame().getCombat().isUnblocked(c)) { if (!c.isAttacking(ai) || !game.getCombat().isUnblocked(c)) {
return false; return false;
} }
return ComputerUtilCombat.damageIfUnblocked(c, ai, Singletons.getModel().getGame().getCombat()) > 0; return ComputerUtilCombat.damageIfUnblocked(c, ai, game.getCombat()) > 0;
} }
}); });
chosen.add(ComputerUtilCard.getBestCreatureAI(sourcesToChooseFrom)); chosen.add(ComputerUtilCard.getBestCreatureAI(sourcesToChooseFrom));

View File

@@ -10,11 +10,11 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.Constant; import forge.Constant;
import forge.Singletons;
import forge.card.CardType; import forge.card.CardType;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -52,6 +52,7 @@ public class ChooseTypeEffect extends SpellAbilityEffect {
final List<Player> tgtPlayers = getTargetPlayers(sa); final List<Player> tgtPlayers = getTargetPlayers(sa);
for (final Player p : tgtPlayers) { for (final Player p : tgtPlayers) {
final GameState game = p.getGame();
if ((tgt == null) || p.canBeTargetedBy(sa)) { if ((tgt == null) || p.canBeTargetedBy(sa)) {
if (type.equals("Card")) { if (type.equals("Card")) {
@@ -95,7 +96,7 @@ public class ChooseTypeEffect extends SpellAbilityEffect {
if (sa.hasParam("AILogic")) { if (sa.hasParam("AILogic")) {
final String logic = sa.getParam("AILogic"); final String logic = sa.getParam("AILogic");
if (logic.equals("MostProminentOnBattlefield")) { if (logic.equals("MostProminentOnBattlefield")) {
chosen = ComputerUtilCard.getMostProminentCreatureType(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)); chosen = ComputerUtilCard.getMostProminentCreatureType(game.getCardsIn(ZoneType.Battlefield));
} }
else if (logic.equals("MostProminentComputerControls")) { else if (logic.equals("MostProminentComputerControls")) {
chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield)); chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield));
@@ -103,11 +104,11 @@ public class ChooseTypeEffect extends SpellAbilityEffect {
else if (logic.equals("MostProminentHumanControls")) { else if (logic.equals("MostProminentHumanControls")) {
chosen = ComputerUtilCard.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield)); chosen = ComputerUtilCard.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield));
if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) {
chosen = ComputerUtilCard.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), opp)); chosen = ComputerUtilCard.getMostProminentCreatureType(CardLists.filterControlledBy(game.getCardsInGame(), opp));
} }
} }
else if (logic.equals("MostProminentInComputerDeck")) { else if (logic.equals("MostProminentInComputerDeck")) {
chosen = ComputerUtilCard.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), ai)); chosen = ComputerUtilCard.getMostProminentCreatureType(CardLists.filterControlledBy(game.getCardsInGame(), ai));
} }
else if (logic.equals("MostProminentInComputerGraveyard")) { else if (logic.equals("MostProminentInComputerGraveyard")) {
chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard)); chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard));

View File

@@ -3,7 +3,6 @@ package forge.card.ability.effects;
import java.util.HashMap; import java.util.HashMap;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -59,7 +58,8 @@ public class ClashEffect extends SpellAbilityEffect {
runParams.put("Won", "False"); runParams.put("Won", "False");
} }
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Clashed, runParams, false);
sa.getSourceCard().getGame().getTriggerHandler().runTrigger(TriggerType.Clashed, runParams, false);
} }
/** /**

View File

@@ -2,10 +2,10 @@ package forge.card.ability.effects;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
public class CleanUpEffect extends SpellAbilityEffect { public class CleanUpEffect extends SpellAbilityEffect {
@@ -15,10 +15,11 @@ public class CleanUpEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
Card source = sa.getSourceCard(); Card source = sa.getSourceCard();
final GameState game = source.getGame();
if (sa.hasParam("ClearRemembered")) { if (sa.hasParam("ClearRemembered")) {
source.clearRemembered(); source.clearRemembered();
Singletons.getModel().getGame().getCardState(source).clearRemembered(); game.getCardState(source).clearRemembered();
} }
if (sa.hasParam("ForgetDefined")) { if (sa.hasParam("ForgetDefined")) {
for (final Card card : AbilityUtils.getDefinedCards(source, sa.getParam("ForgetDefined"), sa)) { for (final Card card : AbilityUtils.getDefinedCards(source, sa.getParam("ForgetDefined"), sa)) {
@@ -32,7 +33,7 @@ public class CleanUpEffect extends SpellAbilityEffect {
source.setSVar("ChosenX", ""); source.setSVar("ChosenX", "");
} }
if (sa.hasParam("ClearTriggered")) { if (sa.hasParam("ClearTriggered")) {
Singletons.getModel().getGame().getTriggerHandler().clearDelayedTrigger(source); game.getTriggerHandler().clearDelayedTrigger(source);
} }
if (sa.hasParam("ClearCoinFlips")) { if (sa.hasParam("ClearCoinFlips")) {
source.clearFlipResult(); source.clearFlipResult();

View File

@@ -18,6 +18,7 @@ import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.game.GameState;
import forge.gui.GuiDialog; import forge.gui.GuiDialog;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
@@ -199,11 +200,12 @@ public class CloneEffect extends SpellAbilityEffect {
} }
}; };
final GameState game = sa.getActivatingPlayer().getGame();
String duration = sa.getParam("Duration"); String duration = sa.getParam("Duration");
if (duration.equals("UntilEndOfTurn")) { if (duration.equals("UntilEndOfTurn")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(unclone); game.getEndOfTurn().addUntil(unclone);
} else if (duration.equals("UntilYourNextTurn")) { } else if (duration.equals("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntil(host.getController(), unclone); game.getCleanup().addUntil(host.getController(), unclone);
} }
} }

View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -67,7 +66,7 @@ public class ControlExchangeEffect extends SpellAbilityEffect {
} }
final Player player2 = object2.getController(); final Player player2 = object2.getController();
final long tStamp = Singletons.getModel().getGame().getNextTimestamp(); final long tStamp = sa.getActivatingPlayer().getGame().getNextTimestamp();
object2.setController(object1.getController(), tStamp); object2.setController(object1.getController(), tStamp);
object1.setController(player2, tStamp); object1.setController(player2, tStamp);
} }

View File

@@ -6,13 +6,13 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -85,8 +85,20 @@ public class ControlGainEffect extends SpellAbilityEffect {
final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null; final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null;
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final List<Player> controllers;
if (sa.hasParam("NewController")) {
controllers = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("NewController"), sa);
} else if (tgt != null && tgt.getTargetPlayers() != null && tgt.canTgtPlayer()) {
controllers = tgt.getTargetPlayers();
} else
controllers = new ArrayList<Player>();
final Player newController = controllers.isEmpty() ? sa.getActivatingPlayer() : controllers.get(0);
final GameState game = newController.getGame();
if (sa.hasParam("AllValid")) { if (sa.hasParam("AllValid")) {
tgtCards = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); tgtCards = game.getCardsIn(ZoneType.Battlefield);
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa); tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
} else if (sa.hasParam("Defined")) { } else if (sa.hasParam("Defined")) {
tgtCards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa); tgtCards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
@@ -94,21 +106,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
tgtCards = getTargetCards(sa); tgtCards = getTargetCards(sa);
} }
List<Player> controllers = new ArrayList<Player>();
if (sa.hasParam("NewController")) {
controllers = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("NewController"), sa);
} else if (tgt != null && tgt.getTargetPlayers() != null && tgt.canTgtPlayer()) {
controllers = tgt.getTargetPlayers();
}
Player newController;
if (controllers.size() == 0) {
newController = sa.getActivatingPlayer();
} else {
newController = controllers.get(0);
}
// check for lose control criteria right away // check for lose control criteria right away
if (lose != null && lose.contains("LeavesPlay") && !source.isInZone(ZoneType.Battlefield)) { if (lose != null && lose.contains("LeavesPlay") && !source.isInZone(ZoneType.Battlefield)) {
return; return;
@@ -127,7 +125,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
return; return;
} }
long tStamp = Singletons.getModel().getGame().getNextTimestamp(); long tStamp = game.getNextTimestamp();
if (lose != null) { if (lose != null) {
tgtC.addTempController(newController, tStamp); tgtC.addTempController(newController, tStamp);
} else { } else {
@@ -155,7 +153,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
sa.getSourceCard().addChangeControllerCommand(this.getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws)); sa.getSourceCard().addChangeControllerCommand(this.getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws));
} }
if (lose.contains("EOT")) { if (lose.contains("EOT")) {
Singletons.getModel().getGame().getEndOfTurn().addAt(this.getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws)); game.getEndOfTurn().addAt(this.getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws));
} }
} }
@@ -192,14 +190,15 @@ public class ControlGainEffect extends SpellAbilityEffect {
@Override @Override
public void run() { public void run() {
final GameState game = hostCard.getGame();
final Ability ability = new Ability(hostCard, ManaCost.ZERO) { final Ability ability = new Ability(hostCard, ManaCost.ZERO) {
@Override @Override
public void resolve() { public void resolve() {
if (bNoRegen) { if (bNoRegen) {
Singletons.getModel().getGame().getAction().destroyNoRegeneration(c, null); game.getAction().destroyNoRegeneration(c, null);
} else { } else {
Singletons.getModel().getGame().getAction().destroy(c, null); game.getAction().destroy(c, null);
} }
} }
}; };
@@ -210,7 +209,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
} }
ability.setStackDescription(sb.toString()); ability.setStackDescription(sb.toString());
Singletons.getModel().getGame().getStack().addSimultaneousStackEntry(ability); game.getStack().addSimultaneousStackEntry(ability);
} }
}; };

View File

@@ -15,7 +15,6 @@ import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardLists; import forge.CardLists;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.CardRulesPredicates; import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -25,6 +24,7 @@ import forge.card.mana.ManaCost;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.player.HumanPlayer; import forge.game.player.HumanPlayer;
import forge.game.player.Player; import forge.game.player.Player;
@@ -56,6 +56,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(final SpellAbility sa) { public void resolve(final SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final GameState game = hostCard.getGame();
final ArrayList<String> keywords = new ArrayList<String>(); final ArrayList<String> keywords = new ArrayList<String>();
if (sa.hasParam("Keywords")) { if (sa.hasParam("Keywords")) {
keywords.addAll(Arrays.asList(sa.getParam("Keywords").split(" & "))); keywords.addAll(Arrays.asList(sa.getParam("Keywords").split(" & ")));
@@ -224,7 +225,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
continue; continue;
} }
} }
copy = Singletons.getModel().getGame().getAction().moveToPlay(copy); copy = game.getAction().moveToPlay(copy);
copy.setCloneOrigin(hostCard); copy.setCloneOrigin(hostCard);
sa.getSourceCard().addClone(copy); sa.getSourceCard().addClone(copy);
@@ -255,9 +256,9 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
if (sa.getParam("AtEOT").equals("Sacrifice")) { if (sa.getParam("AtEOT").equals("Sacrifice")) {
// maybe do a setSacrificeAtEOT, but // maybe do a setSacrificeAtEOT, but
// probably not. // probably not.
Singletons.getModel().getGame().getAction().sacrifice(target[index], sa); game.getAction().sacrifice(target[index], sa);
} else if (sa.getParam("AtEOT").equals("Exile")) { } else if (sa.getParam("AtEOT").equals("Exile")) {
Singletons.getModel().getGame().getAction().exile(target[index]); game.getAction().exile(target[index]);
} }
} }
@@ -270,11 +271,11 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
@Override @Override
public void run() { public void run() {
sac.setStackDescription(sa.getParam("AtEOT") + " " + target[index] + "."); sac.setStackDescription(sa.getParam("AtEOT") + " " + target[index] + ".");
Singletons.getModel().getGame().getStack().addSimultaneousStackEntry(sac); game.getStack().addSimultaneousStackEntry(sac);
} }
}; // Command }; // Command
if (sa.hasParam("AtEOT")) { if (sa.hasParam("AtEOT")) {
Singletons.getModel().getGame().getEndOfTurn().addAt(atEOT); game.getEndOfTurn().addAt(atEOT);
} }
// end copied Kiki code // end copied Kiki code

View File

@@ -5,9 +5,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.game.GameState;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityStackInstance; import forge.card.spellability.SpellAbilityStackInstance;
@@ -18,14 +18,15 @@ import forge.gui.GuiChoose;
public class CounterEffect extends SpellAbilityEffect { public class CounterEffect extends SpellAbilityEffect {
@Override @Override
protected String getStackDescription(SpellAbility sa) { protected String getStackDescription(SpellAbility sa) {
final GameState game = sa.getActivatingPlayer().getGame();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final List<SpellAbility> sas; final List<SpellAbility> sas;
if (sa.hasParam("AllType")) { if (sa.hasParam("AllType")) {
sas = new ArrayList<SpellAbility>(); sas = new ArrayList<SpellAbility>();
for (int i = 0; i < Singletons.getModel().getGame().getStack().size(); i++) { for (int i = 0; i < game.getStack().size(); i++) {
SpellAbility spell = Singletons.getModel().getGame().getStack().peekAbility(i); SpellAbility spell = game.getStack().peekAbility(i);
if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) { if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) {
continue; continue;
} }
@@ -62,14 +63,15 @@ public class CounterEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final GameState game = sa.getActivatingPlayer().getGame();
// TODO Before this resolves we should see if any of our targets are // TODO Before this resolves we should see if any of our targets are
// still on the stack // still on the stack
final List<SpellAbility> sas; final List<SpellAbility> sas;
if (sa.hasParam("AllType")) { if (sa.hasParam("AllType")) {
sas = new ArrayList<SpellAbility>(); sas = new ArrayList<SpellAbility>();
for (int i = 0; i < Singletons.getModel().getGame().getStack().size(); i++) { for (int i = 0; i < game.getStack().size(); i++) {
SpellAbility spell = Singletons.getModel().getGame().getStack().peekAbility(i); SpellAbility spell = game.getStack().peekAbility(i);
if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) { if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) {
continue; continue;
} }
@@ -97,7 +99,7 @@ public class CounterEffect extends SpellAbilityEffect {
continue; continue;
} }
final SpellAbilityStackInstance si = Singletons.getModel().getGame().getStack().getInstanceFromSpellAbility(tgtSA); final SpellAbilityStackInstance si = game.getStack().getInstanceFromSpellAbility(tgtSA);
if (si == null) { if (si == null) {
continue; continue;
} }
@@ -106,7 +108,7 @@ public class CounterEffect extends SpellAbilityEffect {
// Destroy Permanent may be able to be turned into a SubAbility // Destroy Permanent may be able to be turned into a SubAbility
if (tgtSA.isAbility() && sa.hasParam("DestroyPermanent")) { if (tgtSA.isAbility() && sa.hasParam("DestroyPermanent")) {
Singletons.getModel().getGame().getAction().destroy(tgtSACard, sa); game.getAction().destroy(tgtSACard, sa);
} }
if (sa.hasParam("RememberCountered")) { if (sa.hasParam("RememberCountered")) {
@@ -132,7 +134,8 @@ public class CounterEffect extends SpellAbilityEffect {
* @param sa * @param sa
*/ */
private void removeFromStack(final SpellAbility tgtSA, final SpellAbility srcSA, final SpellAbilityStackInstance si) { private void removeFromStack(final SpellAbility tgtSA, final SpellAbility srcSA, final SpellAbilityStackInstance si) {
Singletons.getModel().getGame().getStack().remove(si); final GameState game = tgtSA.getActivatingPlayer().getGame();
game.getStack().remove(si);
String destination = srcSA.hasParam("Destination") ? srcSA.getParam("Destination") : "Graveyard"; String destination = srcSA.hasParam("Destination") ? srcSA.getParam("Destination") : "Graveyard";
if (srcSA.hasParam("DestinationChoice")) {//Hinder if (srcSA.hasParam("DestinationChoice")) {//Hinder
@@ -148,29 +151,29 @@ public class CounterEffect extends SpellAbilityEffect {
// For Ability-targeted counterspells - do not move it anywhere, // For Ability-targeted counterspells - do not move it anywhere,
// even if Destination$ is specified. // even if Destination$ is specified.
} else if (tgtSA.isFlashBackAbility()) { } else if (tgtSA.isFlashBackAbility()) {
Singletons.getModel().getGame().getAction().exile(tgtSA.getSourceCard()); game.getAction().exile(tgtSA.getSourceCard());
} else if (destination.equals("Graveyard")) { } else if (destination.equals("Graveyard")) {
Singletons.getModel().getGame().getAction().moveToGraveyard(tgtSA.getSourceCard()); game.getAction().moveToGraveyard(tgtSA.getSourceCard());
} else if (destination.equals("Exile")) { } else if (destination.equals("Exile")) {
Singletons.getModel().getGame().getAction().exile(tgtSA.getSourceCard()); game.getAction().exile(tgtSA.getSourceCard());
} else if (destination.equals("TopOfLibrary")) { } else if (destination.equals("TopOfLibrary")) {
Singletons.getModel().getGame().getAction().moveToLibrary(tgtSA.getSourceCard()); game.getAction().moveToLibrary(tgtSA.getSourceCard());
} else if (destination.equals("Hand")) { } else if (destination.equals("Hand")) {
Singletons.getModel().getGame().getAction().moveToHand(tgtSA.getSourceCard()); game.getAction().moveToHand(tgtSA.getSourceCard());
} else if (destination.equals("Battlefield")) { } else if (destination.equals("Battlefield")) {
if (tgtSA instanceof SpellPermanent) { if (tgtSA instanceof SpellPermanent) {
Card c = tgtSA.getSourceCard(); Card c = tgtSA.getSourceCard();
System.out.println(c + " is SpellPermanent"); System.out.println(c + " is SpellPermanent");
c.setController(srcSA.getActivatingPlayer(), 0); c.setController(srcSA.getActivatingPlayer(), 0);
Singletons.getModel().getGame().getAction().moveToPlay(c, srcSA.getActivatingPlayer()); game.getAction().moveToPlay(c, srcSA.getActivatingPlayer());
} else { } else {
Card c = Singletons.getModel().getGame().getAction().moveToPlay(tgtSA.getSourceCard(), srcSA.getActivatingPlayer()); Card c = game.getAction().moveToPlay(tgtSA.getSourceCard(), srcSA.getActivatingPlayer());
c.setController(srcSA.getActivatingPlayer(), 0); c.setController(srcSA.getActivatingPlayer(), 0);
} }
} else if (destination.equals("BottomOfLibrary")) { } else if (destination.equals("BottomOfLibrary")) {
Singletons.getModel().getGame().getAction().moveToBottomOfLibrary(tgtSA.getSourceCard()); game.getAction().moveToBottomOfLibrary(tgtSA.getSourceCard());
} else if (destination.equals("ShuffleIntoLibrary")) { } else if (destination.equals("ShuffleIntoLibrary")) {
Singletons.getModel().getGame().getAction().moveToBottomOfLibrary(tgtSA.getSourceCard()); game.getAction().moveToBottomOfLibrary(tgtSA.getSourceCard());
tgtSA.getSourceCard().getController().shuffle(); tgtSA.getSourceCard().getController().shuffle();
} else { } else {
throw new IllegalArgumentException("AbilityFactory_CounterMagic: Invalid Destination argument for card " throw new IllegalArgumentException("AbilityFactory_CounterMagic: Invalid Destination argument for card "

View File

@@ -10,9 +10,7 @@ import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.FThreads; import forge.FThreads;
import forge.GameEntity; import forge.GameEntity;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.control.input.InputProliferate; import forge.control.input.InputProliferate;
import forge.game.player.Player; import forge.game.player.Player;
@@ -58,10 +56,10 @@ public class CountersProliferateEffect extends SpellAbilityEffect {
@Override @Override
public boolean apply(Card crd) { public boolean apply(Card crd) {
for (final Entry<CounterType, Integer> c1 : crd.getCounters().entrySet()) { for (final Entry<CounterType, Integer> c1 : crd.getCounters().entrySet()) {
if (CardFactoryUtil.isNegativeCounter(c1.getKey()) && enemies.contains(crd.getController())) { if (c1.getKey().isNegativeCounter() && enemies.contains(crd.getController())) {
return true; return true;
} }
if (!CardFactoryUtil.isNegativeCounter(c1.getKey()) && allies.contains(crd.getController())) { if (!c1.getKey().isNegativeCounter() && allies.contains(crd.getController())) {
return true; return true;
} }
} }
@@ -69,7 +67,7 @@ public class CountersProliferateEffect extends SpellAbilityEffect {
} }
}; };
List<Card> cardsToProliferate = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), predProliferate); List<Card> cardsToProliferate = CardLists.filter(ai.getGame().getCardsIn(ZoneType.Battlefield), predProliferate);
List<Player> playersToPoison = new ArrayList<Player>(); List<Player> playersToPoison = new ArrayList<Player>();
for (Player e : enemies) { for (Player e : enemies) {
if (e.getPoisonCounters() > 0) { if (e.getPoisonCounters() > 0) {
@@ -104,12 +102,12 @@ public class CountersProliferateEffect extends SpellAbilityEffect {
// computer // computer
for (final Card c : cardsToProliferate) { for (final Card c : cardsToProliferate) {
for (final Entry<CounterType, Integer> c1 : c.getCounters().entrySet()) { for (final Entry<CounterType, Integer> c1 : c.getCounters().entrySet()) {
if (CardFactoryUtil.isNegativeCounter(c1.getKey()) && enemies.contains(c.getController())) if (c1.getKey().isNegativeCounter() && enemies.contains(c.getController()))
{ {
c.addCounter(c1.getKey(), 1, true); c.addCounter(c1.getKey(), 1, true);
break; break;
} }
if (!CardFactoryUtil.isNegativeCounter(c1.getKey()) && allies.contains(c.getController())) if (!c1.getKey().isNegativeCounter() && allies.contains(c.getController()))
{ {
c.addCounter(c1.getKey(), 1, true); c.addCounter(c1.getKey(), 1, true);
break; break;

View File

@@ -5,11 +5,11 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -43,8 +43,9 @@ public class CountersPutAllEffect extends SpellAbilityEffect {
final int counterAmount = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa); final int counterAmount = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa);
final String valid = sa.getParam("ValidCards"); final String valid = sa.getParam("ValidCards");
final ZoneType zone = sa.hasParam("ValidZone") ? ZoneType.smartValueOf(sa.getParam("ValidZone")) : ZoneType.Battlefield; final ZoneType zone = sa.hasParam("ValidZone") ? ZoneType.smartValueOf(sa.getParam("ValidZone")) : ZoneType.Battlefield;
final GameState game = sa.getActivatingPlayer().getGame();
List<Card> cards = Singletons.getModel().getGame().getCardsIn(zone); List<Card> cards = game.getCardsIn(zone);
cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard()); cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard());
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
@@ -54,7 +55,7 @@ public class CountersPutAllEffect extends SpellAbilityEffect {
} }
for (final Card tgtCard : cards) { for (final Card tgtCard : cards) {
if (Singletons.getModel().getGame().getZoneOf(tgtCard).is(ZoneType.Battlefield)) { if (game.getZoneOf(tgtCard).is(ZoneType.Battlefield)) {
tgtCard.addCounter(CounterType.valueOf(type), counterAmount, true); tgtCard.addCounter(CounterType.valueOf(type), counterAmount, true);
} else { } else {
// adding counters to something like re-suspend cards // adding counters to something like re-suspend cards

View File

@@ -6,7 +6,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -108,7 +107,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
if (max != -1) { if (max != -1) {
counterAmount = max - tgtCard.getCounters(counterType); counterAmount = max - tgtCard.getCounters(counterType);
} }
final Zone zone = Singletons.getModel().getGame().getZoneOf(tgtCard); final Zone zone = tgtCard.getGame().getZoneOf(tgtCard);
if (zone == null || zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Stack)) { if (zone == null || zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Stack)) {
if (remember) { if (remember) {
final int value = tgtCard.getTotalCountersToAdd(counterType, counterAmount, true); final int value = tgtCard.getTotalCountersToAdd(counterType, counterAmount, true);

View File

@@ -5,11 +5,11 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -47,8 +47,9 @@ public class CountersRemoveAllEffect extends SpellAbilityEffect {
int counterAmount = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa); int counterAmount = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa);
final String valid = sa.getParam("ValidCards"); final String valid = sa.getParam("ValidCards");
final ZoneType zone = sa.hasParam("ValidZone") ? ZoneType.smartValueOf(sa.getParam("ValidZone")) : ZoneType.Battlefield; final ZoneType zone = sa.hasParam("ValidZone") ? ZoneType.smartValueOf(sa.getParam("ValidZone")) : ZoneType.Battlefield;
final GameState game = sa.getActivatingPlayer().getGame();
List<Card> cards = Singletons.getModel().getGame().getCardsIn(zone);
List<Card> cards = game.getCardsIn(zone);
cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard()); cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard());
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();

View File

@@ -6,11 +6,11 @@ import java.util.Map;
import forge.Card; import forge.Card;
import forge.CounterType; import forge.CounterType;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.zone.Zone; import forge.game.zone.Zone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
@@ -55,6 +55,7 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
final GameState game = card.getGame();
final String type = sa.getParam("CounterType"); final String type = sa.getParam("CounterType");
int counterAmount = 0; int counterAmount = 0;
if (!sa.getParam("CounterNum").equals("All") && !sa.getParam("CounterNum").equals("Remembered")) { if (!sa.getParam("CounterNum").equals("All") && !sa.getParam("CounterNum").equals("Remembered")) {
@@ -80,7 +81,7 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
} }
for (final Card tgtCard : getTargetCards(sa)) { for (final Card tgtCard : getTargetCards(sa)) {
if ((tgt == null) || tgtCard.canBeTargetedBy(sa)) { if ((tgt == null) || tgtCard.canBeTargetedBy(sa)) {
final Zone zone = Singletons.getModel().getGame().getZoneOf(tgtCard); final Zone zone = game.getZoneOf(tgtCard);
if (sa.getParam("CounterNum").equals("All")) { if (sa.getParam("CounterNum").equals("All")) {
counterAmount = tgtCard.getCounters(counterType); counterAmount = tgtCard.getCounters(counterType);
} else if (sa.getParam("CounterNum").equals("Remembered")) { } else if (sa.getParam("CounterNum").equals("Remembered")) {

View File

@@ -5,11 +5,11 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -46,6 +46,7 @@ public class DamageAllEffect extends SpellAbilityEffect {
final List<Card> definedSources = AbilityUtils.getDefinedCards(sa.getSourceCard(), sa.getParam("DamageSource"), sa); final List<Card> definedSources = AbilityUtils.getDefinedCards(sa.getSourceCard(), sa.getParam("DamageSource"), sa);
final Card card = definedSources.get(0); final Card card = definedSources.get(0);
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = sa.getActivatingPlayer().getGame();
final String damage = sa.getParam("NumDmg"); final String damage = sa.getParam("NumDmg");
final int dmg = AbilityUtils.calculateAmount(sa.getSourceCard(), damage, sa); final int dmg = AbilityUtils.calculateAmount(sa.getSourceCard(), damage, sa);
@@ -64,7 +65,7 @@ public class DamageAllEffect extends SpellAbilityEffect {
} }
if (sa.hasParam("ValidCards")) { if (sa.hasParam("ValidCards")) {
list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); list = game.getCardsIn(ZoneType.Battlefield);
} }
if (targetPlayer != null) { if (targetPlayer != null) {

View File

@@ -5,7 +5,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
@@ -61,7 +60,7 @@ public class DamageEachEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
List<Card> sources = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> sources = card.getGame().getCardsIn(ZoneType.Battlefield);
if (sa.hasParam("ValidCards")) { if (sa.hasParam("ValidCards")) {
sources = CardLists.getValidCards(sources, sa.getParam("ValidCards"), card.getController(), card); sources = CardLists.getValidCards(sources, sa.getParam("ValidCards"), card.getController(), card);
} }

View File

@@ -4,10 +4,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -19,6 +19,7 @@ public class DamagePreventAllEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final GameState game = sa.getActivatingPlayer().getGame();
final int numDam = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa); final int numDam = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa);
String players = ""; String players = "";
@@ -29,7 +30,7 @@ public class DamagePreventAllEffect extends SpellAbilityEffect {
} }
if (sa.hasParam("ValidCards")) { if (sa.hasParam("ValidCards")) {
list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); list = game.getCardsIn(ZoneType.Battlefield);
} }
list = AbilityUtils.filterListByType(list, sa.getParam("ValidCards"), sa); list = AbilityUtils.filterListByType(list, sa.getParam("ValidCards"), sa);
@@ -39,7 +40,7 @@ public class DamagePreventAllEffect extends SpellAbilityEffect {
} }
if (!players.equals("")) { if (!players.equals("")) {
final ArrayList<Player> playerList = new ArrayList<Player>(Singletons.getModel().getGame().getPlayers()); final ArrayList<Player> playerList = new ArrayList<Player>(game.getPlayers());
for (final Player p : playerList) { for (final Player p : playerList) {
if (p.isValid(players, source.getController(), source)) { if (p.isValid(players, source.getController(), source)) {
p.addPreventNextDamage(numDam); p.addPreventNextDamage(numDam);

View File

@@ -7,9 +7,9 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
public class DebuffAllEffect extends SpellAbilityEffect { public class DebuffAllEffect extends SpellAbilityEffect {
@@ -40,6 +40,7 @@ public class DebuffAllEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<String>(); final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<String>();
final GameState game = sa.getActivatingPlayer().getGame();
String valid = ""; String valid = "";
@@ -47,7 +48,7 @@ public class DebuffAllEffect extends SpellAbilityEffect {
valid = sa.getParam("ValidCards"); valid = sa.getParam("ValidCards");
} }
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = game.getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard); list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard);
for (final Card tgtC : list) { for (final Card tgtC : list) {
@@ -62,7 +63,7 @@ public class DebuffAllEffect extends SpellAbilityEffect {
} }
} }
if (!sa.hasParam("Permanent")) { if (!sa.hasParam("Permanent")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(new Command() { game.getEndOfTurn().addUntil(new Command() {
private static final long serialVersionUID = 7486231071095628674L; private static final long serialVersionUID = 7486231071095628674L;
@Override @Override

View File

@@ -7,9 +7,9 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState;
public class DebuffEffect extends SpellAbilityEffect { public class DebuffEffect extends SpellAbilityEffect {
@@ -56,6 +56,7 @@ public class DebuffEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<String>(); final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<String>();
final GameState game = sa.getActivatingPlayer().getGame();
for (final Card tgtC : getTargetCards(sa)) { for (final Card tgtC : getTargetCards(sa)) {
final ArrayList<String> hadIntrinsic = new ArrayList<String>(); final ArrayList<String> hadIntrinsic = new ArrayList<String>();
@@ -69,7 +70,7 @@ public class DebuffEffect extends SpellAbilityEffect {
} }
} }
if (!sa.hasParam("Permanent")) { if (!sa.hasParam("Permanent")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(new Command() { game.getEndOfTurn().addUntil(new Command() {
private static final long serialVersionUID = 5387486776282932314L; private static final long serialVersionUID = 5387486776282932314L;
@Override @Override

View File

@@ -3,7 +3,6 @@ package forge.card.ability.effects;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
@@ -40,6 +39,6 @@ public class DelayedTriggerEffect extends SpellAbilityEffect {
final Trigger delTrig = TriggerHandler.parseTrigger(mapParams, sa.getSourceCard(), true); final Trigger delTrig = TriggerHandler.parseTrigger(mapParams, sa.getSourceCard(), true);
Singletons.getModel().getGame().getTriggerHandler().registerDelayedTrigger(delTrig); sa.getActivatingPlayer().getGame().getTriggerHandler().registerDelayedTrigger(delTrig);
} }
} }

View File

@@ -5,11 +5,11 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -48,6 +48,7 @@ public class DestroyAllEffect extends SpellAbilityEffect {
final boolean noRegen = sa.hasParam("NoRegen"); final boolean noRegen = sa.hasParam("NoRegen");
final Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
final GameState game = sa.getActivatingPlayer().getGame();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
Player targetPlayer = null; Player targetPlayer = null;
@@ -72,7 +73,7 @@ public class DestroyAllEffect extends SpellAbilityEffect {
valid = valid.replace("X", Integer.toString(AbilityUtils.calculateAmount(card, "X", sa))); valid = valid.replace("X", Integer.toString(AbilityUtils.calculateAmount(card, "X", sa)));
} }
List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = game.getCardsIn(ZoneType.Battlefield);
if (targetPlayer != null) { if (targetPlayer != null) {
list = CardLists.filterControlledBy(list, targetPlayer); list = CardLists.filterControlledBy(list, targetPlayer);
@@ -87,13 +88,13 @@ public class DestroyAllEffect extends SpellAbilityEffect {
if (noRegen) { if (noRegen) {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if (Singletons.getModel().getGame().getAction().destroyNoRegeneration(list.get(i), sa) && remDestroyed) { if (game.getAction().destroyNoRegeneration(list.get(i), sa) && remDestroyed) {
card.addRemembered(list.get(i)); card.addRemembered(list.get(i));
} }
} }
} else { } else {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if (Singletons.getModel().getGame().getAction().destroy(list.get(i), sa) && remDestroyed) { if (game.getAction().destroy(list.get(i), sa) && remDestroyed) {
card.addRemembered(list.get(i)); card.addRemembered(list.get(i));
} }
} }

View File

@@ -6,10 +6,10 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardUtil; import forge.CardUtil;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
public class DestroyEffect extends SpellAbilityEffect { public class DestroyEffect extends SpellAbilityEffect {
/* (non-Javadoc) /* (non-Javadoc)
@@ -69,6 +69,7 @@ public class DestroyEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
final GameState game = card.getGame();
final boolean remDestroyed = sa.hasParam("RememberDestroyed"); final boolean remDestroyed = sa.hasParam("RememberDestroyed");
if (remDestroyed) { if (remDestroyed) {
@@ -94,11 +95,11 @@ public class DestroyEffect extends SpellAbilityEffect {
if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) {
boolean destroyed = false; boolean destroyed = false;
if (sac) { if (sac) {
destroyed = Singletons.getModel().getGame().getAction().sacrifice(tgtC, sa); destroyed = game.getAction().sacrifice(tgtC, sa);
} else if (noRegen) { } else if (noRegen) {
destroyed = Singletons.getModel().getGame().getAction().destroyNoRegeneration(tgtC, sa); destroyed = game.getAction().destroyNoRegeneration(tgtC, sa);
} else { } else {
destroyed = Singletons.getModel().getGame().getAction().destroy(tgtC, sa); destroyed = game.getAction().destroy(tgtC, sa);
} if (destroyed && remDestroyed) { } if (destroyed && remDestroyed) {
card.addRemembered(tgtC); card.addRemembered(tgtC);
} }
@@ -109,11 +110,11 @@ public class DestroyEffect extends SpellAbilityEffect {
if (unTgtC.isInPlay()) { if (unTgtC.isInPlay()) {
boolean destroyed = false; boolean destroyed = false;
if (sac) { if (sac) {
destroyed = Singletons.getModel().getGame().getAction().sacrifice(unTgtC, sa); destroyed = game.getAction().sacrifice(unTgtC, sa);
} else if (noRegen) { } else if (noRegen) {
destroyed = Singletons.getModel().getGame().getAction().destroyNoRegeneration(unTgtC, sa); destroyed = game.getAction().destroyNoRegeneration(unTgtC, sa);
} else { } else {
destroyed = Singletons.getModel().getGame().getAction().destroy(unTgtC, sa); destroyed = game.getAction().destroy(unTgtC, sa);
} if (destroyed && remDestroyed) { } if (destroyed && remDestroyed) {
card.addRemembered(unTgtC); card.addRemembered(unTgtC);
} }

View File

@@ -9,11 +9,11 @@ import java.util.Random;
import forge.Card; import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
@@ -52,6 +52,7 @@ public class DigEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final Player player = sa.getActivatingPlayer(); final Player player = sa.getActivatingPlayer();
final GameState game = player.getGame();
Player choser = player; Player choser = player;
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa); int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
final ZoneType destZone1 = sa.hasParam("DestinationZone") ? ZoneType.smartValueOf(sa.getParam("DestinationZone")) final ZoneType destZone1 = sa.hasParam("DestinationZone") ? ZoneType.smartValueOf(sa.getParam("DestinationZone"))
@@ -161,7 +162,7 @@ public class DigEffect extends SpellAbilityEffect {
rest.add(c); rest.add(c);
} }
if (mitosis) { if (mitosis) {
valid = sharesNameWithCardOnBattlefield(top); valid = sharesNameWithCardOnBattlefield(game, top);
} else if (!changeValid.equals("")) { } else if (!changeValid.equals("")) {
if (changeValid.contains("ChosenType")) { if (changeValid.contains("ChosenType")) {
changeValid = changeValid.replace("ChosenType", host.getChosenType()); changeValid = changeValid.replace("ChosenType", host.getChosenType());
@@ -283,9 +284,9 @@ public class DigEffect extends SpellAbilityEffect {
} }
final PlayerZone zone = c.getOwner().getZone(destZone1); final PlayerZone zone = c.getOwner().getZone(destZone1);
if (zone.is(ZoneType.Library)) { if (zone.is(ZoneType.Library)) {
Singletons.getModel().getGame().getAction().moveToLibrary(c, libraryPosition); game.getAction().moveToLibrary(c, libraryPosition);
} else { } else {
c = Singletons.getModel().getGame().getAction().moveTo(zone, c); c = game.getAction().moveTo(zone, c);
if (destZone1.equals(ZoneType.Battlefield)) { if (destZone1.equals(ZoneType.Battlefield)) {
for (final String kw : keywords) { for (final String kw : keywords) {
c.addExtrinsicKeyword(kw); c.addExtrinsicKeyword(kw);
@@ -328,12 +329,12 @@ public class DigEffect extends SpellAbilityEffect {
} else { } else {
chosen = rest.get(0); chosen = rest.get(0);
} }
Singletons.getModel().getGame().getAction().moveToLibrary(chosen, libraryPosition2); game.getAction().moveToLibrary(chosen, libraryPosition2);
rest.remove(chosen); rest.remove(chosen);
} }
} else { // Computer } else { // Computer
for (int i = 0; i < rest.size(); i++) { for (int i = 0; i < rest.size(); i++) {
Singletons.getModel().getGame().getAction().moveToLibrary(rest.get(i), libraryPosition2); game.getAction().moveToLibrary(rest.get(i), libraryPosition2);
} }
} }
} else { } else {
@@ -341,7 +342,7 @@ public class DigEffect extends SpellAbilityEffect {
for (int i = 0; i < rest.size(); i++) { for (int i = 0; i < rest.size(); i++) {
Card c = rest.get(i); Card c = rest.get(i);
final PlayerZone toZone = c.getOwner().getZone(destZone2); final PlayerZone toZone = c.getOwner().getZone(destZone2);
c = Singletons.getModel().getGame().getAction().moveTo(toZone, c); c = game.getAction().moveTo(toZone, c);
if (destZone2.equals(ZoneType.Battlefield) && !keywords.isEmpty()) { if (destZone2.equals(ZoneType.Battlefield) && !keywords.isEmpty()) {
for (final String kw : keywords) { for (final String kw : keywords) {
c.addExtrinsicKeyword(kw); c.addExtrinsicKeyword(kw);
@@ -366,9 +367,9 @@ public class DigEffect extends SpellAbilityEffect {
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private List<Card> sharesNameWithCardOnBattlefield(final List<Card> list) { private List<Card> sharesNameWithCardOnBattlefield(final GameState game, final List<Card> list) {
final List<Card> toReturn = new ArrayList<Card>(); final List<Card> toReturn = new ArrayList<Card>();
final List<Card> play = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final List<Card> play = game.getCardsIn(ZoneType.Battlefield);
for (final Card c : list) { for (final Card c : list) {
for (final Card p : play) { for (final Card p : play) {
if (p.getName().equals(c.getName()) && !toReturn.contains(c)) { if (p.getName().equals(c.getName()) && !toReturn.contains(c)) {

View File

@@ -5,11 +5,11 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -124,6 +124,7 @@ public class DigUntilEffect extends SpellAbilityEffect {
if (revealed.size() > 0) { if (revealed.size() > 0) {
GuiChoose.one(p + " revealed: ", revealed); GuiChoose.one(p + " revealed: ", revealed);
} }
final GameState game = p.getGame();
// TODO Allow Human to choose the order // TODO Allow Human to choose the order
if (foundDest != null) { if (foundDest != null) {
@@ -131,12 +132,12 @@ public class DigUntilEffect extends SpellAbilityEffect {
while (itr.hasNext()) { while (itr.hasNext()) {
final Card c = itr.next(); final Card c = itr.next();
if (sa.hasParam("GainControl") && foundDest.equals(ZoneType.Battlefield)) { if (sa.hasParam("GainControl") && foundDest.equals(ZoneType.Battlefield)) {
c.setController(sa.getActivatingPlayer(), Singletons.getModel().getGame().getNextTimestamp()); c.setController(sa.getActivatingPlayer(), game.getNextTimestamp());
Singletons.getModel().getGame().getAction().moveTo(c.getController().getZone(foundDest), c); game.getAction().moveTo(c.getController().getZone(foundDest), c);
} else if (sa.hasParam("NoMoveFound") && foundDest.equals(ZoneType.Library)) { } else if (sa.hasParam("NoMoveFound") && foundDest.equals(ZoneType.Library)) {
//Don't do anything //Don't do anything
} else { } else {
Singletons.getModel().getGame().getAction().moveTo(foundDest, c, foundLibPos); game.getAction().moveTo(foundDest, c, foundLibPos);
} }
revealed.remove(c); revealed.remove(c);
} }
@@ -152,7 +153,7 @@ public class DigUntilEffect extends SpellAbilityEffect {
final Iterator<Card> itr = revealed.iterator(); final Iterator<Card> itr = revealed.iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
final Card c = itr.next(); final Card c = itr.next();
Singletons.getModel().getGame().getAction().moveTo(revealedDest, c, revealedLibPos); game.getAction().moveTo(revealedDest, c, revealedLibPos);
} }
if (sa.hasParam("Shuffle")) { if (sa.hasParam("Shuffle")) {

View File

@@ -11,6 +11,6 @@ import forge.card.spellability.SpellAbility;
public class ETBReplacementEffect extends SpellAbilityEffect { public class ETBReplacementEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
forge.Singletons.getModel().getGame().getAction().moveToPlay(((Card) sa.getReplacingObject("Card"))); sa.getActivatingPlayer().getGame().getAction().moveToPlay(((Card) sa.getReplacingObject("Card")));
} }
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.Command; import forge.Command;
import forge.Singletons;
import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -14,6 +13,7 @@ import forge.card.spellability.SpellAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -37,6 +37,7 @@ public class EffectEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card hostCard = sa.getSourceCard(); final Card hostCard = sa.getSourceCard();
final GameState game = hostCard.getGame();
String[] effectAbilities = null; String[] effectAbilities = null;
String[] effectTriggers = null; String[] effectTriggers = null;
@@ -87,7 +88,7 @@ public class EffectEffect extends SpellAbilityEffect {
} }
// Unique Effects shouldn't be duplicated // Unique Effects shouldn't be duplicated
if (sa.hasParam("Unique") && Singletons.getModel().getGame().isCardInCommand(name)) { if (sa.hasParam("Unique") && game.isCardInCommand(name)) {
return; return;
} }
@@ -186,7 +187,7 @@ public class EffectEffect extends SpellAbilityEffect {
// Remember created effect // Remember created effect
if (sa.hasParam("RememberEffect")) { if (sa.hasParam("RememberEffect")) {
Singletons.getModel().getGame().getCardState(hostCard).addRemembered(eff); game.getCardState(hostCard).addRemembered(eff);
} }
// Duration // Duration
@@ -197,29 +198,29 @@ public class EffectEffect extends SpellAbilityEffect {
@Override @Override
public void run() { public void run() {
Singletons.getModel().getGame().getAction().exile(e); game.getAction().exile(e);
} }
}; };
if ((duration == null) || duration.equals("EndOfTurn")) { if ((duration == null) || duration.equals("EndOfTurn")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(endEffect); game.getEndOfTurn().addUntil(endEffect);
} }
else if (duration.equals("UntilHostLeavesPlay")) { else if (duration.equals("UntilHostLeavesPlay")) {
hostCard.addLeavesPlayCommand(endEffect); hostCard.addLeavesPlayCommand(endEffect);
} }
else if (duration.equals("HostLeavesOrEOT")) { else if (duration.equals("HostLeavesOrEOT")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(endEffect); game.getEndOfTurn().addUntil(endEffect);
hostCard.addLeavesPlayCommand(endEffect); hostCard.addLeavesPlayCommand(endEffect);
} }
else if (duration.equals("UntilYourNextTurn")) { else if (duration.equals("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntil(controller, endEffect); game.getCleanup().addUntil(controller, endEffect);
} }
} }
// TODO: Add targeting to the effect so it knows who it's dealing with // TODO: Add targeting to the effect so it knows who it's dealing with
Singletons.getModel().getGame().getTriggerHandler().suppressMode(TriggerType.ChangesZone); game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
Singletons.getModel().getGame().getAction().moveTo(ZoneType.Command, eff); game.getAction().moveTo(ZoneType.Command, eff);
Singletons.getModel().getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone); game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
} }
} }

View File

@@ -4,11 +4,11 @@ import java.util.List;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -29,9 +29,10 @@ public class EncodeEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard(); final Card host = sa.getSourceCard();
final Player player = sa.getActivatingPlayer(); final Player player = sa.getActivatingPlayer();
final GameState game = player.getGame();
// make list of creatures that controller has on Battlefield // make list of creatures that controller has on Battlefield
List<Card> choices = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); List<Card> choices = game.getCardsIn(ZoneType.Battlefield);
choices = CardLists.getValidCards(choices, "Creature.YouCtrl", host.getController(), host); choices = CardLists.getValidCards(choices, "Creature.YouCtrl", host.getController(), host);
// if no creatures on battlefield, cannot encoded // if no creatures on battlefield, cannot encoded
@@ -48,7 +49,7 @@ public class EncodeEffect extends SpellAbilityEffect {
} }
// move host card to exile // move host card to exile
Card movedCard = Singletons.getModel().getGame().getAction().moveTo(ZoneType.Exile, host); Card movedCard = game.getAction().moveTo(ZoneType.Exile, host);
// choose a creature // choose a creature
Card choice = player.getController().chooseSingleCardForEffect(choices, sa, "Choose a creature you control to encode ", true); Card choice = player.getController().chooseSingleCardForEffect(choices, sa, "Choose a creature you control to encode ", true);

View File

@@ -2,7 +2,6 @@ package forge.card.ability.effects;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState; import forge.game.GameState;
@@ -21,7 +20,7 @@ public class EndTurnEffect extends SpellAbilityEffect {
@Override @Override
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
GameState game = Singletons.getModel().getGame(); GameState game = sa.getActivatingPlayer().getGame();
// Steps taken from gatherer's rulings on Time Stop. // Steps taken from gatherer's rulings on Time Stop.
// 1) All spells and abilities on the stack are exiled. This includes // 1) All spells and abilities on the stack are exiled. This includes
// Time Stop, though it will continue to resolve. It also includes // Time Stop, though it will continue to resolve. It also includes
@@ -32,7 +31,7 @@ public class EndTurnEffect extends SpellAbilityEffect {
game.getStack().getStack().clear(); game.getStack().getStack().clear();
// 2) All attacking and blocking creatures are removed from combat. // 2) All attacking and blocking creatures are removed from combat.
game.getCombat().reset(); game.getCombat().reset(game.getPhaseHandler().getPlayerTurn());
// 3) State-based actions are checked. No player gets priority, and no // 3) State-based actions are checked. No player gets priority, and no
// triggered abilities are put onto the stack. // triggered abilities are put onto the stack.

View File

@@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons;
import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -132,7 +131,7 @@ public class FlipCoinEffect extends SpellAbilityEffect {
public static boolean flipCoinNoCall(final Card source, final Player flipper) { public static boolean flipCoinNoCall(final Card source, final Player flipper) {
final boolean resultIsHeads = MyRandom.getRandom().nextBoolean(); final boolean resultIsHeads = MyRandom.getRandom().nextBoolean();
Singletons.getModel().getGame().getEvents().post(new FlipCoinEvent()); flipper.getGame().getEvents().post(new FlipCoinEvent());
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
result.append(flipper.getName()); result.append(flipper.getName());
result.append("'s flip comes up"); result.append("'s flip comes up");

Some files were not shown because too many files have changed in this diff Show More