use of mage.MageObjectReference in project mage by magefree.
the class VolatileClawsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
Permanent permanent = it.next().getPermanent(game);
if (permanent == null) {
// no longer on the battlefield, remove reference to object
it.remove();
continue;
}
permanent.setIsAllCreatureTypes(game, true);
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class VodalianWarMachineWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
if (event.getSourceId() != null) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (sourcePermanent != null) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility != null) {
Ability ability = stackAbility.getStackAbility();
if (ability != null) {
for (Cost cost : ability.getCosts()) {
if (cost instanceof TapTargetCost && cost.isPaid()) {
TapTargetCost tapCost = (TapTargetCost) cost;
if (tapCost.getTarget().isChosen()) {
MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
Set<MageObjectReference> toAdd;
if (tappedMerfolkIds.get(mor) == null) {
toAdd = new HashSet<>();
} else {
toAdd = tappedMerfolkIds.get(mor);
}
for (UUID targetId : tapCost.getTarget().getTargets()) {
toAdd.add(new MageObjectReference(targetId, game));
}
tappedMerfolkIds.put(mor, toAdd);
break;
}
}
}
}
}
}
}
}
}
use of mage.MageObjectReference in project mage by magefree.
the class WishWatcher method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (source.getControllerId().equals(affectedControllerId)) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
UUID mainCardId = CardUtil.getMainCardId(game, objectId);
if (controller != null && sourceObject != null && controller.getSideboard().contains(mainCardId)) {
WishWatcher watcher = game.getState().getWatcher(WishWatcher.class);
return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
}
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class ManifestTargetPlayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Ability newSource = source.copy();
newSource.setWorksFaceDown(true);
Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
for (Card card : cards) {
ManaCosts manaCosts = null;
if (card.isCreature(game)) {
manaCosts = card.getSpellAbility().getManaCosts();
if (manaCosts == null) {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
}
targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
for (Card card : cards) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
permanent.setManifested(true);
}
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class CaromEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
redirectToObject = new MageObjectReference(source.getTargets().get(1).getFirstTarget(), game);
}
Aggregations