mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
refactor: removed useless code on ChoiceCreatureType usage, removed possibly infinite code (game freezes) (related to #13106);
This commit is contained in:
parent
e3a94c8adf
commit
2949444089
12 changed files with 37 additions and 50 deletions
|
|
@ -69,7 +69,9 @@ class ForTheAncestorsEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
ChoiceCreatureType choice = new ChoiceCreatureType(game, source);
|
||||
player.choose(outcome, choice, game);
|
||||
if (!player.choose(outcome, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
SubType subType = SubType.byDescription(choice.getChoiceKey());
|
||||
FilterCard filter;
|
||||
if (subType != null) {
|
||||
|
|
|
|||
|
|
@ -66,18 +66,14 @@ class HarshMercyEffect extends OneShotEffect {
|
|||
MageObject sourceObject = game.getObject(source);
|
||||
if (controller != null && sourceObject != null) {
|
||||
Set<String> chosenTypes = new HashSet<>();
|
||||
PlayerIteration:
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
Choice typeChoice = new ChoiceCreatureType(game, source);
|
||||
if (player != null && !player.choose(Outcome.DestroyPermanent, typeChoice, game)) {
|
||||
continue PlayerIteration;
|
||||
}
|
||||
String chosenType = typeChoice.getChoiceKey();
|
||||
if (chosenType != null) {
|
||||
game.informPlayers(sourceObject.getIdName() + ": " + player.getLogName() + " has chosen " + chosenType);
|
||||
chosenTypes.add(chosenType);
|
||||
continue;
|
||||
}
|
||||
game.informPlayers(sourceObject.getIdName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
chosenTypes.add(typeChoice.getChoiceKey());
|
||||
}
|
||||
|
||||
FilterPermanent filter = new FilterCreaturePermanent("creatures");
|
||||
|
|
|
|||
|
|
@ -128,13 +128,10 @@ class KaronaFalseGodEffect extends OneShotEffect {
|
|||
if (!controller.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
return false;
|
||||
}
|
||||
String typeChosen = typeChoice.getChoiceKey();
|
||||
if (!typeChosen.isEmpty()) {
|
||||
game.informPlayers(controller.getLogName() + " has chosen " + typeChosen);
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
filter.add(SubType.byDescription(typeChosen).getPredicate());
|
||||
game.addEffect(new BoostAllEffect(3, 3, Duration.EndOfTurn, filter, false), source);
|
||||
}
|
||||
game.informPlayers(controller.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
filter.add(SubType.byDescription(typeChoice.getChoiceKey()).getPredicate());
|
||||
game.addEffect(new BoostAllEffect(3, 3, Duration.EndOfTurn, filter, false), source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class LongListOfTheEntsEffect extends OneShotEffect {
|
|||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
ChoiceCreatureType choice = new ChoiceCreatureType(game, source);
|
||||
|
||||
Object existingEntList = game.getState().getValue(LongListOfTheEnts.getKey(game, source, 0));
|
||||
int offset;
|
||||
Set<SubType> newEntList;
|
||||
|
|
@ -124,12 +124,13 @@ class LongListOfTheEntsEffect extends OneShotEffect {
|
|||
.stream()
|
||||
.map(SubType::toString)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
ChoiceCreatureType choice = new ChoiceCreatureType(game, source);
|
||||
choice.getKeyChoices().keySet().removeIf(chosenTypes::contains);
|
||||
player.choose(Outcome.BoostCreature, choice, game);
|
||||
SubType subType = SubType.byDescription(choice.getChoiceKey());
|
||||
if (subType == null) {
|
||||
if (!player.choose(Outcome.BoostCreature, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
SubType subType = SubType.byDescription(choice.getChoiceKey());
|
||||
game.informPlayers(player.getLogName() + " notes the creature type " + subType);
|
||||
newEntList.add(subType);
|
||||
game.getState().setValue(LongListOfTheEnts.getKey(game, source, offset), newEntList);
|
||||
|
|
|
|||
|
|
@ -78,10 +78,8 @@ class BecomesChosenCreatureTypeControlledEffect extends OneShotEffect {
|
|||
String chosenType = "";
|
||||
if (player != null && card != null) {
|
||||
Choice typeChoice = new ChoiceCreatureType(game, source);
|
||||
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
if (!player.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
if (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
return false;
|
||||
}
|
||||
game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
chosenType = typeChoice.getChoiceKey();
|
||||
|
|
|
|||
|
|
@ -69,9 +69,8 @@ class PatriarchsBiddingEffect extends OneShotEffect {
|
|||
if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
|
||||
continue;
|
||||
}
|
||||
String chosenType = typeChoice.getChoiceKey();
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
|
||||
chosenTypes.add(chosenType);
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
chosenTypes.add(typeChoice.getChoiceKey());
|
||||
}
|
||||
|
||||
List<SubType.SubTypePredicate> predicates = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -73,12 +73,10 @@ class PolJamaarIllusionistEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
ChoiceCreatureType choice = new ChoiceCreatureType(game, source);
|
||||
player.choose(outcome, choice, game);
|
||||
// must use choice.getChoiceKey() so that actual subtype is used
|
||||
SubType subType = SubType.byDescription(choice.getChoiceKey());
|
||||
if (subType == null) {
|
||||
if (!player.choose(outcome, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
SubType subType = SubType.byDescription(choice.getChoiceKey());
|
||||
game.informPlayers(player.getLogName() + " chooses " + subType);
|
||||
int amount = game
|
||||
.getBattlefield()
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ class StandardizeEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = game.getObject(source);
|
||||
String chosenType = "";
|
||||
if (player != null && sourceObject != null) {
|
||||
Choice typeChoice = new ChoiceCreatureType(game, source);
|
||||
typeChoice.setMessage("Choose a creature type other than Wall");
|
||||
|
|
@ -66,16 +65,12 @@ class StandardizeEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
chosenType = typeChoice.getChoiceKey();
|
||||
if (chosenType != null && !chosenType.isEmpty()) {
|
||||
// ADD TYPE TO TARGET
|
||||
game.addEffect(new BecomesSubtypeAllEffect(
|
||||
Duration.EndOfTurn, Arrays.asList(SubType.byDescription(chosenType)),
|
||||
StaticFilters.FILTER_PERMANENT_CREATURE, true
|
||||
), source);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ADD TYPE TO TARGET
|
||||
game.addEffect(new BecomesSubtypeAllEffect(
|
||||
Duration.EndOfTurn, Arrays.asList(SubType.byDescription(typeChoice.getChoiceKey())),
|
||||
StaticFilters.FILTER_PERMANENT_CREATURE, true
|
||||
), source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,9 +67,7 @@ class TribalUnityEffect extends OneShotEffect {
|
|||
Choice typeChoice = new ChoiceCreatureType(game, source);
|
||||
if (player != null && player.choose(outcome, typeChoice, game)) {
|
||||
int boost = amount.calculate(game, source, this);
|
||||
if (typeChoice.getChoiceKey() != null) {
|
||||
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoiceKey());
|
||||
}
|
||||
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoiceKey());
|
||||
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
|
||||
filterCreaturePermanent.add(SubType.byDescription(typeChoice.getChoiceKey()).getPredicate());
|
||||
game.addEffect(new BoostAllEffect(
|
||||
|
|
|
|||
|
|
@ -59,10 +59,9 @@ public class BecomesChosenCreatureTypeTargetEffect extends OneShotEffect {
|
|||
if (nonWall) {
|
||||
typeChoice.getKeyChoices().remove(SubType.WALL.getDescription());
|
||||
}
|
||||
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
if (!player.canRespond()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
|
||||
return false;
|
||||
}
|
||||
game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoiceKey());
|
||||
chosenType = typeChoice.getChoiceKey();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Game's choose dialog to ask about creature type. Return getChoice
|
||||
* Game's choose dialog to ask about creature type.
|
||||
* <p>
|
||||
* Warning, must use getChoiceKey as result
|
||||
*/
|
||||
public class ChoiceCreatureType extends ChoiceImpl {
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,9 @@ class VolosJournalTokenEffect extends OneShotEffect {
|
|||
return true;
|
||||
}
|
||||
|
||||
player.choose(outcome, choice, game);
|
||||
if (!player.choose(outcome, choice, game)) {
|
||||
return false;
|
||||
}
|
||||
notedTypes.add(choice.getChoiceKey());
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue