forked from External/mage
* Fixed a problem with check playable methods causing e.g. endless loop if Shared Fate was on the battlefield.
This commit is contained in:
parent
32bd88a6c0
commit
133cc7342d
19 changed files with 227 additions and 230 deletions
|
|
@ -1,7 +1,28 @@
|
|||
package mage.player.human;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.Modes;
|
||||
import mage.abilities.PlayLandAbility;
|
||||
import mage.abilities.SpecialAction;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.abilities.costs.common.SacrificeSourceCost;
|
||||
import mage.abilities.costs.common.TapSourceCost;
|
||||
|
|
@ -16,6 +37,11 @@ import mage.cards.decks.Deck;
|
|||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.*;
|
||||
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL;
|
||||
import static mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL;
|
||||
import static mage.constants.SpellAbilityType.SPLIT;
|
||||
import static mage.constants.SpellAbilityType.SPLIT_AFTERMATH;
|
||||
import static mage.constants.SpellAbilityType.SPLIT_FUSED;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterAttackingCreature;
|
||||
import mage.filter.common.FilterBlockingCreature;
|
||||
|
|
@ -46,16 +72,6 @@ import mage.util.ManaUtil;
|
|||
import mage.util.MessageToClient;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL;
|
||||
import static mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -268,6 +284,9 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public boolean chooseUse(Outcome outcome, String message, String secondMessage, String trueText, String falseText, Ability source, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
return true;
|
||||
}
|
||||
MessageToClient messageToClient = new MessageToClient(message, secondMessage);
|
||||
Map<String, Serializable> options = new HashMap<>(2);
|
||||
if (trueText != null) {
|
||||
|
|
@ -334,6 +353,14 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public int chooseReplacementEffect(Map<String, String> rEffects, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
logger.warn("player interaction in checkPlayableState.");
|
||||
if (rEffects.size() <= 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
updateGameStatePriority("chooseEffect", game);
|
||||
if (rEffects.size() <= 1) {
|
||||
return 0;
|
||||
|
|
@ -394,6 +421,11 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Choice choice, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
logger.warn("player interaction in checkPlayableState. Choice: " + choice.getMessage());
|
||||
choice.setChoice(choice.getChoices().iterator().next());
|
||||
return true;
|
||||
}
|
||||
if (Outcome.PutManaInPool == outcome) {
|
||||
if (currentlyUnpaidMana != null
|
||||
&& ManaUtil.tryToAutoSelectAManaColor(choice, currentlyUnpaidMana)) {
|
||||
|
|
@ -429,6 +461,11 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game, Map<String, Serializable> options) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
logger.warn("player interaction in checkPlayableState. Target: " + target.getMessage());
|
||||
// TODO: set default choice
|
||||
return true;
|
||||
}
|
||||
// choose one or multiple permanents
|
||||
updateGameStatePriority("choose(5)", game);
|
||||
UUID abilityControllerId = playerId;
|
||||
|
|
@ -520,6 +557,11 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
logger.warn("player interaction in checkPlayableState. Target: " + target.getMessage());
|
||||
// TODO: set default choice
|
||||
return true;
|
||||
}
|
||||
// choose one or multiple targets
|
||||
updateGameStatePriority("chooseTarget", game);
|
||||
UUID abilityControllerId = playerId;
|
||||
|
|
@ -582,6 +624,11 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
logger.warn("player interaction in checkPlayableState. Target: " + target.getMessage());
|
||||
// TODO: set default choice
|
||||
return true;
|
||||
}
|
||||
// choose one or multiple cards
|
||||
if (cards == null) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
|
|||
|
||||
public ExpropriateDilemmaEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "<i>Council's dilemma</i> — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it.";
|
||||
this.staticText = "<i>Council's dilemma</i> — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it";
|
||||
}
|
||||
|
||||
public ExpropriateDilemmaEffect(final ExpropriateDilemmaEffect effect) {
|
||||
|
|
@ -110,7 +110,7 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
|
|||
target.setNotTarget(true);
|
||||
|
||||
if (controller != null
|
||||
&& controller.choose(Outcome.GainControl, target, source.getSourceId(), game)) {
|
||||
&& controller.chooseTarget(Outcome.GainControl, target, source, game)) {
|
||||
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
|
||||
|
||||
if (targetPermanent != null) {
|
||||
|
|
@ -132,9 +132,7 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
|
|||
protected void vote(String choiceOne, String choiceTwo, Player controller, Game game, Ability source) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null
|
||||
&& player.canRespond()
|
||||
&& player.isInGame()) {
|
||||
if (player != null) {
|
||||
if (player.chooseUse(Outcome.Vote, "Choose " + choiceOne + '?', source, game)) {
|
||||
voteOneCount++;
|
||||
game.informPlayers(player.getName() + " has voted for " + choiceOne);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.f;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -6,7 +5,6 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
|
||||
import mage.abilities.keyword.CyclingAbility;
|
||||
|
|
@ -70,9 +68,8 @@ class FluctuatorEffect extends CostModificationEffectImpl {
|
|||
reduceMax = 2;
|
||||
}
|
||||
if (reduceMax > 0) {
|
||||
int reduce = 0;
|
||||
if (abilityToModify.getAbilityType() == AbilityType.ACTIVATED
|
||||
&& ((ActivatedAbility) abilityToModify).isCheckPlayableMode()) {
|
||||
int reduce;
|
||||
if (game.inCheckPlayableState()) {
|
||||
reduce = reduceMax;
|
||||
} else {
|
||||
ChoiceImpl choice = new ChoiceImpl(true);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.m;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -111,7 +110,7 @@ class MizzixOfTheIzmagnusCostReductionEffect extends CostModificationEffectImpl
|
|||
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
|
||||
if (spell != null) {
|
||||
return StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY.match(spell, source.getSourceId(), source.getControllerId(), game);
|
||||
} else if (((SpellAbility) abilityToModify).isCheckPlayableMode()) {
|
||||
} else if (game.inCheckPlayableState()) {
|
||||
// Spell is not on the stack yet, but possible playable spells are determined
|
||||
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
||||
return sourceCard != null && StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY.match(sourceCard, source.getSourceId(), source.getControllerId(), game);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
package mage.cards.n;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.common.CyclingDiscardCost;
|
||||
|
|
@ -70,7 +68,8 @@ class NewPerspectivesCostModificationEffect extends CostModificationEffectImpl {
|
|||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
Player controller = game.getPlayer(abilityToModify.getControllerId());
|
||||
if (controller != null) {
|
||||
if ((abilityToModify instanceof ActivatedAbility && ((ActivatedAbility) abilityToModify).isCheckPlayableMode()) || controller.chooseUse(Outcome.PlayForFree, "Pay {0} to cycle?", source, game)) {
|
||||
if (game.inCheckPlayableState()
|
||||
|| controller.chooseUse(Outcome.PlayForFree, "Pay {0} to cycle?", source, game)) {
|
||||
abilityToModify.getCosts().clear();
|
||||
abilityToModify.getManaCostsToPay().clear();
|
||||
abilityToModify.getCosts().add(new CyclingDiscardCost());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.s;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -78,12 +77,9 @@ class SharedFateReplacementEffect extends ReplacementEffectImpl {
|
|||
Card card = chosenPlayer.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
playerToDraw.moveCardsToExile(
|
||||
card,
|
||||
source,
|
||||
game,
|
||||
false,
|
||||
card, source, game, false,
|
||||
CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + playerToDraw.getId().toString(), game),
|
||||
"Shared Fate (" + playerToDraw.getName() + ')');
|
||||
sourcePermanent.getIdName() + " (" + playerToDraw.getName() + ')');
|
||||
card.setFaceDown(true, game);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
Enchantment
|
||||
Whenever you cast an instant or sorcery spell, copy it for each other instant and sorcery spell you’ve cast before it this turn. You may choose new targets for the copies.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test_CalcBeforeStorm() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
|
||||
|
|
@ -233,7 +232,6 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
addCard(Zone.BATTLEFIELD, playerB, "Augmenting Automaton");
|
||||
|
||||
// turn 1
|
||||
|
||||
// 1a
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
checkLife("0x copy", 1, PhaseStep.BEGIN_COMBAT, playerB, 20 - 3);
|
||||
|
|
@ -255,7 +253,6 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
assertAllCommandsUsed();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_WaitStackResolvedWithBolts() {
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 5);
|
||||
|
|
@ -282,6 +279,8 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
You control enchanted permanent.
|
||||
Cycling {2} ({2}, Discard this card: Draw a card.)
|
||||
*/
|
||||
// Test fails sometimes with the following message:
|
||||
// java.lang.AssertionError: b 0x copy after control - PlayerA have wrong life: 20 <> 17 expected:<17> but was:<20>
|
||||
@Test
|
||||
public void test_GetControlNotCounts() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
|
||||
|
|
@ -296,7 +295,6 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
addCard(Zone.HAND, playerB, "Lay Claim");
|
||||
|
||||
// turn 2
|
||||
|
||||
// pump card for A
|
||||
// 1
|
||||
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
|
|
@ -313,7 +311,6 @@ public class ThousandYearStormTest extends CardTestPlayerBase {
|
|||
checkLife("b 0x copy after control", 3, PhaseStep.UPKEEP, playerA, 20 - 3);
|
||||
|
||||
// turn 4
|
||||
|
||||
// pump for B
|
||||
// 1
|
||||
castSpell(4, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -62,14 +61,6 @@ public interface ActivatedAbility extends Ability {
|
|||
@Override
|
||||
ActivatedAbility copy();
|
||||
|
||||
/**
|
||||
* Set a flag to know, that the ability is only created adn used to check
|
||||
* what's playbable for the player.
|
||||
*/
|
||||
void setCheckPlayableMode();
|
||||
|
||||
boolean isCheckPlayableMode();
|
||||
|
||||
void setMaxActivationsPerTurn(int maxActivationsPerTurn);
|
||||
|
||||
int getMaxActivationsPerTurn(Game game);
|
||||
|
|
|
|||
|
|
@ -46,11 +46,9 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
protected TimingRule timing = TimingRule.INSTANT;
|
||||
protected TargetController mayActivate = TargetController.YOU;
|
||||
protected UUID activatorId;
|
||||
protected boolean checkPlayableMode;
|
||||
|
||||
protected ActivatedAbilityImpl(AbilityType abilityType, Zone zone) {
|
||||
super(abilityType, zone);
|
||||
this.checkPlayableMode = false;
|
||||
}
|
||||
|
||||
public ActivatedAbilityImpl(final ActivatedAbilityImpl ability) {
|
||||
|
|
@ -58,7 +56,6 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
timing = ability.timing;
|
||||
mayActivate = ability.mayActivate;
|
||||
activatorId = ability.activatorId;
|
||||
checkPlayableMode = ability.checkPlayableMode;
|
||||
maxActivationsPerTurn = ability.maxActivationsPerTurn;
|
||||
condition = ability.condition;
|
||||
}
|
||||
|
|
@ -262,16 +259,6 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
this.timing = timing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCheckPlayableMode() {
|
||||
checkPlayableMode = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCheckPlayableMode() {
|
||||
return checkPlayableMode;
|
||||
}
|
||||
|
||||
protected boolean hasMoreActivationsThisTurn(Game game) {
|
||||
if (getMaxActivationsPerTurn(game) == Integer.MAX_VALUE) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package mage.abilities;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
|
@ -15,9 +17,6 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -91,7 +90,7 @@ public class SpellAbility extends ActivatedAbilityImpl {
|
|||
}
|
||||
}
|
||||
// Check if rule modifying events prevent to cast the spell in check playable mode
|
||||
if (this.isCheckPlayableMode()) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
if (game.getContinuousEffects().preventedByRuleModification(
|
||||
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this.getSourceId(), playerId), this, game, true)) {
|
||||
return ActivationStatus.getFalse();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package mage.abilities.effects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.*;
|
||||
|
|
@ -23,11 +27,6 @@ import mage.players.Player;
|
|||
import mage.target.common.TargetCardInHand;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -737,10 +736,7 @@ public class ContinuousEffects implements Serializable {
|
|||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
effect.setValue("targetAbility", targetAbility);
|
||||
if (effect.applies(event, sourceAbility, game)) {
|
||||
if (targetAbility instanceof ActivatedAbility && ((ActivatedAbility) targetAbility).isCheckPlayableMode()) {
|
||||
checkPlayableMode = true;
|
||||
}
|
||||
if (!checkPlayableMode) {
|
||||
if (!game.inCheckPlayableState()) {
|
||||
String message = effect.getInfoMessage(sourceAbility, event, game);
|
||||
if (message != null && !message.isEmpty()) {
|
||||
if (effect.sendMessageToUser()) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -6,7 +5,6 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.choices.ChoiceImpl;
|
||||
|
|
@ -70,12 +68,10 @@ public class SpellsCostReductionAllEffect extends CostModificationEffectImpl {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
if (upTo) {
|
||||
if (abilityToModify instanceof ActivatedAbility) {
|
||||
if (((ActivatedAbility) abilityToModify).isCheckPlayableMode()) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
CardUtil.reduceCost(abilityToModify, this.amount);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Mana mana = abilityToModify.getManaCostsToPay().getMana();
|
||||
int reduceMax = mana.getGeneric();
|
||||
if (reduceMax > 2) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -6,7 +5,6 @@ import java.util.Set;
|
|||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
|
|
@ -85,7 +83,7 @@ public class SpellsCostReductionControllerEffect extends CostModificationEffectI
|
|||
return false;
|
||||
}
|
||||
int reduce = reduceMax;
|
||||
if (!(abilityToModify instanceof ActivatedAbility) || !((ActivatedAbility) abilityToModify).isCheckPlayableMode()) {
|
||||
if (!game.inCheckPlayableState()) {
|
||||
ChoiceImpl choice = new ChoiceImpl(false);
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
for (int i = 0; i <= amount; i++) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
|
|
@ -23,8 +24,6 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
* <p>
|
||||
|
|
@ -122,7 +121,7 @@ class HideawayLookAtFaceDownCardEffect extends AsThoughEffectImpl {
|
|||
|
||||
public HideawayLookAtFaceDownCardEffect() {
|
||||
super(AsThoughEffectType.LOOK_AT_FACE_DOWN, Duration.EndOfGame, Outcome.Benefit);
|
||||
staticText = "You may look at cards exiled with {this}";
|
||||
staticText = "You may look at the cards exiled with {this}";
|
||||
}
|
||||
|
||||
private HideawayLookAtFaceDownCardEffect(final HideawayLookAtFaceDownCardEffect effect) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
|
@ -17,8 +18,6 @@ import mage.target.Target;
|
|||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 702.46. Offering # 702.46a Offering is a static ability of a card that
|
||||
* functions in any zone from which the card can be cast. "[Subtype] offering"
|
||||
|
|
@ -121,7 +120,7 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl {
|
|||
|
||||
if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
|
||||
|
||||
if (CardUtil.isCheckPlayableMode(affectedAbility)) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
return true;
|
||||
}
|
||||
FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
|
||||
|
|
@ -130,7 +129,7 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl {
|
|||
return false;
|
||||
}
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null && !CardUtil.isCheckPlayableMode(affectedAbility)
|
||||
if (player != null && !game.inCheckPlayableState()
|
||||
&& player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
|
||||
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
|
||||
player.chooseTarget(Outcome.Sacrifice, target, source, game);
|
||||
|
|
@ -193,7 +192,7 @@ class OfferingCostReductionEffect extends CostModificationEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (CardUtil.isCheckPlayableMode(abilityToModify)) { // Cost modifaction does not work correctly for checking available spells
|
||||
if (game.inCheckPlayableState()) { // Cost modifaction does not work correctly for checking available spells
|
||||
return false;
|
||||
}
|
||||
if (abilityToModify.getId().equals(spellAbilityId) && abilityToModify instanceof SpellAbility) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageItem;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -41,10 +44,6 @@ import mage.players.Players;
|
|||
import mage.util.MessageToClient;
|
||||
import mage.util.functions.ApplyToPermanent;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface Game extends MageItem, Serializable {
|
||||
|
||||
MatchType getGameType();
|
||||
|
|
@ -131,7 +130,6 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
}
|
||||
|
||||
|
||||
default boolean isActivePlayer(UUID playerId) {
|
||||
return getActivePlayerId() != null && getActivePlayerId().equals(playerId);
|
||||
}
|
||||
|
|
@ -202,7 +200,11 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
boolean isSimulation();
|
||||
|
||||
void setSimulation(boolean simulation);
|
||||
void setSimulation(boolean checkPlayableState);
|
||||
|
||||
boolean inCheckPlayableState();
|
||||
|
||||
void setCheckPlayableState(boolean checkPlayableState);
|
||||
|
||||
MageObject getLastKnownInformation(UUID objectId, Zone zone);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package mage.game;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.MageException;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
|
|
@ -65,11 +69,6 @@ import mage.util.functions.ApplyToPermanent;
|
|||
import mage.watchers.common.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class GameImpl implements Game, Serializable {
|
||||
|
||||
private static final int ROLLBACK_TURNS_MAX = 4;
|
||||
|
|
@ -77,7 +76,9 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
private static final Logger logger = Logger.getLogger(GameImpl.class);
|
||||
|
||||
private transient Object customData;
|
||||
|
||||
protected boolean simulation = false;
|
||||
protected boolean checkPlayableState = false;
|
||||
|
||||
protected final UUID id;
|
||||
|
||||
|
|
@ -163,6 +164,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
this.state = game.state.copy();
|
||||
this.gameCards = game.gameCards;
|
||||
this.simulation = game.simulation;
|
||||
this.checkPlayableState = game.checkPlayableState;
|
||||
this.gameOptions = game.gameOptions;
|
||||
this.lki.putAll(game.lki);
|
||||
this.lkiExtended.putAll(game.lkiExtended);
|
||||
|
|
@ -188,6 +190,16 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
this.simulation = simulation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCheckPlayableState(boolean checkPlayableState) {
|
||||
this.checkPlayableState = checkPlayableState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inCheckPlayableState() {
|
||||
return checkPlayableState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
|
@ -2444,8 +2456,8 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
* exist. Then, if there are any objects still controlled by that player,
|
||||
* those objects are exiled. This is not a state-based action. It happens as
|
||||
* soon as the player leaves the game. If the player who left the game had
|
||||
* priority at the time they left, priority passes to the next player
|
||||
* in turn order who's still in the game. #
|
||||
* priority at the time they left, priority passes to the next player in
|
||||
* turn order who's still in the game. #
|
||||
*
|
||||
* @param playerId
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package mage.players;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.ConditionalMana;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
|
|
@ -65,10 +68,6 @@ import mage.util.GameLog;
|
|||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class PlayerImpl implements Player, Serializable {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PlayerImpl.class);
|
||||
|
|
@ -1589,6 +1588,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public LinkedHashMap<UUID, ActivatedAbility> getUseableActivatedAbilities(MageObject object, Zone zone, Game game) {
|
||||
game.setCheckPlayableState(true);
|
||||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||
if (object instanceof StackAbility) { // It may not be possible to activate abilities of stack abilities
|
||||
return useable;
|
||||
|
|
@ -1606,7 +1606,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
zone, game, object.getAbilities(), useable);
|
||||
}
|
||||
getOtherUseableActivatedAbilities(object, zone, game, useable);
|
||||
|
||||
game.setCheckPlayableState(false);
|
||||
return useable;
|
||||
}
|
||||
|
||||
|
|
@ -3049,8 +3049,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
*/
|
||||
protected boolean canPlay(ActivatedAbility ability, ManaOptions available, MageObject sourceObject, Game game) {
|
||||
if (!(ability instanceof ActivatedManaAbilityImpl)) {
|
||||
ActivatedAbility copy = ability.copy();
|
||||
copy.setCheckPlayableMode(); // prevents from endless loops for asking player to use effects by checking this mode
|
||||
ActivatedAbility copy = ability.copy(); // Copy is needed because cost reduction effects modify e.g. the mana to activate/cast the ability
|
||||
if (!copy.canActivate(playerId, game).canActivate()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3330,7 +3329,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
public List<Ability> getPlayable(Game game, boolean hidden, Zone fromZone, boolean hideDuplicatedAbilities) {
|
||||
List<Ability> playable = new ArrayList<>();
|
||||
|
||||
game.setCheckPlayableState(true);
|
||||
if (!shouldSkipGettingPlayable(game)) {
|
||||
ManaOptions availableMana = getManaAvailable(game);
|
||||
availableMana.addMana(manaPool.getMana());
|
||||
|
|
@ -3455,17 +3454,19 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
playable.addAll(activatedAll);
|
||||
}
|
||||
}
|
||||
|
||||
game.setCheckPlayableState(false);
|
||||
return playable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of card ids that are currently playable.<br>
|
||||
* Used to mark the playable cards in GameView
|
||||
* Also contains number of playable abilities for that object (it's just info, server decides to show choose dialog or not)
|
||||
* Used to mark the playable cards in GameView Also contains number of
|
||||
* playable abilities for that object (it's just info, server decides to
|
||||
* show choose dialog or not)
|
||||
*
|
||||
* @param game
|
||||
* @return A Set of cardIds that are playable and amount of playable abilities
|
||||
* @return A Set of cardIds that are playable and amount of playable
|
||||
* abilities
|
||||
*/
|
||||
@Override
|
||||
public Map<UUID, Integer> getPlayableObjects(Game game, Zone zone) {
|
||||
|
|
@ -3747,11 +3748,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
public boolean lookAtFaceDownCard(Card card, Game game, int abilitiesToActivate) {
|
||||
if (null != game.getContinuousEffects().asThough(card.getId(),
|
||||
AsThoughEffectType.LOOK_AT_FACE_DOWN, card.getSpellAbility(), this.getId(), game)) {
|
||||
// two modes: look at card or not to look and activate other abilities
|
||||
String lookMessage = abilitiesToActivate > 0 ? "Look at that card (it's have "
|
||||
+ abilitiesToActivate + " abilities to activate)?" : "Look at that card?";
|
||||
String lookYes = "Yes, look at card";
|
||||
String lookNo = abilitiesToActivate > 0 ? "No, activate ability" : "No";
|
||||
// two modes: look at the card or do not look and activate other abilities
|
||||
String lookMessage = "Look at " + card.getIdName();
|
||||
String lookYes = "Yes, look at the card";
|
||||
String lookNo = "No, play/activate the card/ability";
|
||||
if (chooseUse(Outcome.Benefit, lookMessage, "", lookYes, lookNo, null, game)) {
|
||||
Cards cards = new CardsImpl(card);
|
||||
this.lookAtCards(getName() + " - " + card.getIdName() + " - "
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package mage.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.abilities.costs.mana.*;
|
||||
|
|
@ -15,10 +17,6 @@ import mage.game.permanent.Permanent;
|
|||
import mage.game.permanent.token.Token;
|
||||
import mage.util.functions.CopyTokenFunction;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
|
|
@ -489,20 +487,6 @@ public final class CardUtil {
|
|||
return uniqueString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the ability is used to check which cards are playable on hand.
|
||||
* (Issue #457)
|
||||
*
|
||||
* @param ability - ability to check
|
||||
* @return
|
||||
*/
|
||||
public static boolean isCheckPlayableMode(Ability ability) {
|
||||
if (ability instanceof ActivatedAbility) {
|
||||
return ((ActivatedAbility) ability).isCheckPlayableMode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tags to mark the additional info of a card (e.g. blue font color)
|
||||
*
|
||||
|
|
@ -560,7 +544,8 @@ public final class CardUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Face down cards and their copy tokens don't have names and that's "empty" names is not equals
|
||||
* Face down cards and their copy tokens don't have names and that's "empty"
|
||||
* names is not equals
|
||||
*/
|
||||
public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) {
|
||||
if (ignoreMtgRuleForEmptyNames) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue