mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Implemented Partners With ability
This commit is contained in:
parent
59a639def4
commit
bd96d30b3d
4 changed files with 198 additions and 11 deletions
|
@ -33,6 +33,7 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.common.CanBeYourCommanderAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.keyword.PartnerAbility;
|
||||
import mage.abilities.keyword.PartnersWithAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
|
@ -133,6 +134,10 @@ public class Commander extends Constructed {
|
|||
invalid.put("Commander", "Sideboard must contain only the commander(s)");
|
||||
valid = false;
|
||||
} else {
|
||||
Set<String> commanderNames = new HashSet<>();
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
commanderNames.add(commander.getName());
|
||||
}
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
if (bannedCommander.contains(commander.getName())) {
|
||||
invalid.put("Commander", "Commander banned (" + commander.getName() + ')');
|
||||
|
@ -144,8 +149,18 @@ public class Commander extends Constructed {
|
|||
valid = false;
|
||||
}
|
||||
if (deck.getSideboard().size() == 2 && !commander.getAbilities().contains(PartnerAbility.getInstance())) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
boolean partnersWith = false;
|
||||
for (Ability ability : commander.getAbilities()) {
|
||||
if (ability instanceof PartnersWithAbility
|
||||
&& commanderNames.contains(((PartnersWithAbility) ability).getPartnerName())) {
|
||||
partnersWith = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!partnersWith) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
FilterMana commanderColor = commander.getColorIdentity();
|
||||
if (commanderColor.isWhite()) {
|
||||
|
|
|
@ -28,15 +28,14 @@
|
|||
package mage.deck;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.abilities.common.CanBeYourCommanderAbility;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.keyword.PartnerAbility;
|
||||
import mage.abilities.keyword.PartnersWithAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Constructed;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.SetType;
|
||||
import mage.filter.FilterMana;
|
||||
|
||||
/**
|
||||
|
@ -90,15 +89,29 @@ public class FreeformCommander extends Constructed {
|
|||
invalid.put("Commander", "Sideboard must contain only the commander(s)");
|
||||
valid = false;
|
||||
} else {
|
||||
Set<String> commanderNames = new HashSet<>();
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
if (!(commander.isCreature() ||
|
||||
commander.isLegendary())) {
|
||||
commanderNames.add(commander.getName());
|
||||
}
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
if (!(commander.isCreature()
|
||||
|| commander.isLegendary())) {
|
||||
invalid.put("Commander", "For Freeform Commander, the commander must be a creature or be legendary. Yours was: " + commander.getName());
|
||||
valid = false;
|
||||
}
|
||||
if (deck.getSideboard().size() == 2 && !commander.getAbilities().contains(PartnerAbility.getInstance())) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
boolean partnersWith = false;
|
||||
for (Ability ability : commander.getAbilities()) {
|
||||
if (ability instanceof PartnersWithAbility
|
||||
&& commanderNames.contains(((PartnersWithAbility) ability).getPartnerName())) {
|
||||
partnersWith = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!partnersWith) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
FilterMana commanderColor = commander.getColorIdentity();
|
||||
if (commanderColor.isWhite()) {
|
||||
|
|
|
@ -29,8 +29,10 @@ package mage.deck;
|
|||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.CanBeYourCommanderAbility;
|
||||
import mage.abilities.keyword.PartnerAbility;
|
||||
import mage.abilities.keyword.PartnersWithAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
|
@ -98,6 +100,10 @@ public class PennyDreadfulCommander extends Constructed {
|
|||
invalid.put("Commander", "Sideboard must contain only the commander(s)");
|
||||
valid = false;
|
||||
} else {
|
||||
Set<String> commanderNames = new HashSet<>();
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
commanderNames.add(commander.getName());
|
||||
}
|
||||
for (Card commander : deck.getSideboard()) {
|
||||
if ((!commander.isCreature() || !commander.isLegendary())
|
||||
&& (!commander.isPlaneswalker() || !commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
|
||||
|
@ -105,8 +111,18 @@ public class PennyDreadfulCommander extends Constructed {
|
|||
valid = false;
|
||||
}
|
||||
if (deck.getSideboard().size() == 2 && !commander.getAbilities().contains(PartnerAbility.getInstance())) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
boolean partnersWith = false;
|
||||
for (Ability ability : commander.getAbilities()) {
|
||||
if (ability instanceof PartnersWithAbility
|
||||
&& commanderNames.contains(((PartnersWithAbility) ability).getPartnerName())) {
|
||||
partnersWith = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!partnersWith) {
|
||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
FilterMana commanderColor = commander.getColorIdentity();
|
||||
if (commanderColor.isWhite()) {
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright 2010 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.abilities.keyword;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPlayer;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class PartnersWithAbility extends EntersBattlefieldTriggeredAbility {
|
||||
|
||||
private final String partnerName;
|
||||
private final String shortName;
|
||||
|
||||
public PartnersWithAbility(String partnerName) {
|
||||
super(new PartnersWithSearchEffect(partnerName), false);
|
||||
this.addTarget(new TargetPlayer());
|
||||
this.partnerName = partnerName;
|
||||
this.shortName = shortenName(partnerName);
|
||||
}
|
||||
|
||||
public PartnersWithAbility(final PartnersWithAbility ability) {
|
||||
super(ability);
|
||||
this.partnerName = ability.partnerName;
|
||||
this.shortName = ability.shortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartnersWithAbility copy() {
|
||||
return new PartnersWithAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Partners with" + partnerName
|
||||
+ " <i>(When this creature enters the battlefield, target player may put " + shortName
|
||||
+ " into their hand from their library, then shuffle.)</i>";
|
||||
}
|
||||
|
||||
public String getPartnerName() {
|
||||
return partnerName;
|
||||
}
|
||||
|
||||
public static String shortenName(String st) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char s : st.toCharArray()) {
|
||||
if (s == ' ' || s == ',') {
|
||||
break;
|
||||
} else {
|
||||
sb.append(s);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class PartnersWithSearchEffect extends OneShotEffect {
|
||||
|
||||
private final String partnerName;
|
||||
|
||||
public PartnersWithSearchEffect(String partnerName) {
|
||||
super(Outcome.Detriment);
|
||||
this.partnerName = partnerName;
|
||||
this.staticText = "";
|
||||
}
|
||||
|
||||
public PartnersWithSearchEffect(final PartnersWithSearchEffect effect) {
|
||||
super(effect);
|
||||
this.partnerName = effect.partnerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartnersWithSearchEffect copy() {
|
||||
return new PartnersWithSearchEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Player player = game.getPlayer(source.getFirstTarget());
|
||||
if (player != null) {
|
||||
FilterCard filter = new FilterCard("card named " + partnerName);
|
||||
filter.add(new NamePredicate(partnerName));
|
||||
TargetCardInLibrary target = new TargetCardInLibrary(filter);
|
||||
if (player.chooseUse(Outcome.Benefit, "Search your library for a card named" + partnerName + " and put it into your hand?", source, game)) {
|
||||
player.searchLibrary(target, game);
|
||||
for (UUID cardId : target.getTargets()) {
|
||||
Card card = player.getLibrary().getCard(cardId, game);
|
||||
if (card != null) {
|
||||
player.revealCards(source, new CardsImpl(card), game);
|
||||
player.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
}
|
||||
player.shuffleLibrary(source, game);
|
||||
}
|
||||
}
|
||||
// prevent undo
|
||||
controller.resetStoredBookmark(game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue