use of mage.MageObjectReference in project mage by magefree.
the class CombatDamageToCreatureWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT || !((DamagedEvent) event).isCombatDamage()) {
return;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent == null || !permanent.isCreature(game)) {
return;
}
MageObjectReference damageSource = new MageObjectReference(event.getSourceId(), game);
dealtCombatDamageToCreature.add(damageSource);
}
use of mage.MageObjectReference in project mage by magefree.
the class WojekSirenBoostEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
if (target != null) {
affectedObjectList.add(new MageObjectReference(target, game));
ObjectColor color = target.getColor(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!permanent.getId().equals(target.getId()) && permanent.getColor(game).shares(color)) {
affectedObjectList.add(new MageObjectReference(permanent, game));
}
}
}
}
use of mage.MageObjectReference in project mage by magefree.
the class CopyEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
// must copy the default side of the card (example: clone with mdf card)
if (!(copyFromObject instanceof Permanent) && (copyFromObject instanceof Card)) {
Card newBluePrint = CardUtil.getDefaultCardSideForBattlefield(game, (Card) copyFromObject);
this.copyFromObject = new PermanentCard(newBluePrint, source.getControllerId(), game);
}
Permanent permanent = game.getPermanent(copyToObjectId);
if (permanent != null) {
affectedObjectList.add(new MageObjectReference(permanent, game));
} else if (source.getAbilityType() == AbilityType.STATIC) {
// for replacement effects that let a permanent enter the battlefield as a copy of another permanent we need to apply that copy
// before the permanent is added to the battlefield
permanent = game.getPermanentEntering(copyToObjectId);
if (permanent != null) {
copyToPermanent(permanent, game, source);
// set reference to the permanent later on the battlefield so we have to add already one (if no token) to the zone change counter
int ZCCDiff = 1;
if (permanent instanceof PermanentToken) {
ZCCDiff = 0;
}
affectedObjectList.add(new MageObjectReference(permanent.getId(), game.getState().getZoneChangeCounter(copyToObjectId) + ZCCDiff, game));
}
}
}
use of mage.MageObjectReference in project mage by magefree.
the class DamageMultiEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
this.damagedSet.clear();
if (source.getTargets().isEmpty()) {
return true;
}
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
if (permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
damagedSet.add(new MageObjectReference(permanent, game));
}
} else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class SetPowerToughnessAllEffect method init.
@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)) {
affectedObjectList.add(new MageObjectReference(perm, game));
}
}
if (lockedInPT) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
}
Aggregations