Add modeTag + hint of used modes for "choose one that hasn't been chosen" abilities. (#10860)

* Add modeTag + hint of used modes on Three Bowls of Porridge

* add ModesAlreadyUsedHint to all the cards.
This commit is contained in:
Susucre 2023-08-27 05:09:04 +02:00 committed by GitHub
parent dcca63b963
commit be4b568e88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 168 additions and 15 deletions

View file

@ -557,6 +557,11 @@ public interface Ability extends Controllable, Serializable {
Ability addHint(Hint hint);
/**
* Tag the current mode to be retrieved elsewhere thanks to the tag.
*/
void setModeTag(String tag);
/**
* For abilities with static icons
*

View file

@ -1390,6 +1390,16 @@ public abstract class AbilityImpl implements Ability {
return this;
}
/**
* sets the mode tag for the current mode.
*/
@Override
public void setModeTag(String tag) {
if (getModes().getMode() != null) {
getModes().getMode().setModeTag(tag);
}
}
@Override
public final List<CardIcon> getIcons() {
return getIcons(null);

View file

@ -17,6 +17,12 @@ public class Mode implements Serializable {
protected final Targets targets;
protected final Effects effects;
protected String flavorWord;
/**
* Optional Tag to distinguish this mode from others.
* In the case of modes that players can only choose once,
* the tag is directly what is displayed in ModesAlreadyUsedHint
*/
protected String modeTag;
public Mode(Effect effect) {
this.id = UUID.randomUUID();
@ -32,6 +38,7 @@ public class Mode implements Serializable {
this.targets = mode.targets.copy();
this.effects = mode.effects.copy();
this.flavorWord = mode.flavorWord;
this.modeTag = mode.modeTag;
}
public UUID setRandomId() {
@ -71,6 +78,21 @@ public class Mode implements Serializable {
return this;
}
/**
* Tag the mode to be retrieved elsewhere thanks to the tag.
*/
public Mode setModeTag(String tag) {
this.modeTag = tag;
return this;
}
/**
* @return the mode tag for this mode, if set
*/
public String getModeTag() {
return this.modeTag == null ? "" : this.modeTag;
}
public String getFlavorWord() {
return flavorWord;
}

View file

@ -15,6 +15,7 @@ import mage.util.CardUtil;
import mage.util.RandomUtil;
import java.util.*;
import java.util.stream.Stream;
/**
* @author BetaSteward_at_googlemail.com
@ -96,6 +97,15 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
return modeToGet;
}
public Stream<Mode> stream() {
return super.values().stream();
}
public Stream<Mode> streamAlreadySelected(Ability source, Game game) {
Set<UUID> selected = getAlreadySelectedModes(source, game);
return stream().filter(m -> selected.contains(m.getId()));
}
public Mode getMode() {
return currentMode;
}

View file

@ -0,0 +1,44 @@
package mage.abilities.hint.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.hint.Hint;
import mage.game.Game;
import java.util.List;
import java.util.stream.Collectors;
/**
* Hint at all the used modes for modal effects that use
* "Choose one that hasn't been chosen" or "Choose one that hasn't been chosen this turn".
* <p>
* Note: the modes need to be set up with a modeTag in order for the hint to find them.
*
* @author Susucr
*/
public enum ModesAlreadyUsedHint implements Hint {
instance;
@Override
public String getText(Game game, Ability ability) {
List<String> used = ability
.getModes()
.streamAlreadySelected(ability, game)
.map(Mode::getModeTag)
.filter(tag -> tag != null && !tag.isEmpty())
.collect(Collectors.toList());
if (used.isEmpty()) {
return "";
}
return "Already used"
+ (ability.getModes().isResetEachTurn() ? " this turn" : "")
+ ": [" + String.join(", ", used) + "]";
}
@Override
public ModesAlreadyUsedHint copy() {
return instance;
}
}

View file

@ -699,6 +699,11 @@ public class StackAbility extends StackObjectImpl implements Ability {
throw new IllegalArgumentException("Stack ability is not supports hint adding");
}
@Override
public void setModeTag(String tag) {
throw new IllegalArgumentException("Stack ability does not supports setting modeTag");
}
@Override
public List<CardIcon> getIcons() {
return this.ability.getIcons();