[refactor] removed Watcher interface and renamed WatcherImpl to Watcher

This commit is contained in:
North 2014-05-31 19:35:21 +03:00
parent 9a9567c359
commit 0cc5308100
80 changed files with 207 additions and 273 deletions

View file

@ -15,7 +15,7 @@ import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
import java.util.UUID;
@ -214,7 +214,7 @@ class MadnessExileEffect extends OneShotEffect<MadnessExileEffect> {
/**
* Whenever phase is changed, this watcher returns all cards exiled by madness to graveyard and informs players about it.
*/
class MadnessCleanUpWatcher extends WatcherImpl<MadnessCleanUpWatcher> {
class MadnessCleanUpWatcher extends Watcher<MadnessCleanUpWatcher> {
public MadnessCleanUpWatcher() {
super("MadnessPlayWasCanceled", WatcherScope.GAME);

View file

@ -30,23 +30,74 @@ package mage.watchers;
import java.io.Serializable;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* watches for certain game events to occur and flags condition
*
* @author BetaSteward_at_googlemail.com
*/
public interface Watcher<T extends Watcher<T>> extends Serializable {
public abstract class Watcher<T extends Watcher<T>> implements Serializable {
UUID getControllerId();
void setControllerId(UUID controllerId);
UUID getSourceId();
void setSourceId(UUID sourceId);
String getKey();
void watch(GameEvent event, Game game);
boolean conditionMet();
void reset();
protected UUID controllerId;
protected UUID sourceId;
protected String key;
protected boolean condition;
protected WatcherScope scope;
T copy();
public Watcher(String key, WatcherScope scope) {
this.key = key;
this.scope = scope;
}
public Watcher(final Watcher watcher) {
this.condition = watcher.condition;
this.key = watcher.key;
this.controllerId = watcher.controllerId;
this.sourceId = watcher.sourceId;
this.scope = watcher.scope;
}
public UUID getControllerId() {
return controllerId;
}
public void setControllerId(UUID controllerId) {
this.controllerId = controllerId;
}
public UUID getSourceId() {
return sourceId;
}
public void setSourceId(UUID sourceId) {
this.sourceId = sourceId;
}
public String getKey() {
switch (scope) {
case GAME:
return key;
case PLAYER:
return controllerId + key;
case CARD:
return sourceId + key;
}
return key;
}
public boolean conditionMet() {
return condition;
}
public void reset() {
condition = false;
}
public abstract void watch(GameEvent event, Game game);
public abstract T copy();
}

View file

@ -1,104 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.watchers;
import java.util.UUID;
import mage.constants.WatcherScope;
/**
*
* watches for certain game events to occur and flags condition
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T> {
protected UUID controllerId;
protected UUID sourceId;
protected String key;
protected boolean condition;
protected WatcherScope scope;
public WatcherImpl(String key, WatcherScope scope) {
this.key = key;
this.scope = scope;
}
public WatcherImpl(final WatcherImpl watcher) {
this.condition = watcher.condition;
this.key = watcher.key;
this.controllerId = watcher.controllerId;
this.sourceId = watcher.sourceId;
this.scope = watcher.scope;
}
@Override
public UUID getControllerId() {
return controllerId;
}
@Override
public void setControllerId(UUID controllerId) {
this.controllerId = controllerId;
}
@Override
public UUID getSourceId() {
return sourceId;
}
@Override
public void setSourceId(UUID sourceId) {
this.sourceId = sourceId;
}
@Override
public String getKey() {
switch (scope) {
case GAME:
return key;
case PLAYER:
return controllerId + key;
case CARD:
return sourceId + key;
}
return key;
}
@Override
public boolean conditionMet() {
return condition;
}
@Override
public void reset() {
condition = false;
}
}

View file

@ -30,7 +30,7 @@ package mage.watchers.common;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
import java.util.HashSet;
import java.util.Set;
@ -39,7 +39,7 @@ import java.util.UUID;
/**
* @author magenoxx_at_gmail.com
*/
public class AttackedThisTurnWatcher extends WatcherImpl<AttackedThisTurnWatcher> {
public class AttackedThisTurnWatcher extends Watcher<AttackedThisTurnWatcher> {
public Set<UUID> attackedThisTurnCreatures = new HashSet<UUID>();

View file

@ -31,7 +31,7 @@ import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
import java.util.UUID;
@ -39,7 +39,7 @@ import java.util.UUID;
* Must be installed to player for proper Bloodthirst work
* @author Loki
*/
public class BloodthirstWatcher extends WatcherImpl<BloodthirstWatcher> {
public class BloodthirstWatcher extends Watcher<BloodthirstWatcher> {
public BloodthirstWatcher(UUID controllerId) {
super("DamagedOpponents", WatcherScope.PLAYER);
this.controllerId = controllerId;

View file

@ -36,7 +36,7 @@ import mage.constants.PhaseStep;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
*
@ -46,7 +46,7 @@ import mage.watchers.WatcherImpl;
*
*/
public class CardsDrawnDuringDrawStepWatcher extends WatcherImpl<CardsDrawnDuringDrawStepWatcher> {
public class CardsDrawnDuringDrawStepWatcher extends Watcher<CardsDrawnDuringDrawStepWatcher> {
private final Map<UUID, Integer> amountOfCardsDrawnThisTurn = new HashMap<>();

View file

@ -39,7 +39,7 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
* Counts amount of cards put into graveyards of players during the current turn.
@ -47,7 +47,7 @@ import mage.watchers.WatcherImpl;
*
* @author LevelX2
*/
public class CardsPutIntoGraveyardWatcher extends WatcherImpl<CardsPutIntoGraveyardWatcher> {
public class CardsPutIntoGraveyardWatcher extends Watcher<CardsPutIntoGraveyardWatcher> {
private final Map<UUID, Integer> amountOfCardsThisTurn = new HashMap<UUID, Integer>();
private final Set<UUID> cardsPutToGraveyardFromBattlefield = new HashSet<UUID>();

View file

@ -5,9 +5,9 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
public class CastFromHandWatcher extends WatcherImpl<CastFromHandWatcher> {
public class CastFromHandWatcher extends Watcher<CastFromHandWatcher> {
public CastFromHandWatcher() {
super("CastFromHand", WatcherScope.CARD);
}

View file

@ -34,7 +34,7 @@ import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
@ -42,7 +42,7 @@ import mage.watchers.WatcherImpl;
*
* @author nantuko, BetaSteward_at_googlemail.com
*/
public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatcher> {
public class CastSpellLastTurnWatcher extends Watcher<CastSpellLastTurnWatcher> {
private final Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<>();
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();

View file

@ -39,7 +39,7 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/* 20130711
*903.14a A player thats been dealt 21 or more combat damage by the same commander
@ -48,7 +48,7 @@ import mage.watchers.WatcherImpl;
*
* @author Plopman
*/
public class CommanderCombatDamageWatcher extends WatcherImpl<CommanderCombatDamageWatcher> {
public class CommanderCombatDamageWatcher extends Watcher<CommanderCombatDamageWatcher> {
public Map<UUID, Integer> damageToPlayer = new HashMap<UUID, Integer>();

View file

@ -31,7 +31,7 @@ import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
import java.util.ArrayList;
import java.util.List;
@ -41,7 +41,7 @@ import java.util.UUID;
*
* @author BetaSteward_at_googlemail.com
*/
public class DamagedByWatcher extends WatcherImpl<DamagedByWatcher> {
public class DamagedByWatcher extends Watcher<DamagedByWatcher> {
public List<UUID> damagedCreatures = new ArrayList<>();

View file

@ -5,13 +5,13 @@ import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
* @author BetaSteward_at_googlemail.com
* @author Loki
*/
public class LandfallWatcher extends WatcherImpl<LandfallWatcher> {
public class LandfallWatcher extends Watcher<LandfallWatcher> {
public LandfallWatcher() {
super("LandPlayed", WatcherScope.PLAYER);

View file

@ -45,7 +45,7 @@ import mage.cards.CardsImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
@ -55,7 +55,7 @@ import mage.watchers.WatcherImpl;
*
* @author noxx
*/
public class MiracleWatcher extends WatcherImpl<MiracleWatcher> {
public class MiracleWatcher extends Watcher<MiracleWatcher> {
private final Map<UUID, Integer> amountOfCardsDrawnThisTurn = new HashMap<>();

View file

@ -35,13 +35,13 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MorbidWatcher extends WatcherImpl<MorbidWatcher> {
public class MorbidWatcher extends Watcher<MorbidWatcher> {
public MorbidWatcher() {
super("Morbid", WatcherScope.GAME);

View file

@ -35,14 +35,14 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.util.CardUtil;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
* Watcher stores whitch sources did damage to a player
*
* @author LevelX
*/
public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySourceWatcher> {
public class PlayerDamagedBySourceWatcher extends Watcher<PlayerDamagedBySourceWatcher> {
private Set<String> damageSourceIds = new HashSet<String>();

View file

@ -35,7 +35,7 @@ import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
@ -45,7 +45,7 @@ import mage.watchers.WatcherImpl;
*
* @author LevelX2
*/
public class PlayerGainedLifeWatcher extends WatcherImpl<PlayerGainedLifeWatcher> {
public class PlayerGainedLifeWatcher extends Watcher<PlayerGainedLifeWatcher> {
private Map<UUID, Integer> amountOfLifeGainedThisTurn = new HashMap<UUID, Integer>();

View file

@ -35,7 +35,7 @@ import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
@ -45,7 +45,7 @@ import mage.watchers.WatcherImpl;
*
* @author LevelX2
*/
public class PlayerLostLifeWatcher extends WatcherImpl<PlayerLostLifeWatcher> {
public class PlayerLostLifeWatcher extends Watcher<PlayerLostLifeWatcher> {
private final Map<UUID, Integer> amountOfLifeLostThisTurn = new HashMap<>();

View file

@ -41,7 +41,7 @@ import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
* Watcher stores with which creature subtypes a player made combat damage to
@ -49,7 +49,7 @@ import mage.watchers.WatcherImpl;
*
* @author LevelX
*/
public class ProwlWatcher extends WatcherImpl<ProwlWatcher> {
public class ProwlWatcher extends Watcher<ProwlWatcher> {
private Map<UUID, Set<String>> damagingSubtypes = new HashMap<UUID, Set<String>>();
private Set<UUID> allSubtypes = new HashSet<UUID>();

View file

@ -44,14 +44,14 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
/**
* Reacts on various events to pair or unpair creatures on the battlefield.
*
* @author noxx
*/
public class SoulbondWatcher extends WatcherImpl<SoulbondWatcher> {
public class SoulbondWatcher extends Watcher<SoulbondWatcher> {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another not paired creature you control");

View file

@ -31,7 +31,7 @@ import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.watchers.WatcherImpl;
import mage.watchers.Watcher;
import java.util.ArrayList;
import java.util.List;
@ -42,7 +42,7 @@ import java.util.UUID;
*
* @author jeffwadsworth
*/
public class SourceDidDamageWatcher extends WatcherImpl<SourceDidDamageWatcher> {
public class SourceDidDamageWatcher extends Watcher<SourceDidDamageWatcher> {
public List<UUID> damageSources = new ArrayList<UUID>();