use of mage.abilities.effects.Effect in project mage by magefree.
the class DestroyPlaneswalkerWhenDamagedTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
boolean applies = filter != null ? permanent.isPlaneswalker(game) && filter.match(permanent, game) : event.getSourceId().equals(getSourceId());
if (applies) {
Effect effect = new DestroyTargetEffect();
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
this.getEffects().clear();
this.addEffect(effect);
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class LicidSpecialActionEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
if (licid != null) {
switch(layer) {
case TypeChangingEffects_4:
licid.removeAllCardTypes(game);
licid.addCardType(game, CardType.ENCHANTMENT);
licid.removeAllSubTypes(game);
licid.addSubType(game, SubType.AURA);
break;
case AbilityAddingRemovingEffects_6:
List<Ability> toRemove = new ArrayList<>();
for (Ability ability : licid.getAbilities(game)) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof LicidEffect) {
toRemove.add(ability);
break;
}
}
}
licid.removeAbilities(toRemove, source.getSourceId(), game);
Ability ability = new EnchantAbility("creature");
ability.setRuleAtTheTop(true);
licid.addAbility(ability, source.getSourceId(), game);
licid.getSpellAbility().getTargets().clear();
Target target = new TargetCreaturePermanent();
target.addTarget(this.getTargetPointer().getFirst(game, source), source, game);
licid.getSpellAbility().getTargets().add(target);
}
return true;
}
discard();
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class LeavesBattlefieldAllTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (setTargetPointer != SetTargetPointer.NONE) {
for (Effect effect : this.getEffects()) {
switch(setTargetPointer) {
case PERMANENT:
effect.setTargetPointer(new FixedTarget(permanent, game));
break;
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
}
}
}
return true;
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class CreateTokenCopyTargetEffect method removeTokensCreatedAtEndOf.
private void removeTokensCreatedAtEndOf(Game game, Ability source, PhaseStep phaseStepToExileCards, boolean exile) {
Effect effect;
if (exile) {
effect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile the token copies");
} else {
effect = new SacrificeTargetEffect("sacrifice the token copies");
}
effect.setTargetPointer(new FixedTargets(addedTokenPermanents, game));
DelayedTriggeredAbility exileAbility;
switch(phaseStepToExileCards) {
case END_TURN:
exileAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
break;
case END_COMBAT:
exileAbility = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
break;
default:
return;
}
game.addDelayedTriggeredAbility(exileAbility, source);
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class CopyPermanentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = game.getObject(source.getSourceId());
}
if (controller == null || sourcePermanent == null) {
return false;
}
Permanent copyFromPermanent = null;
if (useTargetOfAbility) {
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
} else {
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
copyFromPermanent = game.getPermanent(target.getFirstTarget());
}
}
if (copyFromPermanent == null) {
return true;
}
bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
if (bluePrintPermanent == null) {
return false;
}
// if object is a copy of an aura, it needs to attach again for new target
if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
return true;
}
// copied from mage.cards.c.CopyEnchantment.java
// permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
// TODO: fix Animate Dead -- it's can't be copied (can't retarget)
Outcome auraOutcome = Outcome.BoostCreature;
Target auraTarget = null;
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof SpellAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
for (Effect effect : ability.getEffects()) {
if (!(effect instanceof AttachEffect)) {
continue;
}
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
}
}
}
// enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
if (auraTarget == null) {
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof EnchantAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
if (ability.getTargets().size() > 0) {
// Animate Dead don't have targets
auraTarget = ability.getTargets().get(0);
}
}
}
/* if this is a copy of a copy, the copy's target has been
* copied and needs to be cleared
*/
if (auraTarget == null) {
return true;
}
// clear selected target
if (auraTarget.getFirstTarget() != null) {
auraTarget.remove(auraTarget.getFirstTarget());
}
// select new target
auraTarget.setNotTarget(true);
if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
return true;
}
UUID targetId = auraTarget.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) {
targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
} else if (targetPlayer != null) {
targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
} else {
return false;
}
return true;
}
Aggregations