Implemented split card name handling according the rules (two separate names). I guess this fixes #221.

This commit is contained in:
LevelX2 2013-05-27 16:57:16 +02:00
parent 9ea3eb5fe3
commit b7881f8eb2
2 changed files with 34 additions and 4 deletions

View file

@ -144,7 +144,13 @@ public enum CardRepository {
qb.distinct().selectColumns("name");
List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) {
names.add(card.getName());
int result = card.getName().indexOf(" // ");
if (result > 0) {
names.add(card.getName().substring(0, result));
names.add(card.getName().substring(result+4));
} else {
names.add(card.getName());
}
}
} catch (SQLException ex) {
}
@ -159,7 +165,13 @@ public enum CardRepository {
qb.where().not().like("types", new SelectArg('%' + CardType.LAND.name() + '%'));
List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) {
names.add(card.getName());
int result = card.getName().indexOf(" // ");
if (result > 0) {
names.add(card.getName().substring(0, result));
names.add(card.getName().substring(result+4));
} else {
names.add(card.getName());
}
}
} catch (SQLException ex) {
}
@ -175,7 +187,13 @@ public enum CardRepository {
where.and(where.not().like("types", '%' + CardType.CREATURE.name() +'%'),where.not().like("types", '%' + CardType.LAND.name() + '%'));
List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) {
names.add(card.getName());
int result = card.getName().indexOf(" // ");
if (result > 0) {
names.add(card.getName().substring(0, result));
names.add(card.getName().substring(result+4));
} else {
names.add(card.getName());
}
}
} catch (SQLException ex) {
}

View file

@ -27,9 +27,12 @@
*/
package mage.filter.predicate.mageobject;
import mage.Constants.SpellAbilityType;
import mage.MageObject;
import mage.cards.SplitCard;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
/**
*
@ -45,7 +48,16 @@ public class NamePredicate implements Predicate<MageObject> {
@Override
public boolean apply(MageObject input, Game game) {
return name.equals(input.getName());
// 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.
if (input instanceof SplitCard) {
return name.equals(((SplitCard)input).getLeftHalfCard().getName()) || name.equals(((SplitCard)input).getRightHalfCard().getName());
} else if (input instanceof Spell && ((Spell)input).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)){
SplitCard card = (SplitCard) ((Spell)input).getCard();
return name.equals(card.getLeftHalfCard().getName()) || name.equals(card.getRightHalfCard().getName());
} else {
return name.equals(input.getName());
}
}
@Override