mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Make required status of target based on the type of ability
This commit is contained in:
parent
c0aa97802e
commit
250909a464
6 changed files with 40 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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)}
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue