refactor: removed outdated code

This commit is contained in:
Oleg Agafonov 2024-11-12 00:18:08 +04:00
parent fdbc5d6409
commit 52ebba4cd1
31 changed files with 56 additions and 66 deletions

View file

@ -122,10 +122,10 @@ class ChainerNightmareAdeptWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
if (event.getAdditionalReference() == null) {
if (event.getApprovingObject() == null) {
return;
}
morMap.computeIfAbsent(event.getAdditionalReference().getApprovingMageObjectReference(), m -> new HashMap<>())
morMap.computeIfAbsent(event.getApprovingObject().getApprovingMageObjectReference(), m -> new HashMap<>())
.compute(event.getPlayerId(), (u, i) -> i == null ? 0 : Integer.sum(i, -1));
}
}

View file

@ -150,10 +150,10 @@ class ChandraHopesBeaconWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST
|| event.getAdditionalReference() == null) {
|| event.getApprovingObject() == null) {
return;
}
MageObjectReference mor = event.getAdditionalReference().getApprovingMageObjectReference();
MageObjectReference mor = event.getApprovingObject().getApprovingMageObjectReference();
Spell spell = game.getSpell(event.getTargetId());
if (mor == null || spell == null) {
return;

View file

@ -194,10 +194,10 @@ class ChissGoriaForgeTyrantWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getApprovingObject() == null) {
return;
}
MageObjectReference mor = event.getAdditionalReference().getApprovingMageObjectReference();
MageObjectReference mor = event.getApprovingObject().getApprovingMageObjectReference();
Spell spell = game.getSpell(event.getTargetId());
if (mor == null || spell == null) {
return;

View file

@ -237,15 +237,15 @@ class CoramTheUndertakerWatcher extends Watcher {
cardsAllowedToBePlayedOrCast.add(new MageObjectReference(mainCard, game));
return;
}
if (event.getAdditionalReference() == null
|| !MageIdentifier.CoramTheUndertakerWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
if (event.getApprovingObject() == null
|| !MageIdentifier.CoramTheUndertakerWatcher.equals(event.getApprovingObject().getApprovingAbility().getIdentifier())) {
return;
}
if (event.getType() == GameEvent.EventType.LAND_PLAYED) {
landPlayedForSource.add(event.getAdditionalReference().getApprovingMageObjectReference());
landPlayedForSource.add(event.getApprovingObject().getApprovingMageObjectReference());
}
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
spellCastForSource.add(event.getAdditionalReference().getApprovingMageObjectReference());
spellCastForSource.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}

View file

@ -226,7 +226,7 @@ class CourtOfLocthwainWatcher extends Watcher {
&& event.getPlayerId() != null) {
decrementCastAvailable(
event.getPlayerId(),
event.getAdditionalReference().getApprovingMageObjectReference()
event.getApprovingObject().getApprovingMageObjectReference()
);
}
}

View file

