[CLB] Fix Incorrect Volo Behavior (#9190)

This commit is contained in:
Alex Vasile 2022-07-04 22:17:33 -04:00 committed by GitHub
parent 78f3547644
commit dca2ae546e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 23 deletions

View file

@ -90,11 +90,12 @@ class VoloItinerantScholarEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
return player != null && permanent != null if (player == null || permanent == null) {
&& player.drawCards( return false;
VolosJournalToken.getNotedTypes( }
game, permanent.getId(), permanent.getZoneChangeCounter(game) return player.drawCards(
).size(), source, game VolosJournalToken.getNotedTypes(game, permanent).size(),
) > 0; source,
game) > 0;
} }
} }

View file

@ -10,6 +10,7 @@ import mage.constants.*;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
import mage.util.RandomUtil; import mage.util.RandomUtil;
@ -18,14 +19,13 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* @author TheElk801 * @author TheElk801
*/ */
public final class VolosJournalToken extends TokenImpl { public final class VolosJournalToken extends TokenImpl {
private static final FilterCard filter = new FilterCard("spells");
public VolosJournalToken() { public VolosJournalToken() {
super("Volo's Journal", "Volo's Journal, a legendary colorless artifact token with hexproof and \"Whenever you cast a creature spell, note one of its creature types that hasn't been noted for this artifact.\""); super("Volo's Journal", "Volo's Journal, a legendary colorless artifact token with hexproof and \"Whenever you cast a creature spell, note one of its creature types that hasn't been noted for this artifact.\"");
addSuperType(SuperType.LEGENDARY); addSuperType(SuperType.LEGENDARY);
@ -46,12 +46,12 @@ public final class VolosJournalToken extends TokenImpl {
return new VolosJournalToken(this); return new VolosJournalToken(this);
} }
public static Set<String> getNotedTypes(Game game, Ability source) { public static Set<String> getNotedTypes(Game game, Permanent permanent) {
return getNotedTypes(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); if (permanent == null) {
} return new HashSet<>();
}
public static Set<String> getNotedTypes(Game game, UUID sourceId, int zcc) { String key = "notedTypes_" + permanent.getId() + '_' + permanent.getZoneChangeCounter(game);
String key = "notedTypes_" + sourceId + '_' + zcc;
Object value = game.getState().getValue(key); Object value = game.getState().getValue(key);
if (value == null) { if (value == null) {
Set<String> types = new HashSet<>(); Set<String> types = new HashSet<>();
@ -67,7 +67,8 @@ enum VolosJournalTokenHint implements Hint {
@Override @Override
public String getText(Game game, Ability ability) { public String getText(Game game, Ability ability) {
Set<String> types = VolosJournalToken.getNotedTypes(game, ability); Permanent permanent = game.getPermanent(ability.getSourceId());
Set<String> types = VolosJournalToken.getNotedTypes(game, permanent);
int size = types.size(); int size = types.size();
if (size > 0) { if (size > 0) {
return "Creature types noted: " + size + " (" + String.join(", ", types) + ')'; return "Creature types noted: " + size + " (" + String.join(", ", types) + ')';
@ -99,31 +100,44 @@ class VolosJournalTokenEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Set<String> types = VolosJournalToken.getNotedTypes(game, source);
Spell spell = (Spell) getValue("spellCast"); Spell spell = (Spell) getValue("spellCast");
if (spell == null) { if (spell == null) {
return false; return false;
} }
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return true;
}
Permanent permanent = game.getPermanent(source.getSourceId());
Set<String> types = VolosJournalToken.getNotedTypes(game, permanent);
ChoiceCreatureType choice = new ChoiceCreatureType(); ChoiceCreatureType choice = new ChoiceCreatureType();
choice.getChoices().removeIf(types::contains);
// By default ChoiceCreatureType pre-populates all creatures into choices
// Limit the available choices to those on the creature being cast
if (!spell.isAllCreatureTypes(game)) { if (!spell.isAllCreatureTypes(game)) {
spell.getSubtype(game) choice.setChoices(
spell.getSubtype(game)
.stream() .stream()
.filter(subType -> subType.getSubTypeSet() == SubTypeSet.CreatureType) .filter(subType -> subType.getSubTypeSet() == SubTypeSet.CreatureType)
.map(SubType::getDescription) .map(SubType::getDescription)
.forEach(s -> choice.getChoices().removeIf(s::equals)); .collect(Collectors.toSet())
);
} }
// Remove from the possible choices the subtypes which have already been chosen.
choice.getChoices().removeIf(types::contains);
switch (choice.getChoices().size()) { switch (choice.getChoices().size()) {
case 0: case 0:
return false; return false;
case 1: case 1:
types.add(RandomUtil.randomFromCollection(choice.getChoices())); types.add(choice.getChoices().stream().findFirst().get());
return true; return true;
} }
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.choose(outcome, choice, game); player.choose(outcome, choice, game);
types.add(choice.getChoice()); types.add(choice.getChoice());
return true; return true;