(WIP) Replacing blocking/blocked by predicates (#8729)

* replaced blocking/blocked by predicates

* added test for knight of dusk (currently fails)

* added source parameter to filters and everything else that needs it

* some changes to various predicates

* test fix

* small changes to filter code

* merge fix

* fixed a test failure

* small change to Karn, Scion of Urza

* removed sourceId from filter methods and other similar places

* added new getobject method to fix some test failures

* a few more fixes

* fixed merge conflicts

* merge fix
This commit is contained in:
Evan Kranzler 2022-03-23 18:45:02 -04:00 committed by GitHub
parent 53877424a0
commit 80e11b2052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1719 changed files with 3384 additions and 3325 deletions

View file

@ -718,7 +718,7 @@ public final class CardUtil {
public static String createObjectRealtedWindowTitle(Ability source, Game game, String textSuffix) {
String title;
if (source != null) {
MageObject sourceObject = game.getObject(source.getSourceId());
MageObject sourceObject = game.getObject(source);
if (sourceObject != null) {
title = sourceObject.getIdName()
+ " [" + source.getSourceObjectZoneChangeCounter() + "]"
@ -988,7 +988,7 @@ public final class CardUtil {
.stream()
.map(Mode::getTargets)
.flatMap(Collection::stream)
.map(t -> t.possibleTargets(ability.getSourceId(), ability.getControllerId(), game))
.map(t -> t.possibleTargets(ability.getControllerId(), ability, game))
.flatMap(Collection::stream)
.collect(Collectors.toSet());
}
@ -1211,7 +1211,7 @@ public final class CardUtil {
void addCard(Card card, Ability source, Game game);
}
private static List<Card> getCastableComponents(Card cardToCast, FilterCard filter, UUID sourceId, UUID playerId, Game game, SpellCastTracker spellCastTracker) {
private static List<Card> getCastableComponents(Card cardToCast, FilterCard filter, Ability source, UUID playerId, Game game, SpellCastTracker spellCastTracker) {
List<Card> cards = new ArrayList<>();
if (cardToCast instanceof CardWithHalves) {
cards.add(((CardWithHalves) cardToCast).getLeftHalfCard());
@ -1223,7 +1223,7 @@ public final class CardUtil {
cards.add(cardToCast);
}
cards.removeIf(Objects::isNull);
cards.removeIf(card -> !filter.match(card, sourceId, playerId, game));
cards.removeIf(card -> !filter.match(card, playerId, source, game));
if (spellCastTracker != null) {
cards.removeIf(card -> spellCastTracker.checkCard(card, game));
}
@ -1243,7 +1243,7 @@ public final class CardUtil {
public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Cards cards, FilterCard filter, SpellCastTracker spellCastTracker) {
Map<UUID, List<Card>> cardMap = new HashMap<>();
for (Card card : cards.getCards(game)) {
List<Card> castableComponents = getCastableComponents(card, filter, source.getSourceId(), player.getId(), game, spellCastTracker);
List<Card> castableComponents = getCastableComponents(card, filter, source, player.getId(), game, spellCastTracker);
if (!castableComponents.isEmpty()) {
cardMap.put(card.getId(), castableComponents);
}
@ -1292,11 +1292,11 @@ public final class CardUtil {
return result;
}
private static boolean checkForPlayable(Cards cards, FilterCard filter, UUID sourceId, UUID playerId, Game game, SpellCastTracker spellCastTracker) {
private static boolean checkForPlayable(Cards cards, FilterCard filter, Ability source, UUID playerId, Game game, SpellCastTracker spellCastTracker) {
return cards
.getCards(game)
.stream()
.anyMatch(card -> !getCastableComponents(card, filter, sourceId, playerId, game, spellCastTracker).isEmpty());
.anyMatch(card -> !getCastableComponents(card, filter, source, playerId, game, spellCastTracker).isEmpty());
}
public static void castMultipleWithAttributeForFree(Player player, Ability source, Game game, Cards cards, FilterCard filter) {
@ -1319,7 +1319,7 @@ public final class CardUtil {
spellsCast++;
cards.removeZone(Zone.STACK, game);
} else if (!checkForPlayable(
cards, filter, source.getSourceId(), player.getId(), game, spellCastTracker
cards, filter, source, player.getId(), game, spellCastTracker
) || !player.chooseUse(
Outcome.PlayForFree, "Continue casting spells?", source, game
)) {