@ -201,9 +201,9 @@ class EvelynTheCovetousWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if ((event.getType() == GameEvent.EventType.SPELL_CAST || event.getType() == GameEvent.EventType.LAND_PLAYED)
&& event.getAdditionalReference() != null) {
&& event.getApprovingObject() != null) {
usedMap.computeIfAbsent(
event.getAdditionalReference()
event.getApprovingObject()
.getApprovingMageObjectReference(),
x -> new HashSet<>()
).add(event.getPlayerId());

View file

@ -1,7 +1,6 @@
package mage.cards.f;
import mage.MageInt;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.CantBlockAbility;
@ -132,10 +131,10 @@ class FlameskullWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST
|| event.getAdditionalReference() == null) {
|| event.getApprovingObject() == null) {
return;
}
MageObjectReference mor = event.getAdditionalReference().getApprovingMageObjectReference();
MageObjectReference mor = event.getApprovingObject().getApprovingMageObjectReference();
Spell spell = game.getSpell(event.getTargetId());
if (mor == null || spell == null) {
return;

View file

@ -91,7 +91,7 @@ class GaleaKindlerOfHopeTriggeredAbility extends TriggeredAbilityImpl {
if (!isControlledBy(event.getPlayerId())
|| event.getZone() != Zone.LIBRARY
|| !event
.getAdditionalReference()
.getApprovingObject()
.getApprovingMageObjectReference()
.refersTo(this.getSourceObject(game), game)) {
return false;

View file

@ -162,7 +162,7 @@ class GlimpseTheCosmosWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL
&& event.hasApprovingIdentifier(MageIdentifier.GlimpseTheCosmosWatcher)) {
Ability approvingAbility = event.getAdditionalReference().getApprovingAbility();
Ability approvingAbility = event.getApprovingObject().getApprovingAbility();
if (approvingAbility != null
&& approvingAbility.getSourceId().equals(event.getSourceId())) {
sourceCards.add(game.getCard(event.getSourceId()));

View file

@ -185,7 +185,7 @@ class HaukensInsightWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST || event.getType() == GameEvent.EventType.LAND_PLAYED) {
if (event.hasApprovingIdentifier(MageIdentifier.HaukensInsightWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
usedFrom.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}
}

View file

@ -173,12 +173,12 @@ class HedonistsTroveWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST
|| event.getAdditionalReference() == null) {
|| event.getApprovingObject() == null) {
return;
}
playerMap
.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>())
.add(event.getAdditionalReference().getApprovingMageObjectReference());
.add(event.getApprovingObject().getApprovingMageObjectReference());
playerMap.get(event.getPlayerId()).removeIf(Objects::isNull);
}

View file

@ -224,7 +224,7 @@ class IanMalcolmChaoticianWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.SPELL_CAST &&
event.hasApprovingIdentifier(MageIdentifier.IanMalcolmChaoticianWatcher)) {
usedMap.computeIfAbsent(
event.getAdditionalReference()
event.getApprovingObject()
.getApprovingMageObjectReference(),
x -> new HashSet<>()
).add(event.getPlayerId());

View file

@ -211,10 +211,10 @@ class IdolOfEnduranceWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
if (event.getAdditionalReference() == null) {
if (event.getApprovingObject() == null) {
return;
}
morMap.computeIfAbsent(event.getAdditionalReference().getApprovingMageObjectReference(), m -> new HashMap<>())
morMap.computeIfAbsent(event.getApprovingObject().getApprovingMageObjectReference(), m -> new HashMap<>())
.compute(event.getPlayerId(), (u, i) -> i == null ? 0 : Integer.sum(i, -1));
}
}

View file

@ -123,7 +123,7 @@ class KaghaShadowArchdruidWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if ((GameEvent.EventType.SPELL_CAST.equals(event.getType()) || GameEvent.EventType.LAND_PLAYED.equals(event.getType()))
&& event.hasApprovingIdentifier(MageIdentifier.KaghaShadowArchdruidWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
usedFrom.add(event.getApprovingObject().getApprovingMageObjectReference());
}
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;

View file

@ -178,9 +178,9 @@ class KessDissidentMageWatcher extends Watcher {
&& event.hasApprovingIdentifier(MageIdentifier.KessDissidentMageWatcher)) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null) {
allowingObjects.add(event.getAdditionalReference().getApprovingMageObjectReference());
allowingObjects.add(event.getApprovingObject().getApprovingMageObjectReference());
castSpells.put(new MageObjectReference(spell.getMainCard().getId(), game),
event.getAdditionalReference().getApprovingAbility().getSourceId());
event.getApprovingObject().getApprovingAbility().getSourceId());
}
}
}

View file

@ -170,7 +170,7 @@ class KotoseTheSilentSpiderWatcher extends Watcher {
morMap.values().removeIf(Set::isEmpty);
return;
}
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getApprovingObject() == null) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
@ -178,7 +178,7 @@ class KotoseTheSilentSpiderWatcher extends Watcher {
return;
}
morMap.getOrDefault(
event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()
event.getApprovingObject().getApprovingMageObjectReference(), Collections.emptySet()
).removeIf(set -> set
.stream()
.anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId())

