mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Fixed wrong selection count in choose ability mode dialog (cards like Planewide Celebration);
This commit is contained in:
parent
57cb023f78
commit
1d20069ddf
2 changed files with 58 additions and 21 deletions
|
@ -710,9 +710,9 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
String selectedNames = target.getTargetedName(game);
|
String selectedNames = target.getTargetedName(game);
|
||||||
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage()
|
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage()
|
||||||
+ "<br> Amount remaining: " + target.getAmountRemaining()
|
+ "<br> Amount remaining: " + target.getAmountRemaining()
|
||||||
+ (selectedNames.isEmpty() ? "" : ", selected: " + selectedNames),
|
+ (selectedNames.isEmpty() ? "" : ", selected: " + selectedNames),
|
||||||
getRelatedObjectName(source, game)),
|
getRelatedObjectName(source, game)),
|
||||||
target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game),
|
target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game),
|
||||||
target.isRequired(source),
|
target.isRequired(source),
|
||||||
getOptions(target, null));
|
getOptions(target, null));
|
||||||
|
@ -725,7 +725,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
boolean removeMode = target.getTargets().contains(targetId)
|
boolean removeMode = target.getTargets().contains(targetId)
|
||||||
&& chooseUse(outcome, "What do you want to do with " + (targetObject != null ? targetObject.getLogName() : "target") + "?", "",
|
&& chooseUse(outcome, "What do you want to do with " + (targetObject != null ? targetObject.getLogName() : "target") + "?", "",
|
||||||
"Remove from selected", "Add extra amount", source, game);
|
"Remove from selected", "Add extra amount", source, game);
|
||||||
|
|
||||||
if (removeMode) {
|
if (removeMode) {
|
||||||
target.remove(targetId);
|
target.remove(targetId);
|
||||||
|
@ -862,9 +862,9 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (!skippedAtLeastOnce
|
if (!skippedAtLeastOnce
|
||||||
|| (playerId.equals(game.getActivePlayerId())
|
|| (playerId.equals(game.getActivePlayerId())
|
||||||
&& !controllingPlayer
|
&& !controllingPlayer
|
||||||
.getUserData()
|
.getUserData()
|
||||||
.getUserSkipPrioritySteps()
|
.getUserSkipPrioritySteps()
|
||||||
.isStopOnAllEndPhases())) {
|
.isStopOnAllEndPhases())) {
|
||||||
skippedAtLeastOnce = true;
|
skippedAtLeastOnce = true;
|
||||||
if (passWithManaPoolCheck(game)) {
|
if (passWithManaPoolCheck(game)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -896,9 +896,9 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (haveNewObjectsOnStack
|
if (haveNewObjectsOnStack
|
||||||
&& (playerId.equals(game.getActivePlayerId())
|
&& (playerId.equals(game.getActivePlayerId())
|
||||||
&& controllingPlayer
|
&& controllingPlayer
|
||||||
.getUserData()
|
.getUserData()
|
||||||
.getUserSkipPrioritySteps()
|
.getUserSkipPrioritySteps()
|
||||||
.isStopOnStackNewObjects())) {
|
.isStopOnStackNewObjects())) {
|
||||||
// new objects on stack -- disable "pass until stack resolved"
|
// new objects on stack -- disable "pass until stack resolved"
|
||||||
passedUntilStackResolved = false;
|
passedUntilStackResolved = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1235,8 +1235,8 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (passedAllTurns
|
if (passedAllTurns
|
||||||
|| passedUntilEndStepBeforeMyTurn
|
|| passedUntilEndStepBeforeMyTurn
|
||||||
|| (!getControllingPlayersUserData(game)
|
|| (!getControllingPlayersUserData(game)
|
||||||
.getUserSkipPrioritySteps()
|
.getUserSkipPrioritySteps()
|
||||||
.isStopOnDeclareAttackers()
|
.isStopOnDeclareAttackers()
|
||||||
&& (passedTurn
|
&& (passedTurn
|
||||||
|| passedTurnSkipStack
|
|| passedTurnSkipStack
|
||||||
|| passedUntilEndOfTurn
|
|| passedUntilEndOfTurn
|
||||||
|
@ -1419,7 +1419,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
/**
|
/**
|
||||||
* Selects a defender for an attacker and adds the attacker to combat
|
* Selects a defender for an attacker and adds the attacker to combat
|
||||||
*
|
*
|
||||||
* @param defenders - list of possible defender
|
* @param defenders - list of possible defender
|
||||||
* @param attackerId - UUID of attacker
|
* @param attackerId - UUID of attacker
|
||||||
* @param game
|
* @param game
|
||||||
* @return
|
* @return
|
||||||
|
@ -1817,17 +1817,20 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
Map<UUID, String> modeMap = new LinkedHashMap<>();
|
Map<UUID, String> modeMap = new LinkedHashMap<>();
|
||||||
AvailableModes:
|
AvailableModes:
|
||||||
for (Mode mode : modes.getAvailableModes(source, game)) {
|
for (Mode mode : modes.getAvailableModes(source, game)) {
|
||||||
int timesSelected = 0;
|
int timesSelected = modes.getSelectedStats(mode.getId());
|
||||||
for (UUID selectedModeId : modes.getSelectedModes()) {
|
for (UUID selectedModeId : modes.getSelectedModes()) {
|
||||||
Mode selectedMode = modes.get(selectedModeId);
|
Mode selectedMode = modes.get(selectedModeId);
|
||||||
if (mode.getId().equals(selectedMode.getId())) {
|
if (mode.getId().equals(selectedMode.getId())) {
|
||||||
|
// mode selected
|
||||||
if (modes.isEachModeMoreThanOnce()) {
|
if (modes.isEachModeMoreThanOnce()) {
|
||||||
timesSelected++;
|
// can select again
|
||||||
} else {
|
} else {
|
||||||
continue AvailableModes;
|
// hide mode from dialog
|
||||||
|
continue AvailableModes; // TODO: test 2x cheat here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.getTargets().canChoose(source.getSourceId(), source.getControllerId(), game)) { // and needed targets have to be available
|
if (mode.getTargets().canChoose(source.getSourceId(), source.getControllerId(), game)) { // and needed targets have to be available
|
||||||
String modeText = mode.getEffects().getText(mode);
|
String modeText = mode.getEffects().getText(mode);
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
|
@ -1852,11 +1855,12 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
for (Mode mode : modes.getAvailableModes(source, game)) {
|
for (Mode mode : modes.getAvailableModes(source, game)) {
|
||||||
if (mode.getId().equals(response.getUUID())) {
|
if (mode.getId().equals(response.getUUID())) {
|
||||||
|
// TODO: add checks on 2x selects (cheaters can rewrite client side code and select same mode multiple times)
|
||||||
|
// reason: wrong setup eachModeMoreThanOnce and eachModeOnlyOnce in many cards
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (modes.getSelectedModes().size() >= modes.getMinModes()) {
|
||||||
else if (modes.getSelectedModes().size() >= modes.getMinModes()) {
|
|
||||||
/* let the player cancel mode selection if they do not need to select any further modes */
|
/* let the player cancel mode selection if they do not need to select any further modes */
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,15 @@ import java.util.*;
|
||||||
public class Modes extends LinkedHashMap<UUID, Mode> {
|
public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
|
|
||||||
private Mode currentMode; // the current mode of the selected modes
|
private Mode currentMode; // the current mode of the selected modes
|
||||||
private final List<UUID> selectedModes = new ArrayList<>();
|
private final List<UUID> selectedModes = new ArrayList<>(); // all selected modes (this + duplicate)
|
||||||
|
private final Map<UUID, Mode> duplicateModes = new LinkedHashMap<>(); // for 2x selects: copy mode and put it to duplicate list
|
||||||
|
private final Map<UUID, UUID> duplicateToOriginalModeRefs = new LinkedHashMap<>(); // for 2x selects: stores ref from duplicate to original mode
|
||||||
|
|
||||||
private int minModes;
|
private int minModes;
|
||||||
private int maxModes;
|
private int maxModes;
|
||||||
private TargetController modeChooser;
|
private TargetController modeChooser;
|
||||||
private boolean eachModeMoreThanOnce; // each mode can be selected multiple times during one choice
|
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 boolean eachModeOnlyOnce; // state if each mode can be chosen only once as long as the source object exists
|
||||||
private final Map<UUID, Mode> duplicateModes = new LinkedHashMap<>();
|
|
||||||
private OptionalAdditionalModeSourceCosts optionalAdditionalModeSourceCosts = null; // only set if costs have to be paid
|
private OptionalAdditionalModeSourceCosts optionalAdditionalModeSourceCosts = null; // only set if costs have to be paid
|
||||||
private Filter maxModesFilter = null; // calculates the max number of available modes
|
private Filter maxModesFilter = null; // calculates the max number of available modes
|
||||||
private boolean isRandom = false;
|
private boolean isRandom = false;
|
||||||
|
@ -49,6 +51,8 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
for (Map.Entry<UUID, Mode> entry : modes.duplicateModes.entrySet()) {
|
for (Map.Entry<UUID, Mode> entry : modes.duplicateModes.entrySet()) {
|
||||||
duplicateModes.put(entry.getKey(), entry.getValue().copy());
|
duplicateModes.put(entry.getKey(), entry.getValue().copy());
|
||||||
}
|
}
|
||||||
|
duplicateToOriginalModeRefs.putAll(modes.duplicateToOriginalModeRefs);
|
||||||
|
|
||||||
this.minModes = modes.minModes;
|
this.minModes = modes.minModes;
|
||||||
this.maxModes = modes.maxModes;
|
this.maxModes = modes.maxModes;
|
||||||
this.selectedModes.addAll(modes.getSelectedModes());
|
this.selectedModes.addAll(modes.getSelectedModes());
|
||||||
|
@ -116,6 +120,32 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
return selectedModes;
|
return selectedModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSelectedStats(UUID modeId) {
|
||||||
|
int count = 0;
|
||||||
|
if (this.selectedModes.contains(modeId)) {
|
||||||
|
|
||||||
|
// single select
|
||||||
|
count++;
|
||||||
|
|
||||||
|
// multiple select (all 2x select generate new duplicate mode)
|
||||||
|
UUID originalId;
|
||||||
|
if (this.duplicateModes.containsKey(modeId)) {
|
||||||
|
// modeId is duplicate
|
||||||
|
originalId = this.duplicateToOriginalModeRefs.get(modeId);
|
||||||
|
} else {
|
||||||
|
// modeId is original
|
||||||
|
originalId = modeId;
|
||||||
|
}
|
||||||
|
for (UUID id : this.duplicateToOriginalModeRefs.values()) {
|
||||||
|
if (id.equals(originalId)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMinModes(int minModes) {
|
public void setMinModes(int minModes) {
|
||||||
this.minModes = minModes;
|
this.minModes = minModes;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +198,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
if (this.size() > 1) {
|
if (this.size() > 1) {
|
||||||
this.selectedModes.clear();
|
this.selectedModes.clear();
|
||||||
this.duplicateModes.clear();
|
this.duplicateModes.clear();
|
||||||
|
this.duplicateToOriginalModeRefs.clear();
|
||||||
if (this.isRandom) {
|
if (this.isRandom) {
|
||||||
List<Mode> modes = getAvailableModes(source, game);
|
List<Mode> modes = getAvailableModes(source, game);
|
||||||
this.addSelectedMode(modes.get(RandomUtil.nextInt(modes.size())).getId());
|
this.addSelectedMode(modes.get(RandomUtil.nextInt(modes.size())).getId());
|
||||||
|
@ -286,9 +317,11 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
private void addSelectedMode(UUID modeId) {
|
private void addSelectedMode(UUID modeId) {
|
||||||
if (selectedModes.contains(modeId) && eachModeMoreThanOnce) {
|
if (selectedModes.contains(modeId) && eachModeMoreThanOnce) {
|
||||||
Mode duplicateMode = get(modeId).copy();
|
Mode duplicateMode = get(modeId).copy();
|
||||||
|
UUID originalId = modeId;
|
||||||
duplicateMode.setRandomId();
|
duplicateMode.setRandomId();
|
||||||
modeId = duplicateMode.getId();
|
modeId = duplicateMode.getId();
|
||||||
duplicateModes.put(modeId, duplicateMode);
|
duplicateModes.put(modeId, duplicateMode);
|
||||||
|
duplicateToOriginalModeRefs.put(duplicateMode.getId(), originalId);
|
||||||
|
|
||||||
}
|
}
|
||||||
this.selectedModes.add(modeId);
|
this.selectedModes.add(modeId);
|
||||||
|
@ -329,7 +362,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
||||||
nonAvailableModes = getAlreadySelectedModes(source, game);
|
nonAvailableModes = getAlreadySelectedModes(source, game);
|
||||||
}
|
}
|
||||||
for (Mode mode : this.values()) {
|
for (Mode mode : this.values()) {
|
||||||
if (isEachModeOnlyOnce() && nonAvailableModes != null && nonAvailableModes.contains(mode.getId())) {
|
if (isEachModeOnlyOnce() && nonAvailableModes.contains(mode.getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
availableModes.add(mode);
|
availableModes.add(mode);
|
||||||
|
|
Loading…
Reference in a new issue