use of mage.target.Target in project mage by magefree.
the class OfferingCostReductionEffect method applies.
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (sourceId.equals(source.getSourceId())) {
Card card = game.getCard(sourceId);
if (card == null || !card.isOwnedBy(source.getControllerId())) {
return false;
}
// because can activate is always called twice, result from first call will be used
Object object = game.getState().getValue("offering_" + card.getId());
if (object != null && object.equals(true)) {
Object alreadyConfirmed = game.getState().getValue("offering_ok_" + card.getId());
game.getState().setValue("offering_" + card.getId(), null);
game.getState().setValue("offering_ok_" + card.getId(), null);
return alreadyConfirmed != null;
} else {
// first call -> remove previous Ids
game.getState().setValue("offering_Id_" + card.getId(), null);
}
if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
if (game.inCheckPlayableState()) {
return true;
}
FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
Card spellToCast = game.getCard(source.getSourceId());
if (spellToCast == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
if (!target.isChosen()) {
return false;
}
game.getState().setValue("offering_" + card.getId(), true);
Permanent offer = game.getPermanent(target.getFirstTarget());
if (offer != null) {
UUID activationId = UUID.randomUUID();
OfferingCostReductionEffect effect = new OfferingCostReductionEffect(activationId);
effect.setTargetPointer(new FixedTarget(offer, game));
game.addEffect(effect, source);
game.getState().setValue("offering_ok_" + card.getId(), true);
game.getState().setValue("offering_Id_" + card.getId(), activationId);
game.informPlayers(player.getLogName() + " announces to offer " + offer.getLogName() + " to cast " + // No id name to prevent to offer hand card knowledge after cancel casting
GameLog.getColoredObjectName(spellToCast));
return true;
}
} else {
game.getState().setValue("offering_" + card.getId(), true);
}
}
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class AllSunsDawnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToHand = new CardsImpl();
for (Target target : source.getTargets()) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
if (card != null) {
cardsToHand.add(card);
}
}
return controller.moveCards(cardsToHand, Zone.HAND, source, game);
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class CephalidConstableTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
FilterPermanent filter = new FilterPermanent("permanent" + (event.getAmount() > 1 ? "s" : "") + " damaged player control");
filter.add(new ControllerIdPredicate(event.getPlayerId()));
Target target = new TargetPermanent(0, event.getAmount(), filter, false);
this.getTargets().clear();
this.getTargets().add(target);
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class DoomfallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (targetPlayer.choose(outcome, target, source.getSourceId(), game)) {
targetPlayer.moveCards(game.getPermanent(target.getFirstTarget()), Zone.EXILED, source, game);
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class DracoplasmEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.chooseTarget(Outcome.Detriment, target, source, game);
if (!target.getTargets().isEmpty()) {
int power = 0;
int toughness = 0;
for (UUID targetId : target.getTargets()) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature != null && targetCreature.sacrifice(source, game)) {
power = CardUtil.overflowInc(power, targetCreature.getPower().getValue());
toughness = CardUtil.overflowInc(toughness, targetCreature.getToughness().getValue());
}
}
ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, SubLayer.SetPT_7b);
game.addEffect(effect, source);
}
}
return false;
}
Aggregations