use of mage.abilities.TriggeredAbility in project mage by magefree.
the class HushbringerEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Ability ability = (Ability) getValue("targetAbility");
if (ability == null || ability.getAbilityType() != AbilityType.TRIGGERED) {
return false;
}
Permanent permanent;
switch(event.getType()) {
case ENTERS_THE_BATTLEFIELD:
permanent = ((EntersTheBattlefieldEvent) event).getTarget();
break;
case ZONE_CHANGE:
ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
if (!zEvent.isDiesEvent()) {
return false;
}
permanent = zEvent.getTarget();
break;
default:
return false;
}
if (permanent == null || !permanent.isCreature(game)) {
return false;
}
return (((TriggeredAbility) ability).checkTrigger(event, game));
}
use of mage.abilities.TriggeredAbility in project mage by magefree.
the class OrTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
boolean toRet = false;
for (int i = 0; i < triggeredAbilities.length; i++) {
TriggeredAbility ability = triggeredAbilities[i];
if (ability.checkEventType(event, game) && ability.checkTrigger(event, game)) {
triggeringAbilities.add(i);
toRet = true;
}
}
return toRet;
}
use of mage.abilities.TriggeredAbility in project mage by magefree.
the class ForceProjectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && permanent != null) {
// Create a token that is a copy of target creature
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
effect.setTargetPointer(new FixedTarget(permanent, game));
// except that it is an Illusion in addition to its other types
effect.setAdditionalSubType(SubType.SPIRIT);
effect.apply(game, source);
// and gains "When this creature becomes the target of a spell, sacrifice it."
Effect sacrificeEffect = new SacrificeSourceEffect();
sacrificeEffect.setTargetPointer(new FixedTarget(effect.getAddedPermanents().get(0), game));
TriggeredAbility ability = new BecomesTargetTriggeredAbility(sacrificeEffect, new FilterSpell());
game.addTriggeredAbility(ability, null);
return true;
}
return false;
}
use of mage.abilities.TriggeredAbility in project mage by magefree.
the class TheBookOfVileDarknessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<MageObjectReference> morSet = (Set<MageObjectReference>) getValue("BookEyeHand");
if (morSet == null) {
return false;
}
Token token = new VecnaToken();
for (MageObjectReference mor : morSet) {
// the card object in the mor doesn't work, so the permanent object is used
Permanent card = mor.getPermanentOrLKIBattlefield(game);
if (card == null) {
continue;
}
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof TriggeredAbility) {
Ability copyAbility = ability.copy();
copyAbility.newId();
copyAbility.setControllerId(source.getControllerId());
token.addAbility(copyAbility);
}
}
}
return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Aggregations