mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
Refactor: moved ManaPaidSourceWatcher to default watchers, added additional checks;
This commit is contained in:
parent
24847c1fa7
commit
560b56a391
16 changed files with 36 additions and 25 deletions
|
|
@ -64,6 +64,8 @@ import mage.util.GameLog;
|
|||
import mage.util.MessageToClient;
|
||||
import mage.util.RandomUtil;
|
||||
import mage.util.functions.CopyApplier;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.Watchers;
|
||||
import mage.watchers.common.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -1185,18 +1187,29 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
public void initGameDefaultWatchers() {
|
||||
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 AttackedThisTurnWatcher());
|
||||
getState().addWatcher(new PlayersAttackedThisTurnWatcher());
|
||||
getState().addWatcher(new CardsDrawnThisTurnWatcher());
|
||||
getState().addWatcher(new ManaSpentToCastWatcher());
|
||||
List<Watcher> newWatchers = new ArrayList<>();
|
||||
newWatchers.add(new MorbidWatcher());
|
||||
newWatchers.add(new CastSpellLastTurnWatcher());
|
||||
newWatchers.add(new CastSpellYourLastTurnWatcher());
|
||||
newWatchers.add(new PlayerLostLifeWatcher());
|
||||
newWatchers.add(new PlayerLostLifeNonCombatWatcher());
|
||||
newWatchers.add(new BlockedAttackerWatcher());
|
||||
newWatchers.add(new DamageDoneWatcher());
|
||||
newWatchers.add(new PlanarRollWatcher());
|
||||
newWatchers.add(new AttackedThisTurnWatcher());
|
||||
newWatchers.add(new PlayersAttackedThisTurnWatcher());
|
||||
newWatchers.add(new CardsDrawnThisTurnWatcher());
|
||||
newWatchers.add(new ManaSpentToCastWatcher());
|
||||
newWatchers.add(new ManaPaidSourceWatcher());
|
||||
|
||||
// runtime check - allows only GAME scope (one watcher per game)
|
||||
newWatchers.forEach(watcher -> {
|
||||
if (watcher.getScope().equals(WatcherScope.GAME)) {
|
||||
throw new IllegalStateException("Game default watchers must have GAME scope: " + watcher.getClass().getCanonicalName());
|
||||
}
|
||||
});
|
||||
|
||||
newWatchers.forEach(getState()::addWatcher);
|
||||
}
|
||||
|
||||
public void initPlayerDefaultWatchers(UUID playerId) {
|
||||
|
|
|
|||
|
|
@ -169,4 +169,7 @@ public abstract class Watcher implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public WatcherScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Default watcher, no needs to add it to ability
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class ManaPaidSourceWatcher extends Watcher {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue