BecomeCreatureAllEffect used to always calculate the permanent set to apply to every time it is applied

Now we calculate it either at init-time (for abilities with affected object sets) OR at apply-time (Static abilities etc.)
This commit is contained in:
Ben Dawes 2018-01-27 11:51:16 +00:00
parent 1b9ee1c6c4
commit 2f4b6ca713

View file

@ -27,6 +27,7 @@
*/
package mage.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
@ -40,6 +41,9 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
import java.util.HashSet;
import java.util.Set;
/**
* @author LevelX2
*
@ -64,6 +68,16 @@ public class BecomesCreatureAllEffect extends ContinuousEffectImpl {
this.filter = effect.filter.copy();
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (this.affectedObjectsSet) {
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
affectedObjectList.add(new MageObjectReference(perm, game));
}
}
}
@Override
public BecomesCreatureAllEffect copy() {
return new BecomesCreatureAllEffect(this);
@ -71,7 +85,15 @@ public class BecomesCreatureAllEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
Set<Permanent> affectedPermanents = new HashSet<>();
if (this.affectedObjectsSet) {
for(MageObjectReference ref : affectedObjectList) {
affectedPermanents.add(ref.getPermanent(game));
}
} else {
affectedPermanents = new HashSet<>(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game));
}
for(Permanent permanent : affectedPermanents) {
if (permanent != null) {
switch (layer) {
case TypeChangingEffects_4: