From 4833b379df28643e0dfb1ca7dd851af60f77290c Mon Sep 17 00:00:00 2001 From: Plopman Date: Fri, 18 Jan 2013 17:30:27 +0100 Subject: [PATCH] Added Commander DeckValidator --- .../src/mage/deck/Commander.java | 206 ++++++++++++++++++ .../src/mage/game/CommanderDuelType.java | 2 +- 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java diff --git a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java new file mode 100644 index 00000000000..699b36a33bd --- /dev/null +++ b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java @@ -0,0 +1,206 @@ +/* +* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.deck; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import mage.Constants; +import mage.Mana; +import mage.cards.Card; +import mage.cards.decks.Deck; +import mage.cards.decks.DeckValidatorImpl; +import mage.filter.FilterMana; + +/** + * + * @author Plopman + */ + + +public class Commander extends DeckValidatorImpl { + + protected List banned = new ArrayList(); + protected List bannedCommander = new ArrayList(); + + private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*"; + private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*"; + private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*"; + private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*"; + private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*"; + + public Commander(){ + super("Commander"); + + banned.add("Ancestral Recall"); + banned.add("Balance"); + banned.add("Biorhythm"); + banned.add("Channel"); + banned.add("Coalition Victory"); + banned.add("Emrakul, the Aeons Torn"); + banned.add("Fastbond"); + banned.add("Gifts Ungiven"); + banned.add("Griselbrand"); + banned.add("Karakas"); + banned.add("Library of Alexandria"); + banned.add("Limited Resources"); + banned.add("Metalworker"); + banned.add("Mox Emerald"); + banned.add("Mox Jet"); + banned.add("Mox Pearl"); + banned.add("Mox Ruby"); + banned.add("Mox Sapphire"); + banned.add("Painter's Servant"); + banned.add("Panoptic Mirror"); + banned.add("Primeval Titan"); + banned.add("Protean Hulk"); + banned.add("Recurring Nightmare"); + banned.add("Staff of Domination"); + banned.add("Sundering Titan"); + banned.add("Sway of the Stars"); + banned.add("Time Vault"); + banned.add("Time Walk"); + banned.add("Tinker"); + banned.add("Tolarian Academy"); + banned.add("Upheaval"); + banned.add("Worldfire"); + banned.add("Yawgmoth's Bargain"); + + + bannedCommander.add("Braids, Cabal Minion"); + bannedCommander.add("Erayo, Soratami Ascendant"); + bannedCommander.add("Kokusho, The Evening Star"); + bannedCommander.add("Rofellos, Llanowar Emissary"); + + } + + + @Override + public boolean validate(Deck deck) { + boolean valid = true; + + if (deck.getCards().size() != 99) { + invalid.put("Deck", "Must contain 99 cards: has " + deck.getCards().size() + " cards"); + valid = false; + } + + List basicLandNames = new ArrayList(Arrays.asList("Forest", "Island", "Mountain", "Swamp", "Plains")); + Map counts = new HashMap(); + countCards(counts, deck.getCards()); + countCards(counts, deck.getSideboard()); + for (Map.Entry entry: counts.entrySet()) { + if (entry.getValue() > 1) { + if (!basicLandNames.contains(entry.getKey()) && !entry.getKey().equals("Relentless Rats")) { + invalid.put(entry.getKey(), "Too many: " + entry.getValue()); + valid = false; + } + } + } + + for (String bannedCard: banned) { + if (counts.containsKey(bannedCard)) { + invalid.put(bannedCard, "Banned"); + valid = false; + } + } + + if(deck.getSideboard().size() == 1){ + Card commander = (Card)deck.getSideboard().toArray()[0]; + if(commander != null && commander.getCardType().contains(Constants.CardType.CREATURE) && commander.getSupertype().contains("Legendary")){ + FilterMana color = getColorIdentity(commander); + for(Card card : deck.getCards()){ + if(!cardHasValideColor(color, card)){ + invalid.put(card.getName(), "Invalide color"); + valid = false; + } + } + } + else{ + invalid.put("Commander", "Commander invalide"); + valid = false; + } + } + else{ + invalid.put("Commander", "Sideboard must contain only the commander"); + } + + return valid; + } + + public FilterMana getColorIdentity(Card card){ + FilterMana mana = new FilterMana(); + mana.setBlack(card.getManaCost().getText().matches(regexBlack)); + for(String rule : card.getRules()){ + if(rule.matches(regexBlack)){ + mana.setBlack(true); + } + } + mana.setBlue(card.getManaCost().getText().matches(regexBlue)); + for(String rule : card.getRules()){ + if(rule.matches(regexBlue)){ + mana.setBlue(true); + } + } + mana.setGreen(card.getManaCost().getText().matches(regexGreen)); + for(String rule : card.getRules()){ + if(rule.matches(regexGreen)){ + mana.setGreen(true); + } + } + mana.setRed(card.getManaCost().getText().matches(regexRed)); + for(String rule : card.getRules()){ + if(rule.matches(regexRed)){ + mana.setRed(true); + } + } + mana.setWhite(card.getManaCost().getText().matches(regexWhite)); + for(String rule : card.getRules()){ + if(rule.matches(regexWhite)){ + mana.setWhite(true); + } + } + return mana; + } + + public boolean cardHasValideColor(FilterMana commander, Card card){ + FilterMana cardColor = getColorIdentity(card); + if(cardColor.isBlack() && !commander.isBlack() + || cardColor.isBlue() && !commander.isBlue() + || cardColor.isGreen() && !commander.isGreen() + || cardColor.isRed() && !commander.isRed() + || cardColor.isWhite() && !commander.isWhite()){ + return false; + } + return true; + } + + +} diff --git a/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelType.java b/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelType.java index 650f124fa22..37ea9bc88d5 100644 --- a/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelType.java +++ b/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelType.java @@ -37,7 +37,7 @@ import mage.game.match.MatchType; public class CommanderDuelType extends MatchType { public CommanderDuelType() { - this.name = "Commander Duel"; + this.name = "Commander Two Player Duel"; this.maxPlayers = 2; this.minPlayers = 2; this.numTeams = 0;