Modify implementation of Target's required status

This commit is contained in:
Quercitron 2014-06-15 19:23:30 +04:00
parent 6c8b818d89
commit 9629c3f0f5
3 changed files with 13 additions and 4 deletions

View file

@ -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 = true;
boolean required = target.isRequired();
// if there is no cards to select from, then add possibility to cancel choosing action
if (cards == null) {
required = false;

View file

@ -93,6 +93,7 @@ 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);

View file

@ -54,7 +54,8 @@ public abstract class TargetImpl implements Target {
protected Zone zone;
protected int maxNumberOfTargets;
protected int minNumberOfTargets;
protected boolean required = false;
protected boolean required = true;
protected boolean requiredExplicitlySet = false;
protected boolean chosen = false;
// is the target handled as targeted spell/ability (notTarget = true is used for not targeted effects like e.g. sacrifice)
protected boolean notTarget = false;
@ -77,6 +78,7 @@ public abstract class TargetImpl implements Target {
this.maxNumberOfTargets = target.maxNumberOfTargets;
this.minNumberOfTargets = target.minNumberOfTargets;
this.required = target.required;
this.requiredExplicitlySet = target.requiredExplicitlySet;
this.chosen = target.chosen;
this.targets.putAll(target.targets);
this.zoneChangeCounters.putAll(target.zoneChangeCounters);
@ -148,13 +150,18 @@ public abstract class TargetImpl implements Target {
@Override
public boolean isRequired(UUID sourceId, Game game) {
MageObject object = game.getObject(sourceId);
if (object != null && object instanceof Ability) {
if (!requiredExplicitlySet && object != null && object instanceof Ability) {
return isRequired((Ability) object);
} else {
return required;
return isRequired();
}
}
@Override
public boolean isRequired() {
return required;
}
@Override
public boolean isRequired(Ability ability) {
return ability.isActivated() || !(ability.getAbilityType().equals(AbilityType.SPELL) || ability.getAbilityType().equals(AbilityType.ACTIVATED));
@ -163,6 +170,7 @@ public abstract class TargetImpl implements Target {
@Override
public void setRequired(boolean required) {
this.required = required;
this.requiredExplicitlySet = true;
}
@Override