use of mage.abilities.Ability in project mage by magefree.
the class HeavenlyBlademasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (sourcePermanent == null || player == null) {
return false;
}
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
target.getTargets().stream().map(attachmentId -> game.getPermanent(attachmentId)).filter(attachment -> attachment != null).forEachOrdered((attachment) -> {
if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
if (attachment.getAttachedTo() != sourcePermanent.getId()) {
if (attachment.getAttachedTo() != null) {
Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
if (fromPermanent != null) {
fromPermanent.removeAttachment(attachment.getId(), source, game);
}
}
}
sourcePermanent.addAttachment(attachment.getId(), source, game);
game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
}
});
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class MetamorphicAlterationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId());
Permanent copied = (Permanent) game.getState().getValue(source.getSourceId().toString() + ChooseACreature.INFO_KEY);
if (enchantment == null || copied == null) {
return false;
}
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent == null) {
return false;
}
permanent.setName(copied.getName());
permanent.getManaCost().clear();
permanent.getManaCost().addAll(copied.getManaCost());
permanent.setExpansionSetCode(copied.getExpansionSetCode());
permanent.getSuperType().clear();
for (SuperType t : copied.getSuperType()) {
permanent.addSuperType(t);
}
permanent.removeAllCardTypes(game);
for (CardType cardType : copied.getCardType(game)) {
permanent.addCardType(game, cardType);
}
permanent.removeAllSubTypes(game);
permanent.copySubTypesFrom(game, copied);
permanent.getColor(game).setColor(copied.getColor(game));
permanent.removeAllAbilities(source.getSourceId(), game);
for (Ability ability : copied.getAbilities()) {
permanent.addAbility(ability, source.getSourceId(), game);
}
permanent.getPower().setValue(copied.getPower().getBaseValueModified());
permanent.getToughness().setValue(copied.getToughness().getBaseValueModified());
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class PatchworkCrawlerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
if (permanent == null || exileZone == null || exileZone.isEmpty()) {
return false;
}
for (Card card : exileZone.getCards(StaticFilters.FILTER_CARD_CREATURE, game)) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof ActivatedAbility) {
permanent.addAbility(ability, source.getSourceId(), game);
}
}
}
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class PastInFlamesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.getGraveyard().stream().filter((cardId) -> (affectedObjectList.contains(new MageObjectReference(cardId, game)))).forEachOrdered((cardId) -> {
Card card = game.getCard(cardId);
if (card != null) {
FlashbackAbility ability = new FlashbackAbility(card, card.getManaCost());
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
});
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class PrimalEmpathyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
if (flag) {
return player.drawCards(1, source, game) > 0;
}
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
Aggregations