added sourceId to Watchers

This commit is contained in:
BetaSteward 2011-08-12 21:34:03 -04:00
parent ccea6d06d7
commit 981bdf5bfa
31 changed files with 101 additions and 63 deletions

View file

@ -63,7 +63,7 @@ public class AshenSkinZubera extends CardImpl<AshenSkinZubera> {
Ability ability = new DiesTriggeredAbility(new DiscardTargetEffect(new AshenSkinZuberaDynamicValue()));
ability.addTarget(new TargetOpponent());
this.addAbility(ability);
this.watchers.add(new AshenSkinZuberaWatcher(ownerId));
this.addWatcher(new AshenSkinZuberaWatcher());
}
public AshenSkinZubera(final AshenSkinZubera card) {
@ -81,8 +81,8 @@ class AshenSkinZuberaWatcher extends WatcherImpl<AshenSkinZuberaWatcher> {
public int zuberasDiedThisTurn = 0;
public AshenSkinZuberaWatcher(UUID controllerId) {
super("ZuberasDiedAshenSkinZubera", controllerId);
public AshenSkinZuberaWatcher() {
super("ZuberasDiedAshenSkinZubera");
}
public AshenSkinZuberaWatcher(final AshenSkinZuberaWatcher watcher) {

View file

@ -62,7 +62,7 @@ public class DrippingTongueZubera extends CardImpl<DrippingTongueZubera> {
this.power = new MageInt(1);
this.toughness = new MageInt(2);
this.addAbility(new DiesTriggeredAbility(new CreateTokenEffect(new SpiritToken(), new DrippingTongueZuberaDynamicValue()), false));
this.watchers.add(new DrippingTongueZuberaWatcher(ownerId));
this.addWatcher(new DrippingTongueZuberaWatcher());
}
public DrippingTongueZubera (final DrippingTongueZubera card) {
@ -80,8 +80,8 @@ class DrippingTongueZuberaWatcher extends WatcherImpl<DrippingTongueZuberaWatche
public int zuberasDiedThisTurn = 0;
public DrippingTongueZuberaWatcher(UUID controllerId) {
super("ZuberasDiedDrippingTongueZubera", controllerId);
public DrippingTongueZuberaWatcher() {
super("ZuberasDiedDrippingTongueZubera");
}
public DrippingTongueZuberaWatcher(final DrippingTongueZuberaWatcher watcher) {

View file

@ -64,7 +64,7 @@ public class EmberFistZubera extends CardImpl<EmberFistZubera> {
Ability ability = new DiesTriggeredAbility(new DamageTargetEffect(new EmberFistZuberaDynamicValue()));
ability.addTarget(new TargetCreatureOrPlayer());
this.addAbility(ability);
this.watchers.add(new EmberFistZuberaWatcher(ownerId));
this.addWatcher(new EmberFistZuberaWatcher());
}
public EmberFistZubera (final EmberFistZubera card) {
@ -82,8 +82,8 @@ class EmberFistZuberaWatcher extends WatcherImpl<EmberFistZuberaWatcher> {
public int zuberasDiedThisTurn = 0;
public EmberFistZuberaWatcher(UUID controllerId) {
super("ZuberasDiedEmberFistZubera", controllerId);
public EmberFistZuberaWatcher() {
super("ZuberasDiedEmberFistZubera");
}
public EmberFistZuberaWatcher(final EmberFistZuberaWatcher watcher) {

View file

@ -60,7 +60,7 @@ public class FloatingDreamZubera extends CardImpl<FloatingDreamZubera> {
this.power = new MageInt(1);
this.toughness = new MageInt(2);
this.addAbility(new DiesTriggeredAbility(new DrawCardControllerEffect(new FloatingDreamZuberaDynamicValue())));
this.watchers.add(new FloatingDreamZuberaWatcher(ownerId));
this.addWatcher(new FloatingDreamZuberaWatcher());
}
public FloatingDreamZubera(final FloatingDreamZubera card) {
@ -79,8 +79,8 @@ class FloatingDreamZuberaWatcher extends WatcherImpl<FloatingDreamZuberaWatcher>
public int zuberasDiedThisTurn = 0;
public FloatingDreamZuberaWatcher(UUID controllerId) {
super("ZuberasDiedFloatingDreamZubera", controllerId);
public FloatingDreamZuberaWatcher() {
super("ZuberasDiedFloatingDreamZubera");
}
public FloatingDreamZuberaWatcher(final FloatingDreamZuberaWatcher watcher) {

View file

@ -62,7 +62,7 @@ public class SilentChantZubera extends CardImpl<SilentChantZubera> {
this.toughness = new MageInt(2);
Ability ability = new DiesTriggeredAbility(new GainLifeEffect(new SilentChantZuberaDynamicValue()));
this.addAbility(ability);
this.watchers.add(new AshenSkinZuberaWatcher(ownerId));
this.addWatcher(new AshenSkinZuberaWatcher());
}
public SilentChantZubera (final SilentChantZubera card) {
@ -80,8 +80,8 @@ class SilentChantZuberaWatcher extends WatcherImpl<SilentChantZuberaWatcher> {
public int zuberasDiedThisTurn = 0;
public SilentChantZuberaWatcher(UUID controllerId) {
super("ZuberasDiedSilentChantZubera", controllerId);
public SilentChantZuberaWatcher() {
super("ZuberasDiedSilentChantZubera");
}
public SilentChantZuberaWatcher(final SilentChantZuberaWatcher watcher) {

View file

@ -61,8 +61,8 @@ public class AngelicArbiter extends CardImpl<AngelicArbiter> {
this.toughness = new MageInt(6);
this.addAbility(FlyingAbility.getInstance());
this.watchers.add(new AngelicArbiterWatcher1(ownerId));
this.watchers.add(new AngelicArbiterWatcher2(ownerId));
this.addWatcher(new AngelicArbiterWatcher1());
this.addWatcher(new AngelicArbiterWatcher2());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterEffect1()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterEffect2()));
}
@ -80,8 +80,8 @@ public class AngelicArbiter extends CardImpl<AngelicArbiter> {
class AngelicArbiterWatcher1 extends WatcherImpl<AngelicArbiterWatcher1> {
public AngelicArbiterWatcher1(UUID controllerId) {
super("CastSpell", controllerId);
public AngelicArbiterWatcher1() {
super("CastSpell");
}
public AngelicArbiterWatcher1(final AngelicArbiterWatcher1 watcher) {
@ -103,8 +103,8 @@ class AngelicArbiterWatcher1 extends WatcherImpl<AngelicArbiterWatcher1> {
class AngelicArbiterWatcher2 extends WatcherImpl<AngelicArbiterWatcher2> {
public AngelicArbiterWatcher2(UUID controllerId) {
super("Attacked", controllerId);
public AngelicArbiterWatcher2() {
super("Attacked");
}
public AngelicArbiterWatcher2(final AngelicArbiterWatcher2 watcher) {

View file

@ -60,7 +60,7 @@ public class BloodcrazedGoblin extends CardImpl<BloodcrazedGoblin> {
this.power = new MageInt(2);
this.toughness = new MageInt(2);
this.watchers.add(new BloodcrazedGoblinWatcher(ownerId));
this.addWatcher(new BloodcrazedGoblinWatcher());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BloodcrazedGoblinEffect()));
}
@ -77,8 +77,8 @@ public class BloodcrazedGoblin extends CardImpl<BloodcrazedGoblin> {
class BloodcrazedGoblinWatcher extends WatcherImpl<BloodcrazedGoblinWatcher> {
public BloodcrazedGoblinWatcher(UUID controllerId) {
super("OpponentDamaged", controllerId);
public BloodcrazedGoblinWatcher() {
super("OpponentDamaged");
}
public BloodcrazedGoblinWatcher(final BloodcrazedGoblinWatcher watcher) {

View file

@ -52,7 +52,7 @@ public class BloodOgre extends CardImpl<BloodOgre> {
this.toughness = new MageInt(2);
this.addAbility(new BloodthirstAbility(1));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(FirstStrikeAbility.getInstance());
}

View file

@ -51,7 +51,7 @@ public class BloodrageVampire extends CardImpl<BloodrageVampire> {
this.toughness = new MageInt(1);
this.addAbility(new BloodthirstAbility(1));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
}
public BloodrageVampire(final BloodrageVampire card) {

View file

@ -52,7 +52,7 @@ public class CarnageWurm extends CardImpl<CarnageWurm> {
this.toughness = new MageInt(6);
this.addAbility(new BloodthirstAbility(3));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(TrampleAbility.getInstance());
}

View file

@ -52,7 +52,7 @@ public class DuskhunterBat extends CardImpl<DuskhunterBat> {
this.toughness = new MageInt(1);
this.addAbility(new BloodthirstAbility(1));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(FlyingAbility.getInstance());
}

View file

@ -52,7 +52,7 @@ public class FurybornHellkite extends CardImpl<FurybornHellkite> {
this.toughness = new MageInt(6);
this.addAbility(new BloodthirstAbility(6));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(FlyingAbility.getInstance());
}

View file

@ -52,7 +52,7 @@ public class GorehornMinotaurs extends CardImpl<GorehornMinotaurs> {
this.toughness = new MageInt(3);
this.addAbility(new BloodthirstAbility(2));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
}
public GorehornMinotaurs(final GorehornMinotaurs card) {

View file

@ -52,7 +52,7 @@ public class LurkingCrocodile extends CardImpl<LurkingCrocodile> {
this.toughness = new MageInt(2);
this.addAbility(new BloodthirstAbility(1));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(new IslandwalkAbility());
}

View file

@ -52,7 +52,7 @@ public class VampireOutcasts extends CardImpl<VampireOutcasts> {
this.toughness = new MageInt(2);
this.addAbility(new BloodthirstAbility(2));
this.watchers.add(new BloodthirstWatcher(ownerId));
this.addWatcher(new BloodthirstWatcher());
this.addAbility(LifelinkAbility.getInstance());
}

View file

@ -60,7 +60,7 @@ public class Vengevine extends CardImpl<Vengevine> {
this.addAbility(HasteAbility.getInstance());
this.addAbility(new VengevineAbility());
this.watchers.add(new VengevineWatcher(ownerId));
this.addWatcher(new VengevineWatcher());
}
public Vengevine(final Vengevine card) {
@ -112,8 +112,8 @@ class VengevineWatcher extends WatcherImpl<VengevineWatcher> {
int creatureSpellCount = 0;
public VengevineWatcher(UUID controllerId) {
super("CreatureCast", controllerId);
public VengevineWatcher() {
super("CreatureCast");
}
public VengevineWatcher(final VengevineWatcher watcher) {

View file

@ -65,7 +65,7 @@ public class FleshAllergy extends CardImpl<FleshAllergy> {
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new FleshAllergyEffect());
this.watchers.add(new FleshAllergyWatcher(ownerId));
this.addWatcher(new FleshAllergyWatcher());
}
public FleshAllergy (final FleshAllergy card) {
@ -82,8 +82,8 @@ class FleshAllergyWatcher extends WatcherImpl<FleshAllergyWatcher> {
public int creaturesDiedThisTurn = 0;
public FleshAllergyWatcher(UUID controllerId) {
super("CreaturesDiedFleshAllergy", controllerId);
public FleshAllergyWatcher() {
super("CreaturesDiedFleshAllergy");
}
public FleshAllergyWatcher(final FleshAllergyWatcher watcher) {

View file

@ -53,7 +53,7 @@ public class MoltenPsyche extends CardImpl<MoltenPsyche> {
this.expansionSetCode = "SOM";
this.color.setRed(true);
this.getSpellAbility().addEffect(new MoltenPsycheEffect());
this.watchers.add(new MoltenPsycheWatcher(ownerId));
this.addWatcher(new MoltenPsycheWatcher());
}
public MoltenPsyche(final MoltenPsyche card) {
@ -110,8 +110,8 @@ class MoltenPsycheWatcher extends WatcherImpl<MoltenPsycheWatcher> {
private Map<UUID, Integer> draws = new HashMap<UUID, Integer>();
public MoltenPsycheWatcher(UUID controllerId) {
super("CardsDrawnMoltenPsyche", controllerId);
public MoltenPsycheWatcher() {
super("CardsDrawnMoltenPsyche");
}
public MoltenPsycheWatcher(final MoltenPsycheWatcher watcher) {

View file

@ -143,7 +143,7 @@ class MyrBattlesphereEffect extends OneShotEffect<MyrBattlesphereEffect> {
UUID defenderId = game.getCombat().getDefendingPlayer(source.getSourceId());
Player defender = game.getPlayer(defenderId);
if (defender != null) {
defender.damage(source.getCosts().getVariableCosts().get(0).getAmount(), source.getSourceId(), game, false, false);
defender.damage(source.getManaCostsToPay().getVariableCosts().get(0).getAmount(), source.getSourceId(), game, false, false);
return true;
}
return false;

View file

@ -67,7 +67,7 @@ public class SteelHellkite extends CardImpl<SteelHellkite> {
// {X}: Destroy each nonland permanent with converted mana cost X whose controller was dealt combat damage by Steel Hellkite this turn. Activate this ability only once each turn.
this.addAbility(new ActivateOncePerTurnActivatedAbility(Constants.Zone.BATTLEFIELD, new SteelHellkiteDestroyEffect(), new ManaCostsImpl("{X}")));
this.watchers.add(new SteelHellkiteWatcher(ownerId));
this.addWatcher(new SteelHellkiteWatcher());
}
public SteelHellkite(final SteelHellkite card) {
@ -118,8 +118,8 @@ class SteelHellkiteWatcher extends WatcherImpl<SteelHellkiteWatcher> {
public Map<UUID, Set<UUID>> damagedPlayers = new HashMap<UUID, Set<UUID>>();
public SteelHellkiteWatcher(UUID controllerId) {
super("SteelHellkiteWatcher", controllerId);
public SteelHellkiteWatcher() {
super("SteelHellkiteWatcher");
}
public SteelHellkiteWatcher(final SteelHellkiteWatcher watcher) {

View file

@ -58,7 +58,7 @@ public class TunnelIgnus extends CardImpl<TunnelIgnus> {
this.color.setRed(true);
this.power = new MageInt(2);
this.toughness = new MageInt(1);
this.watchers.add(new TunnelIgnusWatcher(ownerId));
this.addWatcher(new TunnelIgnusWatcher());
this.addAbility(new TunnelIgnusTriggeredAbility());
}
@ -76,8 +76,8 @@ public class TunnelIgnus extends CardImpl<TunnelIgnus> {
class TunnelIgnusWatcher extends WatcherImpl {
int count = 0;
public TunnelIgnusWatcher(UUID controllerId) {
super("LandPlayedCount", controllerId);
public TunnelIgnusWatcher() {
super("LandPlayedCount");
}
public TunnelIgnusWatcher(final TunnelIgnusWatcher watcher) {

View file

@ -63,7 +63,7 @@ public class Groundswell extends CardImpl<Groundswell> {
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new GroundswellEffect(Duration.EndOfTurn));
this.watchers.add(new GroundswellWatcher(ownerId));
this.addWatcher(new GroundswellWatcher());
}
public Groundswell(final Groundswell card) {
@ -78,8 +78,8 @@ public class Groundswell extends CardImpl<Groundswell> {
class GroundswellWatcher extends WatcherImpl<GroundswellWatcher> {
public GroundswellWatcher(UUID controllerId) {
super("LandPlayed", controllerId);
public GroundswellWatcher() {
super("LandPlayed");
}
public GroundswellWatcher(final GroundswellWatcher watcher) {

View file

@ -61,7 +61,7 @@ public class SearingBlaze extends CardImpl<SearingBlaze> {
//TODO: change this to only allow creatures controlled by first target
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new SearingBlazeEffect());
this.watchers.add(new SearingBlazeWatcher(ownerId));
this.addWatcher(new SearingBlazeWatcher());
}
public SearingBlaze(final SearingBlaze card) {
@ -77,8 +77,8 @@ public class SearingBlaze extends CardImpl<SearingBlaze> {
class SearingBlazeWatcher extends WatcherImpl<SearingBlazeWatcher> {
public SearingBlazeWatcher(UUID controllerId) {
super("LandPlayed", controllerId);
public SearingBlazeWatcher() {
super("LandPlayed");
}
public SearingBlazeWatcher(final SearingBlazeWatcher watcher) {

View file

@ -56,7 +56,7 @@ public class ArchiveTrap extends CardImpl<ArchiveTrap> {
this.getSpellAbility().addTarget(new TargetOpponent());
this.getSpellAbility().addEffect(new PutLibraryIntoGraveTargetEffect(13));
this.getSpellAbility().addAlternativeCost(new ArchiveTrapAlternativeCost());
this.watchers.add(new ArchiveTrapWatcher(ownerId));
this.addWatcher(new ArchiveTrapWatcher());
}
public ArchiveTrap(final ArchiveTrap card) {
@ -72,8 +72,8 @@ public class ArchiveTrap extends CardImpl<ArchiveTrap> {
class ArchiveTrapWatcher extends WatcherImpl<ArchiveTrapWatcher> {
public ArchiveTrapWatcher(UUID controllerId) {
super("LibrarySearched", controllerId);
public ArchiveTrapWatcher() {
super("LibrarySearched");
}
public ArchiveTrapWatcher(final ArchiveTrapWatcher watcher) {

View file

@ -38,6 +38,7 @@ import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
import mage.watchers.Watchers;
public interface Card extends MageObject {
@ -50,6 +51,7 @@ public interface Card extends MageObject {
public void setControllerId(UUID controllerId);
public void setOwnerId(UUID ownerId);
public void addAbility(Ability ability);
public void addWatcher(Watcher watcher);
public SpellAbility getSpellAbility();
public List<String> getRules();
public Watchers getWatchers();

View file

@ -48,6 +48,7 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentCard;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
import mage.watchers.Watchers;
import org.apache.log4j.Logger;
@ -101,6 +102,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
this.objectId = UUID.randomUUID();
this.abilities.newId();
this.abilities.setSourceId(objectId);
this.watchers.setSourceId(objectId);
}
public static Card createCard(String name) {
@ -151,6 +153,13 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
abilities.add(ability);
}
@Override
public void addWatcher(Watcher watcher) {
watcher.setSourceId(this.getId());
watcher.setControllerId(this.ownerId);
watchers.add(watcher);
}
@Override
public SpellAbility getSpellAbility() {
for (Ability ability: abilities.getActivatedAbilities(Zone.HAND)) {

View file

@ -52,6 +52,7 @@ import mage.watchers.Watchers;
import java.util.List;
import java.util.UUID;
import mage.watchers.Watcher;
/**
*
@ -249,6 +250,9 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
public void addAbility(Ability ability) {}
@Override
public void addWatcher(Watcher watcher) {}
@Override
public SpellAbility getSpellAbility() {
return ability;
}

View file

@ -41,6 +41,8 @@ public interface Watcher<T extends Watcher<T>> extends Serializable {
public UUID getControllerId();
public void setControllerId(UUID controllerId);
public UUID getSourceId();
public void setSourceId(UUID sourceId);
public String getKey();
public void watch(GameEvent event, Game game);
public boolean conditionMet();

View file

@ -39,18 +39,19 @@ import java.util.UUID;
public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T> {
protected UUID controllerId;
protected UUID sourceId;
protected String key;
protected boolean condition;
public WatcherImpl(String key, UUID controllerId) {
public WatcherImpl(String key) {
this.key = key;
this.controllerId = controllerId;
}
public WatcherImpl(final WatcherImpl watcher) {
this.condition = watcher.condition;
this.key = watcher.key;
this.controllerId = watcher.controllerId;
this.sourceId = watcher.sourceId;
}
@Override
@ -63,6 +64,16 @@ public abstract class WatcherImpl<T extends WatcherImpl<T>> implements Watcher<T
this.controllerId = controllerId;
}
@Override
public UUID getSourceId() {
return sourceId;
}
@Override
public void setSourceId(UUID sourceId) {
this.sourceId = sourceId;
}
@Override
public String getKey() {
return key;

View file

@ -59,6 +59,18 @@ public class Watchers extends ArrayList<Watcher> {
}
}
public void setSourceId(UUID sourceId) {
for (Watcher watcher: this) {
watcher.setSourceId(sourceId);
}
}
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().equals(controllerId) && watcher.getKey().equals(key))

View file

@ -5,15 +5,13 @@ import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
import java.util.UUID;
/**
* Must be installed to card for proper Bloodthirst work
* @author Loki
*/
public class BloodthirstWatcher extends WatcherImpl<BloodthirstWatcher> {
public BloodthirstWatcher(UUID controllerId) {
super("DamagedOpponents", controllerId);
public BloodthirstWatcher() {
super("DamagedOpponents");
}
public BloodthirstWatcher(final BloodthirstWatcher watcher) {