mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
add hasName method
This commit is contained in:
parent
fda43021a4
commit
29acaa423b
9 changed files with 49 additions and 33 deletions
|
|
@ -63,6 +63,8 @@ public interface MageObject extends MageItem, Serializable, Copyable<MageObject>
|
|||
|
||||
void setName(String name);
|
||||
|
||||
boolean hasName(String name);
|
||||
|
||||
default List<CardType> getCardType() {
|
||||
return getCardType(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,6 +119,11 @@ public abstract class MageObjectImpl implements MageObject {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return Objects.equals(name, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardType> getCardType(Game game) {
|
||||
if (game != null) {
|
||||
|
|
|
|||
|
|
@ -235,4 +235,9 @@ public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
|||
// split card and it's halfes contains own mana costs, so no need to rewrite logic
|
||||
return super.getManaValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return super.hasName(name) || this.getLeftHalfCard().hasName(name) || this.getRightHalfCard().hasName(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
package mage.filter.predicate.mageobject;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.cards.CardWithHalves;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author North
|
||||
|
|
@ -39,10 +34,7 @@ public class NamePredicate implements Predicate<MageObject> {
|
|||
|
||||
@Override
|
||||
public boolean apply(MageObject input, Game game) {
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
// If a player names a card, the player may name either half of a split card, but not both.
|
||||
// If a player names a card, the player may name either half of a split card, but not both.
|
||||
// A split card has the chosen name if one of its two names matches the chosen name.
|
||||
// This is NOT the same for double faced cards, where only the front side matches
|
||||
|
||||
|
|
@ -50,29 +42,7 @@ public class NamePredicate implements Predicate<MageObject> {
|
|||
// If the back face of a modal double-faced card is countered, you will not be able to exile any cards,
|
||||
// including the one that you countered, because those cards have only their front-face characteristics
|
||||
// (including name) in the graveyard, hand, and library. (2021-04-16)
|
||||
|
||||
if (input instanceof SplitCard) {
|
||||
return CardUtil.haveSameNames(name, ((CardWithHalves) input).getLeftHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
|
||||
CardUtil.haveSameNames(name, ((CardWithHalves) input).getRightHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
|
||||
CardUtil.haveSameNames(name, input.getName(), this.ignoreMtgRuleForEmptyNames);
|
||||
} else if (input instanceof Spell && ((Spell) input).getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
SplitCard card = (SplitCard) ((Spell) input).getCard();
|
||||
return CardUtil.haveSameNames(name, card.getLeftHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
|
||||
CardUtil.haveSameNames(name, card.getRightHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
|
||||
CardUtil.haveSameNames(name, card.getName(), this.ignoreMtgRuleForEmptyNames);
|
||||
} else if (input instanceof Spell && ((Spell) input).isFaceDown(game)) {
|
||||
// face down spells don't have names, so it's not equal, see https://github.com/magefree/mage/issues/6569
|
||||
return false;
|
||||
} else {
|
||||
if (name.contains(" // ")) {
|
||||
String leftName = name.substring(0, name.indexOf(" // "));
|
||||
String rightName = name.substring(name.indexOf(" // ") + 4);
|
||||
return CardUtil.haveSameNames(leftName, input.getName(), this.ignoreMtgRuleForEmptyNames) ||
|
||||
CardUtil.haveSameNames(rightName, input.getName(), this.ignoreMtgRuleForEmptyNames);
|
||||
} else {
|
||||
return CardUtil.haveSameNames(name, input.getName(), this.ignoreMtgRuleForEmptyNames);
|
||||
}
|
||||
}
|
||||
return name != null && input.hasName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package mage.game.command;
|
||||
|
||||
import mage.game.permanent.token.TokenImpl;
|
||||
import mage.util.GameLog;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -113,4 +113,9 @@ public abstract class CommandObjectImpl implements CommandObject {
|
|||
public String getLogName() {
|
||||
return GameLog.getColoredObjectIdName(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return Objects.equals(name, this.name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,6 +163,11 @@ public class Commander extends CommandObjectImpl {
|
|||
return sourceObject.getName() + " [" + sourceObject.getId().toString().substring(0, 3) + ']';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return sourceObject.hasName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardType> getCardType(Game game) {
|
||||
return sourceObject.getCardType(game);
|
||||
|
|
|
|||
|
|
@ -260,6 +260,11 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return !faceDown && super.hasName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(GameState state) {
|
||||
StringBuilder sb = threadLocalBuilder.get();
|
||||
|
|
|
|||
|
|
@ -563,6 +563,19 @@ public class Spell extends StackObjectImpl implements Card {
|
|||
public void setName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
if (this.faceDown) {
|
||||
return false;
|
||||
}
|
||||
if (this.getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED
|
||||
&& (((SplitCard) this.card).getLeftHalfCard().hasName(name)
|
||||
|| ((SplitCard) this.card).getRightHalfCard().hasName(name))) {
|
||||
return true;
|
||||
}
|
||||
return this.card.hasName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rarity getRarity() {
|
||||
return card.getRarity();
|
||||
|
|
|
|||
|
|
@ -198,6 +198,11 @@ public class StackAbility extends StackObjectImpl implements Ability {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name) {
|
||||
return Objects.equals(name, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardType> getCardType(Game game) {
|
||||
return emptyCardType;
|
||||
|
|
@ -677,6 +682,7 @@ public class StackAbility extends StackObjectImpl implements Ability {
|
|||
public void initSourceObjectZoneChangeCounter(Game game, boolean force) {
|
||||
ability.initSourceObjectZoneChangeCounter(game, force);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceObjectZoneChangeCounter() {
|
||||
return ability.getSourceObjectZoneChangeCounter();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue