Auto-apply errata when joining PC format table
This commit is contained in:
@@ -91,6 +91,11 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
|||||||
format.validateDeck(deck);
|
format.validateDeck(deck);
|
||||||
valid.append("<b>" + format.getName() + "</b>: <font color='green'>valid</font><br/>");
|
valid.append("<b>" + format.getName() + "</b>: <font color='green'>valid</font><br/>");
|
||||||
} catch (DeckInvalidException exp) {
|
} catch (DeckInvalidException exp) {
|
||||||
|
if (!format.getErrataCardMap().isEmpty()) {
|
||||||
|
LotroDeck deckWithErrata = format.applyErrata(deck);
|
||||||
|
format.validateDeck(deckWithErrata);
|
||||||
|
valid.append("<b>" + format.getName() + "</b>: <font color='yellow'>valid (with PC errata)</font><br/>");
|
||||||
|
}
|
||||||
invalid.append("<b>" + format.getName() + "</b>: <font color='red'>" + exp.getMessage() + "</font><br/>");
|
invalid.append("<b>" + format.getName() + "</b>: <font color='red'>" + exp.getMessage() + "</font><br/>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public interface LotroFormat {
|
|||||||
|
|
||||||
public void validateDeck(LotroDeck deck) throws DeckInvalidException;
|
public void validateDeck(LotroDeck deck) throws DeckInvalidException;
|
||||||
|
|
||||||
|
public LotroDeck applyErrata(LotroDeck deck);
|
||||||
|
|
||||||
public List<Integer> getValidSets();
|
public List<Integer> getValidSets();
|
||||||
|
|
||||||
public List<String> getBannedCards();
|
public List<String> getBannedCards();
|
||||||
|
|||||||
@@ -237,11 +237,6 @@ public class DefaultLotroFormat implements LotroFormat {
|
|||||||
if (bannedBlueprintId.equals(blueprintId) || (allAlternates != null && allAlternates.contains(bannedBlueprintId)))
|
if (bannedBlueprintId.equals(blueprintId) || (allAlternates != null && allAlternates.contains(bannedBlueprintId)))
|
||||||
throw new DeckInvalidException("Deck contains a copy of an X-listed card: " + GameUtils.getFullName(_library.getLotroCardBlueprint(bannedBlueprintId)));
|
throw new DeckInvalidException("Deck contains a copy of an X-listed card: " + GameUtils.getFullName(_library.getLotroCardBlueprint(bannedBlueprintId)));
|
||||||
}
|
}
|
||||||
// Errata
|
|
||||||
for (String originalBlueprintId : _errataCardMap.keySet()) {
|
|
||||||
if (originalBlueprintId.equals(blueprintId) || (allAlternates != null && allAlternates.contains(originalBlueprintId)))
|
|
||||||
throw new DeckInvalidException("Deck contains non-errata of an errata'd card: " + GameUtils.getFullName(_library.getLotroCardBlueprint(originalBlueprintId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (CardNotFoundException e) {
|
} catch (CardNotFoundException e) {
|
||||||
// Ignore this card
|
// Ignore this card
|
||||||
@@ -330,6 +325,20 @@ public class DefaultLotroFormat implements LotroFormat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LotroDeck applyErrata(LotroDeck deck) {
|
||||||
|
LotroDeck deckWithErrata = new LotroDeck(deck.getDeckName());
|
||||||
|
deckWithErrata.setRingBearer(_errataCardMap.getOrDefault(deck.getRingBearer(), deck.getRingBearer()));
|
||||||
|
deckWithErrata.setRing(_errataCardMap.getOrDefault(deck.getRing(), deck.getRing()));
|
||||||
|
for (String card : deck.getAdventureCards()) {
|
||||||
|
deckWithErrata.addCard(_errataCardMap.getOrDefault(card, card));
|
||||||
|
}
|
||||||
|
for (String site : deck.getSites()) {
|
||||||
|
deckWithErrata.addSite(_errataCardMap.getOrDefault(site, site));
|
||||||
|
}
|
||||||
|
return deckWithErrata;
|
||||||
|
}
|
||||||
|
|
||||||
private void validateDeckStructure(LotroDeck deck) throws DeckInvalidException, CardNotFoundException {
|
private void validateDeckStructure(LotroDeck deck) throws DeckInvalidException, CardNotFoundException {
|
||||||
if (deck.getAdventureCards().size() < _minimumDeckSize)
|
if (deck.getAdventureCards().size() < _minimumDeckSize)
|
||||||
throw new DeckInvalidException("Deck contains below minimum number of cards: " + deck.getAdventureCards().size() + "<" + _minimumDeckSize);
|
throw new DeckInvalidException("Deck contains below minimum number of cards: " + deck.getAdventureCards().size() + "<" + _minimumDeckSize);
|
||||||
|
|||||||
@@ -529,6 +529,7 @@ public class HallServer extends AbstractServer {
|
|||||||
throw new HallException("You don't have a deck registered yet");
|
throw new HallException("You don't have a deck registered yet");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
lotroDeck = format.applyErrata(lotroDeck);
|
||||||
lotroDeck = validateUserAndDeck(format, player, collectionType, lotroDeck);
|
lotroDeck = validateUserAndDeck(format, player, collectionType, lotroDeck);
|
||||||
} catch (DeckInvalidException e) {
|
} catch (DeckInvalidException e) {
|
||||||
throw new HallException("Your selected deck is not valid for this format: " + e.getMessage());
|
throw new HallException("Your selected deck is not valid for this format: " + e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user