From 6f8f10fcc331491c7ff7e852537ab0c3cc046d3b Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Thu, 30 Mar 2017 20:08:07 +0200 Subject: [PATCH] move static function to CardImpl, and other api fixes --- .../java/mage/client/cards/CardsList.java | 41 +++++---------- .../java/mage/client/cards/Permanent.java | 27 +++++----- Mage.Common/src/mage/utils/DeckBuilder.java | 15 ++---- .../src/mage/deck/Commander.java | 12 ++--- .../player/ai/ma/ArtificialScoringSystem.java | 5 +- .../java/mage/player/ai/utils/RateCard.java | 10 ++-- .../src/mage/player/human/HumanPlayer.java | 44 ++++------------ Mage.Sets/src/mage/cards/a/AlphaStatus.java | 3 +- Mage.Sets/src/mage/cards/d/DaringThief.java | 10 ++-- .../src/mage/cards/d/DescendantsPath.java | 3 +- Mage.Sets/src/mage/cards/d/Desertion.java | 8 +-- Mage.Sets/src/mage/cards/d/DuskFeaster.java | 4 +- Mage.Sets/src/mage/cards/k/KondasBanner.java | 6 +-- Mage.Sets/src/mage/cards/m/ManaEchoes.java | 6 +-- .../src/mage/cards/m/MycosynthLattice.java | 19 ++----- Mage.Sets/src/mage/cards/p/PrimalSurge.java | 16 +++--- .../src/mage/cards/s/SemblanceAnvil.java | 2 +- .../src/mage/cards/s/ShiftingLoyalties.java | 10 ++-- .../mage/cards/s/StoneforgeMasterwork.java | 6 +-- .../src/mage/cards/t/TheGitrogMonster.java | 2 +- .../src/mage/cards/w/WeightOfConscience.java | 15 +++--- .../cards/abilities/keywords/BestowTest.java | 9 ++-- .../BattlefieldTriggeredAbilitiesTest.java | 3 +- .../test/cards/copy/ProgenitorMimicTest.java | 5 +- .../cards/single/ths/HeliodGodOfTheSun.java | 3 +- Mage/src/main/java/mage/MageObject.java | 50 +++++++++++++++++++ .../abilities/abilityword/KinshipAbility.java | 3 +- .../abilities/keyword/FlankingAbility.java | 20 +++----- .../mage/abilities/keyword/KickerAbility.java | 25 +++------- Mage/src/main/java/mage/cards/CardsImpl.java | 35 +++---------- ...etCreaturePermanentWithDifferentTypes.java | 6 +-- Mage/src/main/java/mage/util/CardUtil.java | 50 ------------------- 32 files changed, 177 insertions(+), 296 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/cards/CardsList.java b/Mage.Client/src/main/java/mage/client/cards/CardsList.java index 45d106c187..fafdece0c1 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardsList.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardsList.java @@ -33,26 +33,6 @@ */ package mage.client.cards; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.beans.Beans; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JTable; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; import mage.cards.MageCard; import mage.client.constants.Constants.DeckEditorMode; import mage.client.constants.Constants.SortBy; @@ -61,15 +41,8 @@ import mage.client.deckeditor.table.TableModel; import mage.client.deckeditor.table.UpdateCountsCallback; import mage.client.dialog.PreferencesDialog; import mage.client.plugins.impl.Plugins; -import mage.client.util.CardViewCardTypeComparator; -import mage.client.util.CardViewColorComparator; -import mage.client.util.CardViewColorIdentityComparator; -import mage.client.util.CardViewCostComparator; -import mage.client.util.CardViewNameComparator; -import mage.client.util.CardViewRarityComparator; +import mage.client.util.*; import mage.client.util.Event; -import mage.client.util.GUISizeHelper; -import mage.client.util.Listener; import mage.client.util.gui.TableSpinnerEditor; import mage.constants.CardType; import mage.view.CardView; @@ -77,6 +50,18 @@ import mage.view.CardsView; import mage.view.SimpleCardView; import org.mage.card.arcane.CardPanel; +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.beans.Beans; +import java.util.*; +import java.util.List; + /** * * @author BetaSteward_at_googlemail.com diff --git a/Mage.Client/src/main/java/mage/client/cards/Permanent.java b/Mage.Client/src/main/java/mage/client/cards/Permanent.java index f23c01cc88..b057f80af0 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Permanent.java +++ b/Mage.Client/src/main/java/mage/client/cards/Permanent.java @@ -34,28 +34,25 @@ package mage.client.cards; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.RenderingHints; +import mage.cards.CardDimensions; +import mage.cards.MagePermanent; +import mage.cards.Sets; +import mage.client.util.Config; +import mage.client.util.TransformedImageCache; +import mage.constants.CardType; +import mage.view.CounterView; +import mage.view.PermanentView; + +import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.swing.PopupFactory; -import mage.cards.CardDimensions; -import mage.cards.MagePermanent; -import mage.cards.Sets; + import static mage.client.constants.Constants.DAMAGE_MAX_LEFT; import static mage.client.constants.Constants.POWBOX_TEXT_MAX_TOP; -import mage.client.util.Config; -import mage.constants.CardType; -import mage.view.CounterView; -import mage.view.PermanentView; -import mage.client.util.TransformedImageCache; /** * diff --git a/Mage.Common/src/mage/utils/DeckBuilder.java b/Mage.Common/src/mage/utils/DeckBuilder.java index 55760f7d28..19922120b3 100644 --- a/Mage.Common/src/mage/utils/DeckBuilder.java +++ b/Mage.Common/src/mage/utils/DeckBuilder.java @@ -1,21 +1,14 @@ package mage.utils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import mage.Mana; import mage.cards.Card; import mage.cards.decks.Deck; -import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.interfaces.rate.RateCallback; import mage.util.RandomUtil; +import java.util.*; + /** * Builds deck from provided card pool. * @@ -246,13 +239,13 @@ public final class DeckBuilder { this.card = card; int type; - if (card.getCardType().contains(CardType.CREATURE)) { + if (card.isCreature()) { type = 10; } else if (card.getSubtype(null).contains("Equipment")) { type = 8; } else if (card.getSubtype(null).contains("Aura")) { type = 5; - } else if (card.getCardType().contains(CardType.INSTANT)) { + } else if (card.isInstant()) { type = 7; } else { type = 6; diff --git a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java index 0a36060891..23e6ee2ec1 100644 --- a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java +++ b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java @@ -27,11 +27,6 @@ */ package mage.deck; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.CanBeYourCommanderAbility; @@ -42,11 +37,12 @@ import mage.cards.ExpansionSet; import mage.cards.Sets; import mage.cards.decks.Constructed; import mage.cards.decks.Deck; -import mage.constants.CardType; import mage.constants.SetType; import mage.filter.FilterMana; import mage.util.CardUtil; +import java.util.*; + /** * * @author Plopman @@ -501,7 +497,7 @@ public class Commander extends Constructed { thisMaxPower = Math.max(thisMaxPower, 1); } - if (card.getCardType().contains(CardType.PLANESWALKER)) { + if (card.isPlaneswalker()) { if (card.getName().toLowerCase().equals("jace, the mind sculptor")) { thisMaxPower = Math.max(thisMaxPower, 6); } @@ -511,7 +507,7 @@ public class Commander extends Constructed { thisMaxPower = Math.max(thisMaxPower, 4); } - if (card.getCardType().contains(CardType.LAND)) { + if (card.isLand()) { thisMaxPower = 0; } diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ma/ArtificialScoringSystem.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ma/ArtificialScoringSystem.java index 04ed14327f..d5ad689c8f 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ma/ArtificialScoringSystem.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ma/ArtificialScoringSystem.java @@ -1,6 +1,5 @@ package mage.player.ai.ma; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.Effect; import mage.abilities.keyword.HasteAbility; @@ -11,6 +10,8 @@ import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** * @author ubeefx, nantuko */ @@ -27,7 +28,7 @@ public final class ArtificialScoringSystem { public static int getCardDefinitionScore(final Game game, final Card card) { int value = 3; //TODO: add new rating system card value - if (card.getCardType().contains(CardType.LAND)) { + if (card.isLand()) { int score = (int) ((value / 2.0f) * 50); //TODO: check this for "any color" lands //TODO: check this for dual and filter lands diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/utils/RateCard.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/utils/RateCard.java index bdd761b68d..bfb41b55fe 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/utils/RateCard.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/utils/RateCard.java @@ -4,7 +4,6 @@ import mage.abilities.Ability; import mage.abilities.effects.Effect; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.Card; -import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Outcome; import mage.target.Target; @@ -57,15 +56,15 @@ public final class RateCard { return rate; } int type; - if (card.getCardType().contains(CardType.PLANESWALKER)) { + if (card.isPlaneswalker()) { type = 15; - } else if (card.getCardType().contains(CardType.CREATURE)) { + } else if (card.isCreature()) { type = 10; } else if (card.getSubtype(null).contains("Equipment")) { type = 8; } else if (card.getSubtype(null).contains("Aura")) { type = 5; - } else if (card.getCardType().contains(CardType.INSTANT)) { + } else if (card.isInstant()) { type = 7; } else { type = 6; @@ -78,8 +77,7 @@ public final class RateCard { } private static int isRemoval(Card card) { - if (card.getSubtype(null).contains("Aura") || card.getCardType().contains(CardType.INSTANT) - || card.getCardType().contains(CardType.SORCERY)) { + if (card.getSubtype(null).contains("Aura") || card.isInstant() || card.isSorcery()) { for (Ability ability : card.getAbilities()) { for (Effect effect : ability.getEffects()) { diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index afc14c45f3..0f8ae477a9 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -27,30 +27,13 @@ */ package mage.player.human; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; import mage.MageObject; -import mage.abilities.Ability; -import mage.abilities.ActivatedAbility; -import mage.abilities.Mode; -import mage.abilities.Modes; -import mage.abilities.PlayLandAbility; -import mage.abilities.SpecialAction; -import mage.abilities.SpellAbility; -import mage.abilities.TriggeredAbility; +import mage.abilities.*; import mage.abilities.costs.VariableCost; import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.costs.mana.PhyrexianManaCost; import mage.abilities.effects.RequirementEffect; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.Card; @@ -58,22 +41,7 @@ import mage.cards.Cards; import mage.cards.decks.Deck; import mage.choices.Choice; import mage.choices.ChoiceImpl; -import mage.constants.AbilityType; -import mage.constants.CardType; -import mage.constants.Constants; -import mage.constants.ManaType; -import mage.constants.Outcome; -import mage.constants.PhaseStep; -import mage.constants.PlayerAction; -import static mage.constants.PlayerAction.HOLD_PRIORITY; -import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_NO; -import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL; -import static mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_NAME_LAST; -import static mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL; -import mage.constants.RangeOfInfluence; -import static mage.constants.SpellAbilityType.SPLIT; -import static mage.constants.SpellAbilityType.SPLIT_FUSED; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.common.FilterAttackingCreature; import mage.filter.common.FilterBlockingCreature; import mage.filter.common.FilterCreatureForCombat; @@ -102,6 +70,12 @@ import mage.util.ManaUtil; import mage.util.MessageToClient; import org.apache.log4j.Logger; +import java.io.Serializable; +import java.util.*; + +import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL; +import static mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL; + /** * * @author BetaSteward_at_googlemail.com @@ -1275,7 +1249,7 @@ public class HumanPlayer extends PlayerImpl { return; } } - if (userData.isUseFirstManaAbility() && object instanceof Permanent && object.getCardType().contains(CardType.LAND)) { + if (userData.isUseFirstManaAbility() && object instanceof Permanent && object.isLand()) { ActivatedAbility ability = abilities.values().iterator().next(); if (ability instanceof ActivatedManaAbilityImpl) { activateAbility(ability, game); diff --git a/Mage.Sets/src/mage/cards/a/AlphaStatus.java b/Mage.Sets/src/mage/cards/a/AlphaStatus.java index 695df00850..673ca8768c 100644 --- a/Mage.Sets/src/mage/cards/a/AlphaStatus.java +++ b/Mage.Sets/src/mage/cards/a/AlphaStatus.java @@ -45,7 +45,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; import java.util.UUID; @@ -92,7 +91,7 @@ class AlphaStatusDynamicValue implements DynamicValue { if (enchanted != null) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), game)) { if (!permanent.getId().equals(enchanted.getId())) { - if (CardUtil.shareSubtypes(enchanted, permanent, game)) { + if (enchanted.shareSubtypes(permanent, game)) { xValue += 2; } } diff --git a/Mage.Sets/src/mage/cards/d/DaringThief.java b/Mage.Sets/src/mage/cards/d/DaringThief.java index 338a024f36..368cae9591 100644 --- a/Mage.Sets/src/mage/cards/d/DaringThief.java +++ b/Mage.Sets/src/mage/cards/d/DaringThief.java @@ -46,8 +46,8 @@ import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetPermanent; import mage.target.common.TargetControlledPermanent; -import mage.util.CardUtil; +import java.util.EnumSet; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -134,9 +134,9 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo return new TargetControlledPermanentSharingOpponentPermanentCardType(this); } - private Set getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { + private EnumSet getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { Player controller = game.getPlayer(sourceControllerId); - Set cardTypes = new HashSet<>(); + EnumSet cardTypes =EnumSet.noneOf(CardType.class); if (controller != null) { for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) { if (controller.hasOpponent(permanent.getControllerId(), game)) { @@ -171,7 +171,7 @@ class DaringThiefSecondTarget extends TargetPermanent { Permanent target1 = game.getPermanent(source.getFirstTarget()); Permanent opponentPermanent = game.getPermanent(id); if (target1 != null && opponentPermanent != null) { - return CardUtil.shareTypes(target1, opponentPermanent); + return target1.shareTypes(opponentPermanent); } } return false; @@ -184,7 +184,7 @@ class DaringThiefSecondTarget extends TargetPermanent { MageObject targetSource = game.getObject(sourceId); for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if (CardUtil.shareTypes(permanent, firstTarget)) { + if (permanent.shareTypes(firstTarget)) { possibleTargets.add(permanent.getId()); } } diff --git a/Mage.Sets/src/mage/cards/d/DescendantsPath.java b/Mage.Sets/src/mage/cards/d/DescendantsPath.java index 7cb0a463b9..3a876bb7cc 100644 --- a/Mage.Sets/src/mage/cards/d/DescendantsPath.java +++ b/Mage.Sets/src/mage/cards/d/DescendantsPath.java @@ -42,7 +42,6 @@ import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.util.CardUtil; import java.util.UUID; @@ -102,7 +101,7 @@ class DescendantsPathEffect extends OneShotEffect { FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); boolean found = false; for (Permanent permanent: game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) { - if (CardUtil.shareSubtypes(card, permanent, game)) { + if (card.shareSubtypes(permanent, game)) { found = true; break; } diff --git a/Mage.Sets/src/mage/cards/d/Desertion.java b/Mage.Sets/src/mage/cards/d/Desertion.java index e94fca2d5f..2ad97057f8 100644 --- a/Mage.Sets/src/mage/cards/d/Desertion.java +++ b/Mage.Sets/src/mage/cards/d/Desertion.java @@ -40,8 +40,6 @@ import mage.game.stack.Spell; import mage.players.Player; import mage.target.TargetSpell; -import java.util.HashSet; -import java.util.Set; import java.util.UUID; /** @@ -90,15 +88,13 @@ class DesertionEffect extends OneShotEffect { if (controller != null) { Spell targetSpell = game.getStack().getSpell(targetPointer.getFirst(game, source)); if (targetSpell != null) { - Set cardTypes = new HashSet<>(targetSpell.getCardType()); - if (!cardTypes.isEmpty()) { //targetPointer.getFirst(game, source) - if (cardTypes.contains(CardType.ARTIFACT) || cardTypes.contains(CardType.CREATURE)) { + if (targetSpell.isArtifact() || targetSpell.isCreature()) { return game.getStack().counter(targetSpell.getId(), source.getSourceId(), game, Zone.BATTLEFIELD, false, ZoneDetail.NONE); } else { return game.getStack().counter(targetSpell.getId(), source.getSourceId(), game); } - } + } } return false; diff --git a/Mage.Sets/src/mage/cards/d/DuskFeaster.java b/Mage.Sets/src/mage/cards/d/DuskFeaster.java index 3b876799d1..fbc5bf50a7 100644 --- a/Mage.Sets/src/mage/cards/d/DuskFeaster.java +++ b/Mage.Sets/src/mage/cards/d/DuskFeaster.java @@ -41,7 +41,7 @@ import mage.constants.*; import mage.game.Game; import mage.players.Player; -import java.util.HashSet; +import java.util.EnumSet; import java.util.UUID; /** @@ -106,7 +106,7 @@ class DuskFeasterCostReductionEffect extends CostModificationEffectImpl { boolean hasDelirium = false; Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - HashSet foundCardTypes = new HashSet<>(); + EnumSet foundCardTypes = EnumSet.noneOf(CardType.class); for (Card card : controller.getGraveyard().getCards(game)) { foundCardTypes.addAll(card.getCardType()); } diff --git a/Mage.Sets/src/mage/cards/k/KondasBanner.java b/Mage.Sets/src/mage/cards/k/KondasBanner.java index f74e32d7ce..a385a89b22 100644 --- a/Mage.Sets/src/mage/cards/k/KondasBanner.java +++ b/Mage.Sets/src/mage/cards/k/KondasBanner.java @@ -29,7 +29,6 @@ */ package mage.cards.k; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.AttachableToRestrictedAbility; import mage.abilities.common.SimpleStaticAbility; @@ -46,7 +45,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.Target; import mage.target.common.TargetControlledCreaturePermanent; -import mage.util.CardUtil; + +import java.util.UUID; /** * @@ -111,7 +111,7 @@ class KondasBannerTypeBoostEffect extends BoostAllEffect { Permanent equipedCreature = game.getPermanent(equipment.getAttachedTo()); if (equipedCreature != null) { for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (CardUtil.shareSubtypes(perm, equipedCreature, game)) { + if (perm.shareSubtypes(equipedCreature, game)) { perm.addPower(power.calculate(game, source, this)); perm.addToughness(toughness.calculate(game, source, this)); diff --git a/Mage.Sets/src/mage/cards/m/ManaEchoes.java b/Mage.Sets/src/mage/cards/m/ManaEchoes.java index bd90a651c7..a8c9c698f2 100644 --- a/Mage.Sets/src/mage/cards/m/ManaEchoes.java +++ b/Mage.Sets/src/mage/cards/m/ManaEchoes.java @@ -27,7 +27,6 @@ */ package mage.cards.m; -import java.util.UUID; import mage.Mana; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility; @@ -42,7 +41,8 @@ import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.util.CardUtil; + +import java.util.UUID; /** * @@ -91,7 +91,7 @@ class ManaEchoesEffect extends OneShotEffect { if (controller != null && permanent != null) { int foundCreatures = 0; for (Permanent perm : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), game)) { - if (CardUtil.shareSubtypes(permanent, perm, game)) { + if (permanent.shareSubtypes(perm, game)) { foundCreatures++; } } diff --git a/Mage.Sets/src/mage/cards/m/MycosynthLattice.java b/Mage.Sets/src/mage/cards/m/MycosynthLattice.java index aa6cf3f4a7..72f82fc9f3 100644 --- a/Mage.Sets/src/mage/cards/m/MycosynthLattice.java +++ b/Mage.Sets/src/mage/cards/m/MycosynthLattice.java @@ -27,9 +27,6 @@ */ package mage.cards.m; -import java.util.List; -import java.util.Set; -import java.util.UUID; import mage.MageObject; import mage.ObjectColor; import mage.abilities.Ability; @@ -40,14 +37,7 @@ import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.AsThoughEffectType; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Layer; -import mage.constants.ManaType; -import mage.constants.Outcome; -import mage.constants.SubLayer; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.command.CommandObject; import mage.game.permanent.Permanent; @@ -55,6 +45,8 @@ import mage.game.stack.Spell; import mage.players.ManaPoolItem; import mage.players.Player; +import java.util.UUID; + /** * @author duncant */ @@ -91,10 +83,7 @@ class PermanentsAreArtifactsEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { - Set cardType = perm.getCardType(); - if (!cardType.contains(CardType.ARTIFACT)) { - cardType.add(CardType.ARTIFACT); - } + perm.getCardType().add(CardType.ARTIFACT); } return true; } diff --git a/Mage.Sets/src/mage/cards/p/PrimalSurge.java b/Mage.Sets/src/mage/cards/p/PrimalSurge.java index d941e8f4a8..b02bd81704 100644 --- a/Mage.Sets/src/mage/cards/p/PrimalSurge.java +++ b/Mage.Sets/src/mage/cards/p/PrimalSurge.java @@ -27,21 +27,20 @@ */ package mage.cards.p; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** * * @author North @@ -96,10 +95,7 @@ class PrimalSurgeEffect extends OneShotEffect { Card card = player.getLibrary().removeFromTop(game); if (card != null) { card.moveToExile(null, "", source.getSourceId(), game); - Set cardType = card.getCardType(); - if ((cardType.contains(CardType.ARTIFACT) || cardType.contains(CardType.CREATURE) - || cardType.contains(CardType.ENCHANTMENT) || cardType.contains(CardType.LAND) - || cardType.contains(CardType.PLANESWALKER)) + if (card.isPermanent() && player.chooseUse(Outcome.PutCardInPlay, "Put " + card.getName() + " onto the battlefield?", source, game)) { card.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, false); diff --git a/Mage.Sets/src/mage/cards/s/SemblanceAnvil.java b/Mage.Sets/src/mage/cards/s/SemblanceAnvil.java index a1c0dee10e..cea6d8f4cc 100644 --- a/Mage.Sets/src/mage/cards/s/SemblanceAnvil.java +++ b/Mage.Sets/src/mage/cards/s/SemblanceAnvil.java @@ -143,7 +143,7 @@ class SemblanceAnvilCostReductionEffect extends CostModificationEffectImpl { List imprinted = permanent.getImprinted(); if (!imprinted.isEmpty()) { Card imprintedCard = game.getCard(imprinted.get(0)); - if (imprintedCard != null && CardUtil.shareTypes(imprintedCard, sourceCard)) { + if (imprintedCard != null && imprintedCard.shareTypes(sourceCard)) { return true; } } diff --git a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java index 922ea52de8..a059a4d5cf 100644 --- a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java +++ b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java @@ -27,9 +27,6 @@ */ package mage.cards.s; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect; @@ -41,7 +38,10 @@ import mage.filter.FilterPermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.util.CardUtil; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; /** * @@ -88,7 +88,7 @@ class TargetPermanentsThatShareCardType extends TargetPermanent { if (targetOne == null || targetTwo == null) { return false; } - return CardUtil.shareTypes(targetOne, targetTwo); + return targetOne.shareTypes(targetTwo); } return true; } diff --git a/Mage.Sets/src/mage/cards/s/StoneforgeMasterwork.java b/Mage.Sets/src/mage/cards/s/StoneforgeMasterwork.java index 4446847b12..fa3d53ccfe 100644 --- a/Mage.Sets/src/mage/cards/s/StoneforgeMasterwork.java +++ b/Mage.Sets/src/mage/cards/s/StoneforgeMasterwork.java @@ -27,7 +27,6 @@ */ package mage.cards.s; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; @@ -43,7 +42,8 @@ import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.util.CardUtil; + +import java.util.UUID; /** * @@ -85,7 +85,7 @@ class StoneforgeMasterworkDynamicValue implements DynamicValue { if (equipped != null) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), sourceAbility.getControllerId(), game)) { if (!permanent.getId().equals(equipped.getId())) { - if (CardUtil.shareSubtypes(equipped, permanent, game)) { + if (equipped.shareSubtypes(permanent, game)) { xValue++; } } diff --git a/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java b/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java index 69d32e7895..5f1fdc2b53 100644 --- a/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java +++ b/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java @@ -112,7 +112,7 @@ class TheGitrogMonsterTriggeredAbility extends TriggeredAbilityImpl { if (cardOwnerId != null && card.getOwnerId().equals(getControllerId()) && cardType != null - && cardType.contains(CardType.LAND)) { + && card.isLand()) { return true; } } diff --git a/Mage.Sets/src/mage/cards/w/WeightOfConscience.java b/Mage.Sets/src/mage/cards/w/WeightOfConscience.java index dad82f569f..b77db39c7b 100644 --- a/Mage.Sets/src/mage/cards/w/WeightOfConscience.java +++ b/Mage.Sets/src/mage/cards/w/WeightOfConscience.java @@ -27,10 +27,6 @@ */ package mage.cards.w; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; @@ -56,6 +52,11 @@ import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetCreaturePermanent; import mage.util.CardUtil; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + /** * * @author emerald000 @@ -158,7 +159,7 @@ class WeightOfConscienceTarget extends TargetControlledCreaturePermanent { Permanent firstTargetCreature = game.getPermanent(firstTargetId); if (firstTargetCreature != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filterUntapped, sourceControllerId, game)) { - if (!permanent.getId().equals(firstTargetId) && CardUtil.shareSubtypes(firstTargetCreature, permanent, game)) { + if (!permanent.getId().equals(firstTargetId) && firstTargetCreature.shareSubtypes(permanent, game)) { possibleTargets.add(permanent.getId()); } } @@ -172,7 +173,7 @@ class WeightOfConscienceTarget extends TargetControlledCreaturePermanent { public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { for (Permanent permanent1 : game.getBattlefield().getActivePermanents(filterUntapped, sourceControllerId, game)) { for (Permanent permanent2 : game.getBattlefield().getActivePermanents(filterUntapped, sourceControllerId, game)) { - if (!Objects.equals(permanent1, permanent2) && CardUtil.shareSubtypes(permanent1, permanent2, game)) { + if (!Objects.equals(permanent1, permanent2) && permanent1.shareSubtypes(permanent2, game)) { return true; } } @@ -198,7 +199,7 @@ class WeightOfConscienceTarget extends TargetControlledCreaturePermanent { } else { Permanent firstTarget = game.getPermanent(this.getTargets().get(0)); - if (firstTarget != null && CardUtil.shareSubtypes(firstTarget, targetPermanent, game)) { + if (firstTarget != null && firstTarget.shareSubtypes(targetPermanent, game)) { return true; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java index 7d0cc9d104..06737b8415 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java @@ -27,7 +27,6 @@ */ package org.mage.test.cards.abilities.keywords; -import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Zone; import mage.game.permanent.Permanent; @@ -109,7 +108,7 @@ public class BestowTest extends CardTestPlayerBase { // because Boon Satyr is no creature on the battlefield, evolve may not trigger assertPermanentCount(playerA, "Boon Satyr", 1); Permanent boonSatyr = getPermanent("Boon Satyr", playerA); - Assert.assertTrue("Boon Satyr may not be a creature", !boonSatyr.getCardType().contains(CardType.CREATURE)); + Assert.assertTrue("Boon Satyr may not be a creature", !boonSatyr.isCreature()); assertPermanentCount(playerA, "Silent Artisan", 1); assertPermanentCount(playerA, "Experiment One", 1); assertPowerToughness(playerA, "Experiment One", 1, 1); @@ -145,8 +144,8 @@ public class BestowTest extends CardTestPlayerBase { assertPowerToughness(playerA, "Hopeful Eidolon", 1, 1); Permanent hopefulEidolon = getPermanent("Hopeful Eidolon", playerA); - Assert.assertTrue("Hopeful Eidolon has to be a creature but is not", hopefulEidolon.getCardType().contains(CardType.CREATURE)); - Assert.assertTrue("Hopeful Eidolon has to be an enchantment but is not", hopefulEidolon.getCardType().contains(CardType.ENCHANTMENT)); + Assert.assertTrue("Hopeful Eidolon has to be a creature but is not", hopefulEidolon.isCreature()); + Assert.assertTrue("Hopeful Eidolon has to be an enchantment but is not", hopefulEidolon.isEnchantment()); } @@ -360,7 +359,7 @@ public class BestowTest extends CardTestPlayerBase { assertPowerToughness(playerB, "Nighthowler", 2, 2); Permanent nighthowler = getPermanent("Nighthowler", playerB); - Assert.assertEquals("Nighthowler has to be a creature", true, nighthowler.getCardType().contains(CardType.CREATURE)); + Assert.assertEquals("Nighthowler has to be a creature", true, nighthowler.isCreature()); } @Test diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/BattlefieldTriggeredAbilitiesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/BattlefieldTriggeredAbilitiesTest.java index d9340ed375..7544e1de02 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/control/BattlefieldTriggeredAbilitiesTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/BattlefieldTriggeredAbilitiesTest.java @@ -1,6 +1,5 @@ package org.mage.test.cards.control; -import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Zone; import mage.game.permanent.Permanent; @@ -47,7 +46,7 @@ public class BattlefieldTriggeredAbilitiesTest extends CardTestPlayerBase { int playerACount = 0; int playerBCount = 0; for (Permanent p : currentGame.getBattlefield().getAllActivePermanents()) { - if (p.getCardType().contains(CardType.LAND)) { + if (p.isLand()) { if (p.getControllerId().equals(playerB.getId())) { playerBCount++; } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/ProgenitorMimicTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/ProgenitorMimicTest.java index 258f9ef0bf..fe8749ad39 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/ProgenitorMimicTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/ProgenitorMimicTest.java @@ -1,6 +1,5 @@ package org.mage.test.cards.copy; -import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Zone; import mage.filter.Filter; @@ -42,7 +41,7 @@ public class ProgenitorMimicTest extends CardTestPlayerBase { int nonTokens = 0; for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) { if (permanent.getControllerId().equals(playerB.getId())) { - if (permanent.getCardType().contains(CardType.CREATURE)) { + if (permanent.isCreature()) { if (permanent instanceof PermanentToken) { tokens++; } else { @@ -122,7 +121,7 @@ public class ProgenitorMimicTest extends CardTestPlayerBase { int nonTokens = 0; for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) { if (permanent.getControllerId().equals(playerB.getId())) { - if (permanent.getCardType().contains(CardType.CREATURE)) { + if (permanent.isCreature()) { if (permanent instanceof PermanentToken) { tokens++; } else { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/ths/HeliodGodOfTheSun.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/ths/HeliodGodOfTheSun.java index b4af708cb2..a6abc84f1c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/ths/HeliodGodOfTheSun.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/ths/HeliodGodOfTheSun.java @@ -4,7 +4,6 @@ */ package org.mage.test.cards.single.ths; -import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Zone; import mage.game.permanent.Permanent; @@ -47,7 +46,7 @@ public class HeliodGodOfTheSun extends CardTestPlayerBase { assertPermanentCount(playerA, "Hold the Gates", 1); Permanent heliodGodOfTheSun = getPermanent("Heliod, God of the Sun", playerA); - Assert.assertTrue(heliodGodOfTheSun.getCardType().contains(CardType.CREATURE)); + Assert.assertTrue(heliodGodOfTheSun.isCreature()); } diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index c41811d4f8..7ec8ec053c 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -4,6 +4,8 @@ import mage.abilities.Abilities; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.keyword.ChangelingAbility; +import mage.cards.Card; import mage.cards.FrameStyle; import mage.constants.CardType; import mage.constants.SuperType; @@ -132,4 +134,52 @@ public interface MageObject extends MageItem, Serializable { default boolean isWorld() { return getSuperType().contains(SuperType.WORLD); } + + + /** + * Checks whether two cards share card types. + * + * + * @param otherCard + * @return + */ + default boolean shareTypes(Card otherCard) { + + if (otherCard == null) { + throw new IllegalArgumentException("Params can't be null"); + } + + for (CardType type : getCardType()) { + if (otherCard.getCardType().contains(type)) { + return true; + } + } + + return false; + } + + + default boolean shareSubtypes(Card otherCard, Game game) { + + if (otherCard == null) { + throw new IllegalArgumentException("Params can't be null"); + } + + if (this.isCreature() && otherCard.isCreature()) { + if (this.getAbilities().contains(ChangelingAbility.getInstance()) + || this.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE) + || otherCard.getAbilities().contains(ChangelingAbility.getInstance()) + || otherCard.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) { + return true; + } + } + for (String subtype : this.getSubtype(game)) { + if (otherCard.getSubtype(game).contains(subtype)) { + return true; + } + } + + return false; + } + } diff --git a/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java b/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java index ccf9cffce7..3bc8a61082 100644 --- a/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java +++ b/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java @@ -45,7 +45,6 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; -import mage.util.CardUtil; /** * @@ -126,7 +125,7 @@ class KinshipBaseEffect extends OneShotEffect { if (card != null) { Cards cards = new CardsImpl(card); controller.lookAtCards(sourcePermanent.getName(), cards, game); - if (CardUtil.shareSubtypes(sourcePermanent, card, game)) { + if (sourcePermanent.shareSubtypes(card, game)) { if (controller.chooseUse(outcome,new StringBuilder("Kinship - Reveal ").append(card.getLogName()).append('?').toString(), source, game)) { controller.revealCards(sourcePermanent.getName(), cards, game); for (Effect effect: kinshipEffects) { diff --git a/Mage/src/main/java/mage/abilities/keyword/FlankingAbility.java b/Mage/src/main/java/mage/abilities/keyword/FlankingAbility.java index 8547d850e9..d8df61ca87 100644 --- a/Mage/src/main/java/mage/abilities/keyword/FlankingAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/FlankingAbility.java @@ -1,7 +1,6 @@ package mage.abilities.keyword; -import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.common.continuous.BoostTargetEffect; @@ -14,7 +13,6 @@ import mage.target.targetpointer.FixedTarget; /** - * * @author Plopman */ @@ -38,16 +36,12 @@ public class FlankingAbility extends TriggeredAbilityImpl { public boolean checkTrigger(GameEvent event, Game game) { if (event.getTargetId().equals(this.getSourceId())) { Permanent permanent = game.getPermanent(event.getSourceId()); - if(permanent != null) - { - boolean hasFlankingAbility = false; - for(Ability ability : permanent.getAbilities()){ - if(ability instanceof FlankingAbility){ - hasFlankingAbility = true; - } - } - - if(!hasFlankingAbility){ + if (permanent != null) { + boolean hasFlankingAbility = + permanent.getAbilities().stream().anyMatch(ability -> ability instanceof FlankingAbility); + + + if (!hasFlankingAbility) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget(event.getSourceId())); } @@ -68,5 +62,5 @@ public class FlankingAbility extends TriggeredAbilityImpl { return new FlankingAbility(this); } - + } diff --git a/Mage/src/main/java/mage/abilities/keyword/KickerAbility.java b/Mage/src/main/java/mage/abilities/keyword/KickerAbility.java index dad2df5a91..67ea722753 100644 --- a/Mage/src/main/java/mage/abilities/keyword/KickerAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/KickerAbility.java @@ -27,20 +27,10 @@ */ package mage.abilities.keyword; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.StaticAbility; -import mage.abilities.costs.Cost; -import mage.abilities.costs.Costs; -import mage.abilities.costs.CostsImpl; -import mage.abilities.costs.OptionalAdditionalCost; -import mage.abilities.costs.OptionalAdditionalCostImpl; -import mage.abilities.costs.OptionalAdditionalSourceCosts; +import mage.abilities.costs.*; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCostsImpl; @@ -51,8 +41,9 @@ import mage.constants.Zone; import mage.game.Game; import mage.players.Player; +import java.util.*; + /** - * * 20121001 702.31. Kicker 702.31a Kicker is a static ability that functions * while the spell with kicker is on the stack. "Kicker [cost]" means "You may * pay an additional [cost] as you cast this spell." Paying a spell's kicker @@ -80,7 +71,6 @@ import mage.players.Player; * 601.2c. * * @author LevelX2 - * */ public class KickerAbility extends StaticAbility implements OptionalAdditionalSourceCosts { @@ -159,10 +149,7 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo public int getKickedCounter(Game game, Ability source) { String key = getActivationKey(source, "", game); - if (activations.containsKey(key)) { - return activations.get(key); - } - return 0; + return activations.getOrDefault(key, 0); } public boolean isKicked(Game game, Ability source, String costText) { @@ -227,10 +214,10 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo && player.chooseUse(Outcome.Benefit, "Pay " + times + kickerCost.getText(false) + " ?", ability, game)) { this.activateKicker(kickerCost, ability, game); if (kickerCost instanceof Costs) { - for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext();) { + for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext(); ) { Object kickerCostObject = itKickerCost.next(); if ((kickerCostObject instanceof Costs) || (kickerCostObject instanceof CostsImpl)) { - for (@SuppressWarnings("unchecked") Iterator itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext();) { + for (@SuppressWarnings("unchecked") Iterator itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext(); ) { addKickerCostsToAbility(itDetails.next(), ability, game); } } else { diff --git a/Mage/src/main/java/mage/cards/CardsImpl.java b/Mage/src/main/java/mage/cards/CardsImpl.java index 49e0622ccd..56eb56a16e 100644 --- a/Mage/src/main/java/mage/cards/CardsImpl.java +++ b/Mage/src/main/java/mage/cards/CardsImpl.java @@ -27,24 +27,15 @@ */ package mage.cards; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; import mage.filter.FilterCard; import mage.game.Game; import mage.util.RandomUtil; import mage.util.ThreadLocalStringBuilder; +import java.io.Serializable; +import java.util.*; + /** - * * @author BetaSteward_at_googlemail.com */ public class CardsImpl extends LinkedHashSet implements Cards, Serializable { @@ -129,13 +120,8 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl @Override public int count(FilterCard filter, UUID playerId, Game game) { - int result = 0; - for (UUID card : this) { - if (filter.match(game.getCard(card), playerId, game)) { - result++; - } - } - return result; + return (int) this.stream().filter(card -> filter.match(game.getCard(card), playerId, game)).count(); + } @Override @@ -143,13 +129,8 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl if (sourceId == null) { return count(filter, playerId, game); } - int result = 0; - for (UUID card : this) { - if (filter.match(game.getCard(card), sourceId, playerId, game)) { - result++; - } - } - return result; + return (int) this.stream().filter(card -> filter.match(game.getCard(card), sourceId, playerId, game)).count(); + } @Override @@ -182,7 +163,7 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl @Override public Set getCards(Game game) { Set cards = new LinkedHashSet<>(); - for (Iterator it = this.iterator(); it.hasNext();) { // Changed to iterator because of ConcurrentModificationException + for (Iterator it = this.iterator(); it.hasNext(); ) { // Changed to iterator because of ConcurrentModificationException UUID cardId = it.next(); Card card = game.getCard(cardId); diff --git a/Mage/src/main/java/mage/target/common/TargetCreaturePermanentWithDifferentTypes.java b/Mage/src/main/java/mage/target/common/TargetCreaturePermanentWithDifferentTypes.java index 9d2b1fd48a..b4006f4e2d 100644 --- a/Mage/src/main/java/mage/target/common/TargetCreaturePermanentWithDifferentTypes.java +++ b/Mage/src/main/java/mage/target/common/TargetCreaturePermanentWithDifferentTypes.java @@ -27,12 +27,12 @@ */ package mage.target.common; -import java.util.UUID; import mage.abilities.Ability; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.util.CardUtil; + +import java.util.UUID; /** * @@ -62,7 +62,7 @@ public class TargetCreaturePermanentWithDifferentTypes extends TargetCreaturePer UUID targetId = (UUID) object; Permanent selectedCreature = game.getPermanent(targetId); if (!creature.getId().equals(selectedCreature.getId())) { - if (CardUtil.shareSubtypes(creature, selectedCreature, game)) { + if (creature.shareSubtypes(selectedCreature, game)) { return false; } } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index baecd62ca6..a431a616f6 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -35,10 +35,8 @@ import mage.abilities.ActivatedAbility; import mage.abilities.SpellAbility; import mage.abilities.costs.VariableCost; import mage.abilities.costs.mana.*; -import mage.abilities.keyword.ChangelingAbility; import mage.cards.Card; import mage.cards.SplitCard; -import mage.constants.CardType; import mage.filter.FilterMana; import mage.game.Game; import mage.game.permanent.Permanent; @@ -84,57 +82,9 @@ public final class CardUtil { "Trap", "Arcane"}; public static final Set NON_CREATURE_SUBTYPES = new HashSet<>(Arrays.asList(NON_CHANGELING_SUBTYPES_VALUES)); - /** - * Checks whether two cards share card types. - * - * @param card1 - * @param card2 - * @return - */ - public static boolean shareTypes(Card card1, Card card2) { - if (card1 == null || card2 == null) { - throw new IllegalArgumentException("Params can't be null"); - } - for (CardType type : card1.getCardType()) { - if (card2.getCardType().contains(type)) { - return true; - } - } - return false; - } - - /** - * Checks whether two cards share card subtypes. - * - * @param card1 - * @param card2 - * @return - */ - public static boolean shareSubtypes(Card card1, Card card2, Game game) { - - if (card1 == null || card2 == null) { - throw new IllegalArgumentException("Params can't be null"); - } - - if (card1.isCreature() && card2.isCreature()) { - if (card1.getAbilities().contains(ChangelingAbility.getInstance()) - || card1.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE) - || card2.getAbilities().contains(ChangelingAbility.getInstance()) - || card2.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) { - return true; - } - } - for (String subtype : card1.getSubtype(game)) { - if (card2.getSubtype(game).contains(subtype)) { - return true; - } - } - - return false; - } /** * Increase spell or ability cost to be paid.