mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Fixed mode handling for modes that can be selected multiple times.
This commit is contained in:
parent
8df5bfa251
commit
24fc597fe5
7 changed files with 188 additions and 40 deletions
|
|
@ -307,8 +307,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
return false;
|
||||
}
|
||||
for (UUID modeId : this.getModes().getSelectedModes()) {
|
||||
Mode mode = this.getModes().get(modeId);
|
||||
this.getModes().setActiveMode(mode);
|
||||
this.getModes().setActiveMode(modeId);
|
||||
//20121001 - 601.2c
|
||||
// 601.2c The player announces his or her choice of an appropriate player, object, or zone for
|
||||
// each target the spell requires. A spell may require some targets only if an alternative or
|
||||
|
|
@ -330,7 +329,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
sourceObject.adjustTargets(this, game);
|
||||
}
|
||||
// Flashback abilities haven't made the choices the underlying spell might need for targetting.
|
||||
if (!(this instanceof FlashbackAbility) && mode.getTargets().size() > 0 && mode.getTargets().chooseTargets(
|
||||
if (!(this instanceof FlashbackAbility) && getTargets().size() > 0 && getTargets().chooseTargets(
|
||||
getEffects().get(0).getOutcome(), this.controllerId, this, noMana, game) == false) {
|
||||
if ((variableManaCost != null || announceString != null) && !game.isSimulation()) {
|
||||
game.informPlayer(controller, (sourceObject != null ? sourceObject.getIdName() : "") + ": no valid targets with this value of X");
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
|
|
@ -54,6 +54,10 @@ public class Mode implements Serializable {
|
|||
this.effects = mode.effects.copy();
|
||||
}
|
||||
|
||||
public UUID setRandomId() {
|
||||
return this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public Mode copy() {
|
||||
return new Mode(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,13 +55,14 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
private TargetController modeChooser;
|
||||
private boolean eachModeMoreThanOnce; // each mode can be selected multiple times during one choice
|
||||
private boolean eachModeOnlyOnce; // state if each mode can be chosen only once as long as the source object exists
|
||||
private final LinkedHashMap<UUID, Mode> duplicateModes = new LinkedHashMap<>();
|
||||
|
||||
public Modes() {
|
||||
this.currentMode = new Mode();
|
||||
this.put(currentMode.getId(), currentMode);
|
||||
this.minModes = 1;
|
||||
this.maxModes = 1;
|
||||
this.selectedModes.add(currentMode.getId());
|
||||
this.addSelectedMode(currentMode.getId());
|
||||
this.modeChooser = TargetController.YOU;
|
||||
this.eachModeOnlyOnce = false;
|
||||
this.eachModeMoreThanOnce = false;
|
||||
|
|
@ -71,6 +72,9 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
for (Map.Entry<UUID, Mode> entry : modes.entrySet()) {
|
||||
this.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
for (Map.Entry<UUID, Mode> entry : modes.duplicateModes.entrySet()) {
|
||||
this.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
this.minModes = modes.minModes;
|
||||
this.maxModes = modes.maxModes;
|
||||
this.selectedModes.addAll(modes.getSelectedModes());
|
||||
|
|
@ -78,7 +82,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
if (modes.getSelectedModes().isEmpty()) {
|
||||
this.currentMode = values().iterator().next();
|
||||
} else {
|
||||
this.currentMode = get(selectedModes.get(0));
|
||||
this.currentMode = get(modes.getMode().getId());
|
||||
}
|
||||
this.modeChooser = modes.modeChooser;
|
||||
this.eachModeOnlyOnce = modes.eachModeOnlyOnce;
|
||||
|
|
@ -89,16 +93,41 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
return new Modes(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mode get(Object key) {
|
||||
Mode modeToGet = super.get(key);
|
||||
if (modeToGet == null && eachModeMoreThanOnce) {
|
||||
modeToGet = duplicateModes.get(key);
|
||||
}
|
||||
return modeToGet;
|
||||
}
|
||||
|
||||
public Mode getMode() {
|
||||
return currentMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mode by index. For modal spells with eachModeMoreThanOnce,
|
||||
* the index returns the n selected mode
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public UUID getModeId(int index) {
|
||||
int idx = 0;
|
||||
for (Mode mode : this.values()) {
|
||||
idx++;
|
||||
if (idx == index) {
|
||||
return mode.getId();
|
||||
if (eachModeMoreThanOnce) {
|
||||
for (UUID modeId : this.selectedModes) {
|
||||
idx++;
|
||||
if (idx == index) {
|
||||
return modeId;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Mode mode : this.values()) {
|
||||
idx++;
|
||||
if (idx == index) {
|
||||
return mode.getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -138,6 +167,12 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
}
|
||||
}
|
||||
|
||||
public void setActiveMode(UUID modeId) {
|
||||
if (selectedModes.contains(modeId)) {
|
||||
this.currentMode = get(modeId);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMode(Mode mode) {
|
||||
this.put(mode.getId(), mode);
|
||||
}
|
||||
|
|
@ -145,6 +180,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
public boolean choose(Game game, Ability source) {
|
||||
if (this.size() > 1) {
|
||||
this.selectedModes.clear();
|
||||
this.duplicateModes.clear();
|
||||
// check if mode modifying abilities exist
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
|
|
@ -163,7 +199,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
for (Mode mode : this.values()) {
|
||||
if ((!isEachModeOnlyOnce() || onceSelectedModes == null || !onceSelectedModes.contains(mode.getId()))
|
||||
&& mode.getTargets().canChoose(source.getSourceId(), source.getControllerId(), game)) {
|
||||
this.selectedModes.add(mode.getId());
|
||||
this.addSelectedMode(mode.getId());
|
||||
}
|
||||
}
|
||||
if (isEachModeOnlyOnce()) {
|
||||
|
|
@ -200,7 +236,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
}
|
||||
return this.selectedModes.size() >= this.getMinModes();
|
||||
}
|
||||
this.selectedModes.add(choice.getId());
|
||||
this.addSelectedMode(choice.getId());
|
||||
if (currentMode == null) {
|
||||
currentMode = choice;
|
||||
}
|
||||
|
|
@ -209,17 +245,15 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
setAlreadySelectedModes(selectedModes, source, game);
|
||||
}
|
||||
return true;
|
||||
} else { // only one mode
|
||||
if (currentMode == null) {
|
||||
this.selectedModes.clear();
|
||||
Mode mode = this.values().iterator().next();
|
||||
this.addSelectedMode(mode.getId());
|
||||
this.setActiveMode(mode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (currentMode == null) {
|
||||
this.selectedModes.clear();
|
||||
Mode copiedMode = this.values().iterator().next().copy();
|
||||
this.selectedModes.add(copiedMode.getId());
|
||||
this.setActiveMode(copiedMode);
|
||||
}
|
||||
if (isEachModeOnlyOnce()) {
|
||||
setAlreadySelectedModes(selectedModes, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -236,6 +270,23 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a mode as selected. If the mode is already selected, it copies the
|
||||
* mode and adds it to the duplicate modes
|
||||
*
|
||||
* @param modeId
|
||||
*/
|
||||
private void addSelectedMode(UUID modeId) {
|
||||
if (selectedModes.contains(modeId) && eachModeMoreThanOnce) {
|
||||
Mode duplicateMode = get(modeId).copy();
|
||||
duplicateMode.setRandomId();
|
||||
modeId = duplicateMode.getId();
|
||||
duplicateModes.put(modeId, duplicateMode);
|
||||
|
||||
}
|
||||
this.selectedModes.add(modeId);
|
||||
}
|
||||
|
||||
// The already once selected modes for a modal card are stored as a state value
|
||||
// That's important for modal abilities with modes that can only selected once while the object stays in its zone
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -211,9 +211,8 @@ public class Spell extends StackObjImpl implements Card {
|
|||
for (SpellAbility spellAbility : this.spellAbilities) {
|
||||
if (spellAbilityHasLegalParts(spellAbility, game)) {
|
||||
for (UUID modeId : spellAbility.getModes().getSelectedModes()) {
|
||||
Mode mode = spellAbility.getModes().get(modeId);
|
||||
spellAbility.getModes().setActiveMode(mode);
|
||||
if (mode.getTargets().stillLegal(spellAbility, game)) {
|
||||
spellAbility.getModes().setActiveMode(modeId);
|
||||
if (spellAbility.getTargets().stillLegal(spellAbility, game)) {
|
||||
if (!spellAbility.getSpellAbilityType().equals(SpellAbilityType.SPLICE)) {
|
||||
updateOptionalCosts(index);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue