* Sideboarding: fixed that it possible to auto-submit 40 cards deck instead 60 in constructed formats (#5579);

Sideboarding: fixed that cheated deck with sideboard can be used instead lose the game;
This commit is contained in:
Oleg Agafonov 2019-04-01 07:34:46 +04:00
parent 3dd6836559
commit de4befb9c2
22 changed files with 204 additions and 124 deletions

View file

@ -1,4 +1,3 @@
package mage.cards.decks;
import mage.cards.Card;
@ -41,12 +40,22 @@ public class Constructed extends DeckValidator {
return setCodes;
}
@Override
public int getDeckMinSize() {
return 60;
}
@Override
public int getSideboardMinSize() {
return 0;
}
@Override
public boolean validate(Deck deck) {
boolean valid = true;
//20091005 - 100.2a
if (deck.getCards().size() < 60) {
invalid.put("Deck", "Must contain at least 60 cards: has only " + deck.getCards().size() + " cards");
if (deck.getCards().size() < getDeckMinSize()) {
invalid.put("Deck", "Must contain at least " + getDeckMinSize() + " cards: has only " + deck.getCards().size() + " cards");
valid = false;
}
//20130713 - 100.4a

View file

@ -1,14 +1,13 @@
package mage.cards.decks;
import mage.cards.Card;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import mage.cards.Card;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class DeckValidator implements Serializable {
@ -32,11 +31,10 @@ public abstract class DeckValidator implements Serializable {
}
protected void countCards(Map<String, Integer> counts, Collection<Card> cards) {
for (Card card: cards) {
for (Card card : cards) {
if (counts.containsKey(card.getName())) {
counts.put(card.getName(), counts.get(card.getName()) + 1);
}
else {
} else {
counts.put(card.getName(), 1);
}
}
@ -45,4 +43,8 @@ public abstract class DeckValidator implements Serializable {
public int getEdhPowerLevel(Deck deck) {
return 0;
}
public abstract int getDeckMinSize();
public abstract int getSideboardMinSize();
}

View file

@ -0,0 +1,45 @@
package mage.cards.decks;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* @author BetaSteward_at_googlemail.com
*/
public enum DeckValidatorFactory {
instance;
private static final Logger logger = Logger.getLogger(DeckValidatorFactory.class);
private final Map<String, Class> deckTypes = new LinkedHashMap<>();
public DeckValidator createDeckValidator(String deckType) {
DeckValidator validator;
try {
Constructor<?> con = deckTypes.get(deckType).getConstructor();
validator = (DeckValidator) con.newInstance();
} catch (Exception ex) {
logger.fatal("DeckValidatorFactory error", ex);
return null;
}
logger.debug("Deck validator created: " + validator.getName());
return validator;
}
public Set<String> getDeckTypes() {
return deckTypes.keySet();
}
public void addDeckType(String name, Class deckType) {
if (deckType != null) {
this.deckTypes.put(name, deckType);
}
}
}

View file

@ -389,7 +389,9 @@ public abstract class MatchImpl implements Match {
// Check if the cards included in the deck are the same as in the original deck
validDeck = (player.getDeck().getDeckCompleteHashCode() == deck.getDeckCompleteHashCode());
if (validDeck == false) {
deck.getCards().clear(); // Clear the deck so the player cheating looses the game
// clear the deck so the player cheating looses the game
deck.getCards().clear();
deck.getSideboard().clear();
}
player.updateDeck(deck);
}

View file

@ -1,13 +1,13 @@
package mage.game.match;
import java.io.Serializable;
import mage.cards.Card;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckValidator;
import mage.players.Player;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MatchPlayer implements Serializable {
@ -78,9 +78,9 @@ public class MatchPlayer implements Serializable {
this.deck = deck;
}
public Deck generateDeck() {
//TODO: improve this
while (deck.getCards().size() < 40 && !deck.getSideboard().isEmpty()) {
public Deck generateDeck(DeckValidator deckValidator) {
// auto complete deck
while (deck.getCards().size() < deckValidator.getDeckMinSize() && !deck.getSideboard().isEmpty()) {
Card card = deck.getSideboard().iterator().next();
deck.getCards().add(card);
deck.getSideboard().remove(card);

View file

@ -1,7 +1,5 @@
package mage.game.tournament;
import java.util.Set;
import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState;
import mage.game.result.ResultProtos.TourneyPlayerProto;
@ -10,8 +8,9 @@ import mage.players.Player;
import mage.players.PlayerType;
import mage.util.TournamentUtil;
import java.util.Set;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayer {
@ -93,7 +92,9 @@ public class TournamentPlayer {
// Check if the cards included in the deck are the same as in the original deck
boolean validDeck = (getDeck().getDeckCompleteHashCode() == deck.getDeckCompleteHashCode());
if (validDeck == false) {
deck.getCards().clear(); // Clear the deck so the player cheating looses the game
// Clear the deck so the player cheating looses the game
deck.getCards().clear();
deck.getSideboard().clear();
}
this.deck = deck;
return validDeck;
@ -177,7 +178,6 @@ public class TournamentPlayer {
/**
* Free resources no longer needed if tournament has ended
*
*/
public void cleanUpOnTournamentEnd() {
this.deck = null;