use of mage.game.permanent.Permanent in project mage by magefree.
the class CreamOfTheCropEffect 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) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, permanent.getPower().getValue()));
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
target.setNotTarget(true);
controller.chooseTarget(Outcome.Benefit, cards, target, source, game);
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true);
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
}
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DefiantVanguardEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent blocker = game.getPermanent(event.getSourceId());
Permanent blocked = game.getPermanent(event.getTargetId());
if (blocker != null && blocked != null) {
// in case the attacker changes zone
game.getState().setValue(blocked.toString(), blocked.getZoneChangeCounter(game));
// in case the blocker changes zone
game.getState().setValue(blocker.toString(), blocker.getZoneChangeCounter(game));
getAllEffects().setTargetPointer(new FixedTarget(blocked.getId()));
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DefilerOfSoulsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("monocolored creature");
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
filter.add(MonocoloredPredicate.instance);
int amount;
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
amount = Math.min(1, realCount);
Target target = new TargetControlledPermanent(amount, amount, filter, false);
target.setNotTarget(true);
// had, if thats the case this ability should fizzle.
if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
boolean abilityApplied = false;
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
for (int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
if (permanent != null) {
abilityApplied |= permanent.sacrifice(source, game);
}
}
return abilityApplied;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DeflectingPalmEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
// only one use
this.discard();
if (preventionData.getPreventedDamage() > 0) {
MageObject damageDealingObject = game.getObject(target.getFirstTarget());
UUID objectControllerId = null;
if (damageDealingObject instanceof Permanent) {
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Ability) {
objectControllerId = ((Ability) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Spell) {
objectControllerId = ((Spell) damageDealingObject).getControllerId();
}
if (objectControllerId != null) {
Player objectController = game.getPlayer(objectControllerId);
if (objectController != null) {
objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DelifsConePreventEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (player != null || permanent != null) {
player.gainLife(permanent.getPower().getValue(), game, source);
return true;
}
return false;
}
Aggregations