mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08:00
over-hauled watchers
This commit is contained in:
parent
caaa81a42b
commit
c00e34c051
46 changed files with 473 additions and 673 deletions
|
|
@ -420,6 +420,12 @@ public final class Constants {
|
|||
EQUIPMENT,
|
||||
AURA
|
||||
}
|
||||
|
||||
public enum WatcherScope {
|
||||
GAME,
|
||||
PLAYER,
|
||||
CARD
|
||||
}
|
||||
|
||||
public static final List<String> PlaneswalkerTypes = new ArrayList<String>()
|
||||
{{add("Ajani"); add("Bolas"); add("Chandra"); add("Elspeth");add("Garruk"); add("Jace"); add("Liliana"); add("Nissa"); add("Sarkhan"); add("Sorin"); add("Tezzeret");}};
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class MorbidCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(source.getControllerId(), "Morbid");
|
||||
Watcher watcher = game.getState().getWatchers().get("Morbid");
|
||||
return watcher.conditionMet();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class NoSpellsWereCastLastTurnCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(source.getControllerId(), "CastSpellLastTurnWatcher");
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
||||
return watcher.getAmountOfSpellsCastOnPrevTurn() == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(source.getControllerId(), "CastSpellLastTurnWatcher");
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
||||
return watcher.getAmountOfSpellsCastOnPrevTurn() >= 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import mage.abilities.effects.OneShotEffect;
|
|||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.common.BloodthirstWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -53,11 +55,14 @@ class BloodthirstEffect extends OneShotEffect<BloodthirstEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(source.getControllerId(), "DamagedOpponents");
|
||||
if (watcher.conditionMet()) {
|
||||
Permanent p = game.getPermanent(source.getSourceId());
|
||||
if (p != null) {
|
||||
p.addCounters(CounterType.P1P1.createInstance(amount), game);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get("DamagedOpponents", source.getControllerId());
|
||||
if (watcher.conditionMet()) {
|
||||
Permanent p = game.getPermanent(source.getSourceId());
|
||||
if (p != null) {
|
||||
p.addCounters(CounterType.P1P1.createInstance(amount), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public interface Card extends MageObject {
|
|||
public void addWatcher(Watcher watcher);
|
||||
public SpellAbility getSpellAbility();
|
||||
public List<String> getRules();
|
||||
public Watchers getWatchers();
|
||||
public List<Watcher> getWatchers();
|
||||
public String getExpansionSetCode();
|
||||
public void setExpansionSetCode(String expansionSetCode);
|
||||
public void setFaceDown(boolean value);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.Constants.Zone;
|
||||
import mage.MageObjectImpl;
|
||||
|
|
@ -50,7 +51,7 @@ import mage.game.events.ZoneChangeEvent;
|
|||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.Watchers;
|
||||
import mage.watchers.WatcherImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T> implements Card {
|
||||
|
|
@ -60,7 +61,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
|||
|
||||
protected UUID ownerId;
|
||||
protected int cardNumber;
|
||||
protected Watchers watchers = new Watchers();
|
||||
protected List<Watcher> watchers = new ArrayList<Watcher>();
|
||||
protected String expansionSetCode;
|
||||
protected Rarity rarity;
|
||||
protected boolean faceDown;
|
||||
|
|
@ -97,7 +98,9 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
|||
cardNumber = card.cardNumber;
|
||||
expansionSetCode = card.expansionSetCode;
|
||||
rarity = card.rarity;
|
||||
watchers = card.watchers.copy();
|
||||
for (Watcher watcher: (List<Watcher>)card.watchers) {
|
||||
this.watchers.add(watcher.copy());
|
||||
}
|
||||
faceDown = card.faceDown;
|
||||
|
||||
canTransform = card.canTransform;
|
||||
|
|
@ -112,7 +115,6 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
|||
this.objectId = UUID.randomUUID();
|
||||
this.abilities.newOriginalId();
|
||||
this.abilities.setSourceId(objectId);
|
||||
this.watchers.setSourceId(objectId);
|
||||
}
|
||||
|
||||
public static Card createCard(String name) {
|
||||
|
|
@ -190,10 +192,10 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Watchers getWatchers() {
|
||||
public List<Watcher> getWatchers() {
|
||||
return watchers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void checkTriggers(Zone zone, GameEvent event, Game game) {
|
||||
for (TriggeredAbility ability : abilities.getTriggeredAbilities(zone)) {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ import mage.watchers.Watcher;
|
|||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.abilities.common.ChancellorAbility;
|
||||
|
||||
import mage.abilities.mana.TriggeredManaAbility;
|
||||
|
|
@ -159,7 +160,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
gameCards.put(card.getId(), card);
|
||||
state.setZone(card.getId(), Zone.OUTSIDE);
|
||||
for (Watcher watcher: card.getWatchers()) {
|
||||
watcher.setControllerId(ownerId);
|
||||
watcher.setControllerId(ownerId);
|
||||
watcher.setSourceId(card.getId());
|
||||
state.getWatchers().add(watcher);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,4 +78,8 @@ public class ZoneChangeEvent extends GameEvent {
|
|||
public Permanent getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public boolean isDiesEvent() {
|
||||
return (toZone == Zone.GRAVEYARD && fromZone == Zone.BATTLEFIELD);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -323,8 +323,8 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
|||
return card.getRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watchers getWatchers() {
|
||||
@Override
|
||||
public List<Watcher> getWatchers() {
|
||||
return card.getWatchers();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ import mage.game.stack.StackAbility;
|
|||
import mage.players.net.UserData;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
import mage.target.common.TargetDiscard;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.common.BloodthirstWatcher;
|
||||
|
||||
public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Serializable {
|
||||
|
|
@ -188,9 +187,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
this.passedTurn = false;
|
||||
this.canGainLife = true;
|
||||
this.canLoseLife = true;
|
||||
Watcher bloodthirst = new BloodthirstWatcher();
|
||||
bloodthirst.setControllerId(playerId);
|
||||
game.getState().getWatchers().add(bloodthirst);
|
||||
game.getState().getWatchers().add(new BloodthirstWatcher(playerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.watchers;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.WatcherScope;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -42,9 +43,11 @@ public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T
|
|||
protected UUID sourceId;
|
||||
protected String key;
|
||||
protected boolean condition;
|
||||
protected WatcherScope scope;
|
||||
|
||||
public WatcherImpl(String key) {
|
||||
public WatcherImpl(String key, WatcherScope scope) {
|
||||
this.key = key;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public WatcherImpl(final WatcherImpl watcher) {
|
||||
|
|
@ -52,6 +55,7 @@ public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T
|
|||
this.key = watcher.key;
|
||||
this.controllerId = watcher.controllerId;
|
||||
this.sourceId = watcher.sourceId;
|
||||
this.scope = watcher.scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -76,6 +80,14 @@ public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T
|
|||
|
||||
@Override
|
||||
public String getKey() {
|
||||
switch (scope) {
|
||||
case GAME:
|
||||
return key;
|
||||
case PLAYER:
|
||||
return controllerId + key;
|
||||
case CARD:
|
||||
return sourceId + key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
package mage.watchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -37,46 +38,59 @@ import mage.game.events.GameEvent;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Watchers extends ArrayList<Watcher> {
|
||||
|
||||
public Watchers copy() {
|
||||
Watchers newCopy = new Watchers();
|
||||
for (Watcher watcher: this) {
|
||||
newCopy.add(watcher.copy());
|
||||
public class Watchers extends HashMap<String, Watcher> {
|
||||
|
||||
public Watchers() {}
|
||||
|
||||
public Watchers(final Watchers watchers) {
|
||||
for (Map.Entry<String, Watcher> entry: watchers.entrySet()) {
|
||||
this.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
return newCopy;
|
||||
}
|
||||
|
||||
public Watchers copy() {
|
||||
return new Watchers(this);
|
||||
}
|
||||
|
||||
|
||||
public void add(Watcher watcher) {
|
||||
if (!this.containsKey(watcher.getKey()))
|
||||
this.put(watcher.getKey(), watcher);
|
||||
}
|
||||
|
||||
public void watch(GameEvent event, Game game) {
|
||||
for (Watcher watcher: this) {
|
||||
for (Watcher watcher: this.values()) {
|
||||
watcher.watch(event, game);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (Watcher watcher: this) {
|
||||
for (Watcher watcher: this.values()) {
|
||||
watcher.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSourceId(UUID sourceId) {
|
||||
for (Watcher watcher: this) {
|
||||
watcher.setSourceId(sourceId);
|
||||
}
|
||||
// public void setSourceId(UUID sourceId) {
|
||||
// for (Watcher watcher: this.values()) {
|
||||
// watcher.setSourceId(sourceId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void setControllerId(UUID controllerId) {
|
||||
// for (Watcher watcher: this.values()) {
|
||||
// watcher.setControllerId(controllerId);
|
||||
// }
|
||||
// }
|
||||
|
||||
public Watcher get(String key, UUID id) {
|
||||
return this.get(id + key);
|
||||
}
|
||||
|
||||
public void setControllerId(UUID controllerId) {
|
||||
for (Watcher watcher: this) {
|
||||
watcher.setControllerId(controllerId);
|
||||
}
|
||||
}
|
||||
|
||||
public Watcher get(UUID controllerId, String key) {
|
||||
for (Watcher watcher: this) {
|
||||
if ((watcher.getControllerId() == null || watcher.getControllerId().equals(controllerId)) && watcher.getKey().equals(key))
|
||||
return watcher;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// public Watcher get(UUID controllerId, UUID sourceId, String key) {
|
||||
// for (Watcher watcher: this) {
|
||||
// if ((watcher.getControllerId() == null || watcher.getControllerId().equals(controllerId)) && watcher.getKey().equals(key) && watcher.getSourceId().equals(sourceId))
|
||||
// return watcher;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamagedPlayerEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -10,8 +12,9 @@ import mage.watchers.WatcherImpl;
|
|||
* @author Loki
|
||||
*/
|
||||
public class BloodthirstWatcher extends WatcherImpl<BloodthirstWatcher> {
|
||||
public BloodthirstWatcher() {
|
||||
super("DamagedOpponents");
|
||||
public BloodthirstWatcher(UUID controllerId) {
|
||||
super("DamagedOpponents", WatcherScope.PLAYER);
|
||||
this.controllerId = controllerId;
|
||||
}
|
||||
|
||||
public BloodthirstWatcher(final BloodthirstWatcher watcher) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.stack.Spell;
|
||||
|
|
@ -8,7 +9,7 @@ import mage.watchers.WatcherImpl;
|
|||
|
||||
public class CastFromHandWatcher extends WatcherImpl<CastFromHandWatcher> {
|
||||
public CastFromHandWatcher() {
|
||||
super("CastFromHand");
|
||||
super("CastFromHand", WatcherScope.CARD);
|
||||
}
|
||||
|
||||
public CastFromHandWatcher(final CastFromHandWatcher watcher) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.watchers.common;
|
||||
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
|
@ -42,7 +43,7 @@ public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatch
|
|||
private int amountOfSpellsCastOnCurrentTurn;
|
||||
|
||||
public CastSpellLastTurnWatcher() {
|
||||
super("CastSpellLastTurnWatcher");
|
||||
super("CastSpellLastTurnWatcher", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public CastSpellLastTurnWatcher(final CastSpellLastTurnWatcher watcher) {
|
||||
|
|
|
|||
76
Mage/src/mage/watchers/common/DamagedByWatcher.java
Normal file
76
Mage/src/mage/watchers/common/DamagedByWatcher.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright 2011 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.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DamagedByWatcher extends WatcherImpl<DamagedByWatcher> {
|
||||
|
||||
public List<UUID> damagedCreatures = new ArrayList<UUID>();
|
||||
|
||||
public DamagedByWatcher() {
|
||||
super("DamagedByWatcher", WatcherScope.CARD);
|
||||
}
|
||||
|
||||
public DamagedByWatcher(final DamagedByWatcher watcher) {
|
||||
super(watcher);
|
||||
this.damagedCreatures = watcher.damagedCreatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamagedByWatcher copy() {
|
||||
return new DamagedByWatcher(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.DAMAGED_CREATURE) {
|
||||
if (sourceId.equals(event.getSourceId()) && !damagedCreatures.contains(event.getTargetId())) {
|
||||
damagedCreatures.add(event.getTargetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
damagedCreatures.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ package mage.watchers.common;
|
|||
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
|
|
@ -43,7 +44,7 @@ import mage.watchers.WatcherImpl;
|
|||
public class MorbidWatcher extends WatcherImpl<MorbidWatcher> {
|
||||
|
||||
public MorbidWatcher() {
|
||||
super("Morbid");
|
||||
super("Morbid", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public MorbidWatcher(final MorbidWatcher watcher) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue