mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 14:32:06 -08:00
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
|
|
@ -5,17 +5,14 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.effects.RestrictionEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.SuperType;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.watchers.common.CastSpellYourLastTurnWatcher;
|
||||
import mage.watchers.common.PermanentsEnteredBattlefieldYourLastTurnWatcher;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author spjspj
|
||||
|
|
@ -28,7 +25,10 @@ public final class Arboria extends CardImpl {
|
|||
this.supertype.add(SuperType.WORLD);
|
||||
|
||||
// Creatures can't attack a player unless that player cast a spell or put a nontoken permanent onto the battlefield during their last turn.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ArboriaEffect()), new PermanentsEnteredBattlefieldYourLastTurnWatcher());
|
||||
Ability ability = new SimpleStaticAbility(new ArboriaEffect());
|
||||
ability.addWatcher(new PermanentsEnteredBattlefieldYourLastTurnWatcher());
|
||||
ability.addWatcher(new CastSpellYourLastTurnWatcher());
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
||||
private Arboria(final Arboria card) {
|
||||
|
|
@ -90,3 +90,94 @@ class ArboriaEffect extends RestrictionEffect {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class CastSpellYourLastTurnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<>();
|
||||
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();
|
||||
private UUID lastActivePlayer = null;
|
||||
|
||||
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 (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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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