Revert module separation to make another commit that would keep files' history

This commit is contained in:
Maxmtg
2014-01-21 06:05:34 +00:00
parent 923bddc90d
commit ecd14e1de4
512 changed files with 45837 additions and 45921 deletions

999
.gitattributes vendored

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,11 @@
<artifactId>forge-core</artifactId> <artifactId>forge-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>forge</groupId>
<artifactId>forge-game</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -18,15 +18,5 @@
<artifactId>forge-core</artifactId> <artifactId>forge-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.googlecode</groupId>
<artifactId>minlog</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>forge</groupId>
<artifactId>forge-ai</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -1,14 +0,0 @@
package forge;
import forge.item.InventoryItem;
public class ImageCacheBridge {
public static Methods instance;
public interface Methods {
String getImageKey(InventoryItem cp, boolean altState);
String getTokenKey(String imageName);
String getMorphImage();
}
}

View File

@@ -1,25 +0,0 @@
package forge;
public class PreferencesBridge {
public static PreferencesSet Instance;
public interface PreferencesSet {
public abstract boolean getEnableAiCheats();
public abstract boolean getCloneModeSource();
public abstract String getLogEntryType();
public abstract String getCurrentAiProfile();
public abstract boolean canRandomFoil();
public abstract boolean isManaBurnEnabled();
public abstract boolean areBlocksFree();
}
}

View File

@@ -1,3 +1,8 @@
/** Forge Card Game. */ /**
package forge.game; *
*/
/**
* @author Max
*
*/
package forge.game;

View File

@@ -1,39 +1,39 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge;
/** /**
* <p> * <p>
* Command interface. * Command interface.
* </p> * </p>
* *
* @author Forge * @author Forge
* @version $Id: Command.java 21051 2013-04-17 11:48:06Z Max mtg $ * @version $Id$
*/ */
public interface Command extends java.io.Serializable, Runnable { public interface Command extends java.io.Serializable, Runnable {
/** Constant <code>Blank</code>. */ /** Constant <code>Blank</code>. */
public final Command BLANK = new Command() { public final Command BLANK = new Command() {
private static final long serialVersionUID = 2689172297036001710L; private static final long serialVersionUID = 2689172297036001710L;
@Override @Override
public void run() { public void run() {
} }
}; };
} }

View File

