From 250909a464e1b9167cf1c352f38f9daac074527e Mon Sep 17 00:00:00 2001 From: Quercitron Date: Thu, 12 Jun 2014 23:35:56 +0400 Subject: [PATCH] Make required status of target based on the type of ability --- .../src/mage/player/human/HumanPlayer.java | 18 +++++++++--------- Mage/src/mage/abilities/Ability.java | 2 ++ Mage/src/mage/abilities/AbilityImpl.java | 7 +++++++ Mage/src/mage/game/stack/StackAbility.java | 5 +++++ Mage/src/mage/target/Target.java | 3 ++- Mage/src/mage/target/TargetImpl.java | 18 +++++++++++++++--- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 7f51ea9930..b8effe5442 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -243,7 +243,7 @@ public class HumanPlayer extends PlayerImpl { updateGameStatePriority("choose(5)", game); while (!abort) { Set cards = target.possibleTargets(null, playerId, game); - game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(), options); + game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(sourceId, game), options); waitForResponse(game); if (response.getUUID() != null) { if (target instanceof TargetPermanent) { @@ -275,7 +275,7 @@ public class HumanPlayer extends PlayerImpl { if (target.getTargets().size() >= target.getNumberOfTargets()) { return true; } - if (!target.isRequired()) { + if (!target.isRequired(sourceId, game)) { return false; } if (cards == null || cards.isEmpty()) { @@ -291,7 +291,7 @@ public class HumanPlayer extends PlayerImpl { updateGameStatePriority("chooseTarget", game); while (!abort) { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); - boolean required = possibleTargets.isEmpty() ? false : target.isRequired(); + boolean required = possibleTargets.isEmpty() ? false : target.isRequired(source); game.fireSelectTargetEvent(playerId, target.getMessage(), possibleTargets, required, getOptions(target)); waitForResponse(game); if (response.getUUID() != null) { @@ -330,7 +330,7 @@ public class HumanPlayer extends PlayerImpl { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { updateGameStatePriority("choose(4)", game); while (!abort) { - boolean required = target.isRequired(); + boolean required = true; // if there is no cards to select from, then add possibility to cancel choosing action if (cards == null) { required = false; @@ -373,7 +373,7 @@ public class HumanPlayer extends PlayerImpl { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { updateGameStatePriority("chooseTarget(5)", game); while (!abort) { - boolean required = target.isRequired(); + boolean required = target.isRequired(source); // if there is no cards to select from, then add possibility to cancel choosing action if (cards == null) { required = false; @@ -383,7 +383,7 @@ public class HumanPlayer extends PlayerImpl { required = false; } } - game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(), null); + game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(source), null); waitForResponse(game); if (response.getUUID() != null) { if (target.canTarget(response.getUUID(), cards, game)) { @@ -408,7 +408,7 @@ public class HumanPlayer extends PlayerImpl { public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { updateGameStatePriority("chooseTargetAmount", game); while (!abort) { - game.fireSelectTargetEvent(playerId, target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired(), null); + game.fireSelectTargetEvent(playerId, target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired(source), null); waitForResponse(game); if (response.getUUID() != null) { if (target.canTarget(response.getUUID(), source, game)) { @@ -417,7 +417,7 @@ public class HumanPlayer extends PlayerImpl { target.addTarget(targetId, amountSelected, source, game); return true; } - } else if (!target.isRequired()) { + } else if (!target.isRequired(source)) { return false; } } @@ -765,7 +765,7 @@ public class HumanPlayer extends PlayerImpl { protected void selectCombatGroup(UUID defenderId, UUID blockerId, Game game) { updateGameStatePriority("selectCombatGroup", game); TargetAttackingCreature target = new TargetAttackingCreature(); - game.fireSelectTargetEvent(playerId, "Select attacker to block", target.possibleTargets(null, playerId, game), target.isRequired(), null); + game.fireSelectTargetEvent(playerId, "Select attacker to block", target.possibleTargets(null, playerId, game), false, null); waitForResponse(game); if (response.getBoolean() != null) { // do nothing diff --git a/Mage/src/mage/abilities/Ability.java b/Mage/src/mage/abilities/Ability.java index ab7fa73a00..2bc9a56941 100644 --- a/Mage/src/mage/abilities/Ability.java +++ b/Mage/src/mage/abilities/Ability.java @@ -314,6 +314,8 @@ public interface Ability extends Controllable, Serializable { */ boolean activate(Game game, boolean noMana); + boolean isActivated(); + /** * Resolves this ability and puts any effects it produces into play. This * method should only be called if the {@link #activate(mage.game.Game, boolean)} diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 4713c812e3..620abe4148 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -97,6 +97,7 @@ public abstract class AbilityImpl implements Ability { protected boolean ruleVisible = true; protected boolean ruleAdditionalCostsVisible = true; protected boolean costModificationActive = true; + protected boolean activated = false; public AbilityImpl(AbilityType abilityType, Zone zone) { this.id = UUID.randomUUID(); @@ -365,8 +366,14 @@ public abstract class AbilityImpl implements Ability { int xValue = getManaCostsToPay().getX(); game.informPlayers(new StringBuilder(controller.getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString()); } + activated = true; return true; } + + @Override + public boolean isActivated() { + return activated; + } /** * Handles the setting of non mana X costs diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java index 2f2defe72b..00d0ca0278 100644 --- a/Mage/src/mage/game/stack/StackAbility.java +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -86,6 +86,11 @@ public class StackAbility implements StackObject, Ability { this.expansionSetCode = spell.expansionSetCode; } + @Override + public boolean isActivated() { + return ability.isActivated(); + } + @Override public boolean resolve(Game game) { if (ability.getTargets().stillLegal(ability, game)) { diff --git a/Mage/src/mage/target/Target.java b/Mage/src/mage/target/Target.java index 84a34d1afb..1e4cb8247e 100644 --- a/Mage/src/mage/target/Target.java +++ b/Mage/src/mage/target/Target.java @@ -93,7 +93,8 @@ public interface Target extends Serializable { List getTargets(); Filter getFilter(); - boolean isRequired(); + boolean isRequired(UUID sourceId, Game game); + boolean isRequired(Ability ability); void setRequired(boolean required); boolean isRandom(); diff --git a/Mage/src/mage/target/TargetImpl.java b/Mage/src/mage/target/TargetImpl.java index 2854665787..18ef3bf515 100644 --- a/Mage/src/mage/target/TargetImpl.java +++ b/Mage/src/mage/target/TargetImpl.java @@ -38,6 +38,8 @@ import mage.game.events.GameEvent.EventType; import mage.players.Player; import java.util.*; +import mage.MageObject; +import mage.constants.AbilityType; /** * @@ -142,10 +144,20 @@ public abstract class TargetImpl implements Target { public Zone getZone() { return zone; } - + @Override - public boolean isRequired() { - return required; + public boolean isRequired(UUID sourceId, Game game) { + MageObject object = game.getObject(sourceId); + if (object != null && object instanceof Ability) { + return isRequired((Ability) object); + } else { + return required; + } + } + + @Override + public boolean isRequired(Ability ability) { + return ability.isActivated() || !(ability.getAbilityType().equals(AbilityType.SPELL) || ability.getAbilityType().equals(AbilityType.ACTIVATED)); } @Override