simplify LKI check using common method

This commit is contained in:
xenohedron 2023-09-30 01:29:32 -04:00
parent 63ae2e5a56
commit 78b5b8bdef
21 changed files with 39 additions and 169 deletions

View file

@ -13,7 +13,6 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
@ -57,12 +56,7 @@ enum CreatureBondValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId());
}
Permanent enchantment = sourceAbility.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return 0;
}

View file

@ -18,7 +18,6 @@ import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
import mage.abilities.common.EnchantedPlayerAttackedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.players.Player;
@ -71,12 +70,7 @@ class CurseOfBountyEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {

View file

@ -15,7 +15,6 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.ZombieToken;
@ -72,12 +71,7 @@ class CurseOfDisturbanceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {

View file

@ -22,7 +22,6 @@ import mage.target.targetpointer.FixedTarget;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.Zone;
/**
* @author Saga
@ -72,12 +71,7 @@ class CurseOfOpulenceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -15,7 +15,6 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -70,12 +69,7 @@ class CurseOfVerbosityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {

View file

@ -19,7 +19,6 @@ import mage.abilities.Ability;
import mage.abilities.common.EnchantedPlayerAttackedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.GainLifeTargetEffect;
import mage.constants.Zone;
import mage.players.Player;
/**
@ -70,12 +69,7 @@ class CurseOfVitalityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {

View file

@ -42,12 +42,12 @@ public final class EndlessEvil extends CardImpl {
this.addAbility(ability);
// At the beginning of your upkeep, create a token thats a copy of enchanted creature, except the token is 1/1.
TriggeredAbility CloneAbility = new BeginningOfUpkeepTriggeredAbility(
TriggeredAbility cloneAbility = new BeginningOfUpkeepTriggeredAbility(
new EndlessEvilCloneEffect(),
TargetController.YOU,
false
);
this.addAbility(CloneAbility);
this.addAbility(cloneAbility);
// When enchanted creature dies, if that creature was a Horror, return Endless Evil to its owners hand.
this.addAbility(new EndlessEvilBounceAbility());
@ -81,11 +81,7 @@ class EndlessEvilCloneEffect extends OneShotEffect {
@Override
public boolean apply (Game game, Ability source) {
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// In the case that Endless Evil is blinked
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Permanent target = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (target != null) {

View file

@ -13,7 +13,6 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -71,12 +70,7 @@ class FollowedFootstepsEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that Followed Footsteps is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Permanent target = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (target != null) {

View file

@ -66,12 +66,7 @@ class FracturedLoyaltyEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that Fractured Loyalty is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}

View file

@ -14,7 +14,6 @@ import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPlayer;
@ -86,8 +85,6 @@ class FrayingSanityTriggeredAbility extends TriggeredAbilityImpl {
class FrayingSanityEffect extends OneShotEffect {
int xAmount = 0;
public FrayingSanityEffect() {
super(Outcome.Detriment);
this.staticText = "";
@ -104,21 +101,14 @@ class FrayingSanityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (watcher != null) {
xAmount = watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
}
int xAmount = (watcher == null) ? 0 : watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
enchantedPlayer.millCards(xAmount, source, game);
return true;
}

View file

@ -70,12 +70,7 @@ class IronclawCurseEffect extends CantBlockAttachedEffect {
if (attacker == null) {
return true;
}
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -15,7 +15,6 @@ import mage.constants.AttachmentType;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
@ -71,12 +70,7 @@ class MirrorMockeryEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -1,4 +1,3 @@
package mage.cards.o;
import mage.MageObject;
@ -60,7 +59,7 @@ public final class OverwhelmingSplendor extends CardImpl {
class OverwhelmingSplendorLoseAbilitiesEffect extends ContinuousEffectImpl {
public OverwhelmingSplendorLoseAbilitiesEffect() {
OverwhelmingSplendorLoseAbilitiesEffect() {
super(Duration.WhileOnBattlefield, Outcome.LoseAbility);
staticText = "Creatures enchanted player controls lose all abilities and have base power and toughness 1/1";
}
@ -76,21 +75,14 @@ class OverwhelmingSplendorLoseAbilitiesEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (enchantment == null) {
return false;
}
return false;
}
Player player = game.getPlayer(enchantment.getAttachedTo());
if (player == null) {
return false;
}
for (Permanent permanent : game.getState().getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game)) {
switch (layer) {
case AbilityAddingRemovingEffects_6:
@ -120,7 +112,7 @@ class OverwhelmingSplendorLoseAbilitiesEffect extends ContinuousEffectImpl {
class OverwhelmingSplendorCantActivateEffect extends ContinuousRuleModifyingEffectImpl {
public OverwhelmingSplendorCantActivateEffect() {
OverwhelmingSplendorCantActivateEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "Enchanted player can't activate abilities that aren't mana abilities or loyalty abilities";
}

View file

@ -19,7 +19,6 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
import mage.constants.Zone;
/**
* @author LoneFox
@ -68,12 +67,7 @@ class SeizuresEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -87,12 +87,7 @@ class SerraBestiaryRuleModifyingEffect extends ContinuousRuleModifyingEffectImpl
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -95,12 +95,7 @@ class TreacherousLinkEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
Player controller = game.getPlayer(source.getControllerId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null && enchantment != null) {

View file

@ -60,7 +60,7 @@ public final class VisionsOfBrutality extends CardImpl {
class VisionsOfBrutalityEffect extends OneShotEffect {
public VisionsOfBrutalityEffect() {
VisionsOfBrutalityEffect() {
super(Outcome.Benefit);
this.staticText = "its controller loses that much life";
}
@ -77,28 +77,20 @@ class VisionsOfBrutalityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (enchantment != null
&& enchantment.getAttachedTo() != null) {
Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (enchanted != null) {
Player controllerEnchanted = game.getPlayer(enchanted.getControllerId());
if (controllerEnchanted != null) {
int damage = (Integer) getValue("damage");
if (damage > 0) {
controllerEnchanted.loseLife(damage, game, source, false);
}
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (controller == null || enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}
Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (enchanted != null) {
Player controllerEnchanted = game.getPlayer(enchanted.getControllerId());
if (controllerEnchanted != null) {
int damage = (Integer) getValue("damage");
if (damage > 0) {
controllerEnchanted.loseLife(damage, game, source, false);
}
}
return true;
}
return false;
return true;
}
}

View file

@ -1,12 +1,10 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -40,12 +38,7 @@ public class DamageAttachedControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -1,12 +1,10 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -47,12 +45,7 @@ public class DamageAttachedEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment == null) {
return false;
}

View file

@ -3,7 +3,6 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -31,12 +30,7 @@ public class ExileAttachedEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
// The LKI must be used for this step. 608.2g
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (controller != null
&& enchantment != null
&& enchantment.getAttachedTo() != null) {

View file

@ -3,7 +3,6 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -28,12 +27,7 @@ public class PhaseOutAttachedEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Permanent enchantment = source.getSourcePermanentOrLKI(game);
if (enchantment != null) {
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null) {