@@ -1,71 +1,71 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* <p> * <p>
* Constant interface. * Constant interface.
* </p> * </p>
* *
* @author Forge * @author Forge
* @version $Id: Constant.java 23713 2013-11-20 08:34:37Z Max mtg $ * @version $Id$
*/ */
public final class Constant { public final class Constant {
// used to pass information between the GUI screens // used to pass information between the GUI screens
/** /**
* The Class Runtime. * The Class Runtime.
*/ */
public static class Preferences { public static class Preferences {
/** The Constant DevMode. */ /** The Constant DevMode. */
// one for normal mode, one for quest mode // one for normal mode, one for quest mode
public static boolean DEV_MODE; public static boolean DEV_MODE;
/** The Constant UpldDrft. */ /** The Constant UpldDrft. */
public static boolean UPLOAD_DRAFT; public static boolean UPLOAD_DRAFT;
} }
public static class Runtime { public static class Runtime {
/** The Constant NetConn. */ /** The Constant NetConn. */
public static volatile boolean NET_CONN = false; public static volatile boolean NET_CONN = false;
/** The Constant width. */ /** The Constant width. */
public static final int WIDTH = 300; public static final int WIDTH = 300;
/** The Constant height. */ /** The Constant height. */
public static final int HEIGHT = 0; public static final int HEIGHT = 0;
} }
/** /**
* The Interface Keywords. * The Interface Keywords.
*/ */
public static class Keywords { public static class Keywords {
/** The loaded. */ /** The loaded. */
public static final boolean[] LOADED = { false }; public static final boolean[] LOADED = { false };
/** The Non stacking list. */ /** The Non stacking list. */
public static final List<String> NON_STACKING_LIST = new ArrayList<String>(); public static final List<String> NON_STACKING_LIST = new ArrayList<String>();
} }
} // Constant } // Constant

View File

@@ -111,7 +111,7 @@ public class ImageCache {
} }
return scaleImage(key, width, height, true); return scaleImage(key, width, height, true);
} }
/** /**
* retrieve an image from the cache. returns null if the image is not found in the cache * retrieve an image from the cache. returns null if the image is not found in the cache
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension. * and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
@@ -250,12 +250,6 @@ public class ImageCache {
return null; return null;
} }
public static String getTokenImageKey(String tokenName) {
return TOKEN_PREFIX + tokenName;
}
private static String getImageLocator(PaperCard cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) { private static String getImageLocator(PaperCard cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) {
final String nameToUse = getNameToUse(cp, backFace); final String nameToUse = getNameToUse(cp, backFace);
if ( null == nameToUse ) if ( null == nameToUse )

View File

@@ -1,22 +0,0 @@
package forge;
import forge.item.InventoryItem;
import forge.properties.NewConstants;
public class ImageCacheProvider implements ImageCacheBridge.Methods {
@Override
public String getImageKey(InventoryItem cp, boolean altState) {
return ImageCache.getImageKey(cp, altState);
}
@Override
public String getTokenKey(String imageName) {
return ImageCache.getTokenImageKey(imageName);
}
@Override
public String getMorphImage() {
return NewConstants.CACHE_MORPH_IMAGE_FILE;
}
}

View File

@@ -1,45 +0,0 @@
package forge;
import forge.PreferencesBridge.PreferencesSet;
import forge.properties.ForgePreferences.FPref;
public class PreferencesProvider implements PreferencesSet {
@Override
public boolean getEnableAiCheats() {
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ENABLE_AI_CHEATS);
}
@Override
public boolean getCloneModeSource() {
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
}
@Override
public String getLogEntryType() {
return Singletons.getModel().getPreferences().getPref(FPref.DEV_LOG_ENTRY_TYPE);
}
@Override
public String getCurrentAiProfile() {
return Singletons.getModel().getPreferences().getPref(FPref.UI_CURRENT_AI_PROFILE);
}
@Override
public boolean canRandomFoil() {
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL);
}
@Override
public boolean isManaBurnEnabled() {
// TODO Auto-generated method stub
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MANABURN);
}
@Override
public boolean areBlocksFree() {
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.MATCHPREF_PROMPT_FREE_BLOCKS);
}
}

View File

@@ -16,6 +16,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import forge.FThreads;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.card.mana.ManaAtom; import forge.card.mana.ManaAtom;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
@@ -132,15 +133,15 @@ public class ComputerUtilMana {
// select which abilities may be used for each shard // select which abilities may be used for each shard
MapOfLists<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost); MapOfLists<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost);
// if (DEBUG_MANA_PAYMENT) { if (DEBUG_MANA_PAYMENT) {
// System.out.println((test ? "test -- " : "PROD -- ") + FThreads.debugGetStackTraceItem(5, true)); System.out.println((test ? "test -- " : "PROD -- ") + FThreads.debugGetStackTraceItem(5, true));
// for (Entry<ManaCostShard, Collection<SpellAbility>> src : sourcesForShards.entrySet()) { for (Entry<ManaCostShard, Collection<SpellAbility>> src : sourcesForShards.entrySet()) {
// System.out.println("\t" +src.getKey() + " : " + src.getValue().size() + " source(s)"); System.out.println("\t" +src.getKey() + " : " + src.getValue().size() + " source(s)");
// for (SpellAbility sss : src.getValue()) { for (SpellAbility sss : src.getValue()) {
// System.out.printf("\t\t%s - %s%n", sss.getSourceCard(), sss); System.out.printf("\t\t%s - %s%n", sss.getSourceCard(), sss);
// } }
// } }
// } }
List<String> paymentPlan = new ArrayList<String>(); List<String> paymentPlan = new ArrayList<String>();
@@ -234,11 +235,11 @@ public class ComputerUtilMana {
} }
handleOfferingsAI(sa, test, cost.isPaid()); handleOfferingsAI(sa, test, cost.isPaid());
// if (DEBUG_MANA_PAYMENT) { if (DEBUG_MANA_PAYMENT) {
// System.err.printf("%s > [%s] payment has %s (%s +%d) for (%s) %s:%n\t%s%n%n", System.err.printf("%s > [%s] payment has %s (%s +%d) for (%s) %s:%n\t%s%n%n",
// FThreads.debugGetCurrThreadId(), test ? "test" : "PROD", cost.isPaid() ? "*PAID*" : "failed", originalCost, FThreads.debugGetCurrThreadId(), test ? "test" : "PROD", cost.isPaid() ? "*PAID*" : "failed", originalCost,
// extraMana, sa.getSourceCard(), sa.toUnsuppressedString(), StringUtils.join(paymentPlan, "\n\t")); extraMana, sa.getSourceCard(), sa.toUnsuppressedString(), StringUtils.join(paymentPlan, "\n\t"));
// } }
if (!cost.isPaid()) { if (!cost.isPaid()) {
if (test) { if (test) {

View File

@@ -1,80 +1,80 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge.ai.ability; package forge.ai.ability;
import java.util.List; import java.util.List;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.ability.AbilityUtils; import forge.game.ability.AbilityUtils;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
/** /**
* <p> * <p>
* AbilityFactory_Turns class. * AbilityFactory_Turns class.
* </p> * </p>
* *
* @author Forge * @author Forge
* @version $Id: AddTurnAi.java 23792 2013-11-24 10:02:58Z Max mtg $ * @version $Id$
*/ */
public class AddTurnAi extends SpellAbilityAi { public class AddTurnAi extends SpellAbilityAi {
@Override @Override
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) { protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
final Player opp = ai.getWeakestOpponent(); final Player opp = ai.getWeakestOpponent();
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
sa.resetTargets(); sa.resetTargets();
if (sa.canTarget(ai)) { if (sa.canTarget(ai)) {
sa.getTargets().add(ai); sa.getTargets().add(ai);
} else if (mandatory) { } else if (mandatory) {
for (final Player ally : ai.getAllies()) { for (final Player ally : ai.getAllies()) {
if (sa.canTarget(ally)) { if (sa.canTarget(ally)) {
sa.getTargets().add(ally); sa.getTargets().add(ally);
break; break;
} }
} }
if (!sa.getTargetRestrictions().isMinTargetsChosen(sa.getSourceCard(), sa) && sa.canTarget(opp)) { if (!sa.getTargetRestrictions().isMinTargetsChosen(sa.getSourceCard(), sa) && sa.canTarget(opp)) {
sa.getTargets().add(opp); sa.getTargets().add(opp);
} else { } else {
return false; return false;
} }
} }
} else { } else {
final List<Player> tgtPlayers = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("Defined"), sa); final List<Player> tgtPlayers = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("Defined"), sa);
for (final Player p : tgtPlayers) { for (final Player p : tgtPlayers) {
if (p.isOpponentOf(ai) && !mandatory) { if (p.isOpponentOf(ai) && !mandatory) {
return false; return false;
} }
} }
// not sure if the AI should be playing with cards that give the // not sure if the AI should be playing with cards that give the
// Human more turns. // Human more turns.
} }
return true; return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility) * @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
*/ */
@Override @Override
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) { protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
return doTriggerAINoCost(aiPlayer, sa, false); return doTriggerAINoCost(aiPlayer, sa, false);
} }
} }

