From 02ba80b7190c70e0e503d5b32cd7483f68a4d7db Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 25 Dec 2014 02:03:21 +0100 Subject: [PATCH] * Switched from UUID to MageObjectReference to handle affected objects of continuous effects. Solvng problems with objects that changed (multiple times) zones while the effect lasts. --- .../src/mage/sets/apocalypse/NightDay.java | 16 ++-- .../mage/sets/bornofthegods/BileBlight.java | 7 +- .../championsofkamigawa/KondasBanner.java | 79 +++++++++---------- .../TakenoSamuraiGeneral.java | 23 +++++- .../sets/commander2013/BroodingSaurian.java | 17 ++-- .../mage/sets/commander2013/HomewardPath.java | 14 ++-- .../mage/sets/gatecrash/LegionLoyalist.java | 5 +- .../sets/guildpact/LeylineOfSingularity.java | 29 ++----- .../src/mage/sets/iceage/DanceOfTheDead.java | 5 +- .../src/mage/sets/innistrad/PastInFlames.java | 5 +- .../SarkhanTheDragonspeaker.java | 14 +--- .../mage/sets/limitedalpha/AnimateDead.java | 5 +- .../src/mage/sets/magic2010/CoatOfArms.java | 18 ++--- .../sets/magic2015/PolymorphistsJest.java | 66 ++++++++-------- .../sets/ninthedition/NaturalAffinity.java | 25 +++--- .../mage/sets/odyssey/TestamentOfFaith.java | 19 ++--- .../mage/sets/ravnika/CrownOfConvergence.java | 10 +-- .../riseoftheeldrazi/CastThroughTime.java | 53 ++++++++----- .../scarsofmirrodin/LiegeOfTheTangle.java | 10 ++- .../mage/sets/tenth/MarchOfTheMachines.java | 14 ++-- .../mage/sets/timespiral/SuddenSpoiling.java | 23 +++--- .../mage/sets/urzasdestiny/Opalescence.java | 32 ++++---- .../src/mage/sets/visions/Necromancy.java | 5 +- .../mage/sets/zendikar/ArmamentMaster.java | 21 +---- .../mage/sets/zendikar/MarshCasualties.java | 23 +++--- .../cards/continuous/EvernightShadeTest.java | 3 + ...hnessCalculationAfterCombatDamageTest.java | 2 - Mage/src/mage/MageObjectReference.java | 8 ++ .../abilities/effects/ContinuousEffect.java | 10 +-- .../BecomesCreatureSourceEffect.java | 18 +++-- .../BecomesFaceDownCreatureAllEffect.java | 6 +- .../common/continious/BoostAllEffect.java | 9 +-- .../continious/BoostControlledEffect.java | 9 +-- .../continious/BoostOpponentsEffect.java | 20 ++++- .../common/continious/BoostSourceEffect.java | 12 ++- .../continious/GainAbilityAllEffect.java | 17 +++- .../GainAbilityControlledEffect.java | 19 ++++- .../continious/GainAbilitySourceEffect.java | 27 +++++-- .../continious/GainAbilityTargetEffect.java | 25 +++--- .../SetPowerToughnessAllEffect.java | 10 ++- .../SwitchPowerToughnessAllEffect.java | 16 ++-- 41 files changed, 407 insertions(+), 342 deletions(-) diff --git a/Mage.Sets/src/mage/sets/apocalypse/NightDay.java b/Mage.Sets/src/mage/sets/apocalypse/NightDay.java index 521297a69de..fb28d01d733 100644 --- a/Mage.Sets/src/mage/sets/apocalypse/NightDay.java +++ b/Mage.Sets/src/mage/sets/apocalypse/NightDay.java @@ -28,8 +28,10 @@ package mage.sets.apocalypse; +import java.util.Iterator; import java.util.List; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.continious.BoostTargetEffect; @@ -106,18 +108,20 @@ class DayEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { List creatures = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getFirstTarget(), game); for (Permanent creature : creatures) { - objects.add(creature.getId()); + affectedObjectList.add(new MageObjectReference(creature)); } } } @Override public boolean apply(Game game, Ability source) { - List creatures = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getFirstTarget(), game); - for (Permanent creature : creatures) { - if (!this.affectedObjectsSet || objects.contains(creature.getId())) { - creature.addPower(1); - creature.addToughness(1); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); + if (permanent != null) { + permanent.addPower(1); + permanent.addToughness(1); + } else { + it.remove(); } } return true; diff --git a/Mage.Sets/src/mage/sets/bornofthegods/BileBlight.java b/Mage.Sets/src/mage/sets/bornofthegods/BileBlight.java index 88ebf9350e8..daac359188a 100644 --- a/Mage.Sets/src/mage/sets/bornofthegods/BileBlight.java +++ b/Mage.Sets/src/mage/sets/bornofthegods/BileBlight.java @@ -28,6 +28,7 @@ package mage.sets.bornofthegods; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.common.continious.BoostAllEffect; import mage.cards.CardImpl; @@ -79,17 +80,17 @@ class BileBlightEffect extends BoostAllEffect { @Override public void init(Ability source, Game game) { super.init(source, game); + affectedObjectList.clear(); if (this.affectedObjectsSet) { - this.objects.clear(); Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source)); if (target != null) { if (target.getName().isEmpty()) { // face down creature - this.objects.add(target.getId()); + affectedObjectList.add(new MageObjectReference(target)); } else { String name = target.getLogName(); for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (perm.getLogName().equals(name)) { - this.objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/KondasBanner.java b/Mage.Sets/src/mage/sets/championsofkamigawa/KondasBanner.java index dda94696fb3..a511dd856d2 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/KondasBanner.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/KondasBanner.java @@ -30,17 +30,18 @@ package mage.sets.championsofkamigawa; import java.util.UUID; - -import mage.constants.*; import mage.abilities.Ability; import mage.abilities.common.EmptyEffect; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continious.BoostAllEffect; -import mage.abilities.keyword.ChangelingAbility; import mage.abilities.keyword.EquipAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SupertypePredicate; @@ -53,7 +54,6 @@ import mage.util.CardUtil; * * @author LevelX */ - public class KondasBanner extends CardImpl { private static final FilterControlledCreaturePermanent legendaryFilter = new FilterControlledCreaturePermanent("Legendary creatures"); @@ -80,8 +80,8 @@ public class KondasBanner extends CardImpl { // Equip {2} this.addAbility(new EquipAbility( Outcome.AddAbility, - new GenericManaCost(2), - new TargetControlledCreaturePermanent(1,1, legendaryFilter, false))); + new GenericManaCost(2), + new TargetControlledCreaturePermanent(1, 1, legendaryFilter, false))); } @@ -92,15 +92,15 @@ public class KondasBanner extends CardImpl { @Override public KondasBanner copy() { return new KondasBanner(this); - } + } } -class KondasBannerTypeBoostEffect extends BoostAllEffect { +class KondasBannerTypeBoostEffect extends BoostAllEffect { private static final String effectText = "Creatures that share a creature type with equipped creature get +1/+1"; KondasBannerTypeBoostEffect() { - super(1,1, Duration.WhileOnBattlefield, new FilterCreaturePermanent(), false); + super(1, 1, Duration.WhileOnBattlefield, new FilterCreaturePermanent(), false); staticText = effectText; } @@ -109,27 +109,24 @@ class KondasBannerTypeBoostEffect extends BoostAllEffect { } @Override - public boolean apply(Game game, Ability source) { - // Check if the equipment is attached - Permanent equipment = game.getPermanent(source.getSourceId()); - if (equipment != null && equipment.getAttachedTo() != null) - { - Permanent equipedCreature = game.getPermanent(equipment.getAttachedTo()); - if (equipedCreature != null) { - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (CardUtil.shareSubtypes(perm, equipedCreature)) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { - perm.addPower(power.calculate(game, source, this)); - perm.addToughness(toughness.calculate(game, source, this)); - } + public boolean apply(Game game, Ability source) { + // Check if the equipment is attached + Permanent equipment = game.getPermanent(source.getSourceId()); + if (equipment != null && equipment.getAttachedTo() != null) { + Permanent equipedCreature = game.getPermanent(equipment.getAttachedTo()); + if (equipedCreature != null) { + for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + if (CardUtil.shareSubtypes(perm, equipedCreature)) { + perm.addPower(power.calculate(game, source, this)); + perm.addToughness(toughness.calculate(game, source, this)); - } } - return true; } + return true; } - return false; } + return false; + } @Override public KondasBannerTypeBoostEffect copy() { @@ -138,13 +135,12 @@ class KondasBannerTypeBoostEffect extends BoostAllEffect { } - -class KondasBannerColorBoostEffect extends BoostAllEffect { +class KondasBannerColorBoostEffect extends BoostAllEffect { private static final String effectText = "Creatures that share a color with equipped creature get +1/+1."; KondasBannerColorBoostEffect() { - super(1,1, Duration.WhileOnBattlefield, new FilterCreaturePermanent(), false); + super(1, 1, Duration.WhileOnBattlefield, new FilterCreaturePermanent(), false); staticText = effectText; } @@ -153,25 +149,22 @@ class KondasBannerColorBoostEffect extends BoostAllEffect { } @Override - public boolean apply(Game game, Ability source) { - // Check if the equipment is attached - Permanent equipment = game.getPermanent(source.getSourceId()); - if (equipment != null && equipment.getAttachedTo() != null) - { - Permanent equipedCreature = game.getPermanent(equipment.getAttachedTo()); - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (equipedCreature.getColor().shares(perm.getColor())) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + public boolean apply(Game game, Ability source) { + // Check if the equipment is attached + Permanent equipment = game.getPermanent(source.getSourceId()); + if (equipment != null && equipment.getAttachedTo() != null) { + Permanent equipedCreature = game.getPermanent(equipment.getAttachedTo()); + for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + if (equipedCreature.getColor().shares(perm.getColor())) { perm.addPower(power.calculate(game, source, this)); perm.addToughness(toughness.calculate(game, source, this)); - } - } - } - return true; + } } - return false; + return true; } + return false; + } @Override public KondasBannerColorBoostEffect copy() { diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/TakenoSamuraiGeneral.java b/Mage.Sets/src/mage/sets/championsofkamigawa/TakenoSamuraiGeneral.java index 44f31a1afda..669731a5e53 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/TakenoSamuraiGeneral.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/TakenoSamuraiGeneral.java @@ -28,6 +28,7 @@ package mage.sets.championsofkamigawa; +import java.util.Iterator; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -41,6 +42,7 @@ import mage.game.Game; import mage.game.permanent.Permanent; import java.util.UUID; +import mage.MageObjectReference; /** * @author Loki @@ -101,7 +103,7 @@ class TakenoSamuraiGeneralEffect extends ContinuousEffectImpl { if (!perm.getId().equals(source.getSourceId())) { for (Ability ability : perm.getAbilities()) { if (ability instanceof BushidoAbility) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -111,8 +113,23 @@ class TakenoSamuraiGeneralEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + if (this.affectedObjectsSet) { + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent permanent = it.next().getPermanent(game); + if (permanent != null) { + for (Ability ability : permanent.getAbilities()) { + if (ability instanceof BushidoAbility) { + int value = ((BushidoAbility) ability).getValue(source, game, this); + permanent.addPower(value); + permanent.addToughness(value); + } + } + } else { + it.remove(); // no longer on the battlefield, remove reference to object + } + } + } else { + for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { if (!perm.getId().equals(source.getSourceId())) { for (Ability ability : perm.getAbilities()) { if (ability instanceof BushidoAbility) { diff --git a/Mage.Sets/src/mage/sets/commander2013/BroodingSaurian.java b/Mage.Sets/src/mage/sets/commander2013/BroodingSaurian.java index 67335d04133..655c475e8e1 100644 --- a/Mage.Sets/src/mage/sets/commander2013/BroodingSaurian.java +++ b/Mage.Sets/src/mage/sets/commander2013/BroodingSaurian.java @@ -27,10 +27,10 @@ */ package mage.sets.commander2013; -import java.util.HashSet; -import java.util.Set; +import java.util.Iterator; import java.util.UUID; import mage.MageInt; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.BeginningOfEndStepTriggeredAbility; import mage.abilities.effects.ContinuousEffectImpl; @@ -42,7 +42,6 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.SubLayer; import mage.constants.TargetController; -import mage.constants.Zone; import mage.filter.FilterPermanent; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; @@ -112,7 +111,7 @@ class BroodingSaurianControlEffect extends ContinuousEffectImpl { FilterPermanent playerFilter = filter.copy(); playerFilter.add(new OwnerIdPredicate(playerId)); for (Permanent permanent :game.getBattlefield().getActivePermanents(playerFilter, playerId, game)) { - objects.add(permanent.getId()); + affectedObjectList.add(new MageObjectReference(permanent)); } } } @@ -120,19 +119,17 @@ class BroodingSaurianControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Set toRemove = new HashSet(); - for (UUID creatureId :objects) { - Permanent creature = game.getPermanent(creatureId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent creature = it.next().getPermanent(game); if (creature != null) { if (!creature.getControllerId().equals(creature.getOwnerId())) { creature.changeControllerId(creature.getOwnerId(), game); } } else { - toRemove.add(creatureId); + it.remove(); } } - objects.removeAll(toRemove); - if (objects.isEmpty()) { + if (affectedObjectList.isEmpty()) { this.discard(); } return true; diff --git a/Mage.Sets/src/mage/sets/commander2013/HomewardPath.java b/Mage.Sets/src/mage/sets/commander2013/HomewardPath.java index ea3621147eb..517218c74e8 100644 --- a/Mage.Sets/src/mage/sets/commander2013/HomewardPath.java +++ b/Mage.Sets/src/mage/sets/commander2013/HomewardPath.java @@ -28,8 +28,10 @@ package mage.sets.commander2013; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; @@ -105,7 +107,7 @@ class HomewardPathControlEffect extends ContinuousEffectImpl { FilterPermanent playerFilter = filter.copy(); playerFilter.add(new OwnerIdPredicate(playerId)); for (Permanent permanent :game.getBattlefield().getActivePermanents(playerFilter, playerId, game)) { - objects.add(permanent.getId()); + affectedObjectList.add(new MageObjectReference(permanent)); } } } @@ -113,19 +115,17 @@ class HomewardPathControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Set toRemove = new HashSet(); - for (UUID creatureId :objects) { - Permanent creature = game.getPermanent(creatureId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent creature = it.next().getPermanent(game); if (creature != null) { if (!creature.getControllerId().equals(creature.getOwnerId())) { creature.changeControllerId(creature.getOwnerId(), game); } } else { - toRemove.add(creatureId); + it.remove(); } } - objects.removeAll(toRemove); - if (objects.isEmpty()) { + if (affectedObjectList.isEmpty()) { this.discard(); } return true; diff --git a/Mage.Sets/src/mage/sets/gatecrash/LegionLoyalist.java b/Mage.Sets/src/mage/sets/gatecrash/LegionLoyalist.java index 68fae0d1197..50fbe497801 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/LegionLoyalist.java +++ b/Mage.Sets/src/mage/sets/gatecrash/LegionLoyalist.java @@ -33,6 +33,7 @@ import java.util.UUID; import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.continious.GainAbilityAllEffect; @@ -99,13 +100,13 @@ class CantBeBlockedByTokenEffect extends RestrictionEffect { public void init(Ability source, Game game) { affectedObjectsSet = true; for (Permanent perm: game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } @Override public boolean applies(Permanent permanent, Ability source, Game game) { - if (objects.contains(permanent.getId())) { + if (affectedObjectList.contains(new MageObjectReference(permanent))) { return true; } return false; diff --git a/Mage.Sets/src/mage/sets/guildpact/LeylineOfSingularity.java b/Mage.Sets/src/mage/sets/guildpact/LeylineOfSingularity.java index e91430e15f5..8e419bd5305 100644 --- a/Mage.Sets/src/mage/sets/guildpact/LeylineOfSingularity.java +++ b/Mage.Sets/src/mage/sets/guildpact/LeylineOfSingularity.java @@ -27,7 +27,9 @@ */ package mage.sets.guildpact; +import java.util.Iterator; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.common.SimpleStaticAbility; @@ -95,32 +97,11 @@ class SetSupertypeAllEffect extends ContinuousEffectImpl { return new SetSupertypeAllEffect(this); } - @Override - public void init(Ability source, Game game) { - super.init(source, game); - if (affectedObjectsSet) { - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - objects.add(perm.getId()); - } - } - } - @Override public boolean apply(Game game, Ability source) { - if (affectedObjectsSet) { - for (UUID permanentId :objects) { - Permanent permanent = game.getPermanent(permanentId); - if (permanent != null) { - if (!permanent.getSupertype().contains("Legendary")) { - permanent.getSupertype().add("Legendary"); - } - } - } - } else { - for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!permanent.getSupertype().contains("Legendary")) { - permanent.getSupertype().add("Legendary"); - } + for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + if (!permanent.getSupertype().contains("Legendary")) { + permanent.getSupertype().add("Legendary"); } } return true; diff --git a/Mage.Sets/src/mage/sets/iceage/DanceOfTheDead.java b/Mage.Sets/src/mage/sets/iceage/DanceOfTheDead.java index 3440373b048..7360d2429ad 100644 --- a/Mage.Sets/src/mage/sets/iceage/DanceOfTheDead.java +++ b/Mage.Sets/src/mage/sets/iceage/DanceOfTheDead.java @@ -28,6 +28,7 @@ package mage.sets.iceage; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; @@ -259,12 +260,12 @@ class DanceOfTheDeadChangeAbilityEffect extends ContinuousEffectImpl implements @Override public void init(Ability source, Game game) { super.init(source, game); - getAffectedObjects().add(source.getSourceId()); + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); } @Override public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = affectedObjectList.get(0).getPermanent(game);; if (permanent != null) { Ability abilityToRemove = null; for (Ability ability: permanent.getAbilities()) { diff --git a/Mage.Sets/src/mage/sets/innistrad/PastInFlames.java b/Mage.Sets/src/mage/sets/innistrad/PastInFlames.java index 6e016fe3cb3..16b9d76d901 100644 --- a/Mage.Sets/src/mage/sets/innistrad/PastInFlames.java +++ b/Mage.Sets/src/mage/sets/innistrad/PastInFlames.java @@ -28,6 +28,7 @@ package mage.sets.innistrad; import java.util.UUID; +import mage.MageObjectReference; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Layer; @@ -99,7 +100,7 @@ class PastInFlamesEffect extends ContinuousEffectImpl { for (UUID cardId: player.getGraveyard()) { Card card = game.getCard(cardId); if (card.getCardType().contains(CardType.INSTANT) || card.getCardType().contains(CardType.SORCERY)) { - objects.add(cardId); + affectedObjectList.add(new MageObjectReference(card)); } } } @@ -111,7 +112,7 @@ class PastInFlamesEffect extends ContinuousEffectImpl { Player player = game.getPlayer(source.getControllerId()); if (player != null) { for (UUID cardId: player.getGraveyard()) { - if (objects.contains(cardId)) { + if (affectedObjectList.contains(new MageObjectReference(cardId, game))) { Card card = game.getCard(cardId); FlashbackAbility ability = null; if (card.getCardType().contains(CardType.INSTANT)) { diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/SarkhanTheDragonspeaker.java b/Mage.Sets/src/mage/sets/khansoftarkir/SarkhanTheDragonspeaker.java index fcadc52e0e7..85ce4a6d2ba 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/SarkhanTheDragonspeaker.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/SarkhanTheDragonspeaker.java @@ -28,6 +28,7 @@ package mage.sets.khansoftarkir; import java.util.UUID; +import mage.MageObjectReference; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; @@ -98,8 +99,6 @@ public class SarkhanTheDragonspeaker extends CardImpl { class SarkhanTheDragonspeakerEffect extends ContinuousEffectImpl { - protected int zoneChangeCounter; - SarkhanTheDragonspeakerEffect() { super(Duration.EndOfTurn, Outcome.BecomeCreature); staticText = "Until end of turn, {this} becomes a legendary 4/4 red Dragon creature with flying, indestructible, and haste."; @@ -107,7 +106,6 @@ class SarkhanTheDragonspeakerEffect extends ContinuousEffectImpl { SarkhanTheDragonspeakerEffect(final SarkhanTheDragonspeakerEffect effect) { super(effect); - this.zoneChangeCounter = effect.zoneChangeCounter; } @Override @@ -118,17 +116,13 @@ class SarkhanTheDragonspeakerEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); - this.getAffectedObjects().add(source.getSourceId()); - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - this.zoneChangeCounter = permanent.getZoneChangeCounter(); - } + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); } @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && permanent.getZoneChangeCounter() == this.zoneChangeCounter) { + Permanent permanent = affectedObjectList.get(0).getPermanent(game); + if (permanent != null) { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { diff --git a/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java b/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java index 551d2583102..dc7d87ea25f 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java @@ -28,6 +28,7 @@ package mage.sets.limitedalpha; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; @@ -246,12 +247,12 @@ class AnimateDeadChangeAbilityEffect extends ContinuousEffectImpl implements Sou @Override public void init(Ability source, Game game) { super.init(source, game); - getAffectedObjects().add(source.getSourceId()); + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); } @Override public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = affectedObjectList.get(0).getPermanent(game); if (permanent != null) { Ability abilityToRemove = null; for (Ability ability: permanent.getAbilities()) { diff --git a/Mage.Sets/src/mage/sets/magic2010/CoatOfArms.java b/Mage.Sets/src/mage/sets/magic2010/CoatOfArms.java index 1b5530c8142..47f23dec9d4 100644 --- a/Mage.Sets/src/mage/sets/magic2010/CoatOfArms.java +++ b/Mage.Sets/src/mage/sets/magic2010/CoatOfArms.java @@ -27,8 +27,10 @@ */ package mage.sets.magic2010; +import java.util.Iterator; import java.util.List; import java.util.UUID; +import mage.MageObjectReference; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Layer; @@ -89,24 +91,16 @@ class CoatOfArmsEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); - if (this.affectedObjectsSet) { - List permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); - for (Permanent permanent : permanents) { - objects.add(permanent.getId()); - } - } } @Override public boolean apply(Game game, Ability source) { List permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); for (Permanent permanent : permanents) { - if (!this.affectedObjectsSet || objects.contains(permanent.getId())) { - int amount = getAmount(permanents, permanent); - permanent.addPower(amount); - permanent.addToughness(amount); - } - } + int amount = getAmount(permanents, permanent); + permanent.addPower(amount); + permanent.addToughness(amount); + } return true; } diff --git a/Mage.Sets/src/mage/sets/magic2015/PolymorphistsJest.java b/Mage.Sets/src/mage/sets/magic2015/PolymorphistsJest.java index b340f6a49d8..dee6038a164 100644 --- a/Mage.Sets/src/mage/sets/magic2015/PolymorphistsJest.java +++ b/Mage.Sets/src/mage/sets/magic2015/PolymorphistsJest.java @@ -27,7 +27,9 @@ */ package mage.sets.magic2015; +import java.util.Iterator; import java.util.UUID; +import mage.MageObjectReference; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; @@ -89,26 +91,31 @@ class PolymorphistsJestEffect extends ContinuousEffectImpl { return new PolymorphistsJestEffect(this); } + @Override + public void init(Ability source, Game game) { + super.init(source, game); + if (this.affectedObjectsSet) { + for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, getTargetPointer().getFirst(game, source), game)) { + affectedObjectList.add(new MageObjectReference(permanent)); + } + } + } + @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - switch (layer) { - case TypeChangingEffects_4: - if (sublayer == SubLayer.NA) { - objects.clear(); - for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, getTargetPointer().getFirst(game, source), game)){ - if(permanent != null){ - objects.add(permanent.getId()); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); + if (permanent != null) { + switch (layer) { + case TypeChangingEffects_4: + if (sublayer == SubLayer.NA) { permanent.getSubtype().clear(); permanent.getSubtype().add("Frog"); } - } - } - break; - case ColorChangingEffects_5: - if (sublayer == SubLayer.NA) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); - if (permanent != null){ + + break; + case ColorChangingEffects_5: + if (sublayer == SubLayer.NA) { permanent.getColor().setBlack(false); permanent.getColor().setGreen(false); permanent.getColor().setBlue(false); @@ -116,27 +123,19 @@ class PolymorphistsJestEffect extends ContinuousEffectImpl { permanent.getColor().setBlack(false); permanent.getColor().setColor(ObjectColor.BLUE); } - } - } - break; - case AbilityAddingRemovingEffects_6: - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); - if (permanent != null){ + break; + case AbilityAddingRemovingEffects_6: permanent.removeAllAbilities(source.getSourceId(), game); - } - } - break; - case PTChangingEffects_7: - if (sublayer == SubLayer.SetPT_7b) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); - if(permanent != null){ + break; + case PTChangingEffects_7: + if (sublayer == SubLayer.SetPT_7b) { permanent.getPower().setValue(1); permanent.getToughness().setValue(1); } - } } + } else { + it.remove(); + } } return true; } @@ -146,10 +145,9 @@ class PolymorphistsJestEffect extends ContinuousEffectImpl { return false; } - @Override public boolean hasLayer(Layer layer) { - return layer == Layer.PTChangingEffects_7 || layer == Layer.ColorChangingEffects_5 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.TypeChangingEffects_4; + return layer == Layer.PTChangingEffects_7 || layer == Layer.ColorChangingEffects_5 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.TypeChangingEffects_4; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/ninthedition/NaturalAffinity.java b/Mage.Sets/src/mage/sets/ninthedition/NaturalAffinity.java index 52372898940..166dadb35aa 100644 --- a/Mage.Sets/src/mage/sets/ninthedition/NaturalAffinity.java +++ b/Mage.Sets/src/mage/sets/ninthedition/NaturalAffinity.java @@ -27,16 +27,19 @@ */ package mage.sets.ninthedition; +import java.util.Iterator; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.CardImpl; +import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Layer; +import static mage.constants.Layer.PTChangingEffects_7; +import static mage.constants.Layer.TypeChangingEffects_4; import mage.constants.Outcome; +import mage.constants.Rarity; import mage.constants.SubLayer; import mage.filter.common.FilterLandPermanent; import mage.game.Game; @@ -90,7 +93,7 @@ class BecomesCreatureAllEffect extends ContinuousEffectImpl { super.init(source, game); this.affectedObjectsSet = true; for (Permanent perm: game.getBattlefield().getActivePermanents(new FilterLandPermanent(), source.getControllerId(), source.getSourceId(), game)) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } @@ -99,10 +102,12 @@ class BecomesCreatureAllEffect extends ContinuousEffectImpl { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); if(permanent != null){ permanent.getCardType().add(CardType.CREATURE); + } else { + it.remove(); } } } @@ -110,11 +115,13 @@ class BecomesCreatureAllEffect extends ContinuousEffectImpl { case PTChangingEffects_7: if (sublayer == SubLayer.SetPT_7b) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); if(permanent != null){ permanent.getPower().setValue(2); permanent.getToughness().setValue(2); + } else { + it.remove(); } } } @@ -133,4 +140,4 @@ class BecomesCreatureAllEffect extends ContinuousEffectImpl { return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == Layer.TypeChangingEffects_4; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/odyssey/TestamentOfFaith.java b/Mage.Sets/src/mage/sets/odyssey/TestamentOfFaith.java index ed3d9154329..1023f712802 100644 --- a/Mage.Sets/src/mage/sets/odyssey/TestamentOfFaith.java +++ b/Mage.Sets/src/mage/sets/odyssey/TestamentOfFaith.java @@ -29,7 +29,7 @@ package mage.sets.odyssey; import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.VariableManaCost; @@ -91,7 +91,6 @@ class TestamentOfFaithBecomesCreatureSourceEffect extends ContinuousEffectImpl i super(effect); this.token = effect.token.copy(); this.type = effect.type; - this.zoneChangeCounter = effect.zoneChangeCounter; } @Override @@ -102,17 +101,13 @@ class TestamentOfFaithBecomesCreatureSourceEffect extends ContinuousEffectImpl i @Override public void init(Ability source, Game game) { super.init(source, game); - this.getAffectedObjects().add(source.getSourceId()); - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - this.zoneChangeCounter = permanent.getZoneChangeCounter(); - } + this.getAffectedObjects().add(new MageObjectReference(source.getSourceId(), game)); } @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && permanent.getZoneChangeCounter() == this.zoneChangeCounter) { + Permanent permanent = affectedObjectList.get(0).getPermanent(game); + if (permanent != null) { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { @@ -151,10 +146,8 @@ class TestamentOfFaithBecomesCreatureSourceEffect extends ContinuousEffectImpl i if (sublayer == SubLayer.SetPT_7b) { MageInt power = new MageInt(source.getManaCosts().getVariableCosts().get(0).getAmount()); MageInt toughness = new MageInt(source.getManaCosts().getVariableCosts().get(0).getAmount()); - if (power != null && toughness != null) { - permanent.getPower().setValue(power.getValue()); - permanent.getToughness().setValue(toughness.getValue()); - } + permanent.getPower().setValue(power.getValue()); + permanent.getToughness().setValue(toughness.getValue()); } } return true; diff --git a/Mage.Sets/src/mage/sets/ravnika/CrownOfConvergence.java b/Mage.Sets/src/mage/sets/ravnika/CrownOfConvergence.java index 7a6a8717b14..d73ad9c7e77 100644 --- a/Mage.Sets/src/mage/sets/ravnika/CrownOfConvergence.java +++ b/Mage.Sets/src/mage/sets/ravnika/CrownOfConvergence.java @@ -100,11 +100,11 @@ class CrownOfConvergenceColorBoostEffect extends BoostAllEffect { @Override public boolean apply(Game game, Ability source) { Player you = game.getPlayer(source.getControllerId()); - Card topCard = you.getLibrary().getFromTop(game); - if (you != null && topCard != null) { - for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (permanent.getColor().shares(topCard.getColor()) && !permanent.getColor().isColorless()) { - if (!this.affectedObjectsSet || objects.contains(permanent.getId())) { + if (you != null) { + Card topCard = you.getLibrary().getFromTop(game); + if (topCard != null) { + for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + if (permanent.getColor().shares(topCard.getColor()) && !permanent.getColor().isColorless()) { permanent.addPower(power.calculate(game, source, this)); permanent.addToughness(toughness.calculate(game, source, this)); } diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java index 02d29056293..872e73aac48 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java @@ -48,6 +48,8 @@ import mage.watchers.Watcher; import java.util.Iterator; import java.util.UUID; +import mage.game.stack.Spell; +import mage.game.stack.StackObject; /** * @author magenoxx_at_gmail.com @@ -64,11 +66,9 @@ public class CastThroughTime extends CardImpl { super(ownerId, 55, "Cast Through Time", Rarity.MYTHIC, new CardType[]{CardType.ENCHANTMENT}, "{4}{U}{U}{U}"); this.expansionSetCode = "ROE"; - this.color.setBlue(true); - // Instant and sorcery spells you control have rebound. + // (Exile the spell as it resolves if you cast it from your hand. At the beginning of your next upkeep, you may cast that card from exile without paying its mana cost.) this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainReboundEffect())); - this.addWatcher(new LeavesBattlefieldWatcher()); } @@ -86,7 +86,7 @@ class GainReboundEffect extends ContinuousEffectImpl { public GainReboundEffect() { super(Duration.Custom, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); - staticText = "Instant and sorcery spells you control have rebound"; + staticText = "Instant and sorcery spells you control have rebound (Exile the spell as it resolves if you cast it from your hand. At the beginning of your next upkeep, you may cast that card from exile without paying its mana cost.)"; } public GainReboundEffect(final GainReboundEffect effect) { @@ -104,27 +104,42 @@ class GainReboundEffect extends ContinuousEffectImpl { Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { for (Card card : player.getHand().getCards(CastThroughTime.filter, game)) { - boolean found = false; - for (Ability ability : card.getAbilities()) { - if (ability instanceof ReboundAbility) { - found = true; - break; - } - } - if (!found) { - Ability ability = new AttachedReboundAbility(); - card.addAbility(ability); - ability.setControllerId(source.getControllerId()); - ability.setSourceId(card.getId()); - game.getState().addAbility(ability, source.getSourceId(), card); - } + addReboundAbility(card, source, game); + } + for (Iterator iterator = game.getStack().iterator(); iterator.hasNext();) { + StackObject stackObject = iterator.next(); + if (stackObject instanceof Spell && stackObject.getControllerId().equals(source.getControllerId())) { + Spell spell = (Spell) stackObject; + Card card = spell.getCard(); + if (card != null) { + addReboundAbility(card, source, game); + } + + } } - return true; } return false; } + private void addReboundAbility(Card card, Ability source, Game game) { + if (CastThroughTime.filter.match(card, game)) { + boolean found = false; + for (Ability ability : card.getAbilities()) { + if (ability instanceof ReboundAbility) { + found = true; + break; + } + } + if (!found) { + Ability ability = new AttachedReboundAbility(); + card.addAbility(ability); + ability.setControllerId(source.getControllerId()); + ability.setSourceId(card.getId()); + game.getState().addAbility(ability, card); + } + } + } } class AttachedReboundAbility extends ReboundAbility {} diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/LiegeOfTheTangle.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/LiegeOfTheTangle.java index 6a5bd0ed6cf..ba4b3e27c4a 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/LiegeOfTheTangle.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/LiegeOfTheTangle.java @@ -28,6 +28,7 @@ package mage.sets.scarsofmirrodin; +import java.util.Iterator; import java.util.UUID; import mage.constants.CardType; @@ -38,6 +39,7 @@ import mage.constants.Rarity; import mage.constants.SubLayer; import mage.constants.Zone; import mage.MageInt; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.ContinuousEffectImpl; @@ -130,8 +132,8 @@ class LiegeOfTheTangleEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - for (UUID permId: objects) { - Permanent perm = game.getPermanent(permId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent perm = it.next().getPermanent(game); if (perm != null) { if (perm.getCounters().getCount(CounterType.AWAKENING) > 0) { switch (layer) { @@ -154,6 +156,8 @@ class LiegeOfTheTangleEffect extends ContinuousEffectImpl { break; } } + } else { + it.remove(); } } return true; @@ -169,7 +173,7 @@ class LiegeOfTheTangleEffect extends ContinuousEffectImpl { super.init(source, game); if (this.affectedObjectsSet) { for (UUID permId: targetPointer.getTargets(game, source)) { - objects.add(permId); + affectedObjectList.add(new MageObjectReference(permId, game)); } } } diff --git a/Mage.Sets/src/mage/sets/tenth/MarchOfTheMachines.java b/Mage.Sets/src/mage/sets/tenth/MarchOfTheMachines.java index 0bd1d4ff01f..1c02831ea38 100644 --- a/Mage.Sets/src/mage/sets/tenth/MarchOfTheMachines.java +++ b/Mage.Sets/src/mage/sets/tenth/MarchOfTheMachines.java @@ -27,7 +27,9 @@ */ package mage.sets.tenth; +import java.util.Iterator; import java.util.UUID; +import mage.MageObjectReference; import mage.constants.*; import mage.abilities.Ability; @@ -91,10 +93,10 @@ class MarchOfTheMachinesEffect extends ContinuousEffectImpl { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { - objects.clear(); + affectedObjectList.clear(); for(Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)){ if(permanent != null){ - objects.add(permanent.getId()); + affectedObjectList.add(new MageObjectReference(permanent)); permanent.getCardType().add(CardType.CREATURE); } } @@ -103,9 +105,9 @@ class MarchOfTheMachinesEffect extends ContinuousEffectImpl { case PTChangingEffects_7: if (sublayer == SubLayer.SetPT_7b) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); - if(permanent != null){ + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); + if (permanent != null){ int manaCost = permanent.getManaCost().convertedManaCost(); permanent.getPower().setValue(manaCost); permanent.getToughness().setValue(manaCost); @@ -127,4 +129,4 @@ class MarchOfTheMachinesEffect extends ContinuousEffectImpl { return layer == Layer.PTChangingEffects_7 || layer == Layer.TypeChangingEffects_4; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/timespiral/SuddenSpoiling.java b/Mage.Sets/src/mage/sets/timespiral/SuddenSpoiling.java index 21027c607a0..00eb889a83c 100644 --- a/Mage.Sets/src/mage/sets/timespiral/SuddenSpoiling.java +++ b/Mage.Sets/src/mage/sets/timespiral/SuddenSpoiling.java @@ -28,6 +28,7 @@ package mage.sets.timespiral; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.keyword.SplitSecondAbility; @@ -96,7 +97,7 @@ class SuddenSpoilingEffect extends ContinuousEffectImpl { Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (player != null) { for (Permanent perm: game.getState().getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), player.getId(), game)) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -106,17 +107,17 @@ class SuddenSpoilingEffect extends ContinuousEffectImpl { Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (player != null) { for (Permanent permanent : game.getState().getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), player.getId(), game)) { - switch (layer) { - case AbilityAddingRemovingEffects_6: - permanent.removeAllAbilities(source.getSourceId(), game); - break; - case PTChangingEffects_7: - if (sublayer.equals(SubLayer.SetPT_7b)) { - if(objects.contains(permanent.getId())){ - permanent.getPower().setValue(0); - permanent.getToughness().setValue(2); + if (affectedObjectList.contains(new MageObjectReference(permanent))) { + switch (layer) { + case AbilityAddingRemovingEffects_6: + permanent.removeAllAbilities(source.getSourceId(), game); + break; + case PTChangingEffects_7: + if (sublayer.equals(SubLayer.SetPT_7b)) { + permanent.getPower().setValue(0); + permanent.getToughness().setValue(2); } - } + } } } return true; diff --git a/Mage.Sets/src/mage/sets/urzasdestiny/Opalescence.java b/Mage.Sets/src/mage/sets/urzasdestiny/Opalescence.java index 160efa4d4fb..bb8b0448d10 100644 --- a/Mage.Sets/src/mage/sets/urzasdestiny/Opalescence.java +++ b/Mage.Sets/src/mage/sets/urzasdestiny/Opalescence.java @@ -27,7 +27,9 @@ */ package mage.sets.urzasdestiny; +import java.util.Iterator; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; @@ -99,30 +101,24 @@ class OpalescenceEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - switch (layer) { - case TypeChangingEffects_4: - if (sublayer == SubLayer.NA) { - objects.clear(); - for(Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)){ - objects.add(permanent.getId()); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + switch (layer) { + case TypeChangingEffects_4: + if (sublayer == SubLayer.NA) { if (!permanent.getCardType().contains(CardType.CREATURE)) { permanent.getCardType().add(CardType.CREATURE); } } - } - break; + break; - case PTChangingEffects_7: - if (sublayer == SubLayer.SetPT_7b) { - for(UUID uuid : objects){ - Permanent permanent = game.getPermanent(uuid); - if(permanent != null){ - int manaCost = permanent.getManaCost().convertedManaCost(); - permanent.getPower().setValue(manaCost); - permanent.getToughness().setValue(manaCost); - } + case PTChangingEffects_7: + if (sublayer == SubLayer.SetPT_7b) { + int manaCost = permanent.getManaCost().convertedManaCost(); + permanent.getPower().setValue(manaCost); + permanent.getToughness().setValue(manaCost); } - } + } + } return true; } diff --git a/Mage.Sets/src/mage/sets/visions/Necromancy.java b/Mage.Sets/src/mage/sets/visions/Necromancy.java index 4e839165e79..388c40c0e74 100644 --- a/Mage.Sets/src/mage/sets/visions/Necromancy.java +++ b/Mage.Sets/src/mage/sets/visions/Necromancy.java @@ -28,6 +28,7 @@ package mage.sets.visions; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.EntersBattlefieldTriggeredAbility; @@ -313,12 +314,12 @@ class NecromancyChangeAbilityEffect extends ContinuousEffectImpl implements Sour @Override public void init(Ability source, Game game) { super.init(source, game); - getAffectedObjects().add(source.getSourceId()); + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); } @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = affectedObjectList.get(0).getPermanent(game);; if (permanent != null) { switch (layer) { case TypeChangingEffects_4: diff --git a/Mage.Sets/src/mage/sets/zendikar/ArmamentMaster.java b/Mage.Sets/src/mage/sets/zendikar/ArmamentMaster.java index ae90851063e..a0b0adb0ae6 100644 --- a/Mage.Sets/src/mage/sets/zendikar/ArmamentMaster.java +++ b/Mage.Sets/src/mage/sets/zendikar/ArmamentMaster.java @@ -104,29 +104,14 @@ class ArmamentMasterEffect extends ContinuousEffectImpl { return new ArmamentMasterEffect(this); } - @Override - public void init(Ability source, Game game) { - super.init(source, game); - if (this.affectedObjectsSet) { - List permanents = game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game); - for (Permanent perm : permanents) { - if (!perm.getId().equals(source.getSourceId())) { - objects.add(perm.getId()); - } - } - } - } - @Override public boolean apply(Game game, Ability source) { int count = countEquipment(game, source); List permanents = game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game); for (Permanent perm : permanents) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { - if (!perm.getId().equals(source.getSourceId())) { - perm.addPower(2 * count); - perm.addToughness(2 * count); - } + if (!perm.getId().equals(source.getSourceId())) { + perm.addPower(2 * count); + perm.addToughness(2 * count); } } return true; diff --git a/Mage.Sets/src/mage/sets/zendikar/MarshCasualties.java b/Mage.Sets/src/mage/sets/zendikar/MarshCasualties.java index ca0c2d595ef..5cb5eb1bf39 100644 --- a/Mage.Sets/src/mage/sets/zendikar/MarshCasualties.java +++ b/Mage.Sets/src/mage/sets/zendikar/MarshCasualties.java @@ -27,6 +27,7 @@ */ package mage.sets.zendikar; +import java.util.Iterator; import mage.abilities.Ability; import mage.abilities.condition.common.KickedCondition; import mage.abilities.decorator.ConditionalContinousEffect; @@ -40,6 +41,7 @@ import mage.target.TargetPlayer; import java.util.List; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.keyword.KickerAbility; /** @@ -80,8 +82,8 @@ public class MarshCasualties extends CardImpl { class MarshCasualtiesEffect extends ContinuousEffectImpl { - private int power; - private int toughness; + private final int power; + private final int toughness; public MarshCasualtiesEffect(int power, int toughness) { super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); @@ -104,20 +106,21 @@ class MarshCasualtiesEffect extends ContinuousEffectImpl { public void init(Ability source, Game game) { super.init(source, game); if (this.affectedObjectsSet) { - List creatures = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getFirstTarget(), game); - for (Permanent creature : creatures) { - objects.add(creature.getId()); + for (Permanent creature : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getFirstTarget(), game)) { + affectedObjectList.add(new MageObjectReference(creature)); } } } @Override public boolean apply(Game game, Ability source) { - List creatures = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getFirstTarget(), game); - for (Permanent creature : creatures) { - if (!this.affectedObjectsSet || objects.contains(creature.getId())) { - creature.addPower(power); - creature.addToughness(toughness); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); + if (permanent != null) { + permanent.addPower(power); + permanent.addToughness(toughness); + } else { + it.remove(); } } return true; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/EvernightShadeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/EvernightShadeTest.java index fada03b1349..8aeaca9793e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/EvernightShadeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/EvernightShadeTest.java @@ -17,6 +17,9 @@ public class EvernightShadeTest extends CardTestPlayerBase { public void testBoostWithUndying() { addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); + // Evernight Shade Creature - Shade 1/1 {3}{B} + // {B}: Evernight Shade gets +1/+1 until end of turn. + // Undying (When this creature dies, if it had no +1/+1 counters on it, return it to the battlefield under its owner's control with a +1/+1 counter on it.) addCard(Zone.BATTLEFIELD, playerA, "Evernight Shade"); addCard(Zone.HAND, playerA, "Lightning Bolt"); diff --git a/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java b/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java index 2161857f9bc..3856aa46657 100644 --- a/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java @@ -8,8 +8,6 @@ package org.mage.test.combat; import mage.constants.PhaseStep; import mage.constants.Zone; -import mage.game.permanent.Permanent; -import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; diff --git a/Mage/src/mage/MageObjectReference.java b/Mage/src/mage/MageObjectReference.java index 8ed2fc4c7f3..7578e9da82e 100644 --- a/Mage/src/mage/MageObjectReference.java +++ b/Mage/src/mage/MageObjectReference.java @@ -128,4 +128,12 @@ public class MageObjectReference implements Comparable { return null; } + public Card getCard(Game game) { + Card card = game.getPermanent(sourceId); + if (card != null && card.getZoneChangeCounter() == zoneChangeCounter) { + return card; + } + return null; + } + } diff --git a/Mage/src/mage/abilities/effects/ContinuousEffect.java b/Mage/src/mage/abilities/effects/ContinuousEffect.java index 2088a576630..6f925dc48f6 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffect.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffect.java @@ -28,16 +28,14 @@ package mage.abilities.effects; +import java.util.List; +import mage.MageObjectReference; +import mage.abilities.Ability; import mage.constants.Duration; import mage.constants.Layer; import mage.constants.SubLayer; -import mage.abilities.Ability; import mage.game.Game; -import java.util.Date; -import java.util.List; -import java.util.UUID; - /** * * @author BetaSteward_at_googlemail.com @@ -57,7 +55,7 @@ public interface ContinuousEffect extends Effect { Layer getLayer(); SubLayer getSublayer(); void overrideRuleText(String text); - List getAffectedObjects(); + List getAffectedObjects(); @Override void newId(); diff --git a/Mage/src/mage/abilities/effects/common/continious/BecomesCreatureSourceEffect.java b/Mage/src/mage/abilities/effects/common/continious/BecomesCreatureSourceEffect.java index ad31a534f44..8d369a4ba48 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BecomesCreatureSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BecomesCreatureSourceEffect.java @@ -29,6 +29,7 @@ package mage.abilities.effects.common.continious; import mage.MageInt; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; @@ -49,7 +50,6 @@ public class BecomesCreatureSourceEffect extends ContinuousEffectImpl implements protected Token token; protected String type; - protected int zoneChangeCounter; public BecomesCreatureSourceEffect(Token token, String type, Duration duration) { super(duration, Outcome.BecomeCreature); @@ -62,7 +62,6 @@ public class BecomesCreatureSourceEffect extends ContinuousEffectImpl implements super(effect); this.token = effect.token.copy(); this.type = effect.type; - this.zoneChangeCounter = effect.zoneChangeCounter; } @Override @@ -73,17 +72,20 @@ public class BecomesCreatureSourceEffect extends ContinuousEffectImpl implements @Override public void init(Ability source, Game game) { super.init(source, game); - this.getAffectedObjects().add(source.getSourceId()); - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - this.zoneChangeCounter = permanent.getZoneChangeCounter(); + if (affectedObjectsSet) { + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); } } @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && permanent.getZoneChangeCounter() == this.zoneChangeCounter) { + Permanent permanent; + if (affectedObjectsSet) { + permanent = affectedObjectList.get(0).getPermanent(game); + } else { + permanent = game.getPermanent(source.getSourceId()); + } + if (permanent != null) { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { diff --git a/Mage/src/mage/abilities/effects/common/continious/BecomesFaceDownCreatureAllEffect.java b/Mage/src/mage/abilities/effects/common/continious/BecomesFaceDownCreatureAllEffect.java index 6e7b76453ce..8caca43ec7f 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BecomesFaceDownCreatureAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BecomesFaceDownCreatureAllEffect.java @@ -61,7 +61,6 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple protected Map turnFaceUpAbilityMap = new HashMap<>(); protected FilterPermanent filter; - protected ArrayList objectList = new ArrayList<>(); public BecomesFaceDownCreatureAllEffect(FilterPermanent filter) { super(Duration.EndOfGame, Outcome.BecomeCreature); @@ -71,7 +70,6 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple public BecomesFaceDownCreatureAllEffect(final BecomesFaceDownCreatureAllEffect effect) { super(effect); - this.objectList.addAll(effect.objectList); for (Map.Entry entry: effect.turnFaceUpAbilityMap.entrySet()) { this.turnFaceUpAbilityMap.put(entry.getKey(), entry.getValue()); } @@ -88,7 +86,7 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple super.init(source, game); for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!perm.isFaceDown()) { - objectList.add(new MageObjectReference(perm)); + affectedObjectList.add(new MageObjectReference(perm)); perm.setFaceDown(true); // check for Morph Card card = game.getCard(perm.getId()); @@ -106,7 +104,7 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { boolean targetExists = false; - for (MageObjectReference mor: objectList) { + for (MageObjectReference mor: affectedObjectList) { Permanent permanent = mor.getPermanent(game); if (permanent != null && permanent.isFaceDown()) { targetExists = true; diff --git a/Mage/src/mage/abilities/effects/common/continious/BoostAllEffect.java b/Mage/src/mage/abilities/effects/common/continious/BoostAllEffect.java index 93ac5d67c83..02b1b84d5ad 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BoostAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BoostAllEffect.java @@ -29,7 +29,7 @@ package mage.abilities.effects.common.continious; import java.util.Iterator; -import java.util.UUID; +import mage.MageObjectReference; import mage.constants.Duration; import mage.constants.Layer; import mage.constants.Outcome; @@ -113,7 +113,7 @@ public class BoostAllEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -126,9 +126,8 @@ public class BoostAllEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { if (this.affectedObjectsSet) { - for (Iterator it = objects.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost - UUID permanentId = it.next(); - Permanent permanent = game.getPermanent(permanentId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent permanent = it.next().getPermanent(game); if (permanent != null) { permanent.addPower(power.calculate(game, source, this)); permanent.addToughness(toughness.calculate(game, source, this)); diff --git a/Mage/src/mage/abilities/effects/common/continious/BoostControlledEffect.java b/Mage/src/mage/abilities/effects/common/continious/BoostControlledEffect.java index c88b2350556..b6faf748fe0 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BoostControlledEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BoostControlledEffect.java @@ -29,7 +29,7 @@ package mage.abilities.effects.common.continious; import java.util.Iterator; -import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; @@ -116,7 +116,7 @@ public class BoostControlledEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -129,9 +129,8 @@ public class BoostControlledEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { if (this.affectedObjectsSet) { - for (Iterator it = objects.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost - UUID permanentId = it.next(); - Permanent permanent = game.getPermanent(permanentId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); if (permanent != null) { permanent.addPower(power.calculate(game, source, this)); permanent.addToughness(toughness.calculate(game, source, this)); diff --git a/Mage/src/mage/abilities/effects/common/continious/BoostOpponentsEffect.java b/Mage/src/mage/abilities/effects/common/continious/BoostOpponentsEffect.java index f673d96099a..54bd585e177 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BoostOpponentsEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BoostOpponentsEffect.java @@ -1,5 +1,6 @@ package mage.abilities.effects.common.continious; +import java.util.Iterator; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.constants.Duration; @@ -12,6 +13,7 @@ import mage.game.permanent.Permanent; import java.util.Set; import java.util.UUID; +import mage.MageObjectReference; public class BoostOpponentsEffect extends ContinuousEffectImpl { protected int power; @@ -49,7 +51,7 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { Set opponents = game.getOpponents(source.getControllerId()); for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (opponents.contains(perm.getControllerId())) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -58,8 +60,20 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { Set opponents = game.getOpponents(source.getControllerId()); - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + if (this.affectedObjectsSet) { + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent perm = it.next().getPermanent(game); + if (perm != null) { + if (opponents.contains(perm.getControllerId())) { + perm.addPower(power); + perm.addToughness(toughness); + } + } else { + it.remove(); + } + } + } else { + for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (opponents.contains(perm.getControllerId())) { perm.addPower(power); perm.addToughness(toughness); diff --git a/Mage/src/mage/abilities/effects/common/continious/BoostSourceEffect.java b/Mage/src/mage/abilities/effects/common/continious/BoostSourceEffect.java index f5be27e10bb..26769726c16 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BoostSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BoostSourceEffect.java @@ -28,6 +28,7 @@ package mage.abilities.effects.common.continious; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; @@ -85,7 +86,9 @@ public class BoostSourceEffect extends ContinuousEffectImpl implements SourceEff @Override public void init(Ability source, Game game) { super.init(source, game); - getAffectedObjects().add(source.getSourceId()); + if (affectedObjectsSet) { + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); + } if (lockedIn) { power = new StaticValue(power.calculate(game, source, this)); toughness = new StaticValue(toughness.calculate(game, source, this)); @@ -94,7 +97,12 @@ public class BoostSourceEffect extends ContinuousEffectImpl implements SourceEff @Override public boolean apply(Game game, Ability source) { - Permanent target = game.getPermanent(source.getSourceId()); + Permanent target; + if (affectedObjectsSet) { + target = affectedObjectList.get(0).getPermanent(game); + } else { + target = game.getPermanent(source.getSourceId()); + } if (target != null) { target.addPower(power.calculate(game, source, this)); target.addToughness(toughness.calculate(game, source, this)); diff --git a/Mage/src/mage/abilities/effects/common/continious/GainAbilityAllEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainAbilityAllEffect.java index d58b57609c0..3fd623761af 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainAbilityAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainAbilityAllEffect.java @@ -28,6 +28,8 @@ package mage.abilities.effects.common.continious; +import java.util.Iterator; +import mage.MageObjectReference; import mage.constants.Duration; import mage.constants.Layer; import mage.constants.Outcome; @@ -84,7 +86,7 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -97,8 +99,17 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + if (this.affectedObjectsSet) { + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent permanent = it.next().getPermanent(game); + if (permanent != null) { + permanent.addAbility(ability, source.getSourceId(), game); + } else { + it.remove(); // no longer on the battlefield, remove reference to object + } + } + } else { + for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { perm.addAbility(ability, source.getSourceId(), game); } diff --git a/Mage/src/mage/abilities/effects/common/continious/GainAbilityControlledEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainAbilityControlledEffect.java index 1ec7255d7af..983cb1d2f90 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainAbilityControlledEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainAbilityControlledEffect.java @@ -28,6 +28,8 @@ package mage.abilities.effects.common.continious; +import java.util.Iterator; +import mage.MageObjectReference; import mage.constants.Duration; import mage.constants.Layer; import mage.constants.Outcome; @@ -89,7 +91,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -102,8 +104,19 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { - if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + if (this.affectedObjectsSet) { + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent perm = it.next().getPermanent(game); + if (perm != null) { + for (Ability abilityToAdd : ability) { + perm.addAbility(abilityToAdd, source.getSourceId(), game); + } + } else { + it.remove(); // no longer on the battlefield, remove reference to object + } + } + } else { + for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { for (Ability abilityToAdd : ability) { perm.addAbility(abilityToAdd, source.getSourceId(), game); diff --git a/Mage/src/mage/abilities/effects/common/continious/GainAbilitySourceEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainAbilitySourceEffect.java index 109f4362a27..38faf49a7d3 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainAbilitySourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainAbilitySourceEffect.java @@ -27,6 +27,7 @@ */ package mage.abilities.effects.common.continious; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; @@ -90,13 +91,20 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl implements Sou @Override public void init(Ability source, Game game) { super.init(source, game); - getAffectedObjects().add(source.getSourceId()); + if (affectedObjectsSet) { + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); + } } @Override public boolean apply(Game game, Ability source) { if (onCard) { - Card card = game.getCard(source.getSourceId()); + Card card; + if (affectedObjectsSet) { + card = affectedObjectList.get(0).getCard(game); + } else { + card = game.getCard(source.getSourceId()); + } if (card != null) { // add ability to card only once card.addAbility(ability); @@ -104,15 +112,20 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl implements Sou return true; } } else { - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent; + if (affectedObjectsSet) { + permanent = affectedObjectList.get(0).getPermanent(game); + } else { + permanent = game.getPermanent(source.getSourceId()); + } if (permanent != null) { permanent.addAbility(ability, source.getSourceId(), game); return true; } - if (duration.equals(Duration.Custom)) { - this.discard(); - } } - return false; + if (duration.equals(Duration.Custom)) { + this.discard(); + } + return true; } } diff --git a/Mage/src/mage/abilities/effects/common/continious/GainAbilityTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainAbilityTargetEffect.java index c36f35ee6ed..281b334400b 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainAbilityTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainAbilityTargetEffect.java @@ -29,22 +29,21 @@ package mage.abilities.effects.common.continious; import java.util.Locale; -import mage.constants.Duration; -import mage.constants.Layer; -import mage.constants.Outcome; -import mage.constants.SubLayer; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.effects.ContinuousEffectImpl; +import mage.cards.Card; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.PhaseStep; +import mage.constants.SubLayer; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.Target; -import java.util.UUID; -import mage.cards.Card; -import mage.constants.PhaseStep; -import mage.game.turn.Step; - /** * * @author BetaSteward_at_googlemail.com @@ -139,8 +138,16 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl { } else { for (UUID permanentId : targetPointer.getTargets(game, source)) { Permanent permanent = game.getPermanent(permanentId); + boolean shortLivingLKI = false; + if (permanent == null) { + permanent = (Permanent) game.getShortLivingLKI(permanentId, Zone.BATTLEFIELD); + shortLivingLKI = true; + } if (permanent != null) { permanent.addAbility(ability, source.getSourceId(), game); + if (shortLivingLKI) { // needed for undying because TriggeredAbilities checks if the permanent has still the ability + game.rememberLKI(permanentId, Zone.BATTLEFIELD, permanent); + } affectedTargets++; } } diff --git a/Mage/src/mage/abilities/effects/common/continious/SetPowerToughnessAllEffect.java b/Mage/src/mage/abilities/effects/common/continious/SetPowerToughnessAllEffect.java index 1958b744e57..a95c57a28a1 100644 --- a/Mage/src/mage/abilities/effects/common/continious/SetPowerToughnessAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/SetPowerToughnessAllEffect.java @@ -28,8 +28,10 @@ package mage.abilities.effects.common.continious; +import java.util.Iterator; import java.util.Locale; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.dynamicvalue.DynamicValue; @@ -89,7 +91,7 @@ public class SetPowerToughnessAllEffect extends ContinuousEffectImpl { super.init(source, game); if (affectedObjectsSet) { for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - objects.add(perm.getId()); + affectedObjectList.add(new MageObjectReference(perm)); } } if (lockedInPT) { @@ -103,11 +105,13 @@ public class SetPowerToughnessAllEffect extends ContinuousEffectImpl { int newPower = power.calculate(game, source, this); int newToughness = toughness.calculate(game, source, this); if (affectedObjectsSet) { - for (UUID permanentId :objects) { - Permanent permanent = game.getPermanent(permanentId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + Permanent permanent = it.next().getPermanent(game); if (permanent != null) { permanent.getPower().setValue(newPower); permanent.getToughness().setValue(newToughness); + } else { + it.remove(); // no longer on the battlefield, remove reference to object } } } else { diff --git a/Mage/src/mage/abilities/effects/common/continious/SwitchPowerToughnessAllEffect.java b/Mage/src/mage/abilities/effects/common/continious/SwitchPowerToughnessAllEffect.java index 514d2ec80de..0eb849b22a7 100644 --- a/Mage/src/mage/abilities/effects/common/continious/SwitchPowerToughnessAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/SwitchPowerToughnessAllEffect.java @@ -29,8 +29,10 @@ package mage.abilities.effects.common.continious; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.effects.ContinuousEffectImpl; @@ -71,8 +73,8 @@ public class SwitchPowerToughnessAllEffect extends ContinuousEffectImpl { if (this.affectedObjectsSet) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - for (Permanent creature :game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - this.objects.add(creature.getId()); + for (Permanent perm :game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + affectedObjectList.add(new MageObjectReference(perm)); } } } @@ -83,18 +85,16 @@ public class SwitchPowerToughnessAllEffect extends ContinuousEffectImpl { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { if (this.affectedObjectsSet) { - Set toDelete = new HashSet<>(); - for (UUID creatureId: objects) { - Permanent creature = game.getPermanent(creatureId); + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + Permanent creature = it.next().getPermanent(game); if (creature != null) { int power = creature.getPower().getValue(); creature.getPower().setValue(creature.getToughness().getValue()); creature.getToughness().setValue(power); } else { - toDelete.add(creatureId); + it.remove(); } - } - this.objects.removeAll(toDelete); + } } else { for (Permanent creature :game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { int power = creature.getPower().getValue();