forked from External/mage
changed the constructor for a Watcher. Before, you had to explictly pass the name of the watcher as an argument. But most of the time this was the name of the class itself. So the watcher now determines internally its name. The method 'getBasicKey' can be overridden. Also updated some encapsulation
This commit is contained in:
parent
5c1f41f3a7
commit
c4eeec1bb2
178 changed files with 313 additions and 296 deletions
|
|
@ -15,18 +15,14 @@ import mage.game.events.GameEvent;
|
|||
*/
|
||||
public abstract class Watcher implements Serializable {
|
||||
|
||||
protected String basicKey;
|
||||
protected UUID controllerId;
|
||||
protected UUID sourceId;
|
||||
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;
|
||||
|
||||
public Watcher(WatcherScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +31,6 @@ public abstract class Watcher implements Serializable {
|
|||
this.controllerId = watcher.controllerId;
|
||||
this.sourceId = watcher.sourceId;
|
||||
this.scope = watcher.scope;
|
||||
this.basicKey = watcher.basicKey;
|
||||
}
|
||||
|
||||
public UUID getControllerId() {
|
||||
|
|
@ -57,13 +52,14 @@ public abstract class Watcher implements Serializable {
|
|||
public String getKey() {
|
||||
switch (scope) {
|
||||
case GAME:
|
||||
return basicKey;
|
||||
return getBasicKey();
|
||||
case PLAYER:
|
||||
return controllerId + basicKey;
|
||||
return controllerId + getBasicKey();
|
||||
case CARD:
|
||||
return sourceId + basicKey;
|
||||
return sourceId + getBasicKey();
|
||||
default:
|
||||
return getBasicKey();
|
||||
}
|
||||
return basicKey;
|
||||
}
|
||||
|
||||
public boolean conditionMet() {
|
||||
|
|
@ -74,6 +70,10 @@ public abstract class Watcher implements Serializable {
|
|||
condition = false;
|
||||
}
|
||||
|
||||
protected String getBasicKey(){
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public abstract void watch(GameEvent event, Game game);
|
||||
|
||||
public abstract Watcher copy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue