diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 850465316f..3e9706d336 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -44,6 +44,7 @@ import mage.MageObject; import mage.Mana; import mage.abilities.Ability; import mage.abilities.ActivatedAbility; +import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbilities; import mage.abilities.TriggeredAbility; import mage.abilities.costs.mana.ColoredManaCost; @@ -225,7 +226,8 @@ public class ComputerPlayer> extends PlayerImpl i return true; } } - return false; + if (!target.isRequired()) + return false; } if (target instanceof TargetDiscard) { findPlayables(game); @@ -243,7 +245,8 @@ public class ComputerPlayer> extends PlayerImpl i return true; } } - return false; + if (!target.isRequired()) + return false; } if (target instanceof TargetControlledPermanent) { List targets; @@ -271,7 +274,8 @@ public class ComputerPlayer> extends PlayerImpl i return true; } } - return false; + if (!target.isRequired()) + return false; } if (target instanceof TargetCreatureOrPlayer) { List targets; @@ -300,7 +304,8 @@ public class ComputerPlayer> extends PlayerImpl i return true; } } - return false; + if (!target.isRequired()) + return false; } throw new IllegalStateException("Target wasn't handled. class:" + target.getClass().toString()); } @@ -484,10 +489,13 @@ public class ComputerPlayer> extends PlayerImpl i for (Mana mana: options) { for (Mana avail: available) { if (mana.enough(avail)) { - if (card.getCardType().contains(CardType.INSTANT)) - playableInstant.add(card); - else - playableNonInstant.add(card); + SpellAbility ability = card.getSpellAbility(); + if (ability != null && ability.canActivate(playerId, game)) { + if (card.getCardType().contains(CardType.INSTANT)) + playableInstant.add(card); + else + playableNonInstant.add(card); + } } else { if (!playableInstant.contains(card) && !playableNonInstant.contains(card)) diff --git a/Mage.Server/plugins/mage-player-ai.jar b/Mage.Server/plugins/mage-player-ai.jar index 45016d5014..1e7af9d1ad 100644 Binary files a/Mage.Server/plugins/mage-player-ai.jar and b/Mage.Server/plugins/mage-player-ai.jar differ diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index 1b596b3549..849d5fc582 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -36,8 +36,6 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,11 +54,11 @@ import mage.players.Player; import mage.server.ChatManager; import mage.server.util.ThreadExecutor; import mage.sets.Sets; -import mage.util.Logging; import mage.view.AbilityPickerView; import mage.view.CardsView; import mage.view.GameView; import mage.view.ChatMessage.MessageColor; +import org.apache.log4j.Logger; /** * @@ -69,7 +67,7 @@ import mage.view.ChatMessage.MessageColor; public class GameController implements GameCallback { private static ExecutorService gameExecutor = ThreadExecutor.getInstance().getGameExecutor(); - private final static Logger logger = Logging.getLogger(GameController.class.getName()); + private final static Logger logger = Logger.getLogger(GameController.class); public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt"; private ConcurrentHashMap gameSessions = new ConcurrentHashMap(); @@ -104,7 +102,7 @@ public class GameController implements GameCallback { break; case INFO: ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK); - logger.finest(game.getId() + " " + event.getMessage()); + logger.debug(game.getId() + " " + event.getMessage()); break; case REVEAL: revealCards(event.getMessage(), event.getCards()); @@ -178,7 +176,7 @@ public class GameController implements GameCallback { if (gameFuture == null) { for (final Entry entry: gameSessions.entrySet()) { if (!entry.getValue().init(getGameView(entry.getKey()))) { - logger.severe("Unable to initialize client"); + logger.fatal("Unable to initialize client"); //TODO: generate client error message return; } @@ -238,7 +236,7 @@ public class GameController implements GameCallback { card.putOntoBattlefield(game, Zone.OUTSIDE, null, playerId); } } catch (GameException ex) { - logger.warning(ex.getMessage()); + logger.warn(ex.getMessage()); } addCardsForTesting(game); updateGame(); @@ -434,7 +432,7 @@ public class GameController implements GameCallback { File f = new File(INIT_FILE_PATH); Pattern pattern = Pattern.compile("([a-zA-Z]*):([\\w]*):([a-zA-Z ,\\-.!'\\d]*):([\\d]*)"); if (!f.exists()) { - logger.warning("Couldn't find init file: " + INIT_FILE_PATH); + logger.warn("Couldn't find init file: " + INIT_FILE_PATH); return; } @@ -444,7 +442,7 @@ public class GameController implements GameCallback { try { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); - if (line.startsWith("#")) continue; + if (line.trim().length() == 0 || line.startsWith("#")) continue; Matcher m = pattern.matcher(line); if (m.matches()) { @@ -476,14 +474,14 @@ public class GameController implements GameCallback { game.loadCards(cards, player.getId()); swapWithAnyCard(game, player, card, gameZone); } else { - logger.severe("Couldn't find a card: " + cardName); + logger.fatal("Couldn't find a card: " + cardName); } } } else { - logger.warning("Was skipped: " + line); + logger.warn("Was skipped: " + line); } } else { - logger.warning("Init string wasn't parsed: " + line); + logger.warn("Init string wasn't parsed: " + line); } } } @@ -491,7 +489,7 @@ public class GameController implements GameCallback { scanner.close(); } } catch (Exception e) { - logger.log(Level.SEVERE, "", e); + logger.fatal("", e); } } diff --git a/Mage.Sets/src/mage/sets/conflux/MartialCoup.java b/Mage.Sets/src/mage/sets/conflux/MartialCoup.java index c34dd17e61..25fe18615e 100644 --- a/Mage.Sets/src/mage/sets/conflux/MartialCoup.java +++ b/Mage.Sets/src/mage/sets/conflux/MartialCoup.java @@ -90,8 +90,8 @@ class MartialCoupEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int amount = 0; - if (source.getManaCosts().getVariableCosts().size() > 0) { - amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + if (source.getManaCostsToPay().getVariableCosts().size() > 0) { + amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); } if (amount > 4) { diff --git a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java index 81423c5d42..e361e1a1a0 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java +++ b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java @@ -93,7 +93,7 @@ class EarthquakeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { permanent.damage(amount, source.getId(), game, true, false); diff --git a/Mage.Sets/src/mage/sets/magic2010/Fireball.java b/Mage.Sets/src/mage/sets/magic2010/Fireball.java index 3b6f8ab590..fe6e07fa27 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Fireball.java +++ b/Mage.Sets/src/mage/sets/magic2010/Fireball.java @@ -91,7 +91,7 @@ class FireballEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int numTargets = source.getTargets().get(0).getTargets().size(); - int damage = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); if (numTargets > 0) { int damagePer = damage/numTargets; if (damagePer > 0) { diff --git a/Mage.Sets/src/mage/sets/magic2010/MindSpring.java b/Mage.Sets/src/mage/sets/magic2010/MindSpring.java index b63406a77e..17d3d4d541 100644 --- a/Mage.Sets/src/mage/sets/magic2010/MindSpring.java +++ b/Mage.Sets/src/mage/sets/magic2010/MindSpring.java @@ -84,7 +84,7 @@ class MindSpringEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); Player player = game.getPlayer(source.getControllerId()); if (player != null) { player.drawCards(amount, game); diff --git a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java index 3577003801..c6765dacbc 100644 --- a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java +++ b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java @@ -99,7 +99,7 @@ public class ProteanHydra extends CardImpl { public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { - int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); permanent.addCounters(new PlusOneCounter(amount)); } return true; diff --git a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java index c2474954af..facf503bf0 100644 --- a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java +++ b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java @@ -102,8 +102,8 @@ class VengefulArchonEffect extends PreventionEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); - if (source.getManaCosts().getVariableCosts().size() > 0) - amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + if (source.getManaCostsToPay().getVariableCosts().size() > 0) + amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); } @Override diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java index 5332ac3aaa..b60d402655 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java @@ -76,7 +76,7 @@ class ExsanguinateEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int loseLife = 0; - int damage = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); for (UUID opponentId : game.getOpponents(source.getControllerId())) { loseLife += game.getPlayer(opponentId).loseLife(damage, game); } diff --git a/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java b/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java index 2d524a64d0..98e3cac478 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java @@ -85,7 +85,7 @@ class SigilofDistinctionEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { p.addCounters(CounterType.CHARGE.createInstance(amount)); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 5833e957d9..e02ccec4ed 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -325,6 +325,9 @@ public abstract class GameImpl> implements Game, Serializa for (Player player: state.getPlayers().values()) { player.init(this, testMode); } + for (Player player: state.getPlayers().values()) { + player.beginTurn(this); + } fireInformEvent("game has started"); saveState(); @@ -344,7 +347,7 @@ public abstract class GameImpl> implements Game, Serializa else { choosingPlayer = this.getPlayer(choosingPlayerId); } - if (choosingPlayer.chooseTarget(Outcome.Benefit, targetPlayer, null, this)) { + if (choosingPlayer.choose(Outcome.Benefit, targetPlayer, this)) { startingPlayerId = ((List)targetPlayer.getTargets()).get(0); fireInformEvent(state.getPlayer(startingPlayerId).getName() + " will start"); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index f1b12a0adb..2138df47df 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -168,7 +168,6 @@ public abstract class PlayerImpl> implements Player, Ser this.left = false; this.passed = false; this.passedTurn = false; - findRange(game); } @Override