use of mage.abilities.Ability in project mage by magefree.
the class HandOfVecnaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || player.getHand().size() < 1) {
return false;
}
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null);
List<Permanent> chooseable = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
if (equipped != null) {
chooseable.add(equipped);
}
Permanent toBoost;
switch(chooseable.size()) {
case 0:
return false;
case 1:
toBoost = chooseable.get(0);
break;
default:
FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to");
filter.add(Predicates.or(chooseable.stream().map(permanent -> new MageObjectReferencePredicate(permanent, game)).collect(Collectors.toList())));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
toBoost = game.getPermanent(target.getFirstTarget());
}
int xValue = player.getHand().size();
game.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setTargetPointer(new FixedTarget(toBoost, game)), source);
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class HankyuCost method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
Permanent creature = game.getPermanent(permanent.getAttachedTo());
if (creature == null) {
return false;
}
creature.addAbility(new SimpleActivatedAbility(new AddCountersTargetEffect(CounterType.AIM.createInstance()).setTargetPointer(new FixedTarget(permanent, game)).setText("put an aim counter on " + permanent.getName()), new TapSourceCost()), source.getSourceId(), game);
Ability ability = new SimpleActivatedAbility(new DamageTargetEffect(HankyuValue.instance).setText("this creature deals damage to any target equal " + "to the number of aim counters removed this way"), new TapSourceCost());
ability.addCost(new HankyuCost().setMageObjectReference(source, game));
ability.addTarget(new TargetAnyTarget());
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class HushwingGryffEffect method getInfoMessage.
@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject enteringObject = game.getObject(event.getSourceId());
MageObject sourceObject = game.getObject(source.getSourceId());
Ability ability = (Ability) getValue("targetAbility");
if (enteringObject != null && sourceObject != null && ability != null) {
MageObject abilitObject = game.getObject(ability.getSourceId());
if (abilitObject != null) {
return sourceObject.getLogName() + " prevented ability of " + abilitObject.getLogName() + " to trigger for " + enteringObject.getLogName() + " entering the battlefield.";
}
}
return null;
}
use of mage.abilities.Ability in project mage by magefree.
the class KethisTheHiddenHandGraveyardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
controller.getGraveyard().getCards(game).stream().filter(card -> affectedObjectList.stream().anyMatch(mor -> mor.refersTo(card, game))).forEach(card -> {
Ability ability = new SimpleStaticAbility(Zone.GRAVEYARD, new KethisTheHiddenHandGraveyardEffect());
ability.setSourceId(card.getId());
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
});
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class MindreaverExileEffect method canTarget.
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Spell spell = game.getSpell(id);
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
return super.canTarget(id, source, game) && spell != null && exileZone != null && !exileZone.isEmpty() && exileZone.getCards(game).stream().filter(Objects::nonNull).anyMatch(card -> CardUtil.haveSameNames(spell, card));
}
Aggregations