View file

@ -222,10 +222,10 @@ class LobeliaDefenderOfBagEndWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST || event.getType() == GameEvent.EventType.PLAY_LAND) {
if (event.getAdditionalReference() == null) {
if (event.getApprovingObject() == null) {
return;
}
morMap.computeIfAbsent(event.getAdditionalReference().getApprovingMageObjectReference(), m -> new HashMap<>())
morMap.computeIfAbsent(event.getApprovingObject().getApprovingMageObjectReference(), m -> new HashMap<>())
.compute(event.getPlayerId(), (u, i) -> i == null ? 0 : Integer.sum(i, -1));
}
}

View file

@ -148,14 +148,14 @@ class MaestrosAscendancyWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST
&& event.hasApprovingIdentifier(MageIdentifier.MaestrosAscendencyAlternateCast)
&& event.getAdditionalReference() != null) {
&& event.getApprovingObject() != null) {
playerMap.computeIfAbsent(
event.getAdditionalReference()
event.getApprovingObject()
.getApprovingMageObjectReference(),
x -> new HashSet<>()
).add(event.getPlayerId());
spellMap.computeIfAbsent(
event.getAdditionalReference()
event.getApprovingObject()
.getApprovingMageObjectReference(),
x -> new HashSet<>()
).add(new MageObjectReference(event.getTargetId(), game));

View file

@ -117,11 +117,11 @@ class MarchOfRecklessJoyWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getApprovingObject() == null) {
return;
}
morMap.compute(event
.getAdditionalReference()
.getApprovingObject()
.getApprovingMageObjectReference(),
CardUtil::setOrIncrementValue
);

View file

@ -146,8 +146,8 @@ class MuldrothaTheGravetideWatcher extends Watcher {
private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
if (mageObject != null
&& event.getAdditionalReference() != null
&& MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
&& event.getApprovingObject() != null
&& MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getApprovingObject().getApprovingAbility().getIdentifier())) {
UUID playerId = null;
if (mageObject instanceof Spell) {
playerId = ((Spell) mageObject).getControllerId();
@ -155,10 +155,10 @@ class MuldrothaTheGravetideWatcher extends Watcher {
playerId = ((Permanent) mageObject).getControllerId();
}
if (playerId != null) {
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getApprovingObject().getApprovingMageObjectReference());
if (permanentTypes == null) {
permanentTypes = EnumSet.noneOf(CardType.class);
sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
sourcePlayedPermanentTypes.put(event.getApprovingObject().getApprovingMageObjectReference(), permanentTypes);
}
Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
for (CardType cardType : mageObject.getCardType(game)) {

View file

@ -121,7 +121,7 @@ class NashiMoonSagesScionWatcher extends Watcher {
morMap.values().removeIf(Set::isEmpty);
return;
}
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getApprovingObject() == null) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
@ -129,7 +129,7 @@ class NashiMoonSagesScionWatcher extends Watcher {
return;
}
morMap.getOrDefault(
event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()
event.getApprovingObject().getApprovingMageObjectReference(), Collections.emptySet()
).removeIf(set -> set
.stream()
.anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId())

View file

@ -136,7 +136,7 @@ class OneWithTheMultiverseWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST
&& event.hasApprovingIdentifier(MageIdentifier.OneWithTheMultiverseWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
usedFrom.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}

View file

@ -159,12 +159,12 @@ class RadiantScrollwielderWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getApprovingObject() == null) {
return;
}
morMap.put(
new MageObjectReference(event.getSourceId(), game),
event.getAdditionalReference().getApprovingMageObjectReference()
event.getApprovingObject().getApprovingMageObjectReference()
);
}

View file

@ -142,10 +142,10 @@ class SerpentsSoulJarWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
if (event.getAdditionalReference() == null) {
if (event.getApprovingObject() == null) {
return;
}
morMap.computeIfAbsent(event.getAdditionalReference().getApprovingMageObjectReference(), m -> new HashMap<>())
morMap.computeIfAbsent(event.getApprovingObject().getApprovingMageObjectReference(), m -> new HashMap<>())
.compute(event.getPlayerId(), (u, i) -> i == null ? 0 : Integer.sum(i, -1));
return;
}

