Make required status of target based on the type of ability

This commit is contained in:
Quercitron 2014-06-12 23:35:56 +04:00
parent c0aa97802e
commit 250909a464
6 changed files with 40 additions and 13 deletions

View file

@ -243,7 +243,7 @@ public class HumanPlayer extends PlayerImpl {
updateGameStatePriority("choose(5)", game);
while (!abort) {
Set<UUID> 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<UUID> 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

View file

@ -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)}

View file

@ -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,9 +366,15 @@ 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
* @param controller *

View file

@ -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)) {

View file

@ -93,7 +93,8 @@ public interface Target extends Serializable {
List<UUID> getTargets();
Filter getFilter();
boolean isRequired();
boolean isRequired(UUID sourceId, Game game);
boolean isRequired(Ability ability);
void setRequired(boolean required);
boolean isRandom();

View file

@ -38,6 +38,8 @@ import mage.game.events.GameEvent.EventType;
import mage.players.Player;
import java.util.*;
import mage.MageObject;
import mage.constants.AbilityType;
/**
*
@ -144,9 +146,19 @@ public abstract class TargetImpl implements Target {
}
@Override
public boolean isRequired() {
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
public void setRequired(boolean required) {