Card: use for Remembered/Imprinted that getDefinedCards can filter them now, also use CardPredicates for sharesSomethingWith stuff

also add game.getCardState into sharesNameWith for DoubleFacedCards
This commit is contained in:
Hanmac
2016-06-28 12:04:47 +00:00
parent d5a7df5818
commit c37fce0d93

View File

@@ -4197,6 +4197,16 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} }
return false; return false;
} else if (property.startsWith("SharesCMCWith")) {
if (property.equals("SharesCMCWith")) {
if (!sharesCMCWith(source)) {
return false;
}
} else {
final String restriction = property.split("SharesCMCWith ")[1];
CardCollection list = AbilityUtils.getDefinedCards(source, restriction, spellAbility);
return !CardLists.filter(list, CardPredicates.sharesCMCWith(this)).isEmpty();
}
} else if (property.startsWith("SharesColorWith")) { } else if (property.startsWith("SharesColorWith")) {
if (property.equals("SharesColorWith")) { if (property.equals("SharesColorWith")) {
if (!sharesColorWith(source)) { if (!sharesColorWith(source)) {
@@ -4204,6 +4214,11 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else { } else {
final String restriction = property.split("SharesColorWith ")[1]; final String restriction = property.split("SharesColorWith ")[1];
if (restriction.startsWith("Remembered") || restriction.startsWith("Imprinted")) {
CardCollection list = AbilityUtils.getDefinedCards(source, restriction, spellAbility);
return !CardLists.filter(list, CardPredicates.sharesColorWith(this)).isEmpty();
}
switch (restriction) { switch (restriction) {
case "TopCardOfLibrary": case "TopCardOfLibrary":
final CardCollectionView cards = sourceController.getCardsIn(ZoneType.Library); final CardCollectionView cards = sourceController.getCardsIn(ZoneType.Library);
@@ -4211,20 +4226,6 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
break; break;
case "Remembered":
for (final Object obj : source.getRemembered()) {
if (!(obj instanceof Card) || !sharesColorWith((Card) obj)) {
return false;
}
}
break;
case "Imprinted":
for (final Card card : source.getImprintedCards()) {
if (!sharesColorWith(card)) {
return false;
}
}
break;
case "Equipped": case "Equipped":
if (!source.isEquipment() || !source.isEquipping() if (!source.isEquipment() || !source.isEquipping()
|| !sharesColorWith(source.getEquipping())) { || !sharesColorWith(source.getEquipping())) {
@@ -4401,50 +4402,16 @@ public class Card extends GameEntity implements Comparable<Card> {
} else { } else {
final String restriction = property.split("sharesNameWith ")[1]; final String restriction = property.split("sharesNameWith ")[1];
if (restriction.equals("YourGraveyard")) { if (restriction.equals("YourGraveyard")) {
for (final Card card : sourceController.getCardsIn(ZoneType.Graveyard)) { return !CardLists.filter(sourceController.getCardsIn(ZoneType.Graveyard), CardPredicates.sharesNameWith(this)).isEmpty();
if (sharesNameWith(card)) {
return true;
}
}
return false;
} else if (restriction.equals(ZoneType.Graveyard.toString())) { } else if (restriction.equals(ZoneType.Graveyard.toString())) {
for (final Card card : game.getCardsIn(ZoneType.Graveyard)) { return !CardLists.filter(game.getCardsIn(ZoneType.Graveyard), CardPredicates.sharesNameWith(this)).isEmpty();
if (sharesNameWith(card)) {
return true;
}
}
return false;
} else if (restriction.equals(ZoneType.Battlefield.toString())) { } else if (restriction.equals(ZoneType.Battlefield.toString())) {
for (final Card card : game.getCardsIn(ZoneType.Battlefield)) { return !CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.sharesNameWith(this)).isEmpty();
if (sharesNameWith(card)) {
return true;
}
}
return false;
} else if (restriction.equals("ThisTurnCast")) { } else if (restriction.equals("ThisTurnCast")) {
for (final Card card : CardUtil.getThisTurnCast("Card", source)) { return !CardLists.filter(CardUtil.getThisTurnCast("Card", source), CardPredicates.sharesNameWith(this)).isEmpty();
if (sharesNameWith(card)) { } else if (restriction.startsWith("Remembered") || restriction.startsWith("Imprinted")) {
return true; CardCollection list = AbilityUtils.getDefinedCards(source, restriction, spellAbility);
} return !CardLists.filter(list, CardPredicates.sharesNameWith(this)).isEmpty();
}
return false;
} else if (restriction.equals("Remembered")) {
for (final Object rem : source.getRemembered()) {
if (rem instanceof Card) {
final Card card = (Card) rem;
if (sharesNameWith(card)) {
return true;
}
}
}
return false;
} else if (restriction.equals("Imprinted")) {
for (final Card card : source.getImprintedCards()) {
if (sharesNameWith(card)) {
return true;
}
}
return false;
} else if (restriction.equals("MovedToGrave")) { } else if (restriction.equals("MovedToGrave")) {
for (final SpellAbility sa : source.currentState.getNonManaAbilities()) { for (final SpellAbility sa : source.currentState.getNonManaAbilities()) {
final SpellAbility root = sa.getRootAbility(); final SpellAbility root = sa.getRootAbility();
@@ -4464,14 +4431,8 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
return false; return false;
} else if (restriction.equals("NonToken")) { } else if (restriction.equals("NonToken")) {
final CardCollectionView cards = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), return !CardLists.filter(game.getCardsIn(ZoneType.Battlefield),
Presets.NON_TOKEN); Presets.NON_TOKEN, CardPredicates.sharesNameWith(this)).isEmpty();
for (final Card card : cards) {
if (sharesNameWith(card)) {
return true;
}
}
return false;
} else if (restriction.equals("TriggeredCard")) { } else if (restriction.equals("TriggeredCard")) {
if (spellAbility == null) { if (spellAbility == null) {
System.out.println("Looking at TriggeredCard but no SA?"); System.out.println("Looking at TriggeredCard but no SA?");
@@ -4491,15 +4452,9 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else { } else {
final String restriction = property.split("doesNotShareNameWith ")[1]; final String restriction = property.split("doesNotShareNameWith ")[1];
if (restriction.equals("Remembered")) { if (restriction.startsWith("Remembered") || restriction.startsWith("Imprinted")) {
for (final Object rem : source.getRemembered()) { CardCollection list = AbilityUtils.getDefinedCards(source, restriction, spellAbility);
if (rem instanceof Card) { return CardLists.filter(list, CardPredicates.sharesNameWith(this)).isEmpty();
final Card card = (Card) rem;
if (sharesNameWith(card)) {
return false;
}
}
}
} }
} }
} else if (property.startsWith("sharesControllerWith")) { } else if (property.startsWith("sharesControllerWith")) {
@@ -4509,21 +4464,9 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else { } else {
final String restriction = property.split("sharesControllerWith ")[1]; final String restriction = property.split("sharesControllerWith ")[1];
if (restriction.equals("Remembered")) { if (restriction.startsWith("Remembered") || restriction.startsWith("Imprinted")) {
for (final Object rem : source.getRemembered()) { CardCollection list = AbilityUtils.getDefinedCards(source, restriction, spellAbility);
if (rem instanceof Card) { return !CardLists.filter(list, CardPredicates.sharesControllerWith(this)).isEmpty();
final Card card = (Card) rem;
if (!sharesControllerWith(card)) {
return false;
}
}
}
} else if (restriction.equals("Imprinted")) {
for (final Card card : source.getImprintedCards()) {
if (!sharesControllerWith(card)) {
return false;
}
}
} }
} }
} else if (property.startsWith("sharesOwnerWith")) { } else if (property.startsWith("sharesOwnerWith")) {
@@ -5365,24 +5308,28 @@ public class Card extends GameEntity implements Comparable<Card> {
int y = 0; int y = 0;
int y2 = -1; int y2 = -1;
if (isSplitCard() && getCurrentStateName() == CardStateName.Original) { //need to get GameState for Discarded Cards
x = getState(CardStateName.LeftSplit).getManaCost().getCMC(); final Card host = game.getCardState(this);
x2 = getState(CardStateName.RightSplit).getManaCost().getCMC(); final Card other = game.getCardState(c1);
if (host.isSplitCard() && host.getCurrentStateName() == CardStateName.Original) {
x = host.getState(CardStateName.LeftSplit).getManaCost().getCMC();
x2 = host.getState(CardStateName.RightSplit).getManaCost().getCMC();
} else { } else {
x = getCMC(); x = host.getCMC();
} }
if (c1.isSplitCard() && c1.getCurrentStateName() == CardStateName.Original) { if (other.isSplitCard() && other.getCurrentStateName() == CardStateName.Original) {
y = c1.getState(CardStateName.LeftSplit).getManaCost().getCMC(); y = other.getState(CardStateName.LeftSplit).getManaCost().getCMC();
y2 = c1.getState(CardStateName.RightSplit).getManaCost().getCMC(); y2 = other.getState(CardStateName.RightSplit).getManaCost().getCMC();
if (isSplitCard() && getCurrentStateName() == CardStateName.Original) { if (host.isSplitCard() && host.getCurrentStateName() == CardStateName.Original) {
return x == y || x == y2 || x2 == y || x2 == y2; return x == y || x == y2 || x2 == y || x2 == y2;
} else { } else {
return x == y || x == y2; return x == y || x == y2;
} }
} else { } else {
y = c1.getCMC(); y = other.getCMC();
return x == y || x2 == y; return x == y || x2 == y;
} }
} }