rewrite watchers to GameState.getWatcher(), rather than getWatchers().get(). This hides away the implementation of the watchers. Accepts the class rather than the name. Always returns the specific subclass, so there is no more casting needed. Only 1 line in the common library remains, that is still using the old 'deprecated' method. Needs a new version release to do that.

This commit is contained in:
Ingmar Goudt 2019-01-06 20:58:51 +01:00
parent f01b3d3ca3
commit 9a310732d8
324 changed files with 573 additions and 586 deletions

View file

@ -106,7 +106,7 @@ class AbandonedSarcophagusReplacementEffect extends ReplacementEffectImpl {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
AbandonedSarcophagusWatcher watcher = (AbandonedSarcophagusWatcher) game.getState().getWatchers().get(AbandonedSarcophagusWatcher.class.getSimpleName());
AbandonedSarcophagusWatcher watcher = game.getState().getWatcher(AbandonedSarcophagusWatcher.class);
Card card = game.getCard(event.getTargetId());
if (card == null
|| controller == null

View file

@ -124,7 +124,7 @@ class ControllerDealtDamageByPiratesPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
DamagedByPiratesWatcher watcher = (DamagedByPiratesWatcher) game.getState().getWatchers().get(DamagedByPiratesWatcher.class.getSimpleName());
DamagedByPiratesWatcher watcher = game.getState().getWatcher(DamagedByPiratesWatcher.class);
if (watcher != null) {
return watcher.damagedByEnoughPirates(input.getControllerId(), game);
}

View file

@ -50,7 +50,7 @@ class AetherfluxReservoirDynamicValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if(watcher != null) {
return watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(sourceAbility.getControllerId());
}

View file

@ -61,7 +61,7 @@ class AggravateRequirementEffect extends RequirementEffect {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get(DamagedByWatcher.class.getSimpleName(), source.getSourceId());
DamagedByWatcher watcher = game.getState().getWatcher(DamagedByWatcher.class, source.getSourceId());
if (watcher != null) {
return watcher.wasDamaged(permanent, game);
}

View file

@ -113,7 +113,7 @@ class AlhammarretsArchiveReplacementEffect extends ReplacementEffectImpl {
if (event.getPlayerId().equals(source.getControllerId())) {
if (game.isActivePlayer(event.getPlayerId())
&& game.getPhase().getStep().getType() == PhaseStep.DRAW) {
CardsDrawnDuringDrawStepWatcher watcher = (CardsDrawnDuringDrawStepWatcher) game.getState().getWatchers().get(CardsDrawnDuringDrawStepWatcher.class.getSimpleName());
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
return true;
}

View file

@ -66,7 +66,7 @@ class AngelicArbiterCantAttackTargetEffect extends RestrictionEffect {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (game.isActivePlayer(permanent.getControllerId()) && game.getOpponents(source.getControllerId()).contains(permanent.getControllerId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(permanent.getControllerId()) > 0) {
return true;
}
@ -114,7 +114,7 @@ class AngelicArbiterEffect2 extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.isActivePlayer(event.getPlayerId()) && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
PlayerAttackedWatcher watcher = (PlayerAttackedWatcher) game.getState().getWatchers().get(PlayerAttackedWatcher.class.getSimpleName());
PlayerAttackedWatcher watcher = game.getState().getWatcher(PlayerAttackedWatcher.class);
if (watcher != null && watcher.getNumberOfAttackersCurrentTurn(event.getPlayerId()) > 0) {
return true;
}

View file

@ -72,7 +72,7 @@ class AngelsTrumpetTapEffect extends OneShotEffect {
continue;
}
// Creatures that attacked are safe.
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(creature, game))) {
continue;
}

View file

@ -49,7 +49,7 @@ class OpponentWasNotDealtDamageCondition implements Condition {
public boolean apply(Game game, Ability source) {
UUID activePlayer = game.getState().getActivePlayerId();
if (activePlayer != null) {
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get(BloodthirstWatcher.class.getSimpleName(), activePlayer);
BloodthirstWatcher watcher = game.getState().getWatcher(BloodthirstWatcher.class, activePlayer);
if (watcher != null) {
return !watcher.conditionMet();
}

View file

@ -65,7 +65,7 @@ class ApproachOfTheSecondSunEffect extends OneShotEffect {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (controller != null && spell != null) {
ApproachOfTheSecondSunWatcher watcher
= (ApproachOfTheSecondSunWatcher) game.getState().getWatchers().get(ApproachOfTheSecondSunWatcher.class.getSimpleName());
= game.getState().getWatcher(ApproachOfTheSecondSunWatcher.class);
if (watcher != null
&& !spell.isCopy()
&& watcher.getApproachesCast(controller.getId()) > 1

View file

@ -60,13 +60,13 @@ class ArboriaEffect extends RestrictionEffect {
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) {
CastSpellYourLastTurnWatcher watcher = (CastSpellYourLastTurnWatcher) game.getState().getWatchers().get(CastSpellYourLastTurnWatcher.class.getSimpleName());
CastSpellYourLastTurnWatcher watcher = game.getState().getWatcher(CastSpellYourLastTurnWatcher.class);
if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) {
return true;
}
PermanentsEnteredBattlefieldYourLastTurnWatcher watcher2
= (PermanentsEnteredBattlefieldYourLastTurnWatcher) game.getState().getWatchers().get(PermanentsEnteredBattlefieldYourLastTurnWatcher.class.getSimpleName());
= game.getState().getWatcher(PermanentsEnteredBattlefieldYourLastTurnWatcher.class);
if (watcher2 != null && watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId) != null) {
for (Permanent permanent : watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId)) {

View file

@ -79,7 +79,7 @@ class ArchfiendOfDespairEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
if (controller != null && watcher != null) {
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);

View file

@ -92,7 +92,7 @@ enum OpponentSearchesLibCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
ArchiveTrapWatcher watcher = (ArchiveTrapWatcher) game.getState().getWatchers().get(ArchiveTrapWatcher.class.getSimpleName());
ArchiveTrapWatcher watcher = game.getState().getWatcher(ArchiveTrapWatcher.class);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && watcher != null) {
for (UUID playerId : watcher.getPlayersSearchedLibrary()) {

View file

@ -1,7 +1,6 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility;
@ -22,8 +21,9 @@ import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.watchers.common.CardsAmountDrawnThisTurnWatcher;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class ArchmageAscension extends CardImpl {
@ -74,7 +74,7 @@ class ArchmageAscensionTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Permanent archmage = game.getPermanent(super.getSourceId());
CardsAmountDrawnThisTurnWatcher watcher
= (CardsAmountDrawnThisTurnWatcher) game.getState().getWatchers().get(CardsAmountDrawnThisTurnWatcher.class.getSimpleName());
= game.getState().getWatcher(CardsAmountDrawnThisTurnWatcher.class);
return archmage != null && watcher != null && watcher.getAmountCardsDrawn(this.getControllerId()) >= 2;
}

View file

@ -72,8 +72,8 @@ enum ArclightPhoenixCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
ArclightPhoenixWatcher watcher
= (ArclightPhoenixWatcher) game.getState().getWatchers().get(
ArclightPhoenixWatcher.class.getSimpleName()
= game.getState().getWatcher(
ArclightPhoenixWatcher.class
);
return watcher != null && watcher.getInstantSorceryCount(source.getControllerId()) > 2;
}
@ -81,7 +81,7 @@ enum ArclightPhoenixCondition implements Condition {
class ArclightPhoenixWatcher extends Watcher {
private final Map<UUID, Integer> instantSorceryCount = new HashMap();
private final Map<UUID, Integer> instantSorceryCount = new HashMap<>();
public ArclightPhoenixWatcher() {
super(ArclightPhoenixWatcher.class.getSimpleName(), WatcherScope.GAME);

View file

@ -120,8 +120,7 @@ class AsForetoldAlternativeCost extends AlternativeCostSourceAbility {
if (wasActivated) {
// Get the watcher
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher
= (AsForetoldAltCostUsedWatcher) game.getState().getWatchers()
.get("asForetoldAltCostUsedWatcher", sourceAsForetold);
= game.getState().getWatcher(AsForetoldAltCostUsedWatcher.class, sourceAsForetold);
// Mark as used
asForetoldAltCostUsedWatcher.markUsedThisTurn();
@ -161,8 +160,8 @@ class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
if (sourcePermanent != null) {
// Get the watcher
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher
= (AsForetoldAltCostUsedWatcher) game.getState().getWatchers()
.get("asForetoldAltCostUsedWatcher", sourcePermanent.getId());
= game.getState().getWatcher(
AsForetoldAltCostUsedWatcher.class, sourcePermanent.getId());
// If we haven't used it yet this turn, give the option of using the zero alternative cost
if (!asForetoldAltCostUsedWatcher.hasBeenUsedThisTurn()) {

View file

@ -95,7 +95,7 @@ class AsmiraHolyAvengerDynamicValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
AsmiraHolyAvengerWatcher watcher = (AsmiraHolyAvengerWatcher) game.getState().getWatchers().get(AsmiraHolyAvengerWatcher.class.getSimpleName(), sourceAbility.getControllerId());
AsmiraHolyAvengerWatcher watcher = game.getState().getWatcher(AsmiraHolyAvengerWatcher.class, sourceAbility.getControllerId());
if (watcher != null) {
return watcher.getCreaturesCount();
}

View file

@ -98,7 +98,7 @@ class AureliasFuryEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
AureliasFuryDamagedByWatcher watcher = (AureliasFuryDamagedByWatcher) game.getState().getWatchers().get(AureliasFuryDamagedByWatcher.class.getSimpleName(), source.getSourceId());
AureliasFuryDamagedByWatcher watcher = game.getState().getWatcher(AureliasFuryDamagedByWatcher.class, source.getSourceId());
if (watcher != null) {
for (UUID creatureId : watcher.getDamagedCreatures()) {
Permanent permanent = game.getPermanent(creatureId);

View file

@ -53,7 +53,7 @@ class AvengingArrowTarget extends TargetPermanent {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
SourceDidDamageWatcher watcher = game.getState().getWatcher(SourceDidDamageWatcher.class);
if (watcher != null) {
if (watcher.damageSources.contains(id)) {
return super.canTarget(id, source, game);
@ -66,7 +66,7 @@ class AvengingArrowTarget extends TargetPermanent {
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
SourceDidDamageWatcher watcher = game.getState().getWatcher(SourceDidDamageWatcher.class);
if (watcher != null) {
for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId);

View file

@ -89,7 +89,7 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
effect.apply(game, source);
// Make blocked creatures unblocked
BlockedByOnlyOneCreatureThisCombatWatcher watcher = (BlockedByOnlyOneCreatureThisCombatWatcher) game.getState().getWatchers().get(BlockedByOnlyOneCreatureThisCombatWatcher.class.getSimpleName());
BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
if (watcher != null) {
Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
if (combatGroups != null) {

View file

@ -50,7 +50,7 @@ enum BalothCageTrapCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
PermanentsEnteredBattlefieldWatcher watcher = (PermanentsEnteredBattlefieldWatcher) game.getState().getWatchers().get(PermanentsEnteredBattlefieldWatcher.class.getSimpleName());
PermanentsEnteredBattlefieldWatcher watcher = game.getState().getWatcher(PermanentsEnteredBattlefieldWatcher.class);
if (watcher != null) {
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
List<Permanent> permanents = watcher.getThisTurnEnteringPermanents(opponentId);

View file

@ -1,7 +1,6 @@
package mage.cards.b;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -26,8 +25,9 @@ import mage.target.targetpointer.FixedTarget;
import mage.watchers.Watcher;
import mage.watchers.common.AttackedThisTurnWatcher;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class Berserk extends CardImpl {
@ -76,7 +76,7 @@ class BerserkReplacementEffect extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL && event.getSourceId().equals(source.getSourceId())) {
CombatDamageStepStartedWatcher watcher = (CombatDamageStepStartedWatcher) game.getState().getWatchers().get(CombatDamageStepStartedWatcher.class.getSimpleName());
CombatDamageStepStartedWatcher watcher = game.getState().getWatcher(CombatDamageStepStartedWatcher.class);
return watcher == null || watcher.conditionMet();
}
return false;
@ -96,7 +96,7 @@ class BerserkReplacementEffect extends ContinuousRuleModifyingEffectImpl {
class CombatDamageStepStartedWatcher extends Watcher {
public CombatDamageStepStartedWatcher() {
super(CombatDamageStepStartedWatcher.class.getSimpleName(), WatcherScope.GAME);
super(CombatDamageStepStartedWatcher.class, WatcherScope.GAME);
}
public CombatDamageStepStartedWatcher(final CombatDamageStepStartedWatcher watcher) {
@ -170,14 +170,12 @@ class BerserkDelayedDestroyEffect extends OneShotEffect {
if (controller != null) {
Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (permanent != null) {
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
if (watcher instanceof AttackedThisTurnWatcher) {
if (((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
return permanent.destroy(source.getSourceId(), game, false);
}
}
}
}
return false;
}
}

View file

@ -69,7 +69,7 @@ class BloodcrazedGoblinEffect extends RestrictionEffect {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get(BloodthirstWatcher.class.getSimpleName(), source.getControllerId()); // BloodthirstWatcher
BloodthirstWatcher watcher = game.getState().getWatcher(BloodthirstWatcher.class, source.getControllerId()); // BloodthirstWatcher
return watcher != null && !watcher.conditionMet();
}
return false;

View file

@ -98,7 +98,7 @@ class BontuTheGlorifiedRestrictionEffect extends RestrictionEffect {
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
Player controller = game.getPlayer(source.getControllerId());
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
CreaturesDiedWatcher watcher = game.getState().getWatcher(CreaturesDiedWatcher.class);
if (controller != null
&& watcher != null) {
return (watcher.getAmountOfCreaturesDiedThisTurnByController(controller.getId()) == 0);

View file

@ -62,7 +62,7 @@ class BoseijuWhoSheltersAllWatcher extends Watcher {
private final String originalId;
public BoseijuWhoSheltersAllWatcher(UUID originalId) {
super(BoseijuWhoSheltersAllWatcher.class.getSimpleName(), WatcherScope.CARD);
super(BoseijuWhoSheltersAllWatcher.class, WatcherScope.CARD);
this.originalId = originalId.toString();
}
@ -137,7 +137,7 @@ class BoseijuWhoSheltersAllCantCounterEffect extends ContinuousRuleModifyingEffe
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
BoseijuWhoSheltersAllWatcher watcher = (BoseijuWhoSheltersAllWatcher) game.getState().getWatchers().get(BoseijuWhoSheltersAllWatcher.class.getSimpleName(), source.getSourceId());
BoseijuWhoSheltersAllWatcher watcher = game.getState().getWatcher(BoseijuWhoSheltersAllWatcher.class, source.getSourceId());
Spell spell = game.getStack().getSpell(event.getTargetId());
return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId());
}

View file

@ -56,7 +56,7 @@ enum BriarbridgePatrolCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
PermanentsSacrificedWatcher watcher = (PermanentsSacrificedWatcher) game.getState().getWatchers().get(PermanentsSacrificedWatcher.class.getSimpleName());
PermanentsSacrificedWatcher watcher = game.getState().getWatcher(PermanentsSacrificedWatcher.class);
if (watcher != null) {
List<Permanent> sacrificedPermanents = watcher.getThisTurnSacrificedPermanents(source.getControllerId());
if (sacrificedPermanents != null && !sacrificedPermanents.isEmpty()) {

View file

@ -53,7 +53,7 @@ class BrimstoneVolleyEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int damage = 3;
Watcher watcher = game.getState().getWatchers().get(MorbidWatcher.class.getSimpleName());
MorbidWatcher watcher = game.getState().getWatcher(MorbidWatcher.class);
if (watcher != null && watcher.conditionMet()) {
damage = 5;
}

View file

@ -74,7 +74,7 @@ public final class BrutalHordechief extends CardImpl {
@Override
public boolean apply(Game game, Ability source) {
ChooseBlockersRedundancyWatcher watcher = (ChooseBlockersRedundancyWatcher) game.getState().getWatchers().get(ChooseBlockersRedundancyWatcher.class.getSimpleName());
ChooseBlockersRedundancyWatcher watcher = game.getState().getWatcher(ChooseBlockersRedundancyWatcher.class);
if (watcher != null) {
watcher.increment();
return true;
@ -155,7 +155,7 @@ class BrutalHordechiefChooseBlockersEffect extends ContinuousRuleModifyingEffect
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
ChooseBlockersRedundancyWatcher watcher = (ChooseBlockersRedundancyWatcher) game.getState().getWatchers().get(ChooseBlockersRedundancyWatcher.class.getSimpleName());
ChooseBlockersRedundancyWatcher watcher = game.getState().getWatcher(ChooseBlockersRedundancyWatcher.class);
if(watcher == null){
return false;
}

View file

@ -184,7 +184,7 @@ class BurningCinderFuryOfCrimsonChaosFireCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
BurningCinderFuryOfCrimsonChaosFireWatcher watcher = (BurningCinderFuryOfCrimsonChaosFireWatcher) game.getState().getWatchers().get(BurningCinderFuryOfCrimsonChaosFireWatcher.class.getSimpleName());
BurningCinderFuryOfCrimsonChaosFireWatcher watcher = game.getState().getWatcher(BurningCinderFuryOfCrimsonChaosFireWatcher.class);
if (watcher != null) {
return !watcher.tappedNonlandThisTurn(game.getActivePlayerId());
}

View file

@ -114,7 +114,7 @@ class CallerOfTheClawDynamicValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
CallerOfTheClawWatcher watcher = (CallerOfTheClawWatcher) game.getState().getWatchers().get(CallerOfTheClawWatcher.class.getSimpleName(), sourceAbility.getControllerId());
CallerOfTheClawWatcher watcher = game.getState().getWatcher(CallerOfTheClawWatcher.class, sourceAbility.getControllerId());
if (watcher != null) {
return watcher.getCreaturesCount();
}

View file

@ -93,7 +93,7 @@ class CathedralMembraneEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
CathedralMembraneWatcher watcher = (CathedralMembraneWatcher) game.getState().getWatchers().get(CathedralMembraneWatcher.class.getSimpleName(), source.getSourceId());
CathedralMembraneWatcher watcher = game.getState().getWatcher(CathedralMembraneWatcher.class, source.getSourceId());
if (watcher != null) {
for (UUID uuid : watcher.getBlockedCreatures()) {
Permanent permanent = game.getPermanent(uuid);

View file

@ -197,7 +197,7 @@ class CavernOfSoulsCantCounterEffect extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
CavernOfSoulsWatcher watcher = (CavernOfSoulsWatcher) game.getState().getWatchers().get(CavernOfSoulsWatcher.class.getSimpleName(), source.getSourceId());
CavernOfSoulsWatcher watcher = game.getState().getWatcher(CavernOfSoulsWatcher.class, source.getSourceId());
Spell spell = game.getStack().getSpell(event.getTargetId());
return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId());
}

View file

@ -66,7 +66,7 @@ class CerebralVortexEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
CerebralVortexWatcher watcher = (CerebralVortexWatcher) game.getState().getWatchers().get(CerebralVortexWatcher.class.getSimpleName());
CerebralVortexWatcher watcher = game.getState().getWatcher(CerebralVortexWatcher.class);
if (watcher != null) {
targetPlayer.damage(watcher.getDraws(targetPlayer.getId()), source.getSourceId(), game, false, true);
return true;

View file

@ -86,7 +86,7 @@ class ChainsOfMephistophelesReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.isActivePlayer(event.getPlayerId()) && game.getPhase().getStep().getType() == PhaseStep.DRAW) {
CardsDrawnDuringDrawStepWatcher watcher = (CardsDrawnDuringDrawStepWatcher) game.getState().getWatchers().get(CardsDrawnDuringDrawStepWatcher.class.getSimpleName());
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
return true;
}

View file

@ -62,7 +62,7 @@ class ChargingCinderhornCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher != null) {
return watcher.getAttackedThisTurnCreatures().isEmpty();
}

View file

@ -52,7 +52,7 @@ class SourceControllerLostLifeCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
if (watcher != null) {
return watcher.getLifeLost(sourceAbility.getControllerId());
}

View file

@ -12,6 +12,7 @@ import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.h.HomicidalBruteWatcher;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
@ -54,31 +55,7 @@ public final class CivilizedScholar extends CardImpl {
}
}
class HomicidalBruteWatcher extends Watcher {
public HomicidalBruteWatcher() {
super(HomicidalBruteWatcher.class.getSimpleName(), WatcherScope.CARD);
}
public HomicidalBruteWatcher(final HomicidalBruteWatcher watcher) {
super(watcher);
}
@Override
public HomicidalBruteWatcher copy() {
return new HomicidalBruteWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
if (condition == true) {
return;
}
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED && event.getSourceId().equals(sourceId)) {
condition = true;
}
}
}
class CivilizedScholarEffect extends OneShotEffect {
@ -87,7 +64,7 @@ class CivilizedScholarEffect extends OneShotEffect {
staticText = "Draw a card, then discard a card. If a creature card is discarded this way, untap {this}, then transform it";
}
public CivilizedScholarEffect(final CivilizedScholarEffect effect) {
private CivilizedScholarEffect(final CivilizedScholarEffect effect) {
super(effect);
}

View file

@ -55,7 +55,7 @@ enum CobraTrapCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
CobraTrapWatcher watcher = (CobraTrapWatcher) game.getState().getWatchers().get(CobraTrapWatcher.class.getSimpleName());
CobraTrapWatcher watcher = game.getState().getWatcher(CobraTrapWatcher.class);
return watcher != null && watcher.conditionMet(source.getControllerId());
}

View file

@ -117,7 +117,7 @@ class FirstCastCreatureSpellPredicate implements ObjectPlayerPredicate<ObjectPla
public boolean apply(ObjectPlayer<Controllable> input, Game game) {
if (input.getObject() instanceof Spell
&& ((Spell) input.getObject()).isCreature()) {
ConduitOfRuinWatcher watcher = (ConduitOfRuinWatcher) game.getState().getWatchers().get(ConduitOfRuinWatcher.class.getSimpleName());
ConduitOfRuinWatcher watcher = game.getState().getWatcher(ConduitOfRuinWatcher.class);
return watcher != null && watcher.creatureSpellsCastThisTurn(input.getPlayerId()) == 0;
}
return false;

View file

@ -96,7 +96,7 @@ class ContainmentPriestReplacementEffect extends ReplacementEffectImpl {
card = card.getSecondCardFace();
}
if (card != null && card.isCreature()) { // TODO: Bestow Card cast as Enchantment probably not handled correctly
CreatureWasCastWatcher watcher = (CreatureWasCastWatcher) game.getState().getWatchers().get(CreatureWasCastWatcher.class.getSimpleName());
CreatureWasCastWatcher watcher = game.getState().getWatcher(CreatureWasCastWatcher.class);
return watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId());
}
}

View file

@ -76,7 +76,7 @@ class CorrosiveOozeEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
CorrosiveOozeCombatWatcher watcher = (CorrosiveOozeCombatWatcher) game.getState().getWatchers().get(CorrosiveOozeCombatWatcher.class.getSimpleName());
CorrosiveOozeCombatWatcher watcher = game.getState().getWatcher(CorrosiveOozeCombatWatcher.class);
if (controller != null && watcher != null) {
MageObjectReference sourceMor = new MageObjectReference(source.getSourceObject(game), game);
// get equipmentsToDestroy of creatres already left the battlefield
@ -118,8 +118,8 @@ class CorrosiveOozeEffect extends OneShotEffect {
class CorrosiveOozeCombatWatcher extends Watcher {
public final HashMap<MageObjectReference, HashSet<MageObjectReference>> oozeBlocksOrBlocked = new HashMap<>();
public final HashMap<MageObjectReference, HashSet<MageObjectReference>> oozeEquipmentsToDestroy = new HashMap<>();
private final Map<MageObjectReference, Set<MageObjectReference>> oozeBlocksOrBlocked = new HashMap<>();
private final Map<MageObjectReference, Set<MageObjectReference>> oozeEquipmentsToDestroy = new HashMap<>();
public CorrosiveOozeCombatWatcher() {
super(CorrosiveOozeCombatWatcher.class.getSimpleName(), WatcherScope.GAME);
@ -127,11 +127,11 @@ class CorrosiveOozeCombatWatcher extends Watcher {
public CorrosiveOozeCombatWatcher(final CorrosiveOozeCombatWatcher watcher) {
super(watcher);
for (Map.Entry<MageObjectReference, HashSet<MageObjectReference>> entry : watcher.oozeBlocksOrBlocked.entrySet()) {
HashSet<MageObjectReference> newSet = new HashSet<>(entry.getValue());
for (Map.Entry<MageObjectReference, Set<MageObjectReference>> entry : watcher.oozeBlocksOrBlocked.entrySet()) {
Set<MageObjectReference> newSet = new HashSet<>(entry.getValue());
oozeBlocksOrBlocked.put(entry.getKey(), newSet);
}
for (Map.Entry<MageObjectReference, HashSet<MageObjectReference>> entry : watcher.oozeEquipmentsToDestroy.entrySet()) {
for (Map.Entry<MageObjectReference, Set<MageObjectReference>> entry : watcher.oozeEquipmentsToDestroy.entrySet()) {
HashSet<MageObjectReference> newSet = new HashSet<>(entry.getValue());
oozeEquipmentsToDestroy.put(entry.getKey(), newSet);
}
@ -148,7 +148,7 @@ class CorrosiveOozeCombatWatcher extends Watcher {
if (attacker != null && CardUtil.haveSameNames(attacker.getName(), "Corrosive Ooze")) { // To check for name is not working if Ooze is copied but name changed
if (blocker != null && hasAttachedEquipment(game, blocker)) {
MageObjectReference oozeMor = new MageObjectReference(attacker, game);
HashSet<MageObjectReference> relatedCreatures = oozeBlocksOrBlocked.getOrDefault(oozeMor, new HashSet<>());
Set<MageObjectReference> relatedCreatures = oozeBlocksOrBlocked.getOrDefault(oozeMor, new HashSet<>());
relatedCreatures.add(new MageObjectReference(event.getSourceId(), game));
oozeBlocksOrBlocked.put(oozeMor, relatedCreatures);
}
@ -156,7 +156,7 @@ class CorrosiveOozeCombatWatcher extends Watcher {
if (blocker != null && CardUtil.haveSameNames(blocker.getName(), "Corrosive Ooze")) {
if (attacker != null && hasAttachedEquipment(game, attacker)) {
MageObjectReference oozeMor = new MageObjectReference(blocker, game);
HashSet<MageObjectReference> relatedCreatures = oozeBlocksOrBlocked.getOrDefault(oozeMor, new HashSet<>());
Set<MageObjectReference> relatedCreatures = oozeBlocksOrBlocked.getOrDefault(oozeMor, new HashSet<>());
relatedCreatures.add(new MageObjectReference(event.getTargetId(), game));
oozeBlocksOrBlocked.put(oozeMor, relatedCreatures);
}
@ -167,14 +167,14 @@ class CorrosiveOozeCombatWatcher extends Watcher {
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
if (game.getTurn() != null && TurnPhase.COMBAT == game.getTurn().getPhaseType()) {
// Check if a previous blocked or blocked by creatures is leaving the battlefield
for (Map.Entry<MageObjectReference, HashSet<MageObjectReference>> entry : oozeBlocksOrBlocked.entrySet()) {
for (Map.Entry<MageObjectReference, Set<MageObjectReference>> entry : oozeBlocksOrBlocked.entrySet()) {
for (MageObjectReference mor : entry.getValue()) {
if (mor.refersTo(((ZoneChangeEvent) event).getTarget(), game)) {
// check for equipments and remember
for (UUID attachmentId : ((ZoneChangeEvent) event).getTarget().getAttachments()) {
Permanent attachment = game.getPermanent(attachmentId);
if (attachment != null && attachment.hasSubtype(SubType.EQUIPMENT, game)) {
HashSet<MageObjectReference> toDestroy = oozeEquipmentsToDestroy.getOrDefault(entry.getKey(), new HashSet<>());
Set<MageObjectReference> toDestroy = oozeEquipmentsToDestroy.getOrDefault(entry.getKey(), new HashSet<>());
toDestroy.add(new MageObjectReference(attachment, game));
oozeEquipmentsToDestroy.put(entry.getKey(), toDestroy);
}

View file

@ -63,7 +63,7 @@ class CryOfTheCarnariumExileEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (player == null || watcher == null) {
return false;
}

View file

@ -77,7 +77,7 @@ class CurseOfExhaustionEffect extends ContinuousRuleModifyingEffectImpl {
if (enchantment != null && enchantment.getAttachedTo() != null) {
Player player = game.getPlayer(enchantment.getAttachedTo());
if (player != null && event.getPlayerId().equals(player.getId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) > 0) {
return true;
}

View file

@ -52,7 +52,7 @@ public final class CustodiSoulcaller extends CardImpl {
public void adjustTargets(Ability ability, Game game) {
if (ability.getClass().equals(AttacksTriggeredAbility.class)) {
ability.getTargets().clear();
CustodiSoulcallerWatcher watcher = (CustodiSoulcallerWatcher) game.getState().getWatchers().get(CustodiSoulcallerWatcher.class.getSimpleName());
CustodiSoulcallerWatcher watcher = game.getState().getWatcher(CustodiSoulcallerWatcher.class);
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId());
if (watcher != null && watcher.playersAttacked != null) {
int xValue = watcher.getNumberOfAttackedPlayers(sourcePermanent.getControllerId());

View file

@ -30,10 +30,7 @@ import mage.target.common.TargetLandPermanent;
import mage.target.targetpointer.FixedTarget;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
/**
* @author MTGfan
@ -151,7 +148,7 @@ class CyclopeanTombEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObjectReference mor = new MageObjectReference(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game);
CyclopeanTombCounterWatcher watcher = (CyclopeanTombCounterWatcher) game.getState().getWatchers().get(CyclopeanTombCounterWatcher.class.getSimpleName());
CyclopeanTombCounterWatcher watcher = game.getState().getWatcher(CyclopeanTombCounterWatcher.class);
if (controller != null && watcher != null) {
Set<MageObjectReference> landRef = watcher.landMiredByCyclopeanTombInstance(mor, game);
@ -190,7 +187,7 @@ class CyclopeanTombEffect extends OneShotEffect {
class CyclopeanTombCounterWatcher extends Watcher {
private final HashMap<MageObjectReference, Set<MageObjectReference>> counterData = new HashMap<>();
private final Map<MageObjectReference, Set<MageObjectReference>> counterData = new HashMap<>();
CyclopeanTombCounterWatcher() {
super(CyclopeanTombCounterWatcher.class.getSimpleName(), WatcherScope.GAME);

View file

@ -103,7 +103,7 @@ class DampingSphereIncreasementAllEffect extends SpellsCostIncreasementAllEffect
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null) {
int additionalCost = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(abilityToModify.getControllerId());
CardUtil.increaseCost(abilityToModify, additionalCost);

View file

@ -1,8 +1,5 @@
package mage.cards.d;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
@ -12,19 +9,18 @@ import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.DeathtouchAbility;
import mage.constants.SubType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class DarkbladeAgent extends CardImpl {
@ -77,9 +73,8 @@ enum DarkbladeAgentCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
DarkbladeAgentWatcher watcher
= (DarkbladeAgentWatcher) game.getState().getWatchers().get(
DarkbladeAgentWatcher.class.getSimpleName()
);
= game.getState().getWatcher(
DarkbladeAgentWatcher.class);
return watcher != null
&& watcher.getSurveiledThisTurn(source.getControllerId());
}
@ -87,10 +82,10 @@ enum DarkbladeAgentCondition implements Condition {
class DarkbladeAgentWatcher extends Watcher {
private final Set<UUID> surveiledThisTurn = new HashSet();
private final Set<UUID> surveiledThisTurn = new HashSet<>();
public DarkbladeAgentWatcher() {
super(DarkbladeAgentWatcher.class.getSimpleName(), WatcherScope.GAME);
super(DarkbladeAgentWatcher.class, WatcherScope.GAME);
}
public DarkbladeAgentWatcher(final DarkbladeAgentWatcher watcher) {

View file

@ -69,7 +69,7 @@ class DesolationEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
DesolationWatcher watcher = (DesolationWatcher) game.getState().getWatchers().get(DesolationWatcher.class.getSimpleName());
DesolationWatcher watcher = game.getState().getWatcher(DesolationWatcher.class);
if (watcher != null) {
for (UUID playerId : watcher.getPlayersTappedForMana()) {
Player player = game.getPlayer(playerId);

View file

@ -90,7 +90,7 @@ class DraconicRoarEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
DragonOnTheBattlefieldWhileSpellWasCastWatcher watcher = (DragonOnTheBattlefieldWhileSpellWasCastWatcher) game.getState().getWatchers().get(DragonOnTheBattlefieldWhileSpellWasCastWatcher.class.getSimpleName());
DragonOnTheBattlefieldWhileSpellWasCastWatcher watcher = game.getState().getWatcher(DragonOnTheBattlefieldWhileSpellWasCastWatcher.class);
if (watcher != null && watcher.castWithConditionTrue(source.getId())) {
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (permanent != null) {

View file

@ -49,7 +49,7 @@ class CardsDiscardedThisTurnWatcher extends Watcher {
private final Map<UUID, Integer> amountOfCardsDiscardedThisTurn = new HashMap<>();
public CardsDiscardedThisTurnWatcher() {
super(CardsDiscardedThisTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
super(CardsDiscardedThisTurnWatcher.class, WatcherScope.GAME);
}
public CardsDiscardedThisTurnWatcher(final CardsDiscardedThisTurnWatcher watcher) {
@ -102,7 +102,7 @@ class DreamSalvageEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
CardsDiscardedThisTurnWatcher watcher = (CardsDiscardedThisTurnWatcher) game.getState().getWatchers().get(CardsDiscardedThisTurnWatcher.class.getSimpleName());
CardsDiscardedThisTurnWatcher watcher = game.getState().getWatcher(CardsDiscardedThisTurnWatcher.class);
Player targetOpponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent != null

View file

@ -57,7 +57,7 @@ class CastBlueSpellThisTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
SpellsCastWatcher watcher = (SpellsCastWatcher) game.getState().getWatchers().get(SpellsCastWatcher.class.getSimpleName());
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher != null) {
List<Spell> spells = watcher.getSpellsCastThisTurn(source.getControllerId());
if (spells != null) {

View file

@ -74,7 +74,7 @@ class NoMoreThanOneCreatureCanAttackEachTurnEffect extends RestrictionEffect {
if (!game.getCombat().getAttackers().isEmpty()) {
return false;
}
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if(watcher == null){
return false;
}
@ -111,7 +111,7 @@ class NoMoreThanOneCreatureCanBlockEachTurnEffect extends RestrictionEffect {
if (!game.getCombat().getBlockers().isEmpty()) {
return false;
}
BlockedThisTurnWatcher watcher = (BlockedThisTurnWatcher) game.getState().getWatchers().get(BlockedThisTurnWatcher.class.getSimpleName());
BlockedThisTurnWatcher watcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
if(watcher == null){
return false;
}

View file

@ -70,7 +70,7 @@ enum HadAnotherCreatureEnterTheBattlefieldCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
PermanentsEnteredBattlefieldWatcher watcher = (PermanentsEnteredBattlefieldWatcher) game.getState().getWatchers().get(PermanentsEnteredBattlefieldWatcher.class.getSimpleName());
PermanentsEnteredBattlefieldWatcher watcher = game.getState().getWatcher(PermanentsEnteredBattlefieldWatcher.class);
return sourcePermanent != null
&& watcher != null
&& watcher.anotherCreatureEnteredBattlefieldUnderPlayersControlLastTurn(sourcePermanent, game);

View file

@ -78,7 +78,7 @@ class ErayoSoratamiAscendantTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
return watcher != null && watcher.getAmountOfSpellsAllPlayersCastOnCurrentTurn() == 4;
}
@ -134,7 +134,7 @@ class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 1) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));

View file

@ -66,7 +66,7 @@ class ErdwalIlluminatorTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
InvestigatedWatcher watcher = (InvestigatedWatcher) game.getState().getWatchers().get(InvestigatedWatcher.class.getSimpleName());
InvestigatedWatcher watcher = game.getState().getWatcher(InvestigatedWatcher.class);
return watcher != null && watcher.getTimesInvestigated(getControllerId()) == 1;
}

View file

@ -55,7 +55,7 @@ class ErgRaidersCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent raiders = game.getPermanentOrLKIBattlefield(source.getSourceId());
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
// wasControlledFromStartOfControllerTurn should be checked during resolution I guess, but shouldn't be relevant
return raiders != null &&raiders.wasControlledFromStartOfControllerTurn() && watcher != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(raiders, game));
}

View file

@ -116,7 +116,7 @@ class EtherswornCanonistReplacementEffect extends ContinuousRuleModifyingEffectI
public boolean applies(GameEvent event, Ability source, Game game) {
Card card = game.getCard(event.getSourceId());
if (card != null && !card.isArtifact()) {
EtherswornCanonistWatcher watcher = (EtherswornCanonistWatcher) game.getState().getWatchers().get(EtherswornCanonistWatcher.class.getSimpleName());
EtherswornCanonistWatcher watcher = game.getState().getWatcher(EtherswornCanonistWatcher.class);
return watcher != null && watcher.castNonArtifactSpell(event.getPlayerId());
}
return false;

View file

@ -56,7 +56,7 @@ class TargetCreaturePermanentThatDealtDamageThisTurn extends TargetPermanent {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
SourceDidDamageWatcher watcher = game.getState().getWatcher(SourceDidDamageWatcher.class);
if (watcher != null) {
if (watcher.damageSources.contains(id)) {
return super.canTarget(id, source, game);
@ -73,7 +73,7 @@ class TargetCreaturePermanentThatDealtDamageThisTurn extends TargetPermanent {
}
int count = 0;
MageObject targetSource = game.getObject(sourceId);
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
SourceDidDamageWatcher watcher = game.getState().getWatcher(SourceDidDamageWatcher.class);
if (watcher != null && targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && watcher.damageSources.contains(permanent.getId())) {
@ -93,7 +93,7 @@ class TargetCreaturePermanentThatDealtDamageThisTurn extends TargetPermanent {
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
SourceDidDamageWatcher watcher = game.getState().getWatcher(SourceDidDamageWatcher.class);
if (watcher != null) {
for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId);

View file

@ -57,7 +57,7 @@ enum FairgroundsTrumpeterCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
FairgroundsTrumpeterWatcher watcher = (FairgroundsTrumpeterWatcher) game.getState().getWatchers().get(FairgroundsTrumpeterWatcher.class.getSimpleName());
FairgroundsTrumpeterWatcher watcher = game.getState().getWatcher(FairgroundsTrumpeterWatcher.class);
return watcher != null && watcher.p1p1AddedToPermanent(source.getControllerId());
}

View file

@ -57,7 +57,7 @@ class FaithsRewardEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
FaithsRewardWatcher watcher = (FaithsRewardWatcher) game.getState().getWatchers().get(FaithsRewardWatcher.class.getSimpleName());
FaithsRewardWatcher watcher = game.getState().getWatcher(FaithsRewardWatcher.class);
if (watcher != null) {
for (UUID id : watcher.cards) {
Card c = game.getCard(id);
@ -80,7 +80,7 @@ class FaithsRewardWatcher extends Watcher {
List<UUID> cards = new ArrayList<>();
public FaithsRewardWatcher() {
super(FaithsRewardWatcher.class.getSimpleName(), WatcherScope.GAME);
super(FaithsRewardWatcher.class, WatcherScope.GAME);
}
public FaithsRewardWatcher(final FaithsRewardWatcher watcher) {

View file

@ -104,7 +104,7 @@ class FalseOrdersUnblockEffect extends OneShotEffect {
effect.apply(game, source);
// Make blocked creatures unblocked
BlockedByOnlyOneCreatureThisCombatWatcher watcher = (BlockedByOnlyOneCreatureThisCombatWatcher) game.getState().getWatchers().get(BlockedByOnlyOneCreatureThisCombatWatcher.class.getSimpleName());
BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
if (watcher != null) {
Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
if (combatGroups != null) {

View file

@ -54,7 +54,7 @@ enum FeastOnTheFallenCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
if (watcher != null) {
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
if (watcher.getLifeLostLastTurn(opponentId) > 0) {

View file

@ -65,7 +65,7 @@ class FellShepherdWatcher extends Watcher {
private Set<UUID> creatureIds = new HashSet<>();
public FellShepherdWatcher() {
super(FellShepherdWatcher.class.getSimpleName(), WatcherScope.PLAYER);
super(FellShepherdWatcher.class, WatcherScope.PLAYER);
condition = true;
}
@ -118,7 +118,7 @@ class FellShepherdEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
FellShepherdWatcher watcher = (FellShepherdWatcher) game.getState().getWatchers().get(FellShepherdWatcher.class.getSimpleName(), source.getControllerId());
FellShepherdWatcher watcher = game.getState().getWatcher(FellShepherdWatcher.class, source.getControllerId());
if (watcher != null) {
StringBuilder sb = new StringBuilder();
for (UUID creatureId : watcher.getCreaturesIds()) {

View file

@ -45,7 +45,7 @@ class FinalPunishmentAmount implements DynamicValue {
@Override
public int calculate(Game game, Ability source, Effect effect) {
AmountOfDamageAPlayerReceivedThisTurnWatcher watcher
= (AmountOfDamageAPlayerReceivedThisTurnWatcher) game.getState().getWatchers().get(AmountOfDamageAPlayerReceivedThisTurnWatcher.class.getSimpleName());
= game.getState().getWatcher(AmountOfDamageAPlayerReceivedThisTurnWatcher.class);
if(watcher != null) {
return watcher.getAmountOfDamageReceivedThisTurn(source.getFirstTarget());
}

View file

@ -59,7 +59,7 @@ class FireAndBrimstonePredicate extends PlayerPredicate {
if (player == null || playerId == null) {
return false;
}
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher != null) {
if (!watcher.getAttackedThisTurnCreatures().isEmpty()) {
return player.getId().equals(game.getActivePlayerId());

View file

@ -76,7 +76,7 @@ class FlamebreakCantRegenerateEffect extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get(DamagedByWatcher.class.getSimpleName(), source.getSourceId());
DamagedByWatcher watcher = game.getState().getWatcher(DamagedByWatcher.class, source.getSourceId());
if (watcher != null) {
return watcher.wasDamaged(event.getTargetId(), game);
}

View file

@ -57,7 +57,7 @@ class FleshAllergyWatcher extends Watcher {
public int creaturesDiedThisTurn = 0;
public FleshAllergyWatcher() {
super(FleshAllergyWatcher.class.getSimpleName(), WatcherScope.GAME);
super(FleshAllergyWatcher.class, WatcherScope.GAME);
}
public FleshAllergyWatcher(final FleshAllergyWatcher watcher) {
@ -105,7 +105,7 @@ class FleshAllergyEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
FleshAllergyWatcher watcher = (FleshAllergyWatcher) game.getState().getWatchers().get(FleshAllergyWatcher.class.getSimpleName());
FleshAllergyWatcher watcher = game.getState().getWatcher(FleshAllergyWatcher.class);
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (permanent != null && watcher != null) {
Player player = game.getPlayer(permanent.getControllerId());

View file

@ -89,7 +89,7 @@ class FoulTongueInvocationEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
DragonOnTheBattlefieldWhileSpellWasCastWatcher watcher = (DragonOnTheBattlefieldWhileSpellWasCastWatcher) game.getState().getWatchers().get(DragonOnTheBattlefieldWhileSpellWasCastWatcher.class.getSimpleName());
DragonOnTheBattlefieldWhileSpellWasCastWatcher watcher = game.getState().getWatcher(DragonOnTheBattlefieldWhileSpellWasCastWatcher.class);
if (watcher != null && watcher.castWithConditionTrue(source.getId())) {
controller.gainLife(4, game, source);
}

View file

@ -113,7 +113,7 @@ class FrayingSanityEffect extends OneShotEffect {
}
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (watcher != null) {
xAmount = watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
}

View file

@ -75,7 +75,7 @@ class FreeRangeChickenEffect extends OneShotEffect {
if (firstRoll == secondRoll) {
game.addEffect(new BoostSourceEffect(firstRoll, firstRoll, Duration.EndOfTurn), source);
}
FreeRangeChickenWatcher watcher = (FreeRangeChickenWatcher) game.getState().getWatchers().get(FreeRangeChickenWatcher.class.getSimpleName());
FreeRangeChickenWatcher watcher = game.getState().getWatcher(FreeRangeChickenWatcher.class);
if (watcher != null) {
int totalRoll = firstRoll + secondRoll;
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
@ -98,7 +98,7 @@ class FreeRangeChickenWatcher extends Watcher {
private final Map<UUID, Integer> totalRolls = new HashMap<>();
public FreeRangeChickenWatcher() {
super(FreeRangeChickenWatcher.class.getSimpleName(), WatcherScope.GAME);
super(FreeRangeChickenWatcher.class, WatcherScope.GAME);
}
public FreeRangeChickenWatcher(final FreeRangeChickenWatcher watcher) {

View file

@ -41,7 +41,7 @@ class FreshMeatDynamicValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
CreaturesDiedWatcher watcher = game.getState().getWatcher(CreaturesDiedWatcher.class);
if (watcher != null) {
return watcher.getAmountOfCreaturesDiedThisTurnByController(sourceAbility.getControllerId());
}

View file

@ -50,7 +50,7 @@ class SourceWasBlockedThisTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
WasBlockedThisTurnWatcher watcher = (WasBlockedThisTurnWatcher) game.getState().getWatchers().get(WasBlockedThisTurnWatcher.class.getSimpleName());
WasBlockedThisTurnWatcher watcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
return sourcePermanent != null && watcher != null && watcher.getWasBlockedThisTurnCreatures().contains(new MageObjectReference(sourcePermanent, game));
}
}

View file

@ -80,7 +80,7 @@ class GarnaTheBloodflameEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
GarnaTheBloodflameWatcher watcher = (GarnaTheBloodflameWatcher) game.getState().getWatchers().get(GarnaTheBloodflameWatcher.class.getSimpleName());
GarnaTheBloodflameWatcher watcher = (GarnaTheBloodflameWatcher) game.getState().getWatcher(GarnaTheBloodflameWatcher.class);
if (watcher != null) {
Set<Card> toHand = new HashSet<>();
for (UUID cardId : watcher.getCardsPutToGraveyardThisTurn()) {

View file

@ -98,7 +98,7 @@ class GazeOfTheGorgonEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && targetCreature != null) {
BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatcher(BlockedAttackerWatcher.class);
if (watcher != null) {
List<Permanent> toDestroy = new ArrayList<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {

View file

@ -63,7 +63,7 @@ class GeneratorServantWatcher extends Watcher {
public List<UUID> creatures = new ArrayList<>();
public GeneratorServantWatcher() {
super(GeneratorServantWatcher.class.getSimpleName(), WatcherScope.CARD);
super(GeneratorServantWatcher.class, WatcherScope.CARD);
}
public GeneratorServantWatcher(final GeneratorServantWatcher watcher) {
@ -114,7 +114,7 @@ class GeneratorServantHasteEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
GeneratorServantWatcher watcher = (GeneratorServantWatcher) game.getState().getWatchers().get(GeneratorServantWatcher.class.getSimpleName(), source.getSourceId());
GeneratorServantWatcher watcher = (GeneratorServantWatcher) game.getState().getWatcher(GeneratorServantWatcher.class, source.getSourceId());
if (watcher != null) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents()) {
if (watcher.creatures.contains(perm.getId())) {

View file

@ -63,7 +63,7 @@ class CantAttackIfAttackedLastTurnEffect extends RestrictionEffect {
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) {
AttackedLastTurnWatcher watcher = (AttackedLastTurnWatcher) game.getState().getWatchers().get(AttackedLastTurnWatcher.class.getSimpleName());
AttackedLastTurnWatcher watcher = (AttackedLastTurnWatcher) game.getState().getWatcher(AttackedLastTurnWatcher.class);
if (watcher != null) {
Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
MageObjectReference mor = new MageObjectReference(attacker, game);

View file

@ -68,7 +68,7 @@ class GiltspireAvengerTarget extends TargetPermanent {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), source.getControllerId());
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, source.getControllerId());
if (watcher != null && watcher.hasSourceDoneDamage(id, game)) {
return super.canTarget(id, source, game);
}
@ -79,7 +79,7 @@ class GiltspireAvengerTarget extends TargetPermanent {
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), sourceControllerId);
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && watcher != null && watcher.hasSourceDoneDamage(targetId, game)) {
@ -97,7 +97,7 @@ class GiltspireAvengerTarget extends TargetPermanent {
}
int count = 0;
MageObject targetSource = game.getObject(sourceId);
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), sourceControllerId);
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
&& watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) {

View file

@ -120,7 +120,7 @@ class GisaAndGeralfCastFromGraveyardEffect extends AsThoughEffectImpl {
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (objectId.equals(getTargetPointer().getFirst(game, source))) {
if (affectedControllerId.equals(source.getControllerId())) {
GisaAndGeralfWatcher watcher = (GisaAndGeralfWatcher) game.getState().getWatchers().get(GisaAndGeralfWatcher.class.getSimpleName(), source.getSourceId());
GisaAndGeralfWatcher watcher = (GisaAndGeralfWatcher) game.getState().getWatcher(GisaAndGeralfWatcher.class, source.getSourceId());
return watcher != null && !watcher.isAbilityUsed();
}
}

View file

@ -73,7 +73,7 @@ class GleancrawlerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && watcher != null) {
Set<MageObjectReference> cardsToGraveyardThisTurn = watcher.getCardsPutToGraveyardFromBattlefield();

View file

@ -79,7 +79,7 @@ class GlyphKeeperAbility extends TriggeredAbilityImpl {
if (event.getTargetId().equals(this.getSourceId())) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isCreature()) {
NumberOfTimesPermanentTargetedATurnWatcher watcher = (NumberOfTimesPermanentTargetedATurnWatcher) game.getState().getWatchers().get(NumberOfTimesPermanentTargetedATurnWatcher.class.getSimpleName());
NumberOfTimesPermanentTargetedATurnWatcher watcher = (NumberOfTimesPermanentTargetedATurnWatcher) game.getState().getWatcher(NumberOfTimesPermanentTargetedATurnWatcher.class);
if (watcher != null
&& watcher.notMoreThanOnceTargetedThisTurn(permanent, game)) {
for (Effect effect : getEffects()) {

View file

@ -106,7 +106,7 @@ class GlyphOfDoomEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && targetCreature != null) {
BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatcher(BlockedAttackerWatcher.class);
if (watcher != null) {
List<Permanent> toDestroy = new ArrayList<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {

View file

@ -69,7 +69,7 @@ class GoblinCohortEffect extends RestrictionEffect {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
PlayerCastCreatureWatcher watcher = (PlayerCastCreatureWatcher) game.getState().getWatchers().get(PlayerCastCreatureWatcher.class.getSimpleName());
PlayerCastCreatureWatcher watcher = (PlayerCastCreatureWatcher) game.getState().getWatcher(PlayerCastCreatureWatcher.class);
if (watcher != null && !watcher.playerDidCastCreatureThisTurn(source.getControllerId())) {
return true;
}

View file

@ -96,7 +96,7 @@ class DontUntapIfAttackedLastTurnSourceEffect extends ContinuousRuleModifyingEff
&& event.getTargetId().equals(source.getSourceId())) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) {
AttackedLastTurnWatcher watcher = (AttackedLastTurnWatcher) game.getState().getWatchers().get(AttackedLastTurnWatcher.class.getSimpleName());
AttackedLastTurnWatcher watcher = (AttackedLastTurnWatcher) game.getState().getWatcher(AttackedLastTurnWatcher.class);
if (watcher != null) {
Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(permanent.getControllerId());
MageObjectReference mor = new MageObjectReference(permanent, game);

View file

@ -86,7 +86,7 @@ class GomazoaEffect extends OneShotEffect {
players.add(gomazoa.getOwnerId());
}
BlockedByWatcher watcher = (BlockedByWatcher) game.getState().getWatchers().get(BlockedByWatcher.class.getSimpleName(), source.getSourceId());
BlockedByWatcher watcher = (BlockedByWatcher) game.getState().getWatcher(BlockedByWatcher.class, source.getSourceId());
creaturesBlocked = watcher.blockedByWatcher;
for (UUID blockedById : creaturesBlocked) {

View file

@ -68,7 +68,7 @@ class GontisMachinationsTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(getControllerId())) {
GontisMachinationsFirstLostLifeThisTurnWatcher watcher
= (GontisMachinationsFirstLostLifeThisTurnWatcher) game.getState().getWatchers().get(GontisMachinationsFirstLostLifeThisTurnWatcher.class.getSimpleName());
= (GontisMachinationsFirstLostLifeThisTurnWatcher) game.getState().getWatcher(GontisMachinationsFirstLostLifeThisTurnWatcher.class);
if (watcher != null && watcher.timesLostLifeThisTurn(event.getTargetId()) < 2) {
return true;
}
@ -92,7 +92,7 @@ class GontisMachinationsFirstLostLifeThisTurnWatcher extends Watcher {
private final Map<UUID, Integer> playersLostLife = new HashMap<>();
public GontisMachinationsFirstLostLifeThisTurnWatcher() {
super(GontisMachinationsFirstLostLifeThisTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
super(GontisMachinationsFirstLostLifeThisTurnWatcher.class, WatcherScope.GAME);
}
public GontisMachinationsFirstLostLifeThisTurnWatcher(final GontisMachinationsFirstLostLifeThisTurnWatcher watcher) {

View file

@ -65,7 +65,7 @@ class CreaturesAttackedWatcher extends Watcher {
public final Set<MageObjectReference> attackedThisTurnCreatures = new HashSet<>();
public CreaturesAttackedWatcher() {
super(CreaturesAttackedWatcher.class.getSimpleName(), WatcherScope.GAME);
super(CreaturesAttackedWatcher.class, WatcherScope.GAME);
}
public CreaturesAttackedWatcher(final CreaturesAttackedWatcher watcher) {
@ -153,7 +153,7 @@ class GrandWarlordRadhaEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
CreaturesAttackedWatcher watcher = (CreaturesAttackedWatcher) game.getState().getWatchers().get(CreaturesAttackedWatcher.class.getSimpleName());
CreaturesAttackedWatcher watcher = (CreaturesAttackedWatcher) game.getState().getWatcher(CreaturesAttackedWatcher.class);
if (watcher != null) {
int attackingCreatures = 0;
for (MageObjectReference attacker : watcher.getAttackedThisTurnCreatures()) {

View file

@ -93,7 +93,7 @@ class GrimReminderEffect extends OneShotEffect {
Cards cardsToReveal = new CardsImpl(card);
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
String cardName = card.getName();
GrimReminderWatcher watcher = (GrimReminderWatcher) game.getState().getWatchers().get(GrimReminderWatcher.class.getSimpleName());
GrimReminderWatcher watcher = (GrimReminderWatcher) game.getState().getWatcher(GrimReminderWatcher.class);
if (watcher != null) {
for (UUID playerId : watcher.getPlayersCastSpell(cardName)) {
Player player = game.getPlayer(playerId);
@ -116,7 +116,7 @@ class GrimReminderWatcher extends Watcher {
private final Map<String, Set<UUID>> playersCastSpell = new HashMap<>();
public GrimReminderWatcher() {
super(GrimReminderWatcher.class.getSimpleName(), WatcherScope.GAME);
super(GrimReminderWatcher.class, WatcherScope.GAME);
}
public GrimReminderWatcher(final GrimReminderWatcher watcher) {

View file

@ -49,7 +49,7 @@ public final class GrimReturn extends CardImpl {
@Override
public void adjustTargets(Ability ability, Game game) {
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (watcher != null) {
FilterCard filter = new FilterCreatureCard(textFilter);
List<CardIdPredicate> uuidPredicates = new ArrayList<>();

View file

@ -148,7 +148,7 @@ class GrothamaAllDevouringDrawCardsEffect extends OneShotEffect {
if (controller == null) {
return false;
}
GrothamaAllDevouringWatcher watcher = (GrothamaAllDevouringWatcher) game.getState().getWatchers().get(GrothamaAllDevouringWatcher.class.getSimpleName());
GrothamaAllDevouringWatcher watcher = (GrothamaAllDevouringWatcher) game.getState().getWatcher(GrothamaAllDevouringWatcher.class);
if (watcher == null) {
return false;
}
@ -171,7 +171,7 @@ class GrothamaAllDevouringWatcher extends Watcher {
Map<MageObjectReference, Map<UUID, Integer>> damageMap = new HashMap<>();
GrothamaAllDevouringWatcher() {
super(GrothamaAllDevouringWatcher.class.getSimpleName(), WatcherScope.GAME);
super(GrothamaAllDevouringWatcher.class, WatcherScope.GAME);
}
GrothamaAllDevouringWatcher(final GrothamaAllDevouringWatcher watcher) {

View file

@ -56,7 +56,7 @@ enum GutterbonesCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (game.isActivePlayer(source.getControllerId())) {
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatcher(PlayerLostLifeWatcher.class);
return watcher != null && watcher.getAllOppLifeLost(source.getControllerId(), game) > 0;
}
return false;

View file

@ -83,7 +83,7 @@ class HallowedMoonlightEffect extends ReplacementEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
if (entersTheBattlefieldEvent.getTarget().isCreature()) {
CreatureWasCastWatcher watcher = (CreatureWasCastWatcher) game.getState().getWatchers().get(CreatureWasCastWatcher.class.getSimpleName());
CreatureWasCastWatcher watcher = game.getState().getWatcher(CreatureWasCastWatcher.class);
if (watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId())) {
return true;
}

View file

@ -62,7 +62,7 @@ class CantAttackIfAttackedLastTurnAllEffect extends RestrictionEffect {
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) {
AttackedLastTurnWatcher watcher = (AttackedLastTurnWatcher) game.getState().getWatchers().get(AttackedLastTurnWatcher.class.getSimpleName());
AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
if (watcher != null) {
Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
MageObjectReference mor = new MageObjectReference(attacker, game);

View file

@ -62,7 +62,7 @@ class HardenedBerserkerSpellsCostReductionEffect extends CostModificationEffectI
@Override
public void init(Ability source, Game game) {
super.init(source, game);
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null) {
spellsCast = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId());
}
@ -76,7 +76,7 @@ class HardenedBerserkerSpellsCostReductionEffect extends CostModificationEffectI
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if (watcher != null) {
if (watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) > spellsCast) {
discard(); // only one use

View file

@ -61,7 +61,7 @@ class HarnessTheStormTriggeredAbility extends SpellCastControllerTriggeredAbilit
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
CastFromHandWatcher watcher = (CastFromHandWatcher) game.getState().getWatchers().get(CastFromHandWatcher.class.getSimpleName());
CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class);
if (watcher != null && watcher.spellWasCastFromHand(event.getSourceId())) {
Spell spell = game.getState().getStack().getSpell(event.getSourceId());
if (spell != null) {

View file

@ -66,8 +66,8 @@ class HeatStrokeEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
BlockedThisTurnWatcher blockedWatcher = (BlockedThisTurnWatcher) game.getState().getWatchers().get(BlockedThisTurnWatcher.class.getSimpleName());
WasBlockedThisTurnWatcher wasBlockedThisTurnWatcher = (WasBlockedThisTurnWatcher) game.getState().getWatchers().get(WasBlockedThisTurnWatcher.class.getSimpleName());
BlockedThisTurnWatcher blockedWatcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
WasBlockedThisTurnWatcher wasBlockedThisTurnWatcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
Set<Permanent> inROI = new HashSet<>(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
boolean toRet = false;

View file

@ -66,7 +66,7 @@ class HollowOneReductionEffect extends CostModificationEffectImpl {
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName());
CardsCycledOrDiscardedThisTurnWatcher watcher = game.getState().getWatcher(CardsCycledOrDiscardedThisTurnWatcher.class);
if (watcher != null) {
CardUtil.reduceCost(abilityToModify, watcher.getNumberOfCardsCycledOrDiscardedThisTurn(source.getControllerId()) * 2);
return true;

View file

@ -10,6 +10,7 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -73,7 +74,7 @@ class HomicidalBruteTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.controllerId)) {
Watcher watcher = game.getState().getWatchers().get("HomicidalBruteWatcher", sourceId);
Watcher watcher = game.getState().getWatcher(HomicidalBruteWatcher.class, sourceId);
if (watcher == null || !watcher.conditionMet()) {
return true;
}
@ -87,3 +88,5 @@ class HomicidalBruteTriggeredAbility extends TriggeredAbilityImpl {
}
}

View file

@ -0,0 +1,32 @@
package mage.cards.h;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
public class HomicidalBruteWatcher extends Watcher {
public HomicidalBruteWatcher() {
super(HomicidalBruteWatcher.class.getSimpleName(), WatcherScope.CARD);
}
public HomicidalBruteWatcher(final HomicidalBruteWatcher watcher) {
super(watcher);
}
@Override
public HomicidalBruteWatcher copy() {
return new HomicidalBruteWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
if (condition) {
return;
}
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED && event.getSourceId().equals(sourceId)) {
condition = true;
}
}
}

View file

@ -128,7 +128,7 @@ class HopeOfGhirapurPlayerLostLifePredicate implements ObjectSourcePlayerPredica
if (targetPlayer == null) {
return false;
}
HopeOfGhirapurCombatDamageWatcher watcher = (HopeOfGhirapurCombatDamageWatcher) game.getState().getWatchers().get(HopeOfGhirapurCombatDamageWatcher.class.getSimpleName());
HopeOfGhirapurCombatDamageWatcher watcher = game.getState().getWatcher(HopeOfGhirapurCombatDamageWatcher.class);
if (watcher != null) {
return watcher.playerGotCombatDamage(input.getSourceId(), input.getObject().getId(), game);
}

View file

@ -62,7 +62,7 @@ class CastRedSpellThisTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
HotHeadedGiantWatcher watcher = (HotHeadedGiantWatcher) game.getState().getWatchers().get(HotHeadedGiantWatcher.class.getSimpleName(), source.getControllerId());
HotHeadedGiantWatcher watcher = game.getState().getWatcher(HotHeadedGiantWatcher.class, source.getControllerId());
if (watcher != null) {
return watcher.conditionMet();
}

View file

@ -70,7 +70,7 @@ class HuntDownEffect extends RequirementEffect {
&& blocker.canBlock(source.getTargets().get(1).getFirstTarget(), game)) {
Permanent attacker = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (attacker != null) {
BlockedAttackerWatcher blockedAttackerWatcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
if (blockedAttackerWatcher != null
&& blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) {
// has already blocked this turn, so no need to do again

Some files were not shown because too many files have changed in this diff Show more