Remove KickerAbility.getSpellKickedCount (#12553)

* Remove KickerAbility.getSpellKickedCount

* Check spell LKI instead of only current spell object

* Remove bad LKI storage under wrong ID
This commit is contained in:
ssk97 2024-07-22 20:13:48 -07:00 committed by GitHub
parent 2118570a0d
commit 78649c1a62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 91 additions and 127 deletions

View file

@ -24,8 +24,7 @@ public enum KickedCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return KickerAbility.getKickedCounter(game, source) >= kickedCount // for on battlefield
|| KickerAbility.getSpellKickedCount(game, source.getSourceId()) >= kickedCount; // for on stack
return KickerAbility.getKickedCounter(game, source) >= kickedCount;
}
@Override

View file

@ -20,7 +20,6 @@ public class KickedCostCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return KickerAbility.getKickedCounterStrict(game, source, kickerCostText) > 0
|| KickerAbility.getSpellKickedCountStrict(game, source.getSourceId(), kickerCostText) > 0;
return KickerAbility.getKickedCounterStrict(game, source, kickerCostText) > 0;
}
}

View file

@ -9,11 +9,13 @@ import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
/**
@ -269,21 +271,4 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo
return sb.toString();
}
/**
* Find spell's kicked stats. Must be used on stack only, e.g. for SPELL_CAST events
*/
public static int getSpellKickedCount(Game game, UUID spellId) {
return getSpellKickedCountStrict(game, spellId, "");
}
/**
* Find spell's kicked stats. Must be used on stack only, e.g. for SPELL_CAST events
*/
public static int getSpellKickedCountStrict(Game game, UUID spellId, String needKickerCost) {
Spell spell = game.getSpellOrLKIStack(spellId);
if (spell != null) {
return KickerAbility.getKickedCounterStrict(game, spell.getSpellAbility(), needKickerCost);
}
return 0;
}
}

View file

@ -562,7 +562,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
if (removed) {
if (fromZone != Zone.OUTSIDE) {
game.rememberLKI(lkiObject != null ? lkiObject.getId() : objectId, fromZone, lkiObject != null ? lkiObject : this);
game.rememberLKI(fromZone, lkiObject != null ? lkiObject : this);
}
} else {
logger.warn("Couldn't find card in fromZone, card=" + getIdName() + ", fromZone=" + fromZone);

View file

@ -4,13 +4,12 @@ import mage.MageObject;
import mage.abilities.keyword.KickerAbility;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
/**
* Find spell's kicked stats.
* <p>
* Warning, must be used for SPELL_CAST events only
* (if you need kicked stats in ETB effects then search object's abilities instead spell,
* see MultikickerCount as example)
*
* @author TheElk801
*/
@ -19,7 +18,11 @@ public enum KickedSpellPredicate implements Predicate<MageObject> {
@Override
public boolean apply(MageObject input, Game game) {
return KickerAbility.getSpellKickedCount(game, input.getId()) > 0;
if (input instanceof Spell) {
return KickerAbility.getKickedCounter(game, ((Spell) input).getSpellAbility()) > 0;
} else {
return false;
}
}
@Override

View file

@ -305,7 +305,7 @@ public interface Game extends MageItem, Serializable, Copyable<Game> {
*/
boolean checkShortLivingLKI(UUID objectId, Zone zone);
void rememberLKI(UUID objectId, Zone zone, MageObject object);
void rememberLKI(Zone zone, MageObject object);
void resetLKI();

View file

@ -714,12 +714,6 @@ public abstract class GameImpl implements Game {
// SyrCarahTheBoldTest.java for an example of when this check is relevant.
if (obj instanceof Spell) {
spell = (Spell) obj;
} else if (obj != null) {
logger.error(String.format(
"getSpellOrLKIStack got non-spell id %s correlating to non-spell object %s.",
obj.getClass().getName(), obj.getName()),
new Throwable()
);
}
}
return spell;
@ -1801,7 +1795,6 @@ public abstract class GameImpl implements Game {
} finally {
if (top != null) {
state.getStack().remove(top, this); // seems partly redundant because move card from stack to grave is already done and the stack removed
rememberLKI(top.getSourceId(), Zone.STACK, top);
checkInfiniteLoop(top.getSourceId());
if (!getTurn().isEndTurnRequested()) {
while (state.hasSimultaneousEvents()) {
@ -3320,7 +3313,7 @@ public abstract class GameImpl implements Game {
}
}
for (Card card : toOutside) {
rememberLKI(card.getId(), Zone.BATTLEFIELD, card);
rememberLKI(Zone.BATTLEFIELD, card);
}
// needed to send event that permanent leaves the battlefield to allow non stack effects to execute
player.moveCards(toOutside, Zone.OUTSIDE, null, this);
@ -3592,12 +3585,12 @@ public abstract class GameImpl implements Game {
/**
* Remembers object state to be used as Last Known Information.
*
* @param objectId
* @param zone
* @param object
*/
@Override
public void rememberLKI(UUID objectId, Zone zone, MageObject object) {
public void rememberLKI(Zone zone, MageObject object) {
UUID objectId = object.getId();
if (object instanceof Permanent || object instanceof StackObject) {
MageObject copy = object.copy();

View file

@ -1727,7 +1727,8 @@ public final class CardUtil {
/**
* Returns the entire cost tags map of either the source ability, or the permanent source of the ability. May be null.
* Works in any moment (even before source ability activated)
* Usually you should use one of the single tag functions instead: getSourceCostsTag() or checkSourceCostsTagExists()
* <p>
* Usually you should use one of the single tag functions instead: getSourceCostsTag() or checkSourceCostsTagExists().
* Use this function with caution, as it directly exposes the backing data structure.
*
* @param game
@ -1751,9 +1752,9 @@ public final class CardUtil {
}
// from any ability before resolve (on stack) - access by spell ability
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject instanceof Spell) {
return ((Spell) sourceObject).getSpellAbility().getCostsTagMap();
Spell sourceObject = game.getSpellOrLKIStack(source.getSourceId());
if (sourceObject != null) {
return sourceObject.getSpellAbility().getCostsTagMap();
}
return null;