move static function to CardImpl, and other api fixes

This commit is contained in:
ingmargoudt 2017-03-30 20:08:07 +02:00
parent 0791283a6b
commit 6f8f10fcc3
32 changed files with 177 additions and 296 deletions

View file

@ -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

View file

@ -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;
/**
*

View file

@ -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;

View file

@ -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;
}

View file

@ -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

View file

@ -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()) {

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
Player controller = game.getPlayer(sourceControllerId);
Set<CardType> cardTypes = new HashSet<>();
EnumSet<CardType> 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());
}
}

View file

@ -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;
}

View file

@ -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<CardType> 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;

View file

@ -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<CardType> foundCardTypes = new HashSet<>();
EnumSet<CardType> foundCardTypes = EnumSet.noneOf(CardType.class);
for (Card card : controller.getGraveyard().getCards(game)) {
foundCardTypes.addAll(card.getCardType());
}

View file

@ -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));

View file

@ -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++;
}
}

View file

@ -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> cardType = perm.getCardType();
if (!cardType.contains(CardType.ARTIFACT)) {
cardType.add(CardType.ARTIFACT);
}
perm.getCardType().add(CardType.ARTIFACT);
}
return true;
}

View file

@ -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> 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);

View file

@ -143,7 +143,7 @@ class SemblanceAnvilCostReductionEffect extends CostModificationEffectImpl {
List<UUID> 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;
}
}

View file

@ -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;
}

View file

@ -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++;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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++;
}

View file

@ -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 {

View file

@ -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());
}

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext();) {
for (@SuppressWarnings("unchecked") Iterator<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext(); ) {
addKickerCostsToAbility(itDetails.next(), ability, game);
}
} else {

View file

@ -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<UUID> implements Cards, Serializable {
@ -129,13 +120,8 @@ 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) {
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<UUID> 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<UUID> implements Cards, Serializabl
@Override
public Set<Card> getCards(Game game) {
Set<Card> cards = new LinkedHashSet<>();
for (Iterator<UUID> it = this.iterator(); it.hasNext();) { // Changed to iterator because of ConcurrentModificationException
for (Iterator<UUID> it = this.iterator(); it.hasNext(); ) { // Changed to iterator because of ConcurrentModificationException
UUID cardId = it.next();
Card card = game.getCard(cardId);

View file

@ -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;
}
}

View file

@ -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<String> 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.