@Override public boolean apply(Game game, Ability source) { if (this.affectedObjectsSet) { for (Iterator<MageObjectReference> 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)); } else { it.remove(); // no longer on the battlefield, remove reference to object } } } else { setRuntimeData(source, game); for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { perm.addPower(power.calculate(game, source, this)); perm.addToughness(toughness.calculate(game, source, this)); } } } return true; }
@Override public void init(Ability source, Game game) { super.init(source, game); setRuntimeData(source, game); if (this.affectedObjectsSet) { for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { affectedObjectList.add(new MageObjectReference(perm, game)); } } } if (lockedInPT) { power = new StaticValue(power.calculate(game, source, this)); toughness = new StaticValue(toughness.calculate(game, source, this)); } }