cleanup calls to respect range of influence

This commit is contained in:
xenohedron 2024-06-02 02:42:13 -04:00
parent 156c474df8
commit 4025b312ad
29 changed files with 39 additions and 41 deletions

View file

@ -59,7 +59,7 @@ class AlphaStatusDynamicValue implements DynamicValue {
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, sourceAbility.getControllerId(), sourceAbility, game)) {
if (!permanent.getId().equals(enchanted.getId())) {
if (enchanted.shareCreatureTypes(game, permanent)) {
xValue += 2;

View file

@ -163,7 +163,7 @@ class AminatouUltimateEffect extends OneShotEffect {
}
FilterNonlandPermanent nextPlayerNonlandPermanentsFilter = new FilterNonlandPermanent();
nextPlayerNonlandPermanentsFilter.add(new ControllerIdPredicate(nextPlayer));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(nextPlayerNonlandPermanentsFilter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(nextPlayerNonlandPermanentsFilter, source.getControllerId(), source, game)) {
if (permanent.getId().equals(source.getSourceId())) {
continue;
}

View file

@ -58,7 +58,7 @@ class ArmoryAutomatonEffect extends OneShotEffect {
filter.add(SubType.EQUIPMENT.getPredicate());
}
public ArmoryAutomatonEffect() {
ArmoryAutomatonEffect() {
super(Outcome.Benefit);
this.staticText = "attach any number of target Equipment to it";
}
@ -84,7 +84,7 @@ class ArmoryAutomatonEffect extends OneShotEffect {
filterSourceId.add(new CardIdPredicate(source.getSourceId()));
currentFilter.add(Predicates.not(new AttachedToPredicate(filterSourceId)));
int countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
int countBattlefield = game.getBattlefield().getActivePermanents(currentFilter, source.getControllerId(), source, game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Select and attach a target Equipment?", source, game)) {
Target targetEquipment = new TargetPermanent(currentFilter);
targetEquipment.setRequired(false);
@ -102,7 +102,7 @@ class ArmoryAutomatonEffect extends OneShotEffect {
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
countBattlefield = game.getBattlefield().getActivePermanents(currentFilter, source.getControllerId(), source, game).size();
}
return true;
}

View file

@ -87,7 +87,7 @@ class BanishmentEffect extends OneShotEffect {
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new NamePredicate(targeted.getName()));
Set<Card> toExile = game.getBattlefield().getAllActivePermanents(filter, game)
Set<Card> toExile = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)
.stream().filter(p -> controller.hasOpponent(p.getControllerId(),game))
.collect(Collectors.toCollection(LinkedHashSet::new));

View file

@ -100,7 +100,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect {
List<Permanent> fromBattlefield = new ArrayList<>();
List<Card> fromHandGraveyard = new ArrayList<>();
int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
int countBattlefield = game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size() - sourcePermanent.getAttachments().size();
while (controller.canRespond()
&& countBattlefield > 0
&& controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
@ -117,7 +117,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect {
fromBattlefield.add(aura);
filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
countBattlefield = game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size() - sourcePermanent.getAttachments().size();
}
int countHand = controller.getHand().count(filterAuraCard, game);

View file

@ -58,7 +58,7 @@ enum AllColorCondition implements Condition {
FilterCreaturePermanent filter = new FilterCreaturePermanent("Nonartifact creatures");
filter.add(Predicates.not(CardType.ARTIFACT.getPredicate()));
ObjectColor allColor = new ObjectColor("WUBRG");
for (Permanent thing : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent thing : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
allColor = allColor.intersection(thing.getColor(game));
}
return !allColor.isColorless();

View file

@ -87,7 +87,7 @@ class CorneredMarketReplacementEffect extends ContinuousRuleModifyingEffectImpl
// play land check
if (card.isLand(game)
&& !card.isBasic(game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
if (CardUtil.haveSameNames(card, permanent.getName(), game)) {
return true;
@ -98,7 +98,7 @@ class CorneredMarketReplacementEffect extends ContinuousRuleModifyingEffectImpl
}
// cast spell check
if (spell != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
if (CardUtil.haveSameNames(card, permanent.getName(), game)) {
return true;

View file

@ -64,6 +64,6 @@ class DeathbringerRegentCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return CastFromHandSourcePermanentCondition.instance.apply(game, source)
&& game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game).size() >= 6;
&& game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game).size() >= 6;
}
}

View file

@ -67,7 +67,7 @@ class DisarmEffect extends OneShotEffect {
equipmentFilter.add(new AttachedToPredicate(creatureFilter));
equipmentFilter.add(SubType.EQUIPMENT.getPredicate());
for (Permanent equipment : game.getBattlefield().getAllActivePermanents(equipmentFilter, game)) {
for (Permanent equipment : game.getBattlefield().getActivePermanents(equipmentFilter, source.getControllerId(), source, game)) {
creature.removeAttachment(equipment.getId(), source, game);
}
return true;

View file

@ -61,13 +61,13 @@ class FacesOfThePastEffect extends OneShotEffect {
Player controller = game.getPlayer(targetPermanent.getControllerId());
if (controller != null) {
if (controller.chooseUse(outcome, "Tap all untapped creatures that share a creature type with " + targetPermanent.getLogName() + "? (Otherwise, untaps all tapped)", source, game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game)) {
if (!permanent.isTapped() && targetPermanent.shareCreatureTypes(game, permanent)) {
permanent.tap(source, game);
}
}
} else {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game)) {
if (permanent.isTapped() && targetPermanent.shareCreatureTypes(game, permanent)) {
permanent.untap(game);
}

View file

@ -65,7 +65,7 @@ class GlobalRuinDestroyLandEffect extends OneShotEffect {
Set<UUID> lands = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if(player != null) {
if (player != null) {
for (SubType landName : Arrays.stream(SubType.values()).filter(p -> p.getSubTypeSet() == SubTypeSet.BasicLandType).collect(Collectors.toSet())) {
FilterControlledLandPermanent filter = new FilterControlledLandPermanent(landName + " you control");
filter.add(landName.getPredicate());
@ -77,7 +77,7 @@ class GlobalRuinDestroyLandEffect extends OneShotEffect {
}
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_LAND, source.getControllerId(), source, game)) {
if (!lands.contains(permanent.getId())) {
permanent.sacrifice(source, game);
}

View file

@ -70,7 +70,7 @@ class GreaterWerewolfEffect extends OneShotEffect {
if (sourcePermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
Effect effect = new AddCountersTargetEffect(CounterType.M0M2.createInstance(), Outcome.UnboostCreature);
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);

View file

@ -63,7 +63,7 @@ class JoragaInvocationEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game)) {
ContinuousEffect effect = new MustBeBlockedByAtLeastOneTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);

View file

@ -67,7 +67,7 @@ class MarchOfTheMachinesEffect extends ContinuousEffectImpl {
case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
affectedObjectList.clear();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
affectedObjectList.add(new MageObjectReference(permanent, game));
permanent.addCardType(game, CardType.CREATURE);

View file

@ -75,7 +75,7 @@ class MirrorWeaveEffect extends OneShotEffect {
Permanent copyFromCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (copyFromCreature != null) {
filter.add(Predicates.not(new PermanentIdPredicate(copyFromCreature.getId())));
for (Permanent copyToCreature : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent copyToCreature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (copyToCreature != null) {
game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToCreature.getId(), source, new EmptyCopyApplier());
}

View file

@ -11,7 +11,6 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.TimingRule;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
@ -69,7 +68,7 @@ class ParallelEvolutionEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(permanent.getControllerId());
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);

View file

@ -58,14 +58,14 @@ class PuppetsVerdictEffect extends OneShotEffect {
FilterCreaturePermanent filterPower2OrLess = new FilterCreaturePermanent("all creatures power 2 or less");
filterPower2OrLess.add(new PowerPredicate(ComparisonType.FEWER_THAN, 3));
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(filterPower2OrLess, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPower2OrLess, source.getControllerId(), source, game)) {
permanent.destroy(source, game, false);
}
return true;
} else {
FilterCreaturePermanent filterPower3OrGreater = new FilterCreaturePermanent("all creatures power 3 or greater");
filterPower3OrGreater.add(new PowerPredicate(ComparisonType.MORE_THAN, 2));
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(filterPower3OrGreater, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPower3OrGreater, source.getControllerId(), source, game)) {
permanent.destroy(source, game, false);
}
return true;

View file

@ -89,7 +89,7 @@ class RhysTheRedeemedEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent.isControlledBy(source.getControllerId())) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));

View file

@ -73,7 +73,7 @@ public final class RootGreevil extends CardImpl {
if (controller != null && controller.choose(Outcome.DestroyPermanent, choice, game)) {
FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent();
filter.add(new ColorPredicate(choice.getColor()));
for (Permanent enchantment : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent enchantment : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
enchantment.destroy(source, game, false);
}
return true;

View file

@ -75,7 +75,7 @@ class ScreamsFromWithinEffect extends OneShotEffect {
Card aura = game.getCard(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (aura != null && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD && player != null && player.getGraveyard().contains(source.getSourceId())) {
for (Permanent creaturePermanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent creaturePermanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game)) {
for (Target target : aura.getSpellAbility().getTargets()) {
if (target.canTarget(creaturePermanent.getId(), game)) {
return player.moveCards(aura, Zone.BATTLEFIELD, source, game);

View file

@ -77,7 +77,7 @@ class SeasonOfTheWitchEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(game.getActivePlayerId());
if (activePlayer != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source, game)) {
// Noncreature cards are safe.
if (!permanent.isCreature(game)) {
continue;

View file

@ -63,7 +63,7 @@ class StenchOfEvilEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
for (Permanent land : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent land : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
UUID landControllerId = land.getControllerId();
if (land.destroy(source, game, false)) {
Cost cost = new ManaCostsImpl<>("{2}");

View file

@ -73,7 +73,7 @@ class TitaniasSongEffect extends ContinuousEffectImpl {
case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
affectedObjectList.clear();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
affectedObjectList.add(new MageObjectReference(permanent, game));
permanent.addCardType(game, CardType.CREATURE);

View file

@ -104,7 +104,7 @@ class VisionCharmEffect extends ContinuousEffectImpl {
FilterPermanent filter = new FilterLandPermanent();
filter.add(SubType.byDescription(targetLandType).getPredicate());
if (getAffectedObjectsSet()) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
affectedObjectList.add(new MageObjectReference(permanent, game));
}
}

View file

@ -65,7 +65,7 @@ public final class VulshokBattlemaster extends CardImpl {
if (battlemaster != null) {
FilterPermanent filter = new FilterPermanent();
filter.add(SubType.EQUIPMENT.getPredicate());
for (Permanent equipment : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent equipment : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (equipment != null) {
//If an Equipment can't equip Vulshok Battlemaster, it isn't attached to the Battlemaster, and it doesn't become unattached (if it's attached to a creature). (https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=48125)
if (!battlemaster.cantBeAttachedBy(equipment, source, game, false)) {

View file

@ -17,7 +17,6 @@ import mage.constants.*;
import mage.filter.FilterObject;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -89,7 +88,7 @@ class WardSliverGainAbilityControlledEffect extends ContinuousEffectImpl {
}
}
if (protectionFilter != null) {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_ALL_SLIVERS, game)) {
for (Permanent perm: game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_ALL_SLIVERS, source.getControllerId(), source, game)) {
perm.addAbility(new ProtectionAbility(protectionFilter), source.getSourceId(), game);
}
return true;

View file

@ -14,8 +14,8 @@ import mage.game.permanent.Permanent;
*/
public class CountersCount implements DynamicValue {
private CounterType counter;
private FilterPermanent filter;
private final CounterType counter;
private final FilterPermanent filter;
public CountersCount(CounterType counterType) {
this(counterType, new FilterPermanent());
@ -34,7 +34,7 @@ public class CountersCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceAbility.getControllerId(), sourceAbility, game)) {
count += permanent.getCounters(game).getCount(counter);
}
return count;

View file

@ -63,7 +63,7 @@ public class UntapLandsEffect extends OneShotEffect {
if (upTo) {
tappedLands = game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game).size();
} else {
tappedLands = game.getBattlefield().getAllActivePermanents(filter, game).size();
tappedLands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game).size();
}
TargetLandPermanent target = new TargetLandPermanent(upTo ? 0 : Math.min(tappedLands, amount), amount, filter, true);
if (target.canChoose(source.getControllerId(), source, game)) {

View file

@ -30,7 +30,7 @@ public class TargetTappedPermanentAsYouCast extends TargetPermanent {
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
return game.getBattlefield().getActivePermanents(getFilter(), source.getControllerId(), source, game).stream()
.filter(Permanent::isTapped)
.map(Permanent::getId)
.collect(Collectors.toSet());
@ -38,7 +38,7 @@ public class TargetTappedPermanentAsYouCast extends TargetPermanent {
@Override
public boolean canChoose(UUID sourceControllerId, Ability source, Game game) {
return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
return game.getBattlefield().getActivePermanents(getFilter(), source.getControllerId(), source, game).stream()
.anyMatch(Permanent::isTapped);
}