View File

@@ -1,109 +1,109 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge.ai.ability; package forge.ai.ability;
import java.util.List; import java.util.List;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardLists; import forge.game.card.CardLists;
import forge.game.card.CounterType; import forge.game.card.CounterType;
import forge.util.Aggregates; import forge.util.Aggregates;
/** /**
* <p> * <p>
* AbilityFactory_Counters class. * AbilityFactory_Counters class.
* </p> * </p>
* *
* @author Forge * @author Forge
* @version $Id: CountersAi.java 23787 2013-11-24 07:09:23Z Max mtg $ * @version $Id$
*/ */
public abstract class CountersAi { public abstract class CountersAi {
// An AbilityFactory subclass for Putting or Removing Counters on Cards. // An AbilityFactory subclass for Putting or Removing Counters on Cards.
/** /**
* <p> * <p>
* chooseCursedTarget. * chooseCursedTarget.
* </p> * </p>
* *
* @param list * @param list
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @param type * @param type
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param amount * @param amount
* a int. * a int.
* @return a {@link forge.game.card.Card} object. * @return a {@link forge.game.card.Card} object.
*/ */
public static Card chooseCursedTarget(final List<Card> list, final String type, final int amount) { public static Card chooseCursedTarget(final List<Card> list, final String type, final int amount) {
Card choice; Card choice;
if (type.equals("M1M1")) { if (type.equals("M1M1")) {
// try to kill the best killable creature, or reduce the best one // try to kill the best killable creature, or reduce the best one
final List<Card> killable = CardLists.filter(list, new Predicate<Card>() { final List<Card> killable = CardLists.filter(list, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getNetDefense() <= amount; return c.getNetDefense() <= amount;
} }
}); });
if (killable.size() > 0) { if (killable.size() > 0) {
choice = ComputerUtilCard.getBestCreatureAI(killable); choice = ComputerUtilCard.getBestCreatureAI(killable);
} else { } else {
choice = ComputerUtilCard.getBestCreatureAI(list); choice = ComputerUtilCard.getBestCreatureAI(list);
} }
} else { } else {
// improve random choice here // improve random choice here
choice = Aggregates.random(list); choice = Aggregates.random(list);
} }
return choice; return choice;
} }
/** /**
* <p> * <p>
* chooseBoonTarget. * chooseBoonTarget.
* </p> * </p>
* *
* @param list * @param list
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @param type * @param type
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @return a {@link forge.game.card.Card} object. * @return a {@link forge.game.card.Card} object.
*/ */
public static Card chooseBoonTarget(final List<Card> list, final String type) { public static Card chooseBoonTarget(final List<Card> list, final String type) {
Card choice; Card choice;
if (type.equals("P1P1")) { if (type.equals("P1P1")) {
choice = ComputerUtilCard.getBestCreatureAI(list); choice = ComputerUtilCard.getBestCreatureAI(list);
} else if (type.equals("DIVINITY")) { } else if (type.equals("DIVINITY")) {
final List<Card> boon = CardLists.filter(list, new Predicate<Card>() { final List<Card> boon = CardLists.filter(list, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getCounters(CounterType.DIVINITY) == 0; return c.getCounters(CounterType.DIVINITY) == 0;
} }
}); });
choice = ComputerUtilCard.getMostExpensivePermanentAI(boon, null, false); choice = ComputerUtilCard.getMostExpensivePermanentAI(boon, null, false);
} else { } else {
// The AI really should put counters on cards that can use it. // The AI really should put counters on cards that can use it.
// Charge counters on things with Charge abilities, etc. Expand // Charge counters on things with Charge abilities, etc. Expand
// these above // these above
choice = Aggregates.random(list); choice = Aggregates.random(list);
} }
return choice; return choice;
} }
} }

