use of mage.MageObjectReference in project mage by magefree.
the class ShamanEnKorRedirectFromTargetEffect method init.
@Override
public void init(Ability source, Game game) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetSource target = new TargetSource();
target.choose(Outcome.PreventDamage, player.getId(), source.getSourceId(), game);
this.sourceObject = new MageObjectReference(target.getFirstTarget(), game);
} else {
discard();
}
}
use of mage.MageObjectReference in project mage by magefree.
the class TeferisTimeTwistReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
Effect effect = new TeferisTimeTwistReturnEffect(new MageObjectReference(permanent.getId(), permanent.getZoneChangeCounter(game) + 1, game));
if (!player.moveCards(permanent, Zone.EXILED, source, game)) {
return false;
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class ToralfsHammerEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedEvent dEvent = (DamagedEvent) event;
if (dEvent.getExcess() < 1 || dEvent.isCombatDamage() || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
return false;
}
this.getEffects().clear();
this.getTargets().clear();
this.addEffect(new DamageTargetEffect(dEvent.getExcess()));
FilterCreaturePlayerOrPlaneswalker filter = new FilterCreaturePlayerOrPlaneswalker();
filter.getPermanentFilter().add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(event.getTargetId(), game))));
this.addTarget(new TargetAnyTarget(filter));
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class TotalWarDestroyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(game.getActivePlayerId());
if (activePlayer != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(activePlayer.getId())) {
// Noncreature cards are safe.
if (!permanent.isCreature(game)) {
continue;
}
// Tapped cards are safe.
if (permanent.isTapped()) {
continue;
}
// Walls are safe.
if (permanent.hasSubtype(SubType.WALL, game)) {
continue;
}
// Creatures that attacked are safe.
AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
continue;
}
// Creatures that weren't controlled since the beginning of turn are safe.
if (!permanent.wasControlledFromStartOfControllerTurn()) {
continue;
}
// Destroy the rest.
permanent.destroy(source, game, false);
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class UnscytheEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((ZoneChangeEvent) event).isDiesEvent()) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTarget().isCreature(game)) {
// target token can't create Zombie
Permanent equipment = game.getPermanent(getSourceId());
// the currently equiped creature must have done damage to the dying creature
if (equipment != null && equipment.getAttachedTo() != null) {
boolean damageDealt = false;
for (MageObjectReference mor : zEvent.getTarget().getDealtDamageByThisTurn()) {
if (mor.refersTo(equipment.getAttachedTo(), game)) {
damageDealt = true;
break;
}
}
if (damageDealt) {
Effect effect = this.getEffects().get(0);
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
return true;
}
}
}
}
return false;
}
Aggregations