use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class DreamTidesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.AIDontUseIt, "Pay {2} and untap a tapped nongreen creature under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (player.choose(Outcome.Detriment, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(2, false);
Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
if (cost.pay(source, game, source, player.getId(), false)) {
tappedCreature.untap(game);
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class EmrakulsEvangelEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent selfPermanent = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(controllerId);
if (selfPermanent != null && player != null) {
// sacrifice self
paid = selfPermanent.sacrifice(source, game);
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, ability, game);
for (UUID permanentId : target.getTargets()) {
Permanent otherPermanent = game.getPermanent(permanentId);
if (otherPermanent != null) {
if (otherPermanent.sacrifice(source, game)) {
numSacrificed++;
}
}
}
}
return paid;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class OgreMarauderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
MageObject sourceObject = game.getObject(source.getSourceId());
Player defender = game.getPlayer(defendingPlayerId);
if (defender != null && sourceObject != null) {
Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
if (cost.canPay(source, source, defendingPlayerId, game) && defender.chooseUse(Outcome.LoseAbility, "Sacrifice a creature to prevent that " + sourceObject.getLogName() + " can't be blocked?", source, game)) {
if (!cost.pay(source, game, source, defendingPlayerId, false, null)) {
// cost was not payed - so source can't be blocked
ContinuousEffect effect = new CantBeBlockedSourceEffect(Duration.EndOfTurn);
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class ThelonsChantEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player != null && sourcePermanent != null) {
boolean paid = false;
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (player.chooseUse(Outcome.Detriment, "Put a -1/-1 counter on a creature you control? (otherwise " + sourcePermanent.getLogName() + " deals 3 damage to you)", source, game) && player.choose(Outcome.UnboostCreature, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.M1M1.createInstance(), player.getId(), source, game);
paid = true;
}
}
if (!paid) {
player.damage(3, source.getSourceId(), source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class UnnaturalHungerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent aura = game.getPermanent(source.getSourceId());
if (aura != null) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
// not attached permanent
filter.add(Predicates.not(new PermanentIdPredicate(aura.getAttachedTo())));
Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(filter));
Player enchantedCreatureController = game.getPlayer(attachedTo.getControllerId());
if (enchantedCreatureController != null && cost.canPay(source, source, enchantedCreatureController.getId(), game) && enchantedCreatureController.chooseUse(outcome, "Sacrifice another creature to prevent " + attachedTo.getPower().getValue() + " damage?", source, game) && cost.pay(source, game, source, enchantedCreatureController.getId(), true)) {
}
if (enchantedCreatureController != null && !cost.isPaid()) {
enchantedCreatureController.damage(attachedTo.getPower().getValue(), source.getSourceId(), source, game);
}
return true;
}
}
return false;
}
Aggregations