mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +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);
|
updateGameStatePriority("choose(5)", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
Set<UUID> cards = target.possibleTargets(null, playerId, game);
|
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);
|
waitForResponse(game);
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
if (target instanceof TargetPermanent) {
|
if (target instanceof TargetPermanent) {
|
||||||
|
@ -275,7 +275,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (target.getTargets().size() >= target.getNumberOfTargets()) {
|
if (target.getTargets().size() >= target.getNumberOfTargets()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!target.isRequired()) {
|
if (!target.isRequired(sourceId, game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (cards == null || cards.isEmpty()) {
|
if (cards == null || cards.isEmpty()) {
|
||||||
|
@ -291,7 +291,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
updateGameStatePriority("chooseTarget", game);
|
updateGameStatePriority("chooseTarget", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
|
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));
|
game.fireSelectTargetEvent(playerId, target.getMessage(), possibleTargets, required, getOptions(target));
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
|
@ -330,7 +330,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||||
updateGameStatePriority("choose(4)", game);
|
updateGameStatePriority("choose(4)", game);
|
||||||
while (!abort) {
|
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 there is no cards to select from, then add possibility to cancel choosing action
|
||||||
if (cards == null) {
|
if (cards == null) {
|
||||||
required = false;
|
required = false;
|
||||||
|
@ -373,7 +373,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||||
updateGameStatePriority("chooseTarget(5)", game);
|
updateGameStatePriority("chooseTarget(5)", game);
|
||||||
while (!abort) {
|
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 there is no cards to select from, then add possibility to cancel choosing action
|
||||||
if (cards == null) {
|
if (cards == null) {
|
||||||
required = false;
|
required = false;
|
||||||
|
@ -383,7 +383,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
required = false;
|
required = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(), null);
|
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(source), null);
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
if (target.canTarget(response.getUUID(), cards, game)) {
|
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) {
|
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
||||||
updateGameStatePriority("chooseTargetAmount", game);
|
updateGameStatePriority("chooseTargetAmount", game);
|
||||||
while (!abort) {
|
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);
|
waitForResponse(game);
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
if (target.canTarget(response.getUUID(), source, game)) {
|
if (target.canTarget(response.getUUID(), source, game)) {
|
||||||
|
@ -417,7 +417,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
target.addTarget(targetId, amountSelected, source, game);
|
target.addTarget(targetId, amountSelected, source, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (!target.isRequired()) {
|
} else if (!target.isRequired(source)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -765,7 +765,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
protected void selectCombatGroup(UUID defenderId, UUID blockerId, Game game) {
|
protected void selectCombatGroup(UUID defenderId, UUID blockerId, Game game) {
|
||||||
updateGameStatePriority("selectCombatGroup", game);
|
updateGameStatePriority("selectCombatGroup", game);
|
||||||
TargetAttackingCreature target = new TargetAttackingCreature();
|
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);
|
waitForResponse(game);
|
||||||
if (response.getBoolean() != null) {
|
if (response.getBoolean() != null) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
|
@ -314,6 +314,8 @@ public interface Ability extends Controllable, Serializable {
|
||||||
*/
|
*/
|
||||||
boolean activate(Game game, boolean noMana);
|
boolean activate(Game game, boolean noMana);
|
||||||
|
|
||||||
|
boolean isActivated();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves this ability and puts any effects it produces into play. This
|
* 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)}
|
* 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 ruleVisible = true;
|
||||||
protected boolean ruleAdditionalCostsVisible = true;
|
protected boolean ruleAdditionalCostsVisible = true;
|
||||||
protected boolean costModificationActive = true;
|
protected boolean costModificationActive = true;
|
||||||
|
protected boolean activated = false;
|
||||||
|
|
||||||
public AbilityImpl(AbilityType abilityType, Zone zone) {
|
public AbilityImpl(AbilityType abilityType, Zone zone) {
|
||||||
this.id = UUID.randomUUID();
|
this.id = UUID.randomUUID();
|
||||||
|
@ -365,8 +366,14 @@ public abstract class AbilityImpl implements Ability {
|
||||||
int xValue = getManaCostsToPay().getX();
|
int xValue = getManaCostsToPay().getX();
|
||||||
game.informPlayers(new StringBuilder(controller.getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString());
|
game.informPlayers(new StringBuilder(controller.getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString());
|
||||||
}
|
}
|
||||||
|
activated = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActivated() {
|
||||||
|
return activated;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the setting of non mana X costs
|
* Handles the setting of non mana X costs
|
||||||
|
|
|
@ -86,6 +86,11 @@ public class StackAbility implements StackObject, Ability {
|
||||||
this.expansionSetCode = spell.expansionSetCode;
|
this.expansionSetCode = spell.expansionSetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActivated() {
|
||||||
|
return ability.isActivated();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean resolve(Game game) {
|
public boolean resolve(Game game) {
|
||||||
if (ability.getTargets().stillLegal(ability, game)) {
|
if (ability.getTargets().stillLegal(ability, game)) {
|
||||||
|
|
|
@ -93,7 +93,8 @@ public interface Target extends Serializable {
|
||||||
List<UUID> getTargets();
|
List<UUID> getTargets();
|
||||||
Filter getFilter();
|
Filter getFilter();
|
||||||
|
|
||||||
boolean isRequired();
|
boolean isRequired(UUID sourceId, Game game);
|
||||||
|
boolean isRequired(Ability ability);
|
||||||
void setRequired(boolean required);
|
void setRequired(boolean required);
|
||||||
|
|
||||||
boolean isRandom();
|
boolean isRandom();
|
||||||
|
|
|
@ -38,6 +38,8 @@ import mage.game.events.GameEvent.EventType;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import mage.MageObject;
|
||||||
|
import mage.constants.AbilityType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -142,10 +144,20 @@ public abstract class TargetImpl implements Target {
|
||||||
public Zone getZone() {
|
public Zone getZone() {
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRequired() {
|
public boolean isRequired(UUID sourceId, Game game) {
|
||||||
return required;
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue