mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
* Optimized handling and call of player.choose choice to prevent problems if a player disconnects or left a game (#4263).
This commit is contained in:
parent
b9ec919f06
commit
b752eacfaa
152 changed files with 1224 additions and 1681 deletions
|
|
@ -342,7 +342,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
&& !getTargets().isEmpty()) {
|
||||
Outcome outcome = getEffects().isEmpty() ? Outcome.Detriment : getEffects().get(0).getOutcome();
|
||||
if (getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game) == false) {
|
||||
if ((variableManaCost != null || announceString != null) && !game.isSimulation()) {
|
||||
if ((variableManaCost != null || announceString != null)) {
|
||||
game.informPlayer(controller, (sourceObject != null ? sourceObject.getIdName() : "") + ": no valid targets");
|
||||
}
|
||||
return false; // when activation of ability is canceled during target selection
|
||||
|
|
@ -405,15 +405,13 @@ public abstract class AbilityImpl implements Ability {
|
|||
logger.debug("activate failed - non mana costs");
|
||||
return false;
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
// inform about x costs now, so canceled announcements are not shown in the log
|
||||
if ((announceString != null) && (!announceString.equals(""))) {
|
||||
game.informPlayers(announceString);
|
||||
}
|
||||
if (variableManaCost != null) {
|
||||
int xValue = getManaCostsToPay().getX();
|
||||
game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText());
|
||||
}
|
||||
// inform about x costs now, so canceled announcements are not shown in the log
|
||||
if ((announceString != null) && (!announceString.equals(""))) {
|
||||
game.informPlayers(announceString);
|
||||
}
|
||||
if (variableManaCost != null) {
|
||||
int xValue = getManaCostsToPay().getX();
|
||||
game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText());
|
||||
}
|
||||
activated = true;
|
||||
// fire if tapped for mana (may only fire now because else costs of ability itself can be payed with mana of abilities that trigger for that event
|
||||
|
|
|
|||
|
|
@ -108,7 +108,9 @@ public class RemoveCounterCost extends CostImpl {
|
|||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
|
||||
controller.choose(Outcome.UnboostCreature, choice, game);
|
||||
if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
counterName = choice.getChoice();
|
||||
} else {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
|
|
@ -117,7 +119,7 @@ public class RemoveCounterCost extends CostImpl {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (counterName != null) {
|
||||
if (counterName != null && !counterName.isEmpty()) {
|
||||
int countersLeft = countersToRemove - countersRemoved;
|
||||
int countersOnPermanent = permanent.getCounters(game).getCount(counterName);
|
||||
int numberOfCountersSelected = 1;
|
||||
|
|
|
|||
|
|
@ -88,10 +88,6 @@ public class ConditionalManaEffect extends ManaEffect {
|
|||
ChoiceColor choice = new ChoiceColor(true);
|
||||
Mana createdMana = null;
|
||||
if (controller.choose(outcome, choice, game)) {
|
||||
if (choice.getColor() == null) {
|
||||
return false; // it happens, don't know how
|
||||
}
|
||||
|
||||
createdMana = choice.getMana(amount);
|
||||
}
|
||||
if (createdMana == null) {
|
||||
|
|
|
|||
|
|
@ -93,11 +93,9 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
|
|||
ChoiceColor choice = new ChoiceColor(true);
|
||||
|
||||
for (int i = 0; i < value; i++) {
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(outcome, choice, game);
|
||||
if (!controller.isInGame()) {
|
||||
return false;
|
||||
}
|
||||
controller.choose(outcome, choice, game);
|
||||
if (choice.getChoice() == null) {
|
||||
return false;
|
||||
}
|
||||
Mana mana = choice.getMana(1);
|
||||
if (mana != null) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import mage.players.Player;
|
|||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
|
||||
|
||||
public AddManaAnyColorAttachedControllerEffect() {
|
||||
|
|
@ -57,19 +56,12 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
|
|||
Permanent land = game.getPermanent(enchantment.getAttachedTo());
|
||||
if (land != null) {
|
||||
Player player = game.getPlayer(land.getControllerId());
|
||||
if (player != null) {
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
while (!player.choose(outcome, choice, game)) {
|
||||
if (!player.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
if (player != null && player.choose(outcome, choice, game)) {
|
||||
Mana mana = choice.getMana(1);
|
||||
if (mana != null) {
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
player.getManaPool().addMana(mana, game, source);
|
||||
return true;
|
||||
}
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
player.getManaPool().addMana(mana, game, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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.
|
||||
|
|
@ -71,12 +71,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
|
|||
if (controller != null) {
|
||||
String mes = String.format("Select color of %d mana to add it to your mana pool", this.amount);
|
||||
ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId()));
|
||||
|
||||
if (controller.choose(outcome, choice, game)) {
|
||||
if (choice.getColor() == null) {
|
||||
// on user's reconnect choice dialog close and return null even with required settings
|
||||
return false;
|
||||
}
|
||||
Mana createdMana = choice.getMana(amount);
|
||||
if (createdMana != null) {
|
||||
checkToFirePossibleEvents(createdMana, game, source);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* Created by Galatolol
|
||||
|
|
@ -16,7 +15,7 @@ public class AddManaOfAnyColorToManaPoolTargetPlayerEffect extends ManaEffect {
|
|||
|
||||
public AddManaOfAnyColorToManaPoolTargetPlayerEffect(String textManaPoolOwner) {
|
||||
super();
|
||||
this.staticText = (textManaPoolOwner.equals("his or her")?"that player adds ":"add ") + "one mana of any color" + " to " + textManaPoolOwner + " mana pool";
|
||||
this.staticText = (textManaPoolOwner.equals("his or her") ? "that player adds " : "add ") + "one mana of any color" + " to " + textManaPoolOwner + " mana pool";
|
||||
}
|
||||
|
||||
public AddManaOfAnyColorToManaPoolTargetPlayerEffect(final AddManaOfAnyColorToManaPoolTargetPlayerEffect effect) {
|
||||
|
|
@ -27,19 +26,12 @@ public class AddManaOfAnyColorToManaPoolTargetPlayerEffect extends ManaEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + "_player");
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
while (!player.choose(outcome, choice, game)) {
|
||||
if (!player.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
if (player != null && player.choose(outcome, choice, game)) {
|
||||
Mana mana = choice.getMana(1);
|
||||
if (mana != null) {
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
player.getManaPool().addMana(mana, game, source);
|
||||
return true;
|
||||
}
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
player.getManaPool().addMana(mana, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -55,4 +47,3 @@ public class AddManaOfAnyColorToManaPoolTargetPlayerEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,10 +84,9 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect {
|
|||
if (choice.getChoices().size() == 1) {
|
||||
choice.setChoice(choice.getChoices().iterator().next());
|
||||
} else {
|
||||
targetController.choose(outcome, choice, game);
|
||||
}
|
||||
if (choice.getChoice() == null) {
|
||||
return false;
|
||||
if (!targetController.choose(outcome, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Mana newMana = new Mana();
|
||||
switch (choice.getChoice()) {
|
||||
|
|
|
|||
|
|
@ -59,14 +59,8 @@ public class ChooseColorEffect extends OneShotEffect {
|
|||
if (mageObject == null) {
|
||||
mageObject = game.getObject(source.getSourceId());
|
||||
}
|
||||
if (controller != null && mageObject != null) {
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(outcome, choice, game);
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
if (controller != null && mageObject != null && controller.choose(outcome, choice, game)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,20 +63,15 @@ public class ChooseCreatureTypeEffect extends OneShotEffect {
|
|||
}
|
||||
if (controller != null && mageObject != null) {
|
||||
Choice typeChoice = new ChoiceCreatureType(mageObject);
|
||||
while (!controller.choose(outcome, typeChoice, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
if (controller.choose(outcome, typeChoice, game)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
|
||||
}
|
||||
}
|
||||
if (typeChoice.getChoice() == null) {
|
||||
return false;
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
|
||||
}
|
||||
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
|
||||
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import mage.cards.repository.ExpansionRepository;
|
|||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
|
@ -73,22 +72,16 @@ public class ChooseExpansionSetEffect extends OneShotEffect {
|
|||
Set<String> sets = new HashSet<String>(setCodes);
|
||||
|
||||
setChoice.setChoices(sets);
|
||||
|
||||
while (!controller.choose(outcome, setChoice, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
if (controller.choose(outcome, setChoice, game)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + " has chosen set " + setChoice.getChoice());
|
||||
}
|
||||
}
|
||||
if (setChoice.getChoice() == null) {
|
||||
return false;
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + " has chosen set " + setChoice.getChoice());
|
||||
}
|
||||
game.getState().setValue(mageObject.getId() + "_set", setChoice.getChoice());
|
||||
this.setValue("setchosen", setChoice.getChoice());
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen set", CardUtil.addToolTipMarkTags("Chosen set: " + setChoice.getChoice()), game);
|
||||
game.getState().setValue(mageObject.getId() + "_set", setChoice.getChoice());
|
||||
this.setValue("setchosen", setChoice.getChoice());
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen set", CardUtil.addToolTipMarkTags("Chosen set: " + setChoice.getChoice()), game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -17,8 +18,6 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fireshoes
|
||||
|
|
@ -45,17 +44,15 @@ public class ChooseLandTypeEffect extends OneShotEffect {
|
|||
Choice typeChoice = new ChoiceImpl(true);
|
||||
typeChoice.setMessage("Choose land type");
|
||||
typeChoice.setChoices(SubType.getLandTypes(false).stream().map(SubType::toString).collect(Collectors.toSet()));
|
||||
while (!controller.choose(outcome, typeChoice, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
if (controller.choose(outcome, typeChoice, game)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
|
||||
}
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
|
||||
}
|
||||
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
|
||||
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@
|
|||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.choices.Choice;
|
||||
|
|
@ -36,10 +39,6 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
|
@ -78,20 +77,14 @@ public class ChooseModeEffect extends OneShotEffect {
|
|||
Choice choice = new ChoiceImpl(true);
|
||||
choice.setMessage(choiceMessage);
|
||||
choice.getChoices().addAll(modes);
|
||||
while (!choice.isChosen()) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
controller.choose(Outcome.Neutral, choice, game);
|
||||
}
|
||||
if (choice.isChosen()) {
|
||||
if (controller.choose(Outcome.Neutral, choice, game)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourcePermanent.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
|
||||
}
|
||||
game.getState().setValue(source.getSourceId() + "_modeChoice", choice.getChoice());
|
||||
sourcePermanent.addInfo("_modeChoice", "<font color = 'blue'>Chosen mode: " + choice.getChoice() + "</font>", game);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,10 +146,8 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
ChoiceColor choiceColor = new ChoiceColor(true);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!choiceColor.isChosen()) {
|
||||
while (!controller.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return computedMana;
|
||||
}
|
||||
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
return computedMana;
|
||||
}
|
||||
}
|
||||
choiceColor.increaseMana(computedMana);
|
||||
|
|
|
|||
|
|
@ -1,119 +1,120 @@
|
|||
/*
|
||||
* 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.effects.common;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.MeldCard;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author emerald000
|
||||
*/
|
||||
public class MeldEffect extends OneShotEffect {
|
||||
|
||||
private final String meldWithName;
|
||||
private final MeldCard meldCard;
|
||||
|
||||
public MeldEffect(String meldWithName, MeldCard meldCard) {
|
||||
super(Outcome.Benefit);
|
||||
this.meldWithName = meldWithName;
|
||||
this.meldCard = meldCard;
|
||||
}
|
||||
|
||||
public MeldEffect(final MeldEffect effect) {
|
||||
super(effect);
|
||||
this.meldWithName = effect.meldWithName;
|
||||
this.meldCard = effect.meldCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MeldEffect copy() {
|
||||
return new MeldEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
// Find the two permanents to meld.
|
||||
UUID sourceId = source.getSourceId();
|
||||
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
|
||||
filter.add(new NamePredicate(meldWithName));
|
||||
TargetPermanent target = new TargetControlledCreaturePermanent(filter);
|
||||
Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
|
||||
if (meldWithList.isEmpty()) {
|
||||
return false; // possible permanent has left the battlefield meanwhile
|
||||
}
|
||||
UUID meldWithId;
|
||||
if (meldWithList.size() == 1) {
|
||||
meldWithId = meldWithList.iterator().next();
|
||||
} else {
|
||||
controller.choose(Outcome.BoostCreature, target, sourceId, game);
|
||||
meldWithId = target.getFirstTarget();
|
||||
}
|
||||
// Exile the two permanents to meld.
|
||||
Permanent sourcePermanent = game.getPermanent(sourceId);
|
||||
Permanent meldWithPermanent = game.getPermanent(meldWithId);
|
||||
if (sourcePermanent != null && meldWithPermanent != null) {
|
||||
Set<Card> toExile = new HashSet<>();
|
||||
toExile.add(sourcePermanent);
|
||||
toExile.add(meldWithPermanent);
|
||||
controller.moveCards(toExile, Zone.EXILED, source, game);
|
||||
// Create the meld card and move it to the battlefield.
|
||||
Card sourceCard = game.getExile().getCard(sourceId, game);
|
||||
Card meldWithCard = game.getExile().getCard(meldWithId, game);
|
||||
if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
|
||||
meldCard.setOwnerId(controller.getId());
|
||||
meldCard.setTopHalfCard(meldWithCard, game);
|
||||
meldCard.setBottomHalfCard(sourceCard, game);
|
||||
meldCard.setMelded(true);
|
||||
game.addMeldCard(meldCard.getId(), meldCard);
|
||||
game.getState().addCard(meldCard);
|
||||
meldCard.setZone(Zone.EXILED, game);
|
||||
controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.effects.common;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.MeldCard;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author emerald000
|
||||
*/
|
||||
public class MeldEffect extends OneShotEffect {
|
||||
|
||||
private final String meldWithName;
|
||||
private final MeldCard meldCard;
|
||||
|
||||
public MeldEffect(String meldWithName, MeldCard meldCard) {
|
||||
super(Outcome.Benefit);
|
||||
this.meldWithName = meldWithName;
|
||||
this.meldCard = meldCard;
|
||||
}
|
||||
|
||||
public MeldEffect(final MeldEffect effect) {
|
||||
super(effect);
|
||||
this.meldWithName = effect.meldWithName;
|
||||
this.meldCard = effect.meldCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MeldEffect copy() {
|
||||
return new MeldEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
// Find the two permanents to meld.
|
||||
UUID sourceId = source.getSourceId();
|
||||
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
|
||||
filter.add(new NamePredicate(meldWithName));
|
||||
TargetPermanent target = new TargetControlledCreaturePermanent(filter);
|
||||
Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
|
||||
if (meldWithList.isEmpty()) {
|
||||
return false; // possible permanent has left the battlefield meanwhile
|
||||
}
|
||||
UUID meldWithId = null;
|
||||
if (meldWithList.size() == 1) {
|
||||
meldWithId = meldWithList.iterator().next();
|
||||
} else {
|
||||
if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
|
||||
meldWithId = target.getFirstTarget();
|
||||
}
|
||||
}
|
||||
// Exile the two permanents to meld.
|
||||
Permanent sourcePermanent = game.getPermanent(sourceId);
|
||||
Permanent meldWithPermanent = game.getPermanent(meldWithId);
|
||||
if (sourcePermanent != null && meldWithPermanent != null) {
|
||||
Set<Card> toExile = new HashSet<>();
|
||||
toExile.add(sourcePermanent);
|
||||
toExile.add(meldWithPermanent);
|
||||
controller.moveCards(toExile, Zone.EXILED, source, game);
|
||||
// Create the meld card and move it to the battlefield.
|
||||
Card sourceCard = game.getExile().getCard(sourceId, game);
|
||||
Card meldWithCard = game.getExile().getCard(meldWithId, game);
|
||||
if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
|
||||
meldCard.setOwnerId(controller.getId());
|
||||
meldCard.setTopHalfCard(meldWithCard, game);
|
||||
meldCard.setBottomHalfCard(sourceCard, game);
|
||||
meldCard.setMelded(true);
|
||||
game.addMeldCard(meldCard.getId(), meldCard);
|
||||
game.getState().addCard(meldCard);
|
||||
meldCard.setZone(Zone.EXILED, game);
|
||||
controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,20 +106,17 @@ public class NameACardEffect extends OneShotEffect {
|
|||
break;
|
||||
}
|
||||
cardChoice.clearChoice();
|
||||
while (!controller.choose(Outcome.Detriment, cardChoice, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
if (controller.choose(Outcome.Detriment, cardChoice, game)) {
|
||||
String cardName = cardChoice.getChoice();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ", named card: [" + cardName + ']');
|
||||
}
|
||||
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, cardName);
|
||||
if (sourceObject instanceof Permanent) {
|
||||
((Permanent) sourceObject).addInfo(INFO_KEY, CardUtil.addToolTipMarkTags("Named card: " + cardName), game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
String cardName = cardChoice.getChoice();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ", named card: [" + cardName + ']');
|
||||
}
|
||||
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, cardName);
|
||||
if (sourceObject instanceof Permanent) {
|
||||
((Permanent) sourceObject).addInfo(INFO_KEY, CardUtil.addToolTipMarkTags("Named card: " + cardName), game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
*/
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.mana.*;
|
||||
|
|
@ -37,11 +41,6 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* http://mtgsalvation.gamepedia.com/Land_changers
|
||||
*
|
||||
|
|
@ -114,15 +113,14 @@ public class BecomesBasicLandTargetEffect extends ContinuousEffectImpl {
|
|||
// choose land type
|
||||
if (chooseLandType) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Choice choice = new ChoiceBasicLandType();
|
||||
controller.choose(outcome, choice, game);
|
||||
Choice choice = new ChoiceBasicLandType();
|
||||
if (controller != null && controller.choose(outcome, choice, game)) {
|
||||
landTypes.add(SubType.byDescription(choice.getChoice()));
|
||||
} else {
|
||||
this.discard();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (loseOther) {
|
||||
landTypesToAdd.addAll(landTypes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@ public class BecomesChosenCreatureTypeTargetEffect extends OneShotEffect {
|
|||
public BecomesChosenCreatureTypeTargetEffect(boolean nonWall) {
|
||||
super(Outcome.BoostCreature);
|
||||
this.nonWall = nonWall;
|
||||
if(nonWall) {
|
||||
if (nonWall) {
|
||||
staticText = "choose a creature type other than Wall. Target creature becomes that type until end of turn";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
staticText = "target creature becomes the creature type of your choice until end of turn";
|
||||
}
|
||||
|
||||
|
|
@ -47,17 +46,15 @@ public class BecomesChosenCreatureTypeTargetEffect extends OneShotEffect {
|
|||
if (player != null && card != null) {
|
||||
Choice typeChoice = new ChoiceCreatureType();
|
||||
String msg = "Choose a creature type";
|
||||
if(nonWall) {
|
||||
if (nonWall) {
|
||||
msg += " other than Wall";
|
||||
}
|
||||
typeChoice.setMessage(msg);
|
||||
if(nonWall) {
|
||||
if (nonWall) {
|
||||
typeChoice.getChoices().remove(SubType.WALL.getDescription());
|
||||
}
|
||||
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
if (!player.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
if (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
return false;
|
||||
}
|
||||
game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
|
||||
chosenType = typeChoice.getChoice();
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@ public class BecomesColorOrColorsTargetEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
ChoiceColor choiceColor = new ChoiceColor();
|
||||
controller.choose(Outcome.Benefit, choiceColor, game);
|
||||
if (!controller.canRespond()) {
|
||||
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
return false;
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
|
|
|
|||
|
|
@ -77,17 +77,11 @@ public class BecomesColorSourceEffect extends ContinuousEffectImpl {
|
|||
}
|
||||
if (setColor == null) {
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(Outcome.PutManaInPool, choice, game);
|
||||
if (!controller.canRespond()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (choice.getColor() != null) {
|
||||
setColor = choice.getColor();
|
||||
} else {
|
||||
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
|
||||
discard();
|
||||
return;
|
||||
}
|
||||
setColor = choice.getColor();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + " has chosen the color: " + setColor.toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
* 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.effects.common.continuous;
|
||||
|
||||
|
|
@ -82,17 +82,11 @@ public class BecomesColorTargetEffect extends ContinuousEffectImpl {
|
|||
}
|
||||
if (setColor == null) {
|
||||
ChoiceColor choice = new ChoiceColor();
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(Outcome.PutManaInPool, choice, game);
|
||||
if (!controller.canRespond()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (choice.getColor() != null) {
|
||||
setColor = choice.getColor();
|
||||
} else {
|
||||
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
|
||||
discard();
|
||||
return;
|
||||
}
|
||||
setColor = choice.getColor();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + " has chosen the color: " + setColor.toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,16 +78,11 @@ public class GainProtectionFromColorAllEffect extends GainAbilityAllEffect {
|
|||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (sourceObject != null && controller != null) {
|
||||
choice.clearChoice();
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(Outcome.Protect, choice, game);
|
||||
if (!controller.canRespond()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (choice.isChosen() && !game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen protection from " + choice.getChoice());
|
||||
if (!controller.choose(Outcome.Protect, choice, game)) {
|
||||
discard();
|
||||
return;
|
||||
}
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen protection from " + choice.getChoice());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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.
|
||||
|
|
@ -43,14 +43,13 @@ import mage.players.Player;
|
|||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect {
|
||||
|
||||
FilterCard protectionFilter;
|
||||
|
||||
public GainProtectionFromColorSourceEffect(Duration duration) {
|
||||
super(new ProtectionAbility(new FilterCard()), duration);
|
||||
protectionFilter = (FilterCard)((ProtectionAbility)ability).getFilter();
|
||||
protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
|
||||
}
|
||||
|
||||
public GainProtectionFromColorSourceEffect(final GainProtectionFromColorSourceEffect effect) {
|
||||
|
|
@ -65,23 +64,18 @@ public class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect
|
|||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
super.init(source, game);
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
if (controller != null) {
|
||||
ChoiceColor colorChoice = new ChoiceColor(true);
|
||||
colorChoice.setMessage("Choose color for protection ability");
|
||||
while (!colorChoice.isChosen()) {
|
||||
controller.choose(outcome, colorChoice, game);
|
||||
if (!controller.canRespond()) {
|
||||
discard();
|
||||
return;
|
||||
}
|
||||
if (controller.choose(outcome, colorChoice, game)) {
|
||||
game.informPlayers("Choosen color: " + colorChoice.getColor());
|
||||
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
|
||||
protectionFilter.setMessage(colorChoice.getChoice());
|
||||
((ProtectionAbility) ability).setFilter(protectionFilter);
|
||||
return;
|
||||
}
|
||||
game.informPlayers("Choosen color: " + colorChoice.getColor());
|
||||
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
|
||||
protectionFilter.setMessage(colorChoice.getChoice());
|
||||
((ProtectionAbility)ability).setFilter(protectionFilter);
|
||||
return;
|
||||
}
|
||||
discard();
|
||||
}
|
||||
|
|
@ -102,4 +96,4 @@ public class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect
|
|||
public String getText(Mode mode) {
|
||||
return "{this} gains protection from the color of your choice " + duration.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,18 +77,12 @@ public class GainProtectionFromColorTargetEffect extends GainAbilityTargetEffect
|
|||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (sourceObject != null && controller != null) {
|
||||
if (!choice.isChosen()) {
|
||||
while (!choice.isChosen()) {
|
||||
controller.choose(Outcome.Protect, choice, game);
|
||||
if (!controller.canRespond()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (choice.isChosen() && !game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen protection from " + choice.getChoice());
|
||||
}
|
||||
if (controller.choose(Outcome.Protect, choice, game)) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen protection from " + choice.getChoice());
|
||||
return;
|
||||
}
|
||||
}
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.choices.ChoiceImpl;
|
||||
|
|
@ -36,9 +38,6 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author a
|
||||
|
|
@ -88,19 +87,18 @@ public class LoseAbilityOrAnotherAbilityTargetEffect extends LoseAbilityTargetEf
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
|
||||
if (player.choose(outcome, chooseAbility, game)) {
|
||||
|
||||
String chosenAbility = chooseAbility.getChoice();
|
||||
|
||||
if (chosenAbility.equals(ability.getRule())) {
|
||||
while (permanent.getAbilities().contains(ability)) {
|
||||
permanent.getAbilities().remove(ability);
|
||||
}
|
||||
}
|
||||
else if (chosenAbility.equals(ability2.getRule())) {
|
||||
} else if (chosenAbility.equals(ability2.getRule())) {
|
||||
while (permanent.getAbilities().contains(ability2)) {
|
||||
permanent.getAbilities().remove(ability2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -112,10 +112,11 @@ public class SpellsCostReductionAllEffect extends CostModificationEffectImpl {
|
|||
if (controller.choose(Outcome.Benefit, choice, game)) {
|
||||
int reduce = Integer.parseInt(choice.getChoice());
|
||||
CardUtil.reduceCost(abilityToModify, reduce);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
CardUtil.reduceCost(abilityToModify, this.amount);
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ import mage.players.Player;
|
|||
import mage.target.Target;
|
||||
import mage.target.common.TargetPermanentOrPlayerWithCounter;
|
||||
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
|
|
@ -88,13 +87,16 @@ public class ProliferateEffect extends OneShotEffect {
|
|||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to proliferate (" + permanent.getIdName() + ')');
|
||||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
permanent.addCounters(newCounter, source, game);
|
||||
break;
|
||||
if (controller.choose(Outcome.Benefit, choice, game)) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
permanent.addCounters(newCounter, source, game);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -115,13 +117,16 @@ public class ProliferateEffect extends OneShotEffect {
|
|||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to proliferate (" + player.getLogName() + ')');
|
||||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
player.addCounters(newCounter, game);
|
||||
break;
|
||||
if (controller.choose(Outcome.Benefit, choice, game)) {
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
player.addCounters(newCounter, game);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,19 +98,22 @@ public class RemoveCounterTargetEffect extends OneShotEffect {
|
|||
if (permanent.getCounters(game).size() > 1) {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<>();
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
|
||||
choices.add(counter.getName());
|
||||
for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
|
||||
if (permanent.getCounters(game).getCount(counterOnPermanent.getName()) > 0) {
|
||||
choices.add(counterOnPermanent.getName());
|
||||
}
|
||||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter type to remove from " + permanent.getName());
|
||||
controller.choose(Outcome.Detriment, choice, game);
|
||||
counterName = choice.getChoice();
|
||||
if (controller.choose(Outcome.Detriment, choice, game)) {
|
||||
counterName = choice.getChoice();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getCount() > 0) {
|
||||
counterName = counter.getName();
|
||||
for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
|
||||
if (counterOnPermanent.getCount() > 0) {
|
||||
counterName = counterOnPermanent.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,11 +212,8 @@ class ConvokeEffect extends OneShotEffect {
|
|||
if (chooseManaType.getChoices().size() > 1) {
|
||||
chooseManaType.getChoices().add("Colorless");
|
||||
chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName());
|
||||
while (!chooseManaType.isChosen()) {
|
||||
controller.choose(Outcome.Benefit, chooseManaType, game);
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
if (!controller.choose(Outcome.Benefit, chooseManaType, game)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
chooseManaType.setChoice(chooseManaType.getChoices().iterator().next());
|
||||
|
|
@ -251,9 +248,7 @@ class ConvokeEffect extends OneShotEffect {
|
|||
manaPool.unlockManaType(ManaType.COLORLESS);
|
||||
manaName = "colorless";
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("Convoke: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay one " + manaName + " mana");
|
||||
}
|
||||
game.informPlayers("Convoke: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay one " + manaName + " mana");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,9 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
|
|||
if (choice.getChoices().size() == 1) {
|
||||
choice.setChoice(choice.getChoices().iterator().next());
|
||||
} else {
|
||||
player.choose(outcome, choice, game);
|
||||
if (!player.choose(outcome, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (choice.getChoice() != null) {
|
||||
Mana mana = new Mana();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue