madness moved to PlayerController

removed imports and sources of warnings
This commit is contained in:
Maxmtg
2013-03-19 09:10:32 +00:00
parent b3c042dd08
commit ecf41ea05d
6 changed files with 40 additions and 64 deletions

View File

@@ -45,7 +45,6 @@ import forge.card.replacement.ReplacementResult;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
import forge.card.spellability.AbilityActivated; import forge.card.spellability.AbilityActivated;
import forge.card.spellability.AbilityStatic; import forge.card.spellability.AbilityStatic;
import forge.card.spellability.Spell;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
@@ -64,8 +63,6 @@ import forge.game.zone.PlayerZoneBattlefield;
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;
import forge.gui.GuiDialog;
/** /**
* Methods for common actions performed during a game. * Methods for common actions performed during a game.
@@ -81,6 +78,7 @@ public class GameAction {
*/ */
private final GameState game; private final GameState game;
public GameAction(GameState game0) { public GameAction(GameState game0) {
game = game0; game = game0;
} }
@@ -120,8 +118,7 @@ public class GameAction {
if (zoneFrom == null && !c.isToken()) { if (zoneFrom == null && !c.isToken()) {
if (position == null) { if (position == null) {
zoneTo.add(c); zoneTo.add(c);
} } else {
else {
zoneTo.add(c, position); zoneTo.add(c, position);
} }
@@ -201,8 +198,7 @@ public class GameAction {
// but how to query for input here and continue later while the callers assume synchronous result? // but how to query for input here and continue later while the callers assume synchronous result?
if (position == null) { if (position == null) {
zoneTo.add(copied); zoneTo.add(copied);
} } else {
else {
zoneTo.add(copied, position); zoneTo.add(copied, position);
} }
@@ -246,7 +242,7 @@ public class GameAction {
(!zoneTo.is(ZoneType.Battlefield) && !c.getName().equals("Skullbriar, the Walking Grave"))) { (!zoneTo.is(ZoneType.Battlefield) && !c.getName().equals("Skullbriar, the Walking Grave"))) {
copied.clearCounters(); copied.clearCounters();
} }
if (!zoneTo.is(ZoneType.Battlefield)) { if (!zoneTo.is(ZoneType.Battlefield)) {
copied.getCharacteristics().resetCardColor(); copied.getCharacteristics().resetCardColor();
} }
@@ -487,8 +483,7 @@ public class GameAction {
} }
private void handleRecoverAbility(final Card recoverable) { private void handleRecoverAbility(final Card recoverable) {
final String recoverCost = recoverable.getKeyword().get(recoverable.getKeywordPosition("Recover")) final String recoverCost = recoverable.getKeyword().get(recoverable.getKeywordPosition("Recover")).split(":")[1];
.split(":")[1];
final Cost cost = new Cost(recoverable, recoverCost, true); final Cost cost = new Cost(recoverable, recoverCost, true);
final Command paidCommand = new Command() { final Command paidCommand = new Command() {
@@ -793,16 +788,7 @@ public class GameAction {
@Override @Override
public void resolve() { public void resolve() {
// pay madness cost here. // pay madness cost here.
if (card.getOwner().isHuman()) { card.getOwner().getController().playMadness(madness);
if (GuiDialog.confirm(card, card + " - Discarded. Pay Madness Cost?")) {
game.getActionPlay().playSpellAbility(madness, player);
}
} else {
Spell spell = (Spell) madness;
if (spell.canPlayFromEffectAI(false, false)) {
ComputerUtil.playStack(madness, (AIPlayer) card.getOwner(), game);
}
}
} }
}; };
@@ -942,12 +928,12 @@ public class GameAction {
return; return;
} }
// final JFrame frame = Singletons.getView().getFrame(); // final JFrame frame = Singletons.getView().getFrame();
// if (!frame.isDisplayable()) { // if (!frame.isDisplayable()) {
// return; // return;
// } // }
if ( game.isGameOver() ) if (game.isGameOver())
return; return;
final boolean refreeze = game.getStack().isFrozen(); final boolean refreeze = game.getStack().isFrozen();
@@ -963,7 +949,7 @@ public class GameAction {
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
game.getTriggerHandler().runTrigger(TriggerType.Always, runParams, false); game.getTriggerHandler().runTrigger(TriggerType.Always, runParams, false);
for (Player p : game.getPlayers()) { for (Player p : game.getPlayers()) {
for (Card c : p.getCardsIn(ZoneType.Battlefield)) { for (Card c : p.getCardsIn(ZoneType.Battlefield)) {
if (!c.getController().equals(p)) { if (!c.getController().equals(p)) {
@@ -1090,7 +1076,7 @@ public class GameAction {
checkAgain = true; checkAgain = true;
// Place triggers on stack // Place triggers on stack
} }
if (this.handleLegendRule()) { if (this.handleLegendRule()) {
checkAgain = true; checkAgain = true;
} }
@@ -1104,8 +1090,8 @@ public class GameAction {
} }
} // for q=0;q<2 } // for q=0;q<2
GameEndReason endGame = this.checkEndGameState(game); GameEndReason endGame = this.checkEndGameState(game);
if ( endGame != null ) { if (endGame != null) {
// Clear Simultaneous triggers at the end of the game // Clear Simultaneous triggers at the end of the game
game.setGameOver(endGame); game.setGameOver(endGame);
game.getStack().clearSimultaneousStack(); game.getStack().clearSimultaneousStack();
@@ -1191,15 +1177,15 @@ public class GameAction {
game.getEvents().post(new CardDestroyedEvent()); game.getEvents().post(new CardDestroyedEvent());
} }
} }
return recheck; return recheck;
} // destroyLegendaryCreatures() } // destroyLegendaryCreatures()
public final boolean sacrifice(final Card c, final SpellAbility source) { public final boolean sacrifice(final Card c, final SpellAbility source) {
if(!c.canBeSacrificedBy(source)) if (!c.canBeSacrificedBy(source))
return false; return false;
this.sacrificeDestroy(c); this.sacrificeDestroy(c);
// Play the Sacrifice sound // Play the Sacrifice sound
@@ -1253,7 +1239,7 @@ public class GameAction {
* @return a boolean. * @return a boolean.
*/ */
public final boolean destroyNoRegeneration(final Card c) { public final boolean destroyNoRegeneration(final Card c) {
if ( !c.canBeDestroyed() ) if (!c.canBeDestroyed())
return false; return false;
if (c.isEnchanted()) { if (c.isEnchanted()) {
@@ -1366,7 +1352,7 @@ public class GameAction {
final boolean persist = (c.hasKeyword("Persist") && (c.getCounters(CounterType.M1M1) == 0)) && !c.isToken(); final boolean persist = (c.hasKeyword("Persist") && (c.getCounters(CounterType.M1M1) == 0)) && !c.isToken();
final boolean undying = (c.hasKeyword("Undying") && (c.getCounters(CounterType.P1P1) == 0)) && !c.isToken(); final boolean undying = (c.hasKeyword("Undying") && (c.getCounters(CounterType.P1P1) == 0)) && !c.isToken();
game.getCombat().removeFromCombat(c); game.getCombat().removeFromCombat(c);
final Card newCard = this.moveToGraveyard(c); final Card newCard = this.moveToGraveyard(c);
@@ -1433,5 +1419,5 @@ public class GameAction {
* @param c * @param c
* a {@link forge.Card} object. * a {@link forge.Card} object.
*/ */
} }

View File

@@ -49,7 +49,6 @@ import forge.card.mana.ManaCost;
import forge.card.mana.ManaPool; import forge.card.mana.ManaPool;
import forge.card.replacement.ReplacementResult; import forge.card.replacement.ReplacementResult;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
import forge.card.spellability.Spell;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
@@ -58,7 +57,6 @@ import forge.game.GameActionUtil;
import forge.game.GameLossReason; import forge.game.GameLossReason;
import forge.game.GameState; import forge.game.GameState;
import forge.game.GlobalRuleChange; import forge.game.GlobalRuleChange;
import forge.game.ai.ComputerUtil;
import forge.game.event.CardDiscardedEvent; import forge.game.event.CardDiscardedEvent;
import forge.game.event.DrawCardEvent; import forge.game.event.DrawCardEvent;
import forge.game.event.LandPlayedEvent; import forge.game.event.LandPlayedEvent;

View File

@@ -114,4 +114,5 @@ public abstract class PlayerController {
public abstract Card chooseCardToDredge(List<Card> dredgers); public abstract Card chooseCardToDredge(List<Card> dredgers);
public abstract void playMiracle(SpellAbility miracle, Card card); public abstract void playMiracle(SpellAbility miracle, Card card);
public abstract void playMadness(SpellAbility madness);
} }

View File

@@ -129,35 +129,23 @@ public class PlayerControllerAi extends PlayerController {
return player; return player;
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#sideboard(forge.deck.Deck)
*/
@Override @Override
public Deck sideboard(Deck deck, GameType gameType) { public Deck sideboard(Deck deck, GameType gameType) {
// AI does not know how to sideboard // AI does not know how to sideboard
return deck; return deck;
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#assignCombatDamage(forge.Card, java.util.List, int, forge.GameEntity)
*/
@Override @Override
public Map<Card, Integer> assignCombatDamage(Card attacker, List<Card> blockers, int damageDealt, GameEntity defender) { public Map<Card, Integer> assignCombatDamage(Card attacker, List<Card> blockers, int damageDealt, GameEntity defender) {
return ComputerUtilCombat.distributeAIDamage(attacker, blockers, damageDealt, defender); return ComputerUtilCombat.distributeAIDamage(attacker, blockers, damageDealt, defender);
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#announceRequirements()
*/
@Override @Override
public String announceRequirements(SpellAbility ability, String announce) { public String announceRequirements(SpellAbility ability, String announce) {
// For now, these "announcements" are made within the AI classes of the appropriate SA effects // For now, these "announcements" are made within the AI classes of the appropriate SA effects
return null; return null;
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#choosePermanentsToSacrifice(java.util.List, int, forge.card.spellability.SpellAbility, boolean, boolean)
*/
@Override @Override
public List<Card> choosePermanentsToSacrifice(List<Card> validTargets, int amount, SpellAbility sa, boolean destroy, boolean isOptional) { public List<Card> choosePermanentsToSacrifice(List<Card> validTargets, int amount, SpellAbility sa, boolean destroy, boolean isOptional) {
return ComputerUtil.choosePermanentsToSacrifice(player, validTargets, amount, sa, destroy, isOptional); return ComputerUtil.choosePermanentsToSacrifice(player, validTargets, amount, sa, destroy, isOptional);
@@ -165,12 +153,12 @@ public class PlayerControllerAi extends PlayerController {
@Override @Override
public Card chooseSingleCardForEffect(List<Card> options, SpellAbility sa, String title, boolean isOptional) { public Card chooseSingleCardForEffect(List<Card> options, SpellAbility sa, String title, boolean isOptional) {
return brains.chooseSingleCardForEffect(options, sa, title, isOptional); return getAi().chooseSingleCardForEffect(options, sa, title, isOptional);
} }
@Override @Override
public boolean confirmAction(SpellAbility sa, String mode, String message) { public boolean confirmAction(SpellAbility sa, String mode, String message) {
return brains.confirmAction(sa, mode, message); return getAi().confirmAction(sa, mode, message);
} }
@Override @Override
@@ -179,7 +167,7 @@ public class PlayerControllerAi extends PlayerController {
} }
@Override @Override
public boolean confirmStaticApplication(Card hostCard, GameEntity affected, String logic, String message) { public boolean confirmStaticApplication(Card hostCard, GameEntity affected, String logic, String message) {
return brains.confirmStaticApplication(hostCard, affected, logic, message); return getAi().confirmStaticApplication(hostCard, affected, logic, message);
} }
@Override @Override
@@ -234,7 +222,7 @@ public class PlayerControllerAi extends PlayerController {
@Override @Override
public Card chooseCardToDredge(List<Card> dredgers) { public Card chooseCardToDredge(List<Card> dredgers) {
return brains.chooseCardToDredge(dredgers); return getAi().chooseCardToDredge(dredgers);
} }
@Override @Override
@@ -242,4 +230,10 @@ public class PlayerControllerAi extends PlayerController {
getAi().chooseAndPlaySa(false, false, miracle); getAi().chooseAndPlaySa(false, false, miracle);
} }
@Override
public void playMadness(SpellAbility madness) {
getAi().chooseAndPlaySa(false, false, madness);
}
} }

View File

@@ -319,18 +319,12 @@ public class PlayerControllerHuman extends PlayerController {
return GuiDialog.confirm(c, "Where will you put " + c.getName() + " in your library", new String[]{"Top", "Bottom"} ); return GuiDialog.confirm(c, "Where will you put " + c.getName() + " in your library", new String[]{"Top", "Bottom"} );
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#chooseCardsToDiscardFrom(forge.game.player.Player, java.util.List, int)
*/
@Override @Override
public List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> valid, int minDiscard) { public List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> valid, int minDiscard) {
int cntToKeepInHand = minDiscard == 0 ? -1 : valid.size() - minDiscard; int cntToKeepInHand = minDiscard == 0 ? -1 : valid.size() - minDiscard;
return GuiChoose.order("Choose cards to Discard", "Discarded", cntToKeepInHand, valid, null, null); return GuiChoose.order("Choose cards to Discard", "Discarded", cntToKeepInHand, valid, null, null);
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#chooseCardToDredge(java.util.List)
*/
@Override @Override
public Card chooseCardToDredge(List<Card> dredgers) { public Card chooseCardToDredge(List<Card> dredgers) {
if (GuiDialog.confirm(null, "Do you want to dredge?", false)) { if (GuiDialog.confirm(null, "Do you want to dredge?", false)) {
@@ -339,13 +333,17 @@ public class PlayerControllerHuman extends PlayerController {
return null; return null;
} }
/* (non-Javadoc)
* @see forge.game.player.PlayerController#playMiracle(forge.card.spellability.SpellAbility, forge.Card)
*/
@Override @Override
public void playMiracle(SpellAbility miracle, Card card) { public void playMiracle(SpellAbility miracle, Card card) {
if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) { if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) {
game.getActionPlay().playSpellAbility(miracle, getPlayer()); game.getActionPlay().playSpellAbility(miracle, getPlayer());
} }
} }
@Override
public void playMadness(SpellAbility madness) {
if (GuiDialog.confirm(madness.getSourceCard(), madness.getSourceCard() + " - Discarded. Pay Madness Cost?")) {
game.getActionPlay().playSpellAbility(madness, getPlayer());
}
}
} }

View File

@@ -268,7 +268,6 @@ public enum CSubmenuPreferences implements ICDoc {
prefs.save(); prefs.save();
} }
@SuppressWarnings("serial")
private void updateAIProfile() { private void updateAIProfile() {
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
final String name = view.getLstChooseAIProfile().getSelectedValue().toString(); final String name = view.getLstChooseAIProfile().getSelectedValue().toString();