forked from External/mage
move watchers used only in Arboria effect
This commit is contained in:
parent
37722a58c2
commit
f801c9851e
4 changed files with 99 additions and 133 deletions
|
|
@ -1338,7 +1338,6 @@ public abstract class GameImpl implements Game {
|
|||
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());
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko, BetaSteward_at_googlemail.com (spjspj)
|
||||
*/
|
||||
public class CastSpellYourLastTurnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<>();
|
||||
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();
|
||||
private UUID lastActivePlayer = null;
|
||||
|
||||
public CastSpellYourLastTurnWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
lastActivePlayer = game.getActivePlayerId();
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null && playerId.equals(lastActivePlayer)) {
|
||||
amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
|
||||
amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
if (amountOfSpellsCastOnPrevTurn != null
|
||||
&& lastActivePlayer != null
|
||||
&& amountOfSpellsCastOnPrevTurn.get(lastActivePlayer) != null) {
|
||||
amountOfSpellsCastOnPrevTurn.remove(lastActivePlayer);
|
||||
}
|
||||
|
||||
amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn);
|
||||
amountOfSpellsCastOnCurrentTurn.clear();
|
||||
lastActivePlayer = null;
|
||||
}
|
||||
|
||||
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {
|
||||
return amountOfSpellsCastOnPrevTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public CastSpellYourLastTurnWatcher copy() {
|
||||
// return new CastSpellYourLastTurnWatcher(this);
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author LevelX2 (spjspj)
|
||||
*/
|
||||
public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, List<Permanent>> enteringBattlefield = new HashMap<>();
|
||||
private final Map<UUID, List<Permanent>> enteringBattlefieldLastTurn = new HashMap<>();
|
||||
private UUID lastActivePlayer = null;
|
||||
|
||||
public PermanentsEnteredBattlefieldYourLastTurnWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
lastActivePlayer = game.getActivePlayerId();
|
||||
|
||||
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
|
||||
Permanent perm = game.getPermanentEntering(event.getTargetId());
|
||||
if (perm == null) {
|
||||
perm = game.getPermanent(event.getTargetId());
|
||||
}
|
||||
if (perm != null) {
|
||||
List<Permanent> permanents;
|
||||
if (!enteringBattlefield.containsKey(perm.getControllerId())) {
|
||||
permanents = new ArrayList<>();
|
||||
enteringBattlefield.put(perm.getControllerId(), permanents);
|
||||
} else {
|
||||
permanents = enteringBattlefield.get(perm.getControllerId());
|
||||
}
|
||||
permanents.add(perm.copy()); // copy needed because attributes like color could be changed later
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
if (enteringBattlefieldLastTurn != null
|
||||
&& lastActivePlayer != null
|
||||
&& enteringBattlefieldLastTurn.get(lastActivePlayer) != null) {
|
||||
enteringBattlefieldLastTurn.remove(lastActivePlayer);
|
||||
}
|
||||
enteringBattlefieldLastTurn.putAll(enteringBattlefield);
|
||||
enteringBattlefield.clear();
|
||||
lastActivePlayer = null;
|
||||
}
|
||||
|
||||
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
return enteringBattlefield.get(playerId);
|
||||
}
|
||||
return enteringBattlefieldLastTurn.get(playerId);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue