forked from External/mage
Refactor: extract card names compare logic (is empty name, is same name)
Fixed last broken tests
This commit is contained in:
parent
96187ad3c0
commit
02b7e2cf10
63 changed files with 614 additions and 466 deletions
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.game.command.emblems;
|
||||
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.LimitedTimesPerTurnActivatedAbility;
|
||||
import mage.abilities.costs.common.DiscardCardCost;
|
||||
|
|
@ -13,19 +11,16 @@ import mage.cards.Sets;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SetType;
|
||||
import mage.constants.TimingRule;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.permanent.token.EmptyToken;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public final class MomirEmblem extends Emblem {
|
||||
|
|
@ -70,7 +65,7 @@ class MomirEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
EmptyToken token = new EmptyToken(); // search for a non custom set creature
|
||||
while (token.getName().isEmpty() && !options.isEmpty()) {
|
||||
while (!options.isEmpty()) {
|
||||
int index = RandomUtil.nextInt(options.size());
|
||||
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
|
||||
if (expansionSet == null || expansionSet.getSetType() == SetType.CUSTOM_SET) {
|
||||
|
|
@ -79,6 +74,7 @@ class MomirEffect extends OneShotEffect {
|
|||
Card card = options.get(index).getCard();
|
||||
if (card != null) {
|
||||
CardUtil.copyTo(token).from(card);
|
||||
break;
|
||||
} else {
|
||||
options.remove(index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.game.permanent;
|
||||
|
||||
import mage.MageObject;
|
||||
|
|
@ -50,6 +49,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.counter = counter;
|
||||
this.sourceObject = sourceObject;
|
||||
}
|
||||
|
||||
Counter counter;
|
||||
MageObject sourceObject;
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = threadLocalBuilder.get();
|
||||
sb.append(this.name).append('-').append(this.expansionSetCode);
|
||||
sb.append(this.getName()).append('-').append(this.expansionSetCode);
|
||||
if (copy) {
|
||||
sb.append(" [Copy]");
|
||||
}
|
||||
|
|
@ -195,10 +195,23 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name.isEmpty()) {
|
||||
if (faceDown) {
|
||||
return EmptyNames.FACE_DOWN_CREATURE.toString();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(GameState state) {
|
||||
StringBuilder sb = threadLocalBuilder.get();
|
||||
sb.append(controllerId).append(name).append(tapped).append(damage);
|
||||
sb.append(controllerId).append(getName()).append(tapped).append(damage);
|
||||
sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue());
|
||||
sb.append(abilities.getValue());
|
||||
for (Counter counter : getCounters(state).values()) {
|
||||
|
|
@ -245,7 +258,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ability
|
||||
* @param game
|
||||
*/
|
||||
|
|
@ -665,7 +677,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.attachedTo = attachToObjectId;
|
||||
this.attachedToZoneChangeCounter = game.getState().getZoneChangeCounter(attachToObjectId);
|
||||
for (Ability ability : this.getAbilities()) {
|
||||
for (Iterator<Effect> ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext();) {
|
||||
for (Iterator<Effect> ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext(); ) {
|
||||
ContinuousEffect effect = (ContinuousEffect) ite.next();
|
||||
game.getContinuousEffects().setOrder(effect);
|
||||
// It's important to update the timestamp of the copied effect in ContinuousEffects because it does the action
|
||||
|
|
@ -715,8 +727,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
* @param game
|
||||
* @param preventable
|
||||
* @param combat
|
||||
* @param markDamage If true, damage will be dealt later in applyDamage
|
||||
* method
|
||||
* @param markDamage If true, damage will be dealt later in applyDamage
|
||||
* method
|
||||
* @return
|
||||
*/
|
||||
private int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage, List<UUID> appliedEffects) {
|
||||
|
|
@ -1441,20 +1453,20 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
//If an object leaves the zone it's in, all attached permanents become unattached
|
||||
//note that this code doesn't actually detach anything, and is a bit of a bandaid
|
||||
public void detachAllAttachments(Game game) {
|
||||
for(UUID attachmentId : getAttachments()) {
|
||||
for (UUID attachmentId : getAttachments()) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
Card attachmentCard = game.getCard(attachmentId);
|
||||
if(attachment != null && attachmentCard != null) {
|
||||
if (attachment != null && attachmentCard != null) {
|
||||
//make bestow cards and licids into creatures
|
||||
//aura test to stop bludgeon brawl shenanigans from using this code
|
||||
//consider adding code to handle that case?
|
||||
if(attachment.hasSubtype(SubType.AURA, game) && attachmentCard.isCreature()) {
|
||||
if (attachment.hasSubtype(SubType.AURA, game) && attachmentCard.isCreature()) {
|
||||
BestowAbility.becomeCreature(attachment, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, List<UUID> appliedEffects) {
|
||||
Zone fromZone = game.getState().getZone(objectId);
|
||||
|
|
@ -1480,7 +1492,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
Zone fromZone = game.getState().getZone(objectId);
|
||||
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, ownerId, fromZone, Zone.EXILED, appliedEffects);
|
||||
ZoneChangeInfo.Exile info = new ZoneChangeInfo.Exile(event, exileId, name);
|
||||
|
||||
|
||||
boolean successfullyMoved = ZonesHandler.moveCard(info, game);
|
||||
//20180810 - 701.3d
|
||||
detachAllAttachments(game);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
package mage.game.permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.constants.EmptyNames;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.token.Token;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class PermanentToken extends PermanentImpl {
|
||||
|
|
@ -42,6 +42,15 @@ public class PermanentToken extends PermanentImpl {
|
|||
this.toughness.resetToBaseValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name.isEmpty()) {
|
||||
return EmptyNames.FACE_DOWN_TOKEN.toString();
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFromToken(Token token, Game game, boolean reset) {
|
||||
this.name = token.getName();
|
||||
this.abilities.clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue