mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
Fix searching for split card halves returning full card in incorrect instances. (#9534)
This commit is contained in:
parent
8f164b1efe
commit
7d57831ed0
3 changed files with 55 additions and 14 deletions
|
|
@ -49,13 +49,13 @@ public class MockSplitCard extends SplitCard {
|
|||
this.addAbility(textAbilityFromString(ruleText));
|
||||
}
|
||||
|
||||
CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode());
|
||||
CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode(), true);
|
||||
if (leftHalf != null) {
|
||||
this.leftHalfCard = new MockSplitCardHalf(leftHalf);
|
||||
((SplitCardHalf) this.leftHalfCard).setParentCard(this);
|
||||
}
|
||||
|
||||
CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode());
|
||||
CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode(), true);
|
||||
if (rightHalf != null) {
|
||||
this.rightHalfCard = new MockSplitCardHalf(rightHalf);
|
||||
((SplitCardHalf) this.rightHalfCard).setParentCard(this);
|
||||
|
|
|
|||
|
|
@ -389,14 +389,17 @@ public enum CardRepository {
|
|||
* Function to find a card by name from a specific set.
|
||||
* Used for building cubes, packs, and for ensuring that dual faces and split cards have sides/halves from the same set.
|
||||
*
|
||||
* @param name name of the card, or side of the card, to find
|
||||
* @param expansion the set name from which to find the card
|
||||
* @param name name of the card, or side of the card, to find
|
||||
* @param expansion the set name from which to find the card
|
||||
* @param returnSplitCardHalf whether to return a half of a split card or the corresponding full card.
|
||||
* Want this `false` when user is searching by either names in a split card so that
|
||||
* the full card can be found by either name.
|
||||
* @return
|
||||
*/
|
||||
public CardInfo findCardWPreferredSet(String name, String expansion) {
|
||||
public CardInfo findCardWPreferredSet(String name, String expansion, boolean returnSplitCardHalf) {
|
||||
List<CardInfo> cards;
|
||||
|
||||
cards = findCards(name);
|
||||
cards = findCards(name, 0, returnSplitCardHalf);
|
||||
|
||||
if (!cards.isEmpty()) {
|
||||
for (CardInfo cardinfo : cards) {
|
||||
|
|
@ -408,6 +411,10 @@ public enum CardRepository {
|
|||
return findPreferredCoreExpansionCard(name);
|
||||
}
|
||||
|
||||
public CardInfo findCardWPreferredSet(String name, String expansion) {
|
||||
return findCardWPreferredSet(name, expansion, false);
|
||||
}
|
||||
|
||||
public List<CardInfo> findCards(String name) {
|
||||
return findCards(name, 0);
|
||||
}
|
||||
|
|
@ -424,12 +431,16 @@ public enum CardRepository {
|
|||
* ALL the others MUST be queried for by the first half of their full name (i.e. "A" from "A // B")
|
||||
* when querying by "name".
|
||||
*
|
||||
* @param name the name of the card to search for
|
||||
* @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets)
|
||||
* @return A list of the reprints of the card if it was found (up to limitByMaxAmount number), or
|
||||
* an empty list if the card was not found.
|
||||
* @param name the name of the card to search for
|
||||
* @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets)
|
||||
* @param returnSplitCardHalf whether to return a half of a split card or the corresponding full card.
|
||||
* Want this `false` when user is searching by either names in a split card so that
|
||||
* the full card can be found by either name.
|
||||
* Want this `true` when the client is searching for info on both halves to display it.
|
||||
* @return a list of the reprints of the card if it was found (up to limitByMaxAmount number),
|
||||
* or an empty list if the card was not found.
|
||||
*/
|
||||
public List<CardInfo> findCards(String name, long limitByMaxAmount) {
|
||||
public List<CardInfo> findCards(String name, long limitByMaxAmount, boolean returnSplitCardHalf) {
|
||||
List<CardInfo> results;
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
if (limitByMaxAmount > 0) {
|
||||
|
|
@ -467,8 +478,8 @@ public enum CardRepository {
|
|||
// Check that a full card was found and not a SplitCardHalf
|
||||
// Can be caused by searching for "Fire" instead of "Fire // Ice"
|
||||
CardInfo firstCardInfo = results.get(0);
|
||||
if (firstCardInfo.isSplitCardHalf()) {
|
||||
// Find the main card by it's setCode and CardNumber
|
||||
if (firstCardInfo.isSplitCardHalf() && !returnSplitCardHalf) {
|
||||
// Find the main card by its setCode and CardNumber
|
||||
queryBuilder.where()
|
||||
.eq("setCode", new SelectArg(firstCardInfo.setCode)).and()
|
||||
.eq("cardNumber", new SelectArg(firstCardInfo.cardNumber));
|
||||
|
|
@ -498,6 +509,10 @@ public enum CardRepository {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCards(String name, long limitByMaxAmount) {
|
||||
return findCards(name, limitByMaxAmount, false);
|
||||
}
|
||||
|
||||
public List<CardInfo> findCardsByClass(String canonicalClassName) {
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue