getPermanent directly, not via getBattlefield

This commit is contained in:
xenohedron 2024-06-02 01:10:46 -04:00
parent ad66b7439b
commit 10230f0d99
30 changed files with 45 additions and 45 deletions

View file

@ -67,7 +67,7 @@ class AetherVialEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (permanent == null) {

View file

@ -66,7 +66,7 @@ class TargetMatchesFilterCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getBattlefield().getPermanent(source.getFirstTarget());
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
if (filter.match(target, source.getControllerId(), source, game)) {
return true;

View file

@ -79,7 +79,7 @@ class DaughterOfAutumnPreventDamageTargetEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getControllerId(), source, game)) {
if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {

View file

@ -87,7 +87,7 @@ class HazduhrTheAbbotRedirectDamageEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getControllerId(), source, game)) {
if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {

View file

@ -90,7 +90,7 @@ class MartyrdomActivatedAbility extends ActivatedAbilityImpl {
if (!playerId.equals(caster)) {
return ActivationStatus.getFalse();
}
Permanent permanent = game.getBattlefield().getPermanent(this.getSourceId());
Permanent permanent = game.getPermanent(this.getSourceId());
if (permanent == null || !permanent.isCreature(game)) {
return ActivationStatus.getFalse();
}
@ -128,7 +128,7 @@ class MartyrdomRedirectDamageTargetEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getControllerId(), source, game)) {
if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {

View file

@ -78,7 +78,7 @@ class MerseineActivatedAbility extends SimpleActivatedAbility {
@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
Permanent sourcePermanent = game.getBattlefield().getPermanent(this.getSourceId());
Permanent sourcePermanent = game.getPermanent(this.getSourceId());
if (sourcePermanent != null) {
Permanent attachedTo = game.getPermanent(sourcePermanent.getAttachedTo());
if (attachedTo != null) {
@ -116,7 +116,7 @@ class MerseineCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
Permanent sourcePermanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Permanent attachedTo = game.getPermanent(sourcePermanent.getAttachedTo());
if (attachedTo != null) {
@ -128,7 +128,7 @@ class MerseineCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent sourcePermanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Permanent attachedTo = game.getPermanent(sourcePermanent.getAttachedTo());
if (attachedTo != null) {

View file

@ -61,7 +61,7 @@ class MurderousSpoilsEffect extends OneShotEffect {
if (target != null) {
List<Permanent> attachments = new ArrayList<>();
for (UUID uuid : target.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached.hasSubtype(SubType.EQUIPMENT, game)) {
attachments.add(attached);
}

View file

@ -59,10 +59,10 @@ enum EnchantedOrEquippedSourceCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
for (UUID uuid : permanent.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached != null
&& (attached.isEnchantment(game)
|| attached.hasSubtype(SubType.EQUIPMENT, game))) {

View file

@ -98,14 +98,14 @@ enum OathkeeperEquippedSamuraiCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (permanent != null) {
Permanent attachedTo = null;
if (permanent.getAttachedTo() != null) {
attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}

View file

@ -77,7 +77,7 @@ enum PalladiaMorsTheRuinerCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
PalladiaMorsTheRuinerWatcher watcher = game.getState().getWatcher(PalladiaMorsTheRuinerWatcher.class);
return permanent != null && !watcher.getDamagers().contains(new MageObjectReference(permanent, game));
}

View file

@ -122,7 +122,7 @@ class PyromancerAscensionCopyTriggeredAbility extends TriggeredAbilityImpl {
if (event.getPlayerId().equals(this.getControllerId())) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (isControlledInstantOrSorcery(spell, game)) {
Permanent permanent = game.getBattlefield().getPermanent(this.getSourceId());
Permanent permanent = game.getPermanent(this.getSourceId());
if (permanent != null && permanent.getCounters(game).getCount(CounterType.QUEST) >= 2) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId()));
return true;

View file

@ -56,7 +56,7 @@ enum RampagingCyclopsCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || !permanent.isAttacking()) {
return false;
}

View file

@ -59,7 +59,7 @@ class RatchetBombEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent p = game.getBattlefield().getPermanent(source.getSourceId());
Permanent p = game.getPermanent(source.getSourceId());
if (p == null) {
p = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (p == null) {

View file

@ -101,7 +101,7 @@ class ShamanEnKorRedirectFromTargetEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getControllerId(), source, game)) {
if (sourceObject.equals(new MageObjectReference(event.getSourceId(), game))) {

View file

@ -69,10 +69,10 @@ class AttachedAttackedOrBlockedSinceYourLastUpkeepCondition implements Condition
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
AttackedOrBlockedSinceYourLastUpkeepWatcher watcher = game.getState().getWatcher(AttackedOrBlockedSinceYourLastUpkeepWatcher.class);
if (permanent != null && permanent.getAttachedTo() != null && watcher != null) {
Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}

View file

@ -77,7 +77,7 @@ class ShimianNightStalkerRedirectDamageEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getControllerId(), source, game)) {
if (event.getSourceId() != null && event.getTargetId() != null) {

View file

@ -58,7 +58,7 @@ class TrainingDroneEffect extends RestrictionEffect {
if (permanent.getId().equals(source.getSourceId())) {
List<UUID> attachments = permanent.getAttachments();
for (UUID uuid : attachments) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached.hasSubtype(SubType.EQUIPMENT, game)) {
return false;
}

View file

@ -71,7 +71,7 @@ class BlockedOrBeenBlockedSinceYourLastUpkeepCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent wiitigo = game.getBattlefield().getPermanent(source.getSourceId());
Permanent wiitigo = game.getPermanent(source.getSourceId());
BlockedOrBeenBlockedSinceYourLastUpkeepWatcher watcher = game.getState().getWatcher(
BlockedOrBeenBlockedSinceYourLastUpkeepWatcher.class);
if (wiitigo != null

View file

@ -26,9 +26,9 @@ public class AttachedToMatchesFilterCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.getAttachedTo() != null) {
Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}

View file

@ -36,11 +36,11 @@ public class EnchantedSourceCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
int numberOfFoundEnchantments = 0;
if (permanent != null) {
for (UUID uuid : permanent.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached != null && attached.isEnchantment(game) && (!aurasOnly || attached.hasSubtype(SubType.AURA, game))) {
numberOfFoundEnchantments += 1;
}

View file

@ -22,7 +22,7 @@ public enum EnchantedTargetCondition implements Condition {
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
if (targetPermanent != null) {
for (UUID uuid : targetPermanent.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached != null && attached.isEnchantment(game)) {
return true;
}

View file

@ -29,11 +29,11 @@ public class EquippedHasSubtypeCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || permanent.getAttachedTo() == null) {
return false;
}
Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}

View file

@ -31,9 +31,9 @@ public class EquippedHasSupertypeCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.getAttachedTo() != null) {
Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}

View file

@ -20,11 +20,11 @@ public enum EquippedMultipleSourceCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
int countEquipped = 0;
if (permanent != null) {
for (UUID uuid : permanent.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached != null && attached.hasSubtype(SubType.EQUIPMENT, game)) {
countEquipped++;
if (countEquipped >= 2) {
@ -41,4 +41,4 @@ public enum EquippedMultipleSourceCondition implements Condition {
return "has multiple Equipments attached";
}
}
}

View file

@ -20,10 +20,10 @@ public enum EquippedSourceCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
for (UUID uuid : permanent.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
Permanent attached = game.getPermanent(uuid);
if (attached != null && attached.hasSubtype(SubType.EQUIPMENT, game)) {
return true;
}

View file

@ -17,7 +17,7 @@ public enum SourceAttackingCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
return permanent.isAttacking();
}
@ -30,4 +30,4 @@ public enum SourceAttackingCondition implements Condition {
}
}
}

View file

@ -17,7 +17,7 @@ public enum SourceBlockedCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
return permanent.isBlocked(game);
}
@ -30,4 +30,4 @@ public enum SourceBlockedCondition implements Condition {
}
}
}

View file

@ -20,7 +20,7 @@ public enum SourceTappedCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
return permanent != null && permanent.isTapped() == tapped;
}

View file

@ -80,7 +80,7 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
if (source != null) {
return source.getControllerId();
}
Permanent permanent = game.getBattlefield().getPermanent(sourceId);
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null) {
return permanent.getControllerId();
}

View file

@ -28,7 +28,7 @@ public class RedirectDamageFromSourceToTargetEffect extends RedirectionEffect {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (event.getTargetId().equals(source.getSourceId())) {
if (getTargetPointer().getFirst(game, source) != null) {