View file

@ -193,7 +193,7 @@ class SerraParagonWatcher extends Watcher {
|| event.getType() == GameEvent.EventType.LAND_PLAYED)
&& event.hasApprovingIdentifier(MageIdentifier.SerraParagonWatcher)) {
map.computeIfAbsent(
event.getAdditionalReference()
event.getApprovingObject()
.getApprovingMageObjectReference(),
x -> new HashSet<>()
).add(event.getPlayerId());

View file

@ -124,10 +124,10 @@ class UnluckyWitnessWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST
|| event.getAdditionalReference() == null) {
|| event.getApprovingObject() == null) {
return;
}
MageObjectReference mor = event.getAdditionalReference().getApprovingMageObjectReference();
MageObjectReference mor = event.getApprovingObject().getApprovingMageObjectReference();
Spell spell = game.getSpell(event.getTargetId());
if (mor == null || spell == null) {
return;

View file

@ -155,10 +155,10 @@ class WhispersteelDaggerWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
if (event.getAdditionalReference() == null) {
if (event.getApprovingObject() == null) {
return;
}
morMap.computeIfAbsent(event.getAdditionalReference().getApprovingMageObjectReference(), m -> new HashMap<>())
morMap.computeIfAbsent(event.getApprovingObject().getApprovingMageObjectReference(), m -> new HashMap<>())
.computeIfAbsent(game.getOwnerId(event.getSourceId()), m -> new HashMap<>())
.compute(event.getPlayerId(), (u, i) -> i == null ? 0 : Integer.sum(i, -1));
return;

View file

@ -121,7 +121,7 @@ class WishWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if ((GameEvent.EventType.SPELL_CAST.equals(event.getType()) || GameEvent.EventType.LAND_PLAYED.equals(event.getType()))
&& event.hasApprovingIdentifier(MageIdentifier.WishWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
usedFrom.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}

View file

@ -116,7 +116,7 @@ class CastFromGraveyardOnceWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (GameEvent.EventType.SPELL_CAST.equals(event.getType())
&& event.hasApprovingIdentifier(MageIdentifier.CastFromGraveyardOnceWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
usedFrom.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}

View file

@ -511,11 +511,6 @@ public class GameEvent implements Serializable {
DAMAGED_BATCH_FOR_ONE_PERMANENT(true),
DESTROY_PERMANENT,
/* DESTROY_PERMANENT_BY_LEGENDARY_RULE
targetId id of the permanent to destroy
playerId controller of the permanent to detroy
*/
DESTROY_PERMANENT_BY_LEGENDARY_RULE,
/* DESTROYED_PERMANENT
targetId id of the destroyed creature
sourceId sourceId of the ability with the destroy effect
@ -819,16 +814,12 @@ public class GameEvent implements Serializable {
}
/**
* Returns possibly approving object that allowed the creation of the event.
* Returns possibly approving object that allowed the creation of the event. Used for cast spell and play land events.
*/
public ApprovingObject getAdditionalReference() {
public ApprovingObject getApprovingObject() {
return approvingObject;
}
public void setAdditionalReference(ApprovingObject approvingObject) {
this.approvingObject = approvingObject;
}
/**
* used to store which replacement effects were already applied to an event
* or any modified events that may replace it

View file

@ -32,7 +32,7 @@ public class OnceEachTurnCastWatcher extends Watcher {
&& event.getPlayerId() != null
&& event.hasApprovingIdentifier(MageIdentifier.OnceEachTurnCastWatcher)) {
usedFrom.computeIfAbsent(event.getPlayerId(), k -> new HashSet<>())
.add(event.getAdditionalReference().getApprovingMageObjectReference());
.add(event.getApprovingObject().getApprovingMageObjectReference());
}
}