View File

@@ -1,272 +1,272 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge.ai.ability; package forge.ai.ability;
import forge.ai.AiCostDecision; import forge.ai.AiCostDecision;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCost; import forge.ai.ComputerUtilCost;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.Game; import forge.game.Game;
import forge.game.ability.AbilityUtils; import forge.game.ability.AbilityUtils;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.cost.Cost; import forge.game.cost.Cost;
import forge.game.cost.CostDiscard; import forge.game.cost.CostDiscard;
import forge.game.cost.CostPart; import forge.game.cost.CostPart;
import forge.game.cost.PaymentDecision; import forge.game.cost.PaymentDecision;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode; import forge.game.player.PlayerActionConfirmMode;
import forge.game.spellability.AbilitySub; import forge.game.spellability.AbilitySub;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions; import forge.game.spellability.TargetRestrictions;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
public class DrawAi extends SpellAbilityAi { public class DrawAi extends SpellAbilityAi {
@Override @Override
public boolean chkAIDrawback(SpellAbility sa, Player ai) { public boolean chkAIDrawback(SpellAbility sa, Player ai) {
return targetAI(ai, sa, false); return targetAI(ai, sa, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility) * @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
*/ */
@Override @Override
protected boolean canPlayAI(Player ai, SpellAbility sa) { protected boolean canPlayAI(Player ai, SpellAbility sa) {
final TargetRestrictions tgt = sa.getTargetRestrictions(); final TargetRestrictions tgt = sa.getTargetRestrictions();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
final Game game = ai.getGame(); final Game game = ai.getGame();
if (abCost != null) { if (abCost != null) {
// AI currently disabled for these costs // AI currently disabled for these costs
if (!ComputerUtilCost.checkCreatureSacrificeCost(ai, abCost, source)) { if (!ComputerUtilCost.checkCreatureSacrificeCost(ai, abCost, source)) {
return false; return false;
} }
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, null)) { if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, null)) {
return false; return false;
} }
if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source)) { if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source)) {
AiCostDecision aiDecisions = new AiCostDecision(ai, sa); AiCostDecision aiDecisions = new AiCostDecision(ai, sa);
for (final CostPart part : abCost.getCostParts()) { for (final CostPart part : abCost.getCostParts()) {
if (part instanceof CostDiscard) { if (part instanceof CostDiscard) {
PaymentDecision decision = part.accept(aiDecisions); PaymentDecision decision = part.accept(aiDecisions);
if ( null == decision ) if ( null == decision )
return false; return false;
for (Card discard : decision.cards) { for (Card discard : decision.cards) {
if (!ComputerUtil.isWorseThanDraw(ai, discard)) { if (!ComputerUtil.isWorseThanDraw(ai, discard)) {
return false; return false;
} }
} }
} }
} }
} }
if (!ComputerUtilCost.checkRemoveCounterCost(abCost, source)) { if (!ComputerUtilCost.checkRemoveCounterCost(abCost, source)) {
return false; return false;
} }
} }
if (!targetAI(ai, sa, false)) { if (!targetAI(ai, sa, false)) {
return false; return false;
} }
if (tgt != null) { if (tgt != null) {
final Player player = sa.getTargets().getFirstTargetedPlayer(); final Player player = sa.getTargets().getFirstTargetedPlayer();
if (player != null && player.isOpponentOf(ai)) { if (player != null && player.isOpponentOf(ai)) {
return true; return true;
} }
} }
// prevent run-away activations - first time will always return true // prevent run-away activations - first time will always return true
if (ComputerUtil.preventRunAwayActivations(sa)) { if (ComputerUtil.preventRunAwayActivations(sa)) {
return false; return false;
} }
if (ComputerUtil.playImmediately(ai, sa)) { if (ComputerUtil.playImmediately(ai, sa)) {
return true; return true;
} }
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases") && !ComputerUtil.castSpellInMain1(ai, sa)) { && !sa.hasParam("ActivationPhases") && !ComputerUtil.castSpellInMain1(ai, sa)) {
return false; return false;
} }
if ((!game.getPhaseHandler().getNextTurn().equals(ai) if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|| game.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
&& !ComputerUtil.activateForCost(sa, ai)) { && !ComputerUtil.activateForCost(sa, ai)) {
return false; return false;
} }
// Don't tap creatures that may be able to block // Don't tap creatures that may be able to block
if (ComputerUtil.waitForBlocking(sa) && !sa.hasParam("ActivationPhases")) { if (ComputerUtil.waitForBlocking(sa) && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
return true; return true;
} }
private boolean targetAI(final Player ai, final SpellAbility sa, final boolean mandatory) { private boolean targetAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
final TargetRestrictions tgt = sa.getTargetRestrictions(); final TargetRestrictions tgt = sa.getTargetRestrictions();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final boolean drawback = (sa instanceof AbilitySub); final boolean drawback = (sa instanceof AbilitySub);
final Game game = ai.getGame(); final Game 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();
final int humanLibrarySize = opp.getCardsIn(ZoneType.Library).size(); final int humanLibrarySize = opp.getCardsIn(ZoneType.Library).size();
final int computerLibrarySize = ai.getCardsIn(ZoneType.Library).size(); final int computerLibrarySize = ai.getCardsIn(ZoneType.Library).size();
final int computerMaxHandSize = ai.getMaxHandSize(); final int computerMaxHandSize = ai.getMaxHandSize();
//if a spell is used don't count the card //if a spell is used don't count the card
if (sa.isSpell() && source.isInZone(ZoneType.Hand)) { if (sa.isSpell() && source.isInZone(ZoneType.Hand)) {
computerHandSize -= 1; computerHandSize -= 1;
} }
int numCards = 1; int numCards = 1;
if (sa.hasParam("NumCards")) { if (sa.hasParam("NumCards")) {
numCards = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa); numCards = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa);
} }
boolean xPaid = false; boolean xPaid = false;
final String num = sa.getParam("NumCards"); final String num = sa.getParam("NumCards");
if ((num != null) && num.equals("X") && source.getSVar(num).equals("Count$xPaid")) { if ((num != null) && num.equals("X") && source.getSVar(num).equals("Count$xPaid")) {
// Set PayX here to maximum value. // Set PayX here to maximum value.
if (sa instanceof AbilitySub && !source.getSVar("PayX").equals("")) { if (sa instanceof AbilitySub && !source.getSVar("PayX").equals("")) {
numCards = Integer.parseInt(source.getSVar("PayX")); numCards = Integer.parseInt(source.getSVar("PayX"));
} else { } else {
numCards = ComputerUtilMana.determineLeftoverMana(sa, ai); numCards = ComputerUtilMana.determineLeftoverMana(sa, ai);
source.setSVar("PayX", Integer.toString(numCards)); source.setSVar("PayX", Integer.toString(numCards));
} }
xPaid = true; xPaid = true;
} }
//if (n) //if (n)
// TODO: if xPaid and one of the below reasons would fail, instead of // TODO: if xPaid and one of the below reasons would fail, instead of
// bailing // bailing
// reduce toPay amount to acceptable level // reduce toPay amount to acceptable level
if (tgt != null) { if (tgt != null) {
// ability is targeted // ability is targeted
sa.resetTargets(); sa.resetTargets();
final boolean canTgtHuman = sa.canTarget(opp); final boolean canTgtHuman = sa.canTarget(opp);
final boolean canTgtComp = sa.canTarget(ai); final boolean canTgtComp = sa.canTarget(ai);
boolean tgtHuman = false; boolean tgtHuman = false;
if (!canTgtHuman && !canTgtComp) { if (!canTgtHuman && !canTgtComp) {
return false; return false;
} }
if (canTgtHuman && !opp.cantLose() && numCards >= humanLibrarySize) { if (canTgtHuman && !opp.cantLose() && numCards >= humanLibrarySize) {
// Deck the Human? DO IT! // Deck the Human? DO IT!
sa.getTargets().add(opp); sa.getTargets().add(opp);
return true; return true;
} }
if (numCards >= computerLibrarySize) { if (numCards >= computerLibrarySize) {
if (xPaid) { if (xPaid) {
numCards = computerLibrarySize - 1; numCards = computerLibrarySize - 1;
source.setSVar("PayX", Integer.toString(numCards)); source.setSVar("PayX", Integer.toString(numCards));
} else { } else {
// Don't deck your self // Don't deck your self
if (!mandatory) { if (!mandatory) {
return false; return false;
} }
tgtHuman = true; tgtHuman = true;
} }
} }
if (computerHandSize + numCards > computerMaxHandSize && game.getPhaseHandler().isPlayerTurn(ai)) { if (computerHandSize + numCards > computerMaxHandSize && 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));
} else { } else {
// Don't draw too many cards and then risk discarding cards // Don't draw too many cards and then risk discarding cards
// at EOT // at EOT
// TODO: "NextUpkeep" is deprecated // TODO: "NextUpkeep" is deprecated
if (!(sa.hasParam("NextUpkeep") || (sa instanceof AbilitySub)) && !mandatory) { if (!(sa.hasParam("NextUpkeep") || (sa instanceof AbilitySub)) && !mandatory) {
return false; return false;
} }
} }
} }
if (numCards == 0 && !mandatory && !drawback) { if (numCards == 0 && !mandatory && !drawback) {
return false; return false;
} }
if ((!tgtHuman || !canTgtHuman) && canTgtComp) { if ((!tgtHuman || !canTgtHuman) && canTgtComp) {
sa.getTargets().add(ai); sa.getTargets().add(ai);
} else if (mandatory && canTgtHuman) { } else if (mandatory && canTgtHuman) {
sa.getTargets().add(opp); sa.getTargets().add(opp);
} else { } else {
return false; return false;
} }
} else if (!mandatory) { } else if (!mandatory) {
// TODO: consider if human is the defined player // TODO: consider if human is the defined player
// ability is not targeted // ability is not targeted
if (numCards >= computerLibrarySize) { if (numCards >= computerLibrarySize) {
if (ai.isCardInPlay("Laboratory Maniac")) { if (ai.isCardInPlay("Laboratory Maniac")) {
return true; return true;
} }
// Don't deck yourself // Don't deck yourself
return false; return false;
} }
if (numCards == 0 && !drawback) { if (numCards == 0 && !drawback) {
return false; return false;
} }
if ((computerHandSize + numCards > computerMaxHandSize) if ((computerHandSize + numCards > computerMaxHandSize)
&& game.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
if (!sa.hasParam("NextUpkeep") && !drawback) { if (!sa.hasParam("NextUpkeep") && !drawback) {
return false; return false;
} }
} }
} }
return true; return true;
} // drawTargetAI() } // drawTargetAI()
@Override @Override
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) { protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
return targetAI(ai, sa, mandatory); return targetAI(ai, sa, mandatory);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String) * @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
*/ */
@Override @Override
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) { public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
int numCards = sa.hasParam("NumCards") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa) : 1; int numCards = sa.hasParam("NumCards") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa) : 1;
// AI shouldn't mill itself // AI shouldn't mill itself
return numCards < player.getZone(ZoneType.Library).size(); return numCards < player.getZone(ZoneType.Library).size();
} }
} }

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