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 f61fa751b5..1e2d3a5996 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 @@ -91,14 +91,15 @@ import mage.cards.repository.ExpansionRepository; * suitable for two player games and some multiplayer games * * @author BetaSteward_at_googlemail.com + * @param */ public class ComputerPlayer> extends PlayerImpl implements Player { private transient final static Logger log = Logger.getLogger(ComputerPlayer.class); - private transient Map unplayable = new TreeMap(); - private transient List playableNonInstant = new ArrayList(); - private transient List playableInstant = new ArrayList(); - private transient List playableAbilities = new ArrayList(); + private transient Map unplayable = new TreeMap<>(); + private transient List playableNonInstant = new ArrayList<>(); + private transient List playableInstant = new ArrayList<>(); + private transient List playableAbilities = new ArrayList<>(); private transient List pickedCards; private transient List chosenColors; @@ -106,12 +107,12 @@ public class ComputerPlayer> extends PlayerImpl i super(name, range); human = false; userData = new UserData(UserGroup.COMPUTER, 64, false); - pickedCards = new ArrayList(); + pickedCards = new ArrayList<>(); } protected ComputerPlayer(UUID id) { super(id); - pickedCards = new ArrayList(); + pickedCards = new ArrayList<>(); } public ComputerPlayer(final ComputerPlayer player) { @@ -222,7 +223,7 @@ public class ComputerPlayer> extends PlayerImpl i return false; } if (target instanceof TargetCardInHand) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); cards.addAll(this.hand.getCards(game)); while(!target.isChosen() && !cards.isEmpty()) { Card pick = pickTarget(cards, outcome, target, null, game); @@ -300,7 +301,7 @@ public class ComputerPlayer> extends PlayerImpl i throw new IllegalStateException("TargetPermanentOrPlayer wasn't handled. class:" + target.getClass().toString()); } if (target instanceof TargetCardInGraveyard) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); for (Player player: game.getPlayers().values()) { for (Card card: player.getGraveyard().getCards(game)) { if (target.canTarget(card.getId(), game)) { @@ -368,7 +369,7 @@ public class ComputerPlayer> extends PlayerImpl i } if (target instanceof TargetDiscard || target instanceof TargetCardInHand) { if (outcome.isGood()) { - ArrayList cardsInHand = new ArrayList(hand.getCards(game)); + ArrayList cardsInHand = new ArrayList<>(hand.getCards(game)); while (!target.isChosen() && !cardsInHand.isEmpty() && target.getMaxNumberOfTargets() < target.getTargets().size()) { Card card = pickBestCard(cardsInHand, null, target, source, game); if (card != null) { @@ -504,7 +505,7 @@ public class ComputerPlayer> extends PlayerImpl i return false; } if (target instanceof TargetCardInGraveyard) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); for (Player player: game.getPlayers().values()) { cards.addAll(player.getGraveyard().getCards(game)); } @@ -517,7 +518,7 @@ public class ComputerPlayer> extends PlayerImpl i return false; } if (target instanceof TargetCardInLibrary) { - List cards = new ArrayList(game.getPlayer(playerId).getLibrary().getCards(game)); + List cards = new ArrayList<>(game.getPlayer(playerId).getLibrary().getCards(game)); Card card = pickTarget(cards, outcome, target, source, game); if (card != null) { target.addTarget(card.getId(), source, game); @@ -526,7 +527,7 @@ public class ComputerPlayer> extends PlayerImpl i return false; } if (target instanceof TargetCardInYourGraveyard) { - List cards = new ArrayList(game.getPlayer(playerId).getGraveyard().getCards(game)); + List cards = new ArrayList<>(game.getPlayer(playerId).getGraveyard().getCards(game)); while(!target.isChosen() && !cards.isEmpty()) { Card card = pickTarget(cards, outcome, target, source, game); if (card != null) { @@ -536,7 +537,7 @@ public class ComputerPlayer> extends PlayerImpl i return target.isChosen(); } if (target instanceof TargetCardInHand) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); cards.addAll(this.hand.getCards(game)); while(!target.isChosen() && !cards.isEmpty()) { Card pick = pickTarget(cards, outcome, target, source, game); @@ -560,7 +561,7 @@ public class ComputerPlayer> extends PlayerImpl i return false; } if (target instanceof TargetCardInOpponentsGraveyard) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); for (UUID uuid: game.getOpponents(playerId)) { Player player = game.getPlayer(uuid); if (player != null) { @@ -598,7 +599,7 @@ public class ComputerPlayer> extends PlayerImpl i } if (target instanceof TargetCardInASingleGraveyard) { - List cards = new ArrayList(); + List cards = new ArrayList<>(); for (Player player: game.getPlayers().values()) { cards.addAll(player.getGraveyard().getCards(game)); } @@ -1177,7 +1178,7 @@ public class ComputerPlayer> extends PlayerImpl i return true; } - ArrayList cardChoices = new ArrayList(cards.getCards(target.getFilter(), game)); + ArrayList cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game)); while (!target.doneChosing()) { Card card = pickTarget(cardChoices, outcome, target, null, game); if (card != null) { @@ -1206,7 +1207,7 @@ public class ComputerPlayer> extends PlayerImpl i UUID opponentId = game.getCombat().getDefenders().iterator().next(); Attackers attackers = getPotentialAttackers(game); List blockers = getOpponentBlockers(opponentId, game); - List actualAttackers = new ArrayList(); + List actualAttackers = new ArrayList<>(); if (blockers.isEmpty()) { actualAttackers = attackers.getAttackers(); } @@ -1258,7 +1259,7 @@ public class ComputerPlayer> extends PlayerImpl i if (object != null) { LinkedHashMap useableAbilities = getSpellAbilities(object, game.getState().getZone(object.getId()), game); if (useableAbilities != null && useableAbilities.size() > 0) { - game.fireGetChoiceEvent(playerId, name, object, new ArrayList(useableAbilities.values())); + game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values())); // TODO: Improve this return (SpellAbility) useableAbilities.values().iterator().next(); } @@ -1338,7 +1339,7 @@ public class ComputerPlayer> extends PlayerImpl i private static void addBasicLands(Deck deck, String landName, int number) { Random random = new Random(); - Set landSets = new HashSet(); + Set landSets = new HashSet<>(); // decide from which sets basic lands are taken from for (String setCode :deck.getExpansionSetCodes()) { @@ -1394,7 +1395,7 @@ public class ComputerPlayer> extends PlayerImpl i public static Deck buildDeck(List cardPool, final List colors) { Deck deck = new Deck(); - List sortedCards = new ArrayList(cardPool); + List sortedCards = new ArrayList<>(cardPool); Collections.sort(sortedCards, new Comparator() { @Override public int compare(Card o1, Card o2) { @@ -1627,6 +1628,7 @@ public class ComputerPlayer> extends PlayerImpl i * 1. there should be at least 3 cards in card pool * 2. at least 2 cards should have different colors * 3. get card colors as chosen starting from most rated card + * @return */ protected List chooseDeckColorsIfPossible() { if (pickedCards.size() > 2) { @@ -1642,7 +1644,7 @@ public class ComputerPlayer> extends PlayerImpl i return o2.score.compareTo(o1.score); } }); - Set chosenSymbols = new HashSet(); + Set chosenSymbols = new HashSet<>(); for (PickedCard picked : pickedCards) { int differentColorsInCost = RateCard.getDifferentColorManaCount(picked.card); // choose only color card, but only if they are not too gold @@ -1659,7 +1661,7 @@ public class ComputerPlayer> extends PlayerImpl i } // only two or three color decks are allowed if (chosenSymbols.size() > 1 && chosenSymbols.size() < 4) { - List colorsChosen = new ArrayList(); + List colorsChosen = new ArrayList<>(); for (String symbol : chosenSymbols) { ColoredManaSymbol manaSymbol = ColoredManaSymbol.lookup(symbol.charAt(0)); if (manaSymbol != null) { @@ -1694,7 +1696,7 @@ public class ComputerPlayer> extends PlayerImpl i if (potential > 0 && creature.getPower().getValue() > 0) { List l = attackers.get(potential); if (l == null) { - attackers.put(potential, l = new ArrayList()); + attackers.put(potential, l = new ArrayList<>()); } l.add(creature); } @@ -1734,7 +1736,7 @@ public class ComputerPlayer> extends PlayerImpl i while(binary.length() < attackersList.size()) { binary = "0" + binary; } - List trialAttackers = new ArrayList(); + List trialAttackers = new ArrayList<>(); for (int j = 0; j < attackersList.size(); j++) { if (binary.charAt(j) == '1') { trialAttackers.add(attackersList.get(j)); @@ -1759,7 +1761,7 @@ public class ComputerPlayer> extends PlayerImpl i TreeNode simulations; - simulations = new TreeNode(combat); + simulations = new TreeNode<>(combat); addBlockSimulations(blockers, simulations, game); combat.simulate(); @@ -1769,14 +1771,14 @@ public class ComputerPlayer> extends PlayerImpl i protected void addBlockSimulations(List blockers, TreeNode node, Game game) { int numGroups = node.getData().groups.size(); - Copier copier = new Copier(); + Copier copier = new Copier<>(); for (Permanent blocker: blockers) { List subList = remove(blockers, blocker); for (int i = 0; i < numGroups; i++) { if (node.getData().groups.get(i).canBlock(blocker, game)) { CombatSimulator combat = copier.copy(node.getData()); combat.groups.get(i).blockers.add(new CreatureSimulator(blocker)); - TreeNode child = new TreeNode(combat); + TreeNode child = new TreeNode<>(combat); node.addChild(child); addBlockSimulations(subList, child, game); combat.simulate(); @@ -1786,7 +1788,7 @@ public class ComputerPlayer> extends PlayerImpl i } protected List remove(List source, Permanent element) { - List newList = new ArrayList(); + List newList = new ArrayList<>(); for (Permanent permanent: source) { if (!permanent.equals(element)) { newList.add(permanent); @@ -1840,7 +1842,7 @@ public class ComputerPlayer> extends PlayerImpl i protected void logState(Game game) { if (log.isTraceEnabled()) { - logList("Computer player " + name + " hand: ", new ArrayList(hand.getCards(game))); + logList(new StringBuilder("Computer player ").append(name).append(" hand: ").toString(), new ArrayList(hand.getCards(game))); } } diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/GoblinWelder.java b/Mage.Sets/src/mage/sets/urzaslegacy/GoblinWelder.java index 7d0642df0c..fdb7cffb2d 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/GoblinWelder.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/GoblinWelder.java @@ -46,9 +46,8 @@ import mage.filter.common.FilterArtifactPermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.TargetCard; import mage.target.common.TargetArtifactPermanent; -import mage.target.common.TargetCardInYourGraveyard; +import mage.target.common.TargetCardInGraveyard; /** * @@ -81,9 +80,7 @@ public class GoblinWelder extends CardImpl { public GoblinWelder copy() { return new GoblinWelder(this); } - - - + public class GoblinWelderEffect extends OneShotEffect { public GoblinWelderEffect() { @@ -98,15 +95,13 @@ public class GoblinWelder extends CardImpl { public boolean apply(Game game, Ability source) { Permanent artifact = game.getPermanent(source.getTargets().get(0).getFirstTarget()); Card card = game.getCard(source.getTargets().get(1).getFirstTarget()); - - if (artifact != null && card != null) { - + Player controller = game.getPlayer(source.getControllerId()); + if (artifact != null && card != null && controller != null) { Zone currentZone = game.getState().getZone(card.getId()); if(artifact.getCardType().contains(CardType.ARTIFACT) && card.getCardType().contains(CardType.ARTIFACT) && currentZone == Zone.GRAVEYARD && card.getOwnerId().equals(artifact.getControllerId())) { - boolean sacrifice = artifact.sacrifice(source.getId(), game); - boolean putOnBF = card.putOntoBattlefield(game, currentZone, source.getId(), card.getOwnerId()); - + boolean sacrifice = artifact.sacrifice(source.getSourceId(), game); + boolean putOnBF = controller.putOntoBattlefieldWithInfo(card, game, Zone.GRAVEYARD, source.getSourceId()); if (sacrifice || putOnBF) { return true; } @@ -126,10 +121,10 @@ public class GoblinWelder extends CardImpl { } } - class GoblinWelderTarget extends TargetCard { + class GoblinWelderTarget extends TargetCardInGraveyard { public GoblinWelderTarget() { - super(1, 1, Zone.GRAVEYARD, new FilterArtifactCard()); + super(1, 1, new FilterArtifactCard()); targetName = "target artifact card in that player's graveyard"; } @@ -139,22 +134,15 @@ public class GoblinWelder extends CardImpl { @Override public boolean canTarget(UUID id, Ability source, Game game) { - UUID firstTarget = source.getFirstTarget(); - Permanent artifact = game.getPermanent(firstTarget); + Permanent artifact = game.getPermanent(source.getFirstTarget()); Player player = game.getPlayer(artifact.getControllerId()); - Card card = game.getCard(id); - if (card != null && player != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) - { - if (player.getGraveyard().contains(id)) - { - return filter.match(card, game); - } + if (card != null && player != null && player.getGraveyard().contains(id)) { + return filter.match(card, game); } return false; } - - + @Override public GoblinWelderTarget copy() {