diff --git a/Mage.Sets/src/mage/sets/dragonsoftarkir/CommuneWithLava.java b/Mage.Sets/src/mage/sets/dragonsoftarkir/CommuneWithLava.java index 4487794cdf..89fe50de8f 100644 --- a/Mage.Sets/src/mage/sets/dragonsoftarkir/CommuneWithLava.java +++ b/Mage.Sets/src/mage/sets/dragonsoftarkir/CommuneWithLava.java @@ -27,7 +27,7 @@ */ package mage.sets.dragonsoftarkir; -import java.util.List; +import java.util.Set; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.AsThoughEffectImpl; @@ -94,14 +94,13 @@ class CommuneWithLavaEffect extends OneShotEffect { Card sourceCard = game.getCard(source.getSourceId()); if (controller != null) { int amount = source.getManaCostsToPay().getX(); - List<Card> cards = controller.getLibrary().getTopCards(game, amount); + Set<Card> cards = controller.getLibrary().getTopCards(game, amount); + controller.moveCardsToExile(cards, source, game, true, CardUtil.getCardExileZoneId(game, source), sourceCard.getIdName()); + for (Card card : cards) { - if (card != null) { - controller.moveCardToExileWithInfo(card, CardUtil.getCardExileZoneId(game, source), sourceCard.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true); - ContinuousEffect effect = new CommuneWithLavaMayPlayEffect(); - effect.setTargetPointer(new FixedTarget(card.getId())); - game.addEffect(effect, source); - } + ContinuousEffect effect = new CommuneWithLavaMayPlayEffect(); + effect.setTargetPointer(new FixedTarget(card.getId())); + game.addEffect(effect, source); } return true; diff --git a/Mage.Sets/src/mage/sets/eventide/SanityGrinding.java b/Mage.Sets/src/mage/sets/eventide/SanityGrinding.java index 063228b681..3ee98ec4d4 100644 --- a/Mage.Sets/src/mage/sets/eventide/SanityGrinding.java +++ b/Mage.Sets/src/mage/sets/eventide/SanityGrinding.java @@ -27,6 +27,8 @@ */ package mage.sets.eventide; +import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; @@ -43,8 +45,6 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetOpponent; -import java.util.UUID; - /** * * @author jeffwadsworth @@ -56,7 +56,6 @@ public class SanityGrinding extends CardImpl { super(ownerId, 29, "Sanity Grinding", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{U}{U}{U}"); this.expansionSetCode = "EVE"; - // Chroma - Reveal the top ten cards of your library. For each blue mana symbol in the mana costs of the revealed cards, target opponent puts the top card of his or her library into his or her graveyard. Then put the cards you revealed this way on the bottom of your library in any order. this.getSpellAbility().addEffect(new SanityGrindingEffect()); this.getSpellAbility().addTarget(new TargetOpponent()); @@ -86,18 +85,15 @@ class SanityGrindingEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player targetOpponent = game.getPlayer(source.getFirstTarget()); Player controller = game.getPlayer(source.getControllerId()); - Cards revealed = new CardsImpl(); - int amount; - if (controller == null) { + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller == null || sourceObject == null) { return false; } - amount = (Math.min(10, controller.getLibrary().size())); - for (int i = 0; i < amount; i++) { - revealed.add(controller.getLibrary().removeFromTop(game)); - } - controller.revealCards("Sanity Grinding", revealed, game); + Cards revealed = new CardsImpl(); + revealed.addAll(controller.getLibrary().getTopCards(game, 10)); + controller.revealCards(sourceObject.getIdName(), revealed, game); + Player targetOpponent = game.getPlayer(source.getFirstTarget()); if (targetOpponent != null) { targetOpponent.moveCards(targetOpponent.getLibrary().getTopCards(game, new ChromaSanityGrindingCount(revealed).calculate(game, source, this)), Zone.LIBRARY, Zone.GRAVEYARD, source, game); diff --git a/Mage.Sets/src/mage/sets/innistrad/HereticsPunishment.java b/Mage.Sets/src/mage/sets/innistrad/HereticsPunishment.java index bfd17fe119..770680727c 100644 --- a/Mage.Sets/src/mage/sets/innistrad/HereticsPunishment.java +++ b/Mage.Sets/src/mage/sets/innistrad/HereticsPunishment.java @@ -27,18 +27,18 @@ */ package mage.sets.innistrad; -import java.util.List; +import java.util.Set; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -54,7 +54,6 @@ public class HereticsPunishment extends CardImpl { super(ownerId, 147, "Heretic's Punishment", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{R}"); this.expansionSetCode = "ISD"; - // {3}{R}: Choose target creature or player, then put the top three cards of your library into your graveyard. Heretic's Punishment deals damage to that creature or player equal to the highest converted mana cost among those cards. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HereticsPunishmentEffect(), new ManaCostsImpl("{3}{R}")); ability.addTarget(new TargetCreatureOrPlayer()); @@ -87,12 +86,12 @@ class HereticsPunishmentEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int maxCost = 0; - List<Card> cardList = controller.getLibrary().getTopCards(game, 3); - for (Card card: cardList) { + Set<Card> cardList = controller.getLibrary().getTopCards(game, 3); + for (Card card : cardList) { int test = card.getManaCost().convertedManaCost(); if (test > maxCost) { maxCost = test; - } + } } controller.moveCards(cardList, Zone.LIBRARY, Zone.GRAVEYARD, source, game); Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); @@ -114,4 +113,4 @@ class HereticsPunishmentEffect extends OneShotEffect { return new HereticsPunishmentEffect(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/NarsetEnlightenedMaster.java b/Mage.Sets/src/mage/sets/khansoftarkir/NarsetEnlightenedMaster.java index 70d9517368..a5093dcec4 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/NarsetEnlightenedMaster.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/NarsetEnlightenedMaster.java @@ -27,7 +27,7 @@ */ package mage.sets.khansoftarkir; -import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.MageObject; @@ -49,7 +49,6 @@ import mage.constants.Zone; import mage.game.Game; import mage.players.Player; import mage.target.targetpointer.FixedTarget; -import mage.util.CardUtil; /** * @@ -89,12 +88,12 @@ public class NarsetEnlightenedMaster extends CardImpl { class NarsetEnlightenedMasterExileEffect extends OneShotEffect { public NarsetEnlightenedMasterExileEffect() { - super(Outcome.Discard); - staticText = "exile the top four cards of your library. Until end of turn, you may cast noncreature cards exiled with {this} this turn without paying their mana costs"; + super(Outcome.Discard); + staticText = "exile the top four cards of your library. Until end of turn, you may cast noncreature cards exiled with {this} this turn without paying their mana costs"; } public NarsetEnlightenedMasterExileEffect(final NarsetEnlightenedMasterExileEffect effect) { - super(effect); + super(effect); } @Override @@ -102,16 +101,16 @@ class NarsetEnlightenedMasterExileEffect extends OneShotEffect { Player player = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); if (player != null && sourceObject != null) { - List<Card> cards = player.getLibrary().getTopCards(game, 4); + Set<Card> cards = player.getLibrary().getTopCards(game, 4); player.moveCards(cards, Zone.LIBRARY, Zone.EXILED, source, game); for (Card card : cards) { - if (game.getState().getZone(card.getId()) == Zone.EXILED && - !card.getCardType().contains(CardType.CREATURE) && - !card.getCardType().contains(CardType.LAND)) { + if (game.getState().getZone(card.getId()) == Zone.EXILED + && !card.getCardType().contains(CardType.CREATURE) + && !card.getCardType().contains(CardType.LAND)) { ContinuousEffect effect = new NarsetEnlightenedMasterCastFromExileEffect(); effect.setTargetPointer(new FixedTarget(card.getId())); game.addEffect(effect, source); - } + } } return true; } @@ -120,7 +119,7 @@ class NarsetEnlightenedMasterExileEffect extends OneShotEffect { @Override public NarsetEnlightenedMasterExileEffect copy() { - return new NarsetEnlightenedMasterExileEffect(this); + return new NarsetEnlightenedMasterExileEffect(this); } } diff --git a/Mage.Sets/src/mage/sets/magic2014/JacesMindseeker.java b/Mage.Sets/src/mage/sets/magic2014/JacesMindseeker.java index bf8354a286..9877bd2dfb 100644 --- a/Mage.Sets/src/mage/sets/magic2014/JacesMindseeker.java +++ b/Mage.Sets/src/mage/sets/magic2014/JacesMindseeker.java @@ -27,7 +27,7 @@ */ package mage.sets.magic2014; -import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; @@ -66,7 +66,7 @@ public class JacesMindseeker extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - // When Jace's Mindseeker enters the battlefield, target opponent puts the top five cards of his or her library into his or her graveyard. + // When Jace's Mindseeker enters the battlefield, target opponent puts the top five cards of his or her library into his or her graveyard. // You may cast an instant or sorcery card from among them without paying its mana cost. Ability ability = new EntersBattlefieldTriggeredAbility(new JaceMindseekerEffect()); ability.addTarget(new TargetOpponent()); @@ -106,17 +106,17 @@ class JaceMindseekerEffect extends OneShotEffect { Cards cardsToCast = new CardsImpl(); Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source)); if (targetOpponent != null) { - List<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 5); + Set<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 5); targetOpponent.moveCards(allCards, Zone.LIBRARY, Zone.GRAVEYARD, source, game); - for(Card card : allCards) { + for (Card card : allCards) { if (filter.match(card, game)) { Zone zone = game.getState().getZone(card.getId()); - // If the five cards are put into a public zone such as exile instead of a graveyard (perhaps due to the ability of Rest in Peace), - // you can cast one of those instant or sorcery cards from that zone. - if (zone.equals(Zone.GRAVEYARD) || zone.equals(Zone.EXILED)) { + // If the five cards are put into a public zone such as exile instead of a graveyard (perhaps due to the ability of Rest in Peace), + // you can cast one of those instant or sorcery cards from that zone. + if (zone.equals(Zone.GRAVEYARD) || zone.equals(Zone.EXILED)) { cardsToCast.add(card); } - } + } } } @@ -127,14 +127,14 @@ class JaceMindseekerEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.GRAVEYARD, filter); // zone should be ignored here target.setNotTarget(true); if (controller.chooseUse(outcome, "Cast an instant or sorcery card from among them for free?", source, game) - && controller.choose(outcome, cardsToCast, target, game)) { + && controller.choose(outcome, cardsToCast, target, game)) { Card card = cardsToCast.get(target.getFirstTarget(), game); if (card != null) { controller.cast(card.getSpellAbility(), game, true); } } } - + } return false; diff --git a/Mage.Sets/src/mage/sets/magic2015/HushwingGryff.java b/Mage.Sets/src/mage/sets/magic2015/HushwingGryff.java index 3cbc4aba1c..c644c08091 100644 --- a/Mage.Sets/src/mage/sets/magic2015/HushwingGryff.java +++ b/Mage.Sets/src/mage/sets/magic2015/HushwingGryff.java @@ -98,28 +98,23 @@ class HushwingGryffEffect extends ContinuousRuleModifyingEffectImpl { } return null; } - + @Override public boolean checksEventType(GameEvent event, Game game) { return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; } - @Override + @Override public boolean applies(GameEvent event, Ability source, Game game) { Ability ability = (Ability) getValue("targetAbility"); if (ability != null && AbilityType.TRIGGERED.equals(ability.getAbilityType())) { - Permanent p = game.getPermanent(event.getTargetId()); - if (p != null && p.getCardType().contains(CardType.CREATURE)) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { return true; } } return false; } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } @Override public HushwingGryffEffect copy() { diff --git a/Mage.Sets/src/mage/sets/magicorigins/TalentOfTheTelepath.java b/Mage.Sets/src/mage/sets/magicorigins/TalentOfTheTelepath.java index 3614a8974e..3ece67c379 100644 --- a/Mage.Sets/src/mage/sets/magicorigins/TalentOfTheTelepath.java +++ b/Mage.Sets/src/mage/sets/magicorigins/TalentOfTheTelepath.java @@ -27,7 +27,7 @@ */ package mage.sets.magicorigins; -import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; @@ -100,7 +100,7 @@ class TalentOfTheTelepathEffect extends OneShotEffect { Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source)); MageObject sourceObject = source.getSourceObject(game); if (targetOpponent != null && sourceObject != null) { - List<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7); + Set<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7); Cards cards = new CardsImpl(Zone.LIBRARY, allCards); targetOpponent.revealCards(sourceObject.getIdName() + " - " + targetOpponent.getName() + "'s top library cards", cards, game); for (Card card : allCards) { diff --git a/Mage.Sets/src/mage/sets/shadowmoor/AdviceFromTheFae.java b/Mage.Sets/src/mage/sets/shadowmoor/AdviceFromTheFae.java index 99251d9485..bf1ed806de 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/AdviceFromTheFae.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/AdviceFromTheFae.java @@ -27,12 +27,10 @@ */ package mage.sets.shadowmoor; -import java.util.List; import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.CardsImpl; @@ -95,12 +93,8 @@ class AdviceFromTheFaeEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); MageObject mageObject = game.getObject(source.getSourceId()); if (controller != null) { - List<Card> cardsFromTopLibrary = controller.getLibrary().getTopCards(game, 5); - Cards cards = new CardsImpl(Zone.LIBRARY); - for (Card card : cardsFromTopLibrary) { - cards.add(card); - } - controller.lookAtCards(mageObject.getIdName(), cards, game); + Cards cardsFromLibrary = new CardsImpl(Zone.LIBRARY, controller.getLibrary().getTopCards(game, 5)); + controller.lookAtCards(mageObject.getIdName(), cardsFromLibrary, game); int max = 0; for (UUID playerId : controller.getInRange()) { FilterCreaturePermanent filter = new FilterCreaturePermanent(); @@ -113,11 +107,11 @@ class AdviceFromTheFaeEffect extends OneShotEffect { } boolean moreCreatures = game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), controller.getId(), game) > max; TargetCard target = new TargetCard(moreCreatures ? 2 : 1, Zone.LIBRARY, new FilterCard()); - if (controller.choose(Outcome.DrawCard, cards, target, game)) { - cards.removeAll(target.getTargets()); + if (controller.choose(Outcome.DrawCard, cardsFromLibrary, target, game)) { + cardsFromLibrary.removeAll(target.getTargets()); controller.moveCards(new CardsImpl(target.getTargets()), null, Zone.HAND, source, game); } - controller.putCardsOnBottomOfLibrary(cards, game, source, true); + controller.putCardsOnBottomOfLibrary(cardsFromLibrary, game, source, true); return true; } return false; diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index eac8d92bc1..e76f6cc21e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -1673,7 +1673,7 @@ public class TestPlayer implements Player { } @Override - public boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game) { + public boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game) { return computerPlayer.moveCards(cards, fromZone, toZone, source, game); } @@ -1688,7 +1688,7 @@ public class TestPlayer implements Player { } @Override - public boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { + public boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { return computerPlayer.moveCards(cards, fromZone, toZone, source, game); } @@ -1703,7 +1703,12 @@ public class TestPlayer implements Player { } @Override - public boolean moveCardsToGraveyardWithInfo(List<Card> allCards, Ability source, Game game, Zone fromZone) { + public boolean moveCardsToExile(Set<Card> cards, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName) { + return computerPlayer.moveCardsToExile(cards, source, game, withName, exileId, exileZoneName); + } + + @Override + public boolean moveCardsToGraveyardWithInfo(Set<Card> allCards, Ability source, Game game, Zone fromZone) { return computerPlayer.moveCardsToGraveyardWithInfo(allCards, source, game, fromZone); } diff --git a/Mage/src/mage/abilities/effects/keyword/ManifestEffect.java b/Mage/src/mage/abilities/effects/keyword/ManifestEffect.java index 7fbb96ce7c..71e6293628 100644 --- a/Mage/src/mage/abilities/effects/keyword/ManifestEffect.java +++ b/Mage/src/mage/abilities/effects/keyword/ManifestEffect.java @@ -27,7 +27,7 @@ */ package mage.abilities.effects.keyword; -import java.util.List; +import java.util.Set; import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCosts; @@ -53,7 +53,7 @@ public class ManifestEffect extends OneShotEffect { private final int amount; - public ManifestEffect(int amount) { + public ManifestEffect(int amount) { super(Outcome.PutCreatureInPlay); this.amount = amount; this.staticText = setText(); @@ -75,8 +75,8 @@ public class ManifestEffect extends OneShotEffect { if (controller != null) { Ability newSource = source.copy(); newSource.setWorksFaceDown(true); - List<Card> cards = controller.getLibrary().getTopCards(game, amount); - for (Card card: cards) { + Set<Card> cards = controller.getLibrary().getTopCards(game, amount); + for (Card card : cards) { ManaCosts manaCosts = null; if (card.getCardType().contains(CardType.CREATURE)) { manaCosts = card.getSpellAbility().getManaCosts(); @@ -84,7 +84,7 @@ public class ManifestEffect extends OneShotEffect { manaCosts = new ManaCostsImpl("{0}"); } } - MageObjectReference objectReference= new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) +1, game); + MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game); game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource); controller.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, newSource.getSourceId(), false, true); Permanent permanent = game.getPermanent(card.getId()); diff --git a/Mage/src/mage/abilities/effects/keyword/ManifestTargetPlayerEffect.java b/Mage/src/mage/abilities/effects/keyword/ManifestTargetPlayerEffect.java index f860993f4a..897ff83f23 100644 --- a/Mage/src/mage/abilities/effects/keyword/ManifestTargetPlayerEffect.java +++ b/Mage/src/mage/abilities/effects/keyword/ManifestTargetPlayerEffect.java @@ -27,12 +27,11 @@ */ package mage.abilities.effects.keyword; -import java.util.List; +import java.util.Set; import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect; import mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect.FaceDownType; @@ -44,20 +43,18 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; /** * * @author LevelX2 */ - public class ManifestTargetPlayerEffect extends OneShotEffect { private final int amount; private final String prefix; - public ManifestTargetPlayerEffect(int amount, String prefix) { + public ManifestTargetPlayerEffect(int amount, String prefix) { super(Outcome.PutCreatureInPlay); this.amount = amount; this.prefix = prefix; @@ -81,8 +78,8 @@ public class ManifestTargetPlayerEffect extends OneShotEffect { if (targetPlayer != null) { Ability newSource = source.copy(); newSource.setWorksFaceDown(true); - List<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount); - for (Card card: cards) { + Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount); + for (Card card : cards) { ManaCosts manaCosts = null; if (card.getCardType().contains(CardType.CREATURE)) { manaCosts = card.getSpellAbility().getManaCosts(); @@ -90,13 +87,13 @@ public class ManifestTargetPlayerEffect extends OneShotEffect { manaCosts = new ManaCostsImpl("{0}"); } } - MageObjectReference objectReference= new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) +1, game); - game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource); + MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game); + game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource); targetPlayer.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, newSource.getSourceId(), false, true); Permanent permanent = game.getPermanent(card.getId()); if (permanent != null) { permanent.setManifested(true); - } + } } return true; } diff --git a/Mage/src/mage/cards/Cards.java b/Mage/src/mage/cards/Cards.java index fffc342824..313f183d6a 100644 --- a/Mage/src/mage/cards/Cards.java +++ b/Mage/src/mage/cards/Cards.java @@ -1,31 +1,30 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.cards; import java.io.Serializable; @@ -39,18 +38,33 @@ import mage.game.Game; public interface Cards extends Set<UUID>, Serializable { void add(Card card); + Card get(UUID cardId, Game game); + void remove(Card card); + void setOwner(UUID ownerId, Game game); + void addAll(List<Card> createCards); + + void addAll(Set<Card> createCards); + Set<Card> getCards(Game game); + Set<Card> getCards(FilterCard filter, Game game); + Set<Card> getCards(FilterCard filter, UUID sourceId, UUID playerId, Game game); + String getValue(Game game); + Collection<Card> getUniqueCards(Game game); + Card getRandom(Game game); + int count(FilterCard filter, Game game); + int count(FilterCard filter, UUID playerId, Game game); + int count(FilterCard filter, UUID sourceId, UUID playerId, Game game); Cards copy(); diff --git a/Mage/src/mage/cards/CardsImpl.java b/Mage/src/mage/cards/CardsImpl.java index c06e6db5f9..d7799289e2 100644 --- a/Mage/src/mage/cards/CardsImpl.java +++ b/Mage/src/mage/cards/CardsImpl.java @@ -1,31 +1,30 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.cards; import java.io.Serializable; @@ -44,20 +43,20 @@ import mage.filter.FilterCard; import mage.game.Game; import mage.util.ThreadLocalStringBuilder; - /** * * @author BetaSteward_at_googlemail.com */ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializable { - + private static final transient ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(200); private static Random rnd = new Random(); private UUID ownerId; private Zone zone; - public CardsImpl() { } + public CardsImpl() { + } public CardsImpl(Card card) { if (card != null) { @@ -74,10 +73,10 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl public CardsImpl(Zone zone) { this.zone = zone; } - + public CardsImpl(Zone zone, Collection<Card> cards) { this(zone); - for (Card card: cards) { + for (Card card : cards) { this.add(card.getId()); } } @@ -117,7 +116,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public void setOwner(UUID ownerId, Game game) { this.ownerId = ownerId; - for (UUID card: this) { + for (UUID card : this) { game.getCard(card).setOwnerId(ownerId); } } @@ -134,7 +133,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public int count(FilterCard filter, Game game) { int result = 0; - for (UUID cardId: this) { + for (UUID cardId : this) { if (filter.match(game.getCard(cardId), game)) { result++; } @@ -145,7 +144,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public int count(FilterCard filter, UUID playerId, Game game) { int result = 0; - for (UUID card: this) { + for (UUID card : this) { if (filter.match(game.getCard(card), playerId, game)) { result++; } @@ -159,7 +158,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl return count(filter, playerId, game); } int result = 0; - for (UUID card: this) { + for (UUID card : this) { if (filter.match(game.getCard(card), sourceId, playerId, game)) { result++; } @@ -170,7 +169,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public Set<Card> getCards(FilterCard filter, UUID sourceId, UUID playerId, Game game) { Set<Card> cards = new LinkedHashSet<>(); - for (UUID card: this) { + for (UUID card : this) { boolean match = filter.match(game.getCard(card), sourceId, playerId, game); if (match) { cards.add(game.getCard(card)); @@ -182,7 +181,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public Set<Card> getCards(FilterCard filter, Game game) { Set<Card> cards = new LinkedHashSet<>(); - for (UUID card: this) { + for (UUID card : this) { boolean match = filter.match(game.getCard(card), game); if (match) { cards.add(game.getCard(card)); @@ -194,11 +193,11 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public Set<Card> getCards(Game game) { Set<Card> cards = new LinkedHashSet<>(); - for (UUID cardId: this) { + for (UUID cardId : this) { Card card = game.getCard(cardId); if (card != null) { // this can happen during the cancelation (player concedes) of a game cards.add(card); - } + } } return cards; } @@ -207,12 +206,12 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl public String getValue(Game game) { StringBuilder sb = threadLocalBuilder.get(); List<String> cards = new ArrayList<>(); - for (UUID cardId: this) { + for (UUID cardId : this) { Card card = game.getCard(cardId); cards.add(card.getName()); } Collections.sort(cards); - for (String name: cards) { + for (String name : cards) { sb.append(name).append(":"); } return sb.toString(); @@ -220,7 +219,14 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public void addAll(List<Card> cards) { - for (Card card: cards) { + for (Card card : cards) { + add(card.getId()); + } + } + + @Override + public void addAll(Set<Card> cards) { + for (Card card : cards) { add(card.getId()); } } @@ -228,7 +234,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl @Override public Collection<Card> getUniqueCards(Game game) { Map<String, Card> cards = new HashMap<>(); - for(UUID cardId: this) { + for (UUID cardId : this) { Card card = game.getCard(cardId); if (!cards.containsKey(card.getName())) { cards.put(card.getName(), card); diff --git a/Mage/src/mage/game/events/ZoneChangeGroupEvent.java b/Mage/src/mage/game/events/ZoneChangeGroupEvent.java index adb3e8cbc4..fa36abb663 100644 --- a/Mage/src/mage/game/events/ZoneChangeGroupEvent.java +++ b/Mage/src/mage/game/events/ZoneChangeGroupEvent.java @@ -1,33 +1,33 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.game.events; -import java.util.List; +import java.util.Set; import java.util.UUID; import mage.cards.Card; import mage.constants.Zone; @@ -37,18 +37,18 @@ import mage.constants.Zone; * @author LevelX2 */ public class ZoneChangeGroupEvent extends GameEvent { - + private final Zone fromZone; private final Zone toZone; - private final List<Card> cards; + private final Set<Card> cards; - public ZoneChangeGroupEvent(List<Card> cards, UUID sourceId, UUID playerId, Zone fromZone, Zone toZone) { + public ZoneChangeGroupEvent(Set<Card> cards, UUID sourceId, UUID playerId, Zone fromZone, Zone toZone) { super(EventType.ZONE_CHANGE_GROUP, null, sourceId, playerId); this.fromZone = fromZone; this.toZone = toZone; this.cards = cards; - } - + } + public Zone getFromZone() { return fromZone; } @@ -57,7 +57,7 @@ public class ZoneChangeGroupEvent extends GameEvent { return toZone; } - public List<Card> getCards() { + public Set<Card> getCards() { return cards; } diff --git a/Mage/src/mage/players/Library.java b/Mage/src/mage/players/Library.java index 190d01782d..ec7cfc1942 100644 --- a/Mage/src/mage/players/Library.java +++ b/Mage/src/mage/players/Library.java @@ -1,31 +1,30 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.players; import java.io.Serializable; @@ -35,6 +34,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Deque; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -65,14 +65,13 @@ public class Library implements Serializable { public Library(final Library lib) { this.emptyDraw = lib.emptyDraw; this.playerId = lib.playerId; - for (UUID id: lib.library) { + for (UUID id : lib.library) { this.library.addLast(id); } } /** - * Don't use this directly. - * Use <player.shuffleLibrary(game)> instead. + * Don't use this directly. Use <player.shuffleLibrary(game)> instead. */ public void shuffle() { UUID[] shuffled = library.toArray(new UUID[0]); @@ -88,7 +87,7 @@ public class Library implements Serializable { /** * Removes the top card of the Library and returns it - * + * * @param game * @return Card * @see Card @@ -133,8 +132,7 @@ public class Library implements Serializable { if (card.getOwnerId().equals(playerId)) { card.setZone(Zone.LIBRARY, game); library.addFirst(card.getId()); - } - else { + } else { game.getPlayer(card.getOwnerId()).getLibrary().putOnTop(card, game); } } @@ -146,8 +144,7 @@ public class Library implements Serializable { library.remove(card.getId()); } library.add(card.getId()); - } - else { + } else { game.getPlayer(card.getOwnerId()).getLibrary().putOnBottom(card, game); } } @@ -166,7 +163,7 @@ public class Library implements Serializable { public void set(Library newLibrary) { library.clear(); - for (UUID card: newLibrary.getCardList()) { + for (UUID card : newLibrary.getCardList()) { library.add(card); } } @@ -177,17 +174,17 @@ public class Library implements Serializable { public List<Card> getCards(Game game) { List<Card> cards = new ArrayList<>(); - for (UUID cardId: library) { + for (UUID cardId : library) { cards.add(game.getCard(cardId)); } return cards; } - public List<Card> getTopCards(Game game, int amount) { - List<Card> cards = new ArrayList<>(); + public Set<Card> getTopCards(Game game, int amount) { + Set<Card> cards = new HashSet<>(); Iterator<UUID> it = library.iterator(); int count = 0; - while(it.hasNext() && count < amount) { + while (it.hasNext() && count < amount) { UUID cardId = it.next(); Card card = game.getCard(cardId); if (card != null) { @@ -200,7 +197,7 @@ public class Library implements Serializable { public Collection<Card> getUniqueCards(Game game) { Map<String, Card> cards = new HashMap<>(); - for (UUID cardId: library) { + for (UUID cardId : library) { Card card = game.getCard(cardId); if (!cards.containsKey(card.getName())) { cards.put(card.getName(), card); @@ -211,7 +208,7 @@ public class Library implements Serializable { public int count(FilterCard filter, Game game) { int result = 0; - for (UUID card: library) { + for (UUID card : library) { if (filter.match(game.getCard(card), game)) { result++; } @@ -219,20 +216,19 @@ public class Library implements Serializable { return result; } - public boolean isEmptyDraw() { return emptyDraw; } public void addAll(Set<Card> cards, Game game) { - for (Card card: cards) { + for (Card card : cards) { card.setZone(Zone.LIBRARY, game); library.add(card.getId()); } } public Card getCard(UUID cardId, Game game) { - for (UUID card: library) { + for (UUID card : library) { if (card.equals(cardId)) { return game.getCard(card); } @@ -242,7 +238,7 @@ public class Library implements Serializable { public Card remove(UUID cardId, Game game) { Iterator<UUID> it = library.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { UUID card = it.next(); if (card.equals(cardId)) { it.remove(); diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index cf94a94608..88aa373b59 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -626,9 +626,11 @@ public interface Player extends MageItem, Copyable<Player> { boolean moveCards(Card card, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName); - boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game); + boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game); - boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName); + boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName); + + boolean moveCardsToExile(Set<Card> cards, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName); /** * Uses card.moveToZone and posts a inform message about moving the card @@ -637,7 +639,6 @@ public interface Player extends MageItem, Copyable<Player> { * @param card * @param sourceId * @param game - * @param fromZone if null, this info isn't postet * @return */ boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game); @@ -687,7 +688,7 @@ public interface Player extends MageItem, Copyable<Player> { * @param fromZone if null, this info isn't postet * @return */ - boolean moveCardsToGraveyardWithInfo(List<Card> cards, Ability source, Game game, Zone fromZone); + boolean moveCardsToGraveyardWithInfo(Set<Card> cards, Ability source, Game game, Zone fromZone); /** * Uses card.moveToZone and posts a inform message about moving the card to diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index cbe259f965..b5b2029a92 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -859,14 +859,16 @@ public abstract class PlayerImpl implements Player, Serializable { /** * Can be cards or permanents that go to library * - * @param cards + * @param cardsToLibrary * @param game * @param source * @param anyOrder * @return */ @Override - public boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) { + public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary, Game game, Ability source, boolean anyOrder) { + Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException + cards.addAll(cardsToLibrary); if (cards.size() != 0) { if (!anyOrder) { for (UUID cardId : cards) { @@ -2879,7 +2881,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCards(Cards cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { - ArrayList<Card> cardList = new ArrayList<>(); + Set<Card> cardList = new HashSet<>(); for (UUID cardId : cards) { if (fromZone == null) { fromZone = game.getState().getZone(cardId); @@ -2906,7 +2908,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCards(Card card, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { - ArrayList<Card> cardList = new ArrayList<>(); + Set<Card> cardList = new HashSet<>(); if (card != null) { cardList.add(card); } @@ -2914,12 +2916,12 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game) { + public boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game) { return moveCards(cards, fromZone, toZone, source, game, true); } @Override - public boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { + public boolean moveCards(Set<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game, boolean withName) { if (cards.isEmpty()) { return true; } @@ -2960,6 +2962,20 @@ public abstract class PlayerImpl implements Player, Serializable { } } + @Override + public boolean moveCardsToExile(Set<Card> cards, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName) { + if (cards.isEmpty()) { + return true; + } + game.fireEvent(new ZoneChangeGroupEvent(cards, source == null ? null : source.getSourceId(), this.getId(), null, Zone.EXILED)); + boolean result = false; + for (Card card : cards) { + Zone fromZone = game.getState().getZone(card.getId()); + result |= moveCardToExileWithInfo(card, exileId, exileZoneName, source == null ? null : source.getSourceId(), game, fromZone, withName); + } + return result; + } + @Override public boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game) { return this.moveCardToHandWithInfo(card, sourceId, game, true); @@ -2974,7 +2990,7 @@ public abstract class PlayerImpl implements Player, Serializable { card = game.getCard(card.getId()); } if (!game.isSimulation()) { - StringBuilder sb = new StringBuilder(this.getLogName()).append(" puts ").append(withName ? card.getLogName() : "a face down card"); + StringBuilder sb = new StringBuilder(this.getLogName()).append(" puts ").append(withName ? card.getLogName() : (card.isFaceDown(game) ? "a face down card" : "a card")); switch (fromZone) { case EXILED: sb.append(" from exile zone "); @@ -2992,7 +3008,7 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public boolean moveCardsToGraveyardWithInfo(List<Card> allCards, Ability source, Game game, Zone fromZone) { + public boolean moveCardsToGraveyardWithInfo(Set<Card> allCards, Ability source, Game game, Zone fromZone) { boolean result = true; UUID sourceId = source == null ? null : source.getSourceId(); while (!allCards.isEmpty()) { diff --git a/Mage/src/mage/target/common/TargetCardInLibrary.java b/Mage/src/mage/target/common/TargetCardInLibrary.java index 69221dc3d8..5d6205e80d 100644 --- a/Mage/src/mage/target/common/TargetCardInLibrary.java +++ b/Mage/src/mage/target/common/TargetCardInLibrary.java @@ -1,33 +1,33 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.target.common; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -42,7 +42,6 @@ import mage.game.Game; import mage.players.Player; import mage.target.TargetCard; - /** * * @author BetaSteward_at_googlemail.com @@ -86,8 +85,7 @@ public class TargetCardInLibrary extends TargetCard { if (librarySearchLimit == Integer.MAX_VALUE) { cards = targetPlayer.getLibrary().getCards(game); } else { - int maxCards = Math.min(librarySearchLimit, targetPlayer.getLibrary().size()); - cards = targetPlayer.getLibrary().getTopCards(game, maxCards); + cards = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit)); } Collections.sort(cards, new CardNameComparator()); while (!isChosen() && !doneChosing()) { @@ -124,7 +122,6 @@ public class TargetCardInLibrary extends TargetCard { this.librarySearchLimit = librarySearchLimit; } - } class CardNameComparator implements Comparator<Card> {