mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
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:
parent
f01b3d3ca3
commit
9a310732d8
324 changed files with 573 additions and 586 deletions
|
|
@ -35,7 +35,7 @@ public class AttacksFirstTimeTriggeredAbility extends TriggeredAbilityImpl {
|
|||
if (!event.getSourceId().equals(this.getSourceId())) {
|
||||
return false;
|
||||
}
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
if (watcher == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public enum AttackedOrBlockedThisCombatSourceCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
if (sourceObject != null) {
|
||||
AttackedOrBlockedThisCombatWatcher watcher = (AttackedOrBlockedThisCombatWatcher) game.getState().getWatchers().get(AttackedOrBlockedThisCombatWatcher.class.getSimpleName());
|
||||
AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
|
||||
if (watcher != null) {
|
||||
for (MageObjectReference mor : watcher.getAttackedThisTurnCreatures()) {
|
||||
if (mor.refersTo(sourceObject, game)) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public enum AttackedThisStepCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
PlayerAttackedStepWatcher watcher = (PlayerAttackedStepWatcher) game.getState().getWatchers().get(PlayerAttackedStepWatcher.class.getSimpleName());
|
||||
PlayerAttackedStepWatcher watcher = game.getState().getWatcher(PlayerAttackedStepWatcher.class);
|
||||
return watcher != null
|
||||
&& watcher.getNumberAttackingCurrentStep(source.getControllerId()) > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public enum AttackedThisTurnCondition 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);
|
||||
return watcher != null && !watcher.getAttackedThisTurnCreatures().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public enum AttackedThisTurnSourceCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
return sourcePermanent != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(sourcePermanent, game));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public enum BlockedThisTurnSourceCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
BlockedThisTurnWatcher watcher = (BlockedThisTurnWatcher) game.getState().getWatchers().get(BlockedThisTurnWatcher.class.getSimpleName());
|
||||
BlockedThisTurnWatcher watcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
|
||||
return sourcePermanent != null && watcher.getBlockedThisTurnCreatures().contains(new MageObjectReference(sourcePermanent, game));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public enum CastFromHandSourceCondition implements Condition {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
CastFromHandWatcher watcher = (CastFromHandWatcher) game.getState().getWatchers().get(CastFromHandWatcher.class.getSimpleName());
|
||||
CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class);
|
||||
if (watcher != null && watcher.spellWasCastFromHand(source.getSourceId())) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public enum ControllerAttackedThisTurnCondition 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);
|
||||
return source.isControlledBy(game.getActivePlayerId()) && watcher != null && !watcher.getAttackedThisTurnCreatures().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class DealtDamageToAnOpponent implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), opponentId);
|
||||
PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, opponentId);
|
||||
if (watcher != null) {
|
||||
if (watcher.hasSourceDoneDamage(source.getSourceId(), game)) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public enum HateCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
LifeLossOtherFromCombatWatcher watcher = (LifeLossOtherFromCombatWatcher) game.getState().getWatchers().get(LifeLossOtherFromCombatWatcher.class.getSimpleName());
|
||||
LifeLossOtherFromCombatWatcher watcher = game.getState().getWatcher(LifeLossOtherFromCombatWatcher.class);
|
||||
return watcher != null && watcher.opponentLostLifeOtherFromCombat(source.getControllerId(), game);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public enum LandfallCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
LandfallWatcher watcher = (LandfallWatcher) game.getState().getWatchers().get(LandfallWatcher.class.getSimpleName());
|
||||
LandfallWatcher watcher = game.getState().getWatcher(LandfallWatcher.class);
|
||||
return watcher != null && watcher.landPlayed(source.getControllerId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public enum LiveLostLastTurnCondition 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) {
|
||||
return watcher.getLifeLostLastTurn(source.getControllerId()) > 0;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class ManaWasSpentCondition implements Condition {
|
|||
if (source.getAbilityType() == AbilityType.SPELL) {
|
||||
return (source.getManaCostsToPay().getPayment().getColor(coloredManaSymbol) > 0);
|
||||
}
|
||||
ManaSpentToCastWatcher watcher = (ManaSpentToCastWatcher) game.getState().getWatchers().get(ManaSpentToCastWatcher.class.getSimpleName(), source.getSourceId());
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, source.getSourceId());
|
||||
if (watcher != null) {
|
||||
Mana payment = watcher.getAndResetLastPayment();
|
||||
if (payment != null) {
|
||||
|
|
@ -42,7 +42,7 @@ public class ManaWasSpentCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("{").append(coloredManaSymbol.toString()).append("} was spent to cast it").toString();
|
||||
return "{" + coloredManaSymbol.toString() + "} was spent to cast it";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public enum MorbidCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(MorbidWatcher.class.getSimpleName());
|
||||
MorbidWatcher watcher = game.getState().getWatcher(MorbidWatcher.class);
|
||||
return watcher != null && watcher.conditionMet();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public enum NoSpellsWereCastLastTurnCondition implements Condition {
|
|||
return false;
|
||||
}
|
||||
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
if(watcher == null){
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class OpponentLostLifeCondition extends IntCompareCondition {
|
|||
@Override
|
||||
protected int getInputValue(Game game, Ability source) {
|
||||
int maxLostLive = 0;
|
||||
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())) {
|
||||
int lostLive = watcher.getLifeLost(opponentId);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public enum PlayLandCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
PlayLandWatcher watcher = (PlayLandWatcher) game.getState().getWatchers().get(PlayLandWatcher.class.getSimpleName());
|
||||
PlayLandWatcher watcher = game.getState().getWatcher(PlayLandWatcher.class);
|
||||
return watcher != null
|
||||
&& watcher.landPlayed(source.getControllerId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public enum RaidCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
PlayerAttackedWatcher watcher = (PlayerAttackedWatcher) game.getState().getWatchers().get(PlayerAttackedWatcher.class.getSimpleName());
|
||||
PlayerAttackedWatcher watcher = game.getState().getWatcher(PlayerAttackedWatcher.class);
|
||||
return watcher != null && watcher.getNumberOfAttackersCurrentTurn(source.getControllerId()) > 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public enum RevoltCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
RevoltWatcher watcher = (RevoltWatcher) game.getState().getWatchers().get(RevoltWatcher.class.getSimpleName());
|
||||
RevoltWatcher watcher = game.getState().getWatcher(RevoltWatcher.class);
|
||||
return watcher != null && watcher.revoltActive(source.getControllerId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SourceDealtDamageCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
DamageDoneWatcher watcher = (DamageDoneWatcher) game.getState().getWatchers().get(DamageDoneWatcher.class.getSimpleName());
|
||||
DamageDoneWatcher watcher = game.getState().getWatcher(DamageDoneWatcher.class);
|
||||
return watcher != null && watcher.damageDoneBy(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game) >= value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public enum TargetAttackedThisTurnCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent creature = game.getPermanentOrLKIBattlefield(source.getTargets().getFirstTarget());
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
return creature != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(creature, game));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public enum TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
if(watcher == null){
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Quercitron
|
||||
*/
|
||||
public class WatcherCondition implements Condition {
|
||||
|
||||
private final String watcherKey;
|
||||
private final WatcherScope watcherScope;
|
||||
private final String text;
|
||||
|
||||
public WatcherCondition(String watcherKey, WatcherScope watcherScope) {
|
||||
this(watcherKey, watcherScope, "");
|
||||
}
|
||||
|
||||
public WatcherCondition(String watcherKey, WatcherScope watcherScope, String text) {
|
||||
this.watcherKey = watcherKey;
|
||||
this.watcherScope = watcherScope;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = null;
|
||||
switch (watcherScope) {
|
||||
case GAME:
|
||||
watcher = game.getState().getWatchers().get(watcherKey);
|
||||
break;
|
||||
case PLAYER:
|
||||
watcher = game.getState().getWatchers().get(watcherKey, source.getControllerId());
|
||||
break;
|
||||
case CARD:
|
||||
watcher = game.getState().getWatchers().get(watcherKey, source.getSourceId());
|
||||
break;
|
||||
}
|
||||
return watcher != null && watcher.conditionMet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,9 +18,9 @@ public class YouGainedLifeCondition extends IntCompareCondition {
|
|||
@Override
|
||||
protected int getInputValue(Game game, Ability source) {
|
||||
int gainedLife = 0;
|
||||
PlayerGainedLifeWatcher watcher = (PlayerGainedLifeWatcher) game.getState().getWatchers().get(PlayerGainedLifeWatcher.class.getSimpleName());
|
||||
PlayerGainedLifeWatcher watcher = game.getState().getWatcher(PlayerGainedLifeWatcher.class);
|
||||
if (watcher != null) {
|
||||
gainedLife = watcher.getLiveGained(source.getControllerId());
|
||||
gainedLife = watcher.getLifeGained(source.getControllerId());
|
||||
}
|
||||
return gainedLife;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class AttackedThisTurnOpponentsCount implements DynamicValue {
|
|||
}
|
||||
|
||||
public int calculate(Game game, UUID controllerId) {
|
||||
PlayersAttackedThisTurnWatcher watcher = (PlayersAttackedThisTurnWatcher) game.getState().getWatchers().get(PlayersAttackedThisTurnWatcher.class.getSimpleName());
|
||||
PlayersAttackedThisTurnWatcher watcher = game.getState().getWatcher(PlayersAttackedThisTurnWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.getAttackedOpponentsCount(controllerId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ public class ControllerGotLifeCount implements DynamicValue, MageSingleton {
|
|||
}
|
||||
|
||||
public int calculate(Game game, UUID controllerId) {
|
||||
PlayerGainedLifeWatcher watcher = (PlayerGainedLifeWatcher) game.getState().getWatchers().get(PlayerGainedLifeWatcher.class.getSimpleName());
|
||||
PlayerGainedLifeWatcher watcher = game.getState().getWatcher(PlayerGainedLifeWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.getLiveGained(controllerId);
|
||||
return watcher.getLifeGained(controllerId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class CreaturesDiedThisTurnCount 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.getAmountOfCreaturesDiedThisTurn();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class OpponentsLostLifeCount implements DynamicValue {
|
|||
}
|
||||
|
||||
public int calculate(Game game, UUID controllerId) {
|
||||
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
|
||||
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.getAllOppLifeLost(controllerId, game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ public class ZuberasDiedDynamicValue implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
ZuberasDiedWatcher watcher = (ZuberasDiedWatcher) game.getState().getWatchers().get(ZuberasDiedWatcher.class.getSimpleName());
|
||||
ZuberasDiedWatcher watcher = game.getState().getWatcher(ZuberasDiedWatcher.class);
|
||||
if(watcher == null){
|
||||
return 0;
|
||||
}
|
||||
return watcher.zuberasDiedThisTurn;
|
||||
return watcher.getZuberasDiedThisTurn();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ public class UntapAllThatAttackedEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
if (watcher instanceof AttackedThisTurnWatcher) {
|
||||
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
if (watcher != null) {
|
||||
Set<MageObjectReference> attackedThisTurn = watcher.getAttackedThisTurnCreatures();
|
||||
for (MageObjectReference mor : attackedThisTurn) {
|
||||
Permanent permanent = mor.getPermanent(game);
|
||||
if (permanent != null && permanent.isCreature()) {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class AttacksIfAbleAllEffect extends RequirementEffect {
|
|||
if (eachCombat) {
|
||||
return true;
|
||||
}
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
return watcher != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game));
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class AttacksIfAbleSourceEffect extends RequirementEffect {
|
|||
if (eachCombat) {
|
||||
return true;
|
||||
}
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
|
||||
return watcher != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game));
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ public class MustBeBlockedByAllTargetEffect extends RequirementEffect {
|
|||
|
||||
public MustBeBlockedByAllTargetEffect(Duration duration) {
|
||||
super(duration);
|
||||
staticText = new StringBuilder("All creatures able to block target creature ")
|
||||
.append(this.getDuration() == Duration.EndOfTurn ? "this turn ":"")
|
||||
.append("do so").toString();
|
||||
staticText = "All creatures able to block target creature " +
|
||||
(this.getDuration() == Duration.EndOfTurn ? "this turn " : "") +
|
||||
"do so";
|
||||
}
|
||||
|
||||
public MustBeBlockedByAllTargetEffect(final MustBeBlockedByAllTargetEffect effect) {
|
||||
|
|
@ -33,7 +33,7 @@ public class MustBeBlockedByAllTargetEffect extends RequirementEffect {
|
|||
Permanent attackingCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
|
||||
if (attackingCreature != null && attackingCreature.isAttacking()) {
|
||||
if (source.getAbilityType() != AbilityType.STATIC) {
|
||||
BlockedAttackerWatcher blockedAttackerWatcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
|
||||
BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
|
||||
if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attackingCreature, permanent, game)) {
|
||||
// has already blocked this turn, so no need to do again
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class MustBeBlockedByTargetSourceEffect extends RequirementEffect {
|
|||
if (blocker != null && blocker.canBlock(source.getSourceId(), game)) {
|
||||
Permanent attacker = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
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
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class CantCastMoreThanOneSpellEffect extends ContinuousRuleModifyingEffec
|
|||
return false;
|
||||
}
|
||||
}
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
return watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) > 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class DealtDamageToCreatureBySourceDies extends ReplacementEffectImpl {
|
|||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
ZoneChangeEvent zce = (ZoneChangeEvent) event;
|
||||
if (zce.isDiesEvent()) {
|
||||
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(zce.getTarget(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class CastOnlyIfYouHaveCastAnotherSpellEffect extends ContinuousRuleModif
|
|||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getSourceId().equals(source.getSourceId())) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,15 +69,15 @@ class BloodthirstEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get(BloodthirstWatcher.class.getSimpleName(), source.getControllerId());
|
||||
BloodthirstWatcher watcher = game.getState().getWatcher(BloodthirstWatcher.class, source.getControllerId());
|
||||
if (watcher != null && watcher.conditionMet()) {
|
||||
Permanent permanent = game.getPermanentEntering(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
ArrayList<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects"); // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(amount), source, game, appliedEffects);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class ExertReplacementEffect extends ReplacementEffectImpl {
|
|||
if (creature != null && controller != null) {
|
||||
if (exertOnlyOncePerTurn) {
|
||||
MageObjectReference creatureReference = new MageObjectReference(creature.getId(), creature.getZoneChangeCounter(game), game);
|
||||
ExertedThisTurnWatcher watcher = (ExertedThisTurnWatcher) game.getState().getWatchers().get(ExertedThisTurnWatcher.class.getSimpleName());
|
||||
ExertedThisTurnWatcher watcher = game.getState().getWatcher(ExertedThisTurnWatcher.class);
|
||||
if (watcher != null && watcher.getExertedThisTurnCreatures().contains(creatureReference)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class GravestormEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
MageObjectReference spellRef = (MageObjectReference) this.getValue("GravestormSpellRef");
|
||||
if (spellRef != null) {
|
||||
GravestormWatcher watcher = (GravestormWatcher) game.getState().getWatchers().get(GravestormWatcher.class.getSimpleName());
|
||||
GravestormWatcher watcher = game.getState().getWatcher(GravestormWatcher.class);
|
||||
if(watcher != null) {
|
||||
int gravestormCount = watcher.getGravestormCount();
|
||||
if (gravestormCount > 0) {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class MeleeDynamicValue implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
MeleeWatcher watcher = (MeleeWatcher) game.getState().getWatchers().get(MeleeWatcher.class.getSimpleName());
|
||||
MeleeWatcher watcher = game.getState().getWatcher(MeleeWatcher.class);
|
||||
if (watcher != null) {
|
||||
if (!valueChecked) {
|
||||
this.lockedInValue = watcher.getNumberOfAttackedPlayers(sourceAbility.getControllerId());
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class ProwlAbility extends StaticAbility implements AlternativeSourceCost
|
|||
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
Player player = game.getPlayer(controllerId);
|
||||
ProwlWatcher prowlWatcher = (ProwlWatcher) game.getState().getWatchers().get(ProwlWatcher.class.getSimpleName());
|
||||
ProwlWatcher prowlWatcher = game.getState().getWatcher(ProwlWatcher.class);
|
||||
Card card = game.getCard(ability.getSourceId());
|
||||
if (player == null || prowlWatcher == null || card == null) {
|
||||
throw new IllegalArgumentException("Params can't be null");
|
||||
|
|
@ -108,7 +108,7 @@ public class ProwlAbility extends StaticAbility implements AlternativeSourceCost
|
|||
this.resetProwl();
|
||||
for (AlternativeCost2 prowlCost : prowlCosts) {
|
||||
if (prowlCost.canPay(ability, sourceId, controllerId, game)
|
||||
&& player.chooseUse(Outcome.Benefit, new StringBuilder("Cast for ").append(PROWL_KEYWORD).append(" cost ").append(prowlCost.getText(true)).append(" ?").toString(), ability, game)) {
|
||||
&& player.chooseUse(Outcome.Benefit, "Cast for " + PROWL_KEYWORD + " cost " + prowlCost.getText(true) + " ?", ability, game)) {
|
||||
prowlCost.activate();
|
||||
ability.getManaCostsToPay().clear();
|
||||
ability.getCosts().clear();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class SpectacleAbility extends SpellAbility {
|
|||
|
||||
@Override
|
||||
public ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
|
||||
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
|
||||
if (watcher != null && watcher.getAllOppLifeLost(playerId, game) > 0) {
|
||||
return super.canActivate(playerId, game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class StormEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
|
||||
if (spellRef != null) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
if (watcher != null) {
|
||||
int stormCount = watcher.getSpellOrder(spellRef, game) - 1;
|
||||
if (stormCount > 0) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class SurgeAbility extends SpellAbility {
|
|||
@Override
|
||||
public ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
// check if controller or teammate has already cast a spell this turn
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||
if (watcher != null) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class BlockedByIdPredicate implements Predicate<Permanent> {
|
|||
} // Check if the blockerId was blocked before, if it does no longer exists now but so the target attacking is still valid
|
||||
Permanent blocker = game.getPermanentOrLKIBattlefield(blockerId);
|
||||
if (blocker != null) {
|
||||
BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
|
||||
BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.creatureHasBlockedAttacker(input, blocker, game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
|
|||
|
||||
switch (controller) {
|
||||
case YOU:
|
||||
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), playerId);
|
||||
PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, playerId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
break;
|
||||
case OPPONENT:
|
||||
for (UUID opponentId : game.getOpponents(playerId)) {
|
||||
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), opponentId);
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, opponentId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
|
|||
case NOT_YOU:
|
||||
for (UUID notYouId : game.getState().getPlayersInRange(playerId, game)) {
|
||||
if (!notYouId.equals(playerId)) {
|
||||
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), notYouId);
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, notYouId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
|
|||
break;
|
||||
case ANY:
|
||||
for (UUID anyId : game.getState().getPlayersInRange(playerId, game)) {
|
||||
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), anyId);
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, anyId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
ability.addEffect(new CommanderCostModification(commander.getId()));
|
||||
getState().setValue(commander.getId() + "_castCount", 0);
|
||||
CommanderInfoWatcher watcher = new CommanderInfoWatcher(commander.getId(), checkCommanderDamage);
|
||||
getState().getWatchers().add(watcher);
|
||||
getState().addWatcher(watcher);
|
||||
watcher.addCardInfoToCommander(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -155,7 +155,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
protected boolean checkStateBasedActions() {
|
||||
for (Player player : getPlayers().values()) {
|
||||
for (UUID commanderId : player.getCommandersIds()) {
|
||||
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get(CommanderInfoWatcher.class.getSimpleName(), commanderId);
|
||||
CommanderInfoWatcher damageWatcher = getState().getWatcher(CommanderInfoWatcher.class, commanderId);
|
||||
if (damageWatcher == null) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1011,22 +1011,21 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
getState().setChoosingPlayerId(null);
|
||||
state.getWatchers().reset(); // watcher objects from cards are reused during match so reset all card watchers already added
|
||||
Watchers watchers = state.getWatchers();
|
||||
state.resetWatchers(); // watcher objects from cards are reused during match so reset all card watchers already added
|
||||
// add default watchers
|
||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||
watchers.add(new PlayerDamagedBySourceWatcher(playerId));
|
||||
watchers.add(new BloodthirstWatcher(playerId));
|
||||
getState().addWatcher(new PlayerDamagedBySourceWatcher(playerId));
|
||||
getState().addWatcher(new BloodthirstWatcher(playerId));
|
||||
}
|
||||
watchers.add(new MorbidWatcher());
|
||||
watchers.add(new CastSpellLastTurnWatcher());
|
||||
watchers.add(new CastSpellYourLastTurnWatcher());
|
||||
watchers.add(new PlayerLostLifeWatcher());
|
||||
watchers.add(new PlayerLostLifeNonCombatWatcher());
|
||||
watchers.add(new BlockedAttackerWatcher());
|
||||
watchers.add(new DamageDoneWatcher());
|
||||
watchers.add(new PlanarRollWatcher());
|
||||
watchers.add(new PlayersAttackedThisTurnWatcher());
|
||||
getState().addWatcher(new MorbidWatcher());
|
||||
getState().addWatcher(new CastSpellLastTurnWatcher());
|
||||
getState().addWatcher(new CastSpellYourLastTurnWatcher());
|
||||
getState().addWatcher(new PlayerLostLifeWatcher());
|
||||
getState().addWatcher(new PlayerLostLifeNonCombatWatcher());
|
||||
getState().addWatcher(new BlockedAttackerWatcher());
|
||||
getState().addWatcher(new DamageDoneWatcher());
|
||||
getState().addWatcher(new PlanarRollWatcher());
|
||||
getState().addWatcher(new PlayersAttackedThisTurnWatcher());
|
||||
|
||||
//20100716 - 103.5
|
||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||
|
|
@ -1117,7 +1116,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
for (Player player : getPlayers().values()) {
|
||||
player.endOfTurn(this);
|
||||
}
|
||||
state.getWatchers().reset();
|
||||
state.resetWatchers();
|
||||
}
|
||||
|
||||
protected UUID pickChoosingPlayer() {
|
||||
|
|
|
|||
|
|
@ -531,10 +531,23 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return this.turnMods;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Watchers getWatchers() {
|
||||
return this.watchers;
|
||||
}
|
||||
|
||||
public <T extends Watcher> T getWatcher(Class<T> watcherClass) {
|
||||
return watcherClass.cast(watchers.get(watcherClass.getSimpleName()));
|
||||
}
|
||||
|
||||
public <T extends Watcher> T getWatcher(Class<T> watcherClass, UUID uuid) {
|
||||
return watcherClass.cast(watchers.get(watcherClass.getSimpleName(), uuid.toString()));
|
||||
}
|
||||
|
||||
public <T extends Watcher> T getWatcher(Class<T> watcherClass,String prefix) {
|
||||
return watcherClass.cast(watchers.get(watcherClass.getSimpleName(), prefix));
|
||||
}
|
||||
|
||||
public SpecialActions getSpecialActions() {
|
||||
return this.specialActions;
|
||||
}
|
||||
|
|
@ -1104,6 +1117,10 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.watchers.add(watcher);
|
||||
}
|
||||
|
||||
public void resetWatchers(){
|
||||
this.watchers.reset();
|
||||
}
|
||||
|
||||
public int getZoneChangeCounter(UUID objectId) {
|
||||
return zoneChangeCounter.getOrDefault(objectId, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class JaceUnravelerOfSecretsTriggeredAbility extends SpellCastOpponentTriggeredA
|
|||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (super.checkTrigger(event, game)) {
|
||||
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(event.getPlayerId());
|
||||
if (spells != null && spells.size() == 1) {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class JayaBallardReplacementEffect extends ReplacementEffectImpl {
|
|||
if (card != null && (card.isInstant() || card.isSorcery())) {
|
||||
// TODO: Find a way to check, that the spell from graveyard was really cast by the ability of the emblem.
|
||||
// currently every spell cast from graveyard will be exiled.
|
||||
CastFromGraveyardWatcher watcher = (CastFromGraveyardWatcher) game.getState().getWatchers().get(CastFromGraveyardWatcher.class.getSimpleName());
|
||||
CastFromGraveyardWatcher watcher = game.getState().getWatcher(CastFromGraveyardWatcher.class);
|
||||
return watcher != null && watcher.spellWasCastFromGraveyard(event.getTargetId(), game.getState().getZoneChangeCounter(event.getTargetId()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class PlanarDieRollCostIncreasingEffect extends CostModificationEffectImpl {
|
|||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
Player activePlayer = game.getPlayer(game.getActivePlayerId());
|
||||
if (activePlayer != null) {
|
||||
PlanarRollWatcher watcher = (PlanarRollWatcher) game.getState().getWatchers().get(PlanarRollWatcher.class.getSimpleName());
|
||||
PlanarRollWatcher watcher = game.getState().getWatcher(PlanarRollWatcher.class);
|
||||
int rolledCounter = 0;
|
||||
if (watcher != null) {
|
||||
rolledCounter = watcher.getNumberTimesPlanarDieRolled(activePlayer.getId());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ public abstract class Watcher implements Serializable {
|
|||
protected boolean condition;
|
||||
protected final WatcherScope scope;
|
||||
|
||||
public Watcher(Class<? extends Watcher> watcherClass, WatcherScope scope){
|
||||
this(watcherClass.getSimpleName(), scope);
|
||||
}
|
||||
|
||||
public Watcher(String basicKey, WatcherScope scope) {
|
||||
this.basicKey = basicKey;
|
||||
this.scope = scope;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,26 @@
|
|||
|
||||
package mage.watchers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Watchers extends HashMap<String, Watcher> {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(Watcher.class.getSimpleName());
|
||||
|
||||
public Watchers() {
|
||||
}
|
||||
|
||||
public Watchers(final Watchers watchers) {
|
||||
watchers.entrySet().forEach((entry) -> this.put(entry.getKey(), entry.getValue().copy()));
|
||||
private Watchers(final Watchers watchers) {
|
||||
watchers.forEach((key, value) -> this.put(key, value.copy()));
|
||||
}
|
||||
|
||||
public Watchers copy() {
|
||||
|
|
@ -37,7 +41,16 @@ public class Watchers extends HashMap<String, Watcher> {
|
|||
this.values().forEach(Watcher::reset);
|
||||
}
|
||||
|
||||
public Watcher get(String key, UUID id) {
|
||||
return this.get(id + key);
|
||||
public Watcher get(String key, String id) {
|
||||
return get(id + key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watcher get(Object key) {
|
||||
if (containsKey(key)) {
|
||||
return super.get(key);
|
||||
}
|
||||
logger.info(key + " not found in watchers");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class PlayerGainedLifeWatcher extends Watcher {
|
|||
super(PlayerGainedLifeWatcher.class.getSimpleName(), WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public PlayerGainedLifeWatcher(final PlayerGainedLifeWatcher watcher) {
|
||||
private PlayerGainedLifeWatcher(final PlayerGainedLifeWatcher watcher) {
|
||||
super(watcher);
|
||||
for (Entry<UUID, Integer> entry : watcher.amountOfLifeGainedThisTurn.entrySet()) {
|
||||
amountOfLifeGainedThisTurn.put(entry.getKey(), entry.getValue());
|
||||
|
|
@ -45,7 +45,7 @@ public class PlayerGainedLifeWatcher extends Watcher {
|
|||
}
|
||||
}
|
||||
|
||||
public int getLiveGained(UUID playerId) {
|
||||
public int getLifeGained(UUID playerId) {
|
||||
return amountOfLifeGainedThisTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,11 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class ZuberasDiedWatcher extends Watcher {
|
||||
|
||||
public int zuberasDiedThisTurn = 0;
|
||||
public int getZuberasDiedThisTurn() {
|
||||
return zuberasDiedThisTurn;
|
||||
}
|
||||
|
||||
private int zuberasDiedThisTurn = 0;
|
||||
|
||||
public ZuberasDiedWatcher() {
|
||||
super(ZuberasDiedWatcher.class.getSimpleName(), WatcherScope.GAME);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue