use of mage.game.permanent.Permanent in project mage by magefree.
the class FroghemothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsToExile = new HashSet<>();
int numCounters = 0;
int lifeGain = 0;
for (UUID cardId : getTargetPointer().getTargets(game, source)) {
Card card = game.getCard(cardId);
if (card != null && game.getState().getZone(cardId) == Zone.GRAVEYARD && cardsToExile.add(card)) {
if (card.isCreature(game)) {
numCounters++;
} else {
lifeGain++;
}
}
}
if (!cardsToExile.isEmpty()) {
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (numCounters > 0) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(numCounters), source.getControllerId(), source, game);
}
}
if (lifeGain > 0) {
controller.gainLife(lifeGain, game, source);
}
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class FrontierSiegeFightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent triggeredCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
Permanent target = game.getPermanent(source.getFirstTarget());
if (triggeredCreature != null && target != null && triggeredCreature.isCreature(game) && target.isCreature(game)) {
triggeredCreature.fight(target, source, game);
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class FrontierWarmongerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Set<UUID> opponents = game.getOpponents(this.getControllerId());
Predicate<UUID> predicate = uuid -> opponents.contains(game.getCombat().getDefendingPlayerId(uuid, game));
if (game.getCombat().getAttackers().stream().noneMatch(predicate)) {
return false;
}
List<Permanent> permanents = game.getCombat().getAttackers().stream().filter(predicate).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
this.getEffects().setTargetPointer(new FixedTargets(permanents, game));
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class FrayingSanityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (enchantment == null) {
return false;
}
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (watcher != null) {
xAmount = watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
}
enchantedPlayer.millCards(xAmount, source, game);
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class FreneticEfreetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean flip = controller.flipCoin(source, game, true);
if (permanent == null) {
return false;
}
if (flip) {
return permanent.phaseOut(game);
} else {
permanent.sacrifice(source, game);
return true;
}
}
Aggregations