use of mage.MageObjectReference in project mage by magefree.
the class BecomesFaceDownCreatureAllEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (!perm.isFaceDown(game) && !perm.isTransformable()) {
affectedObjectList.add(new MageObjectReference(perm, game));
perm.setFaceDown(true, game);
// check for Morph
Card card = game.getCard(perm.getId());
if (card != null) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof MorphAbility) {
this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility) ability).getMorphCosts()));
}
}
}
}
}
}
use of mage.MageObjectReference in project mage by magefree.
the class BoostOpponentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<UUID> opponents = game.getOpponents(source.getControllerId());
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 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);
}
}
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class BoostSourceEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (affectedObjectsSet) {
try {
affectedObjectList.add(new MageObjectReference(source.getSourceId(), game));
} catch (IllegalArgumentException ex) {
Logger.getLogger(BoostSourceEffect.class).error("Could not get sourceId reference: " + source.getRule());
}
}
if (lockedIn) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
}
use of mage.MageObjectReference in project mage by magefree.
the class AegarTheFreezingFlameWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT) {
return;
}
DamagedEvent dEvent = (DamagedEvent) event;
MageObject sourceObject = game.getObject(event.getSourceId());
if (sourceObject == null) {
return;
}
if (game.getSpellOrLKIStack(event.getSourceId()) == null && !sourceObject.hasSubtype(SubType.GIANT, game) && !sourceObject.hasSubtype(SubType.WIZARD, game)) {
return;
}
playerMap.computeIfAbsent(game.getControllerId(event.getSourceId()), x -> new HashSet<>()).add(new MageObjectReference(event.getTargetId(), game));
}
use of mage.MageObjectReference in project mage by magefree.
the class BlazingEffigyWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DAMAGED_PERMANENT) {
if (!event.getSourceId().equals(event.getTargetId())) {
MageObjectReference damageSourceRef = new MageObjectReference(event.getSourceId(), game);
MageObjectReference damageTargetRef = new MageObjectReference(event.getTargetId(), game);
if (game.getPermanentOrLKIBattlefield(event.getSourceId()) != null && game.getPermanentOrLKIBattlefield(event.getSourceId()).getName().equals("Blazing Effigy")) {
damagedObjects.putIfAbsent(damageTargetRef, 0);
damagedObjects.compute(damageTargetRef, (k, damage) -> damage + event.getAmount());
}
}
}
}
Aggregations