use of mage.abilities.effects.Effect in project mage by magefree.
the class DoUnlessAnyOpponentPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
String message;
if (chooseUseText == null) {
String effectText = executingEffects.getText(source.getModes().getMode());
message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() - 1) + ")?";
} else {
message = chooseUseText;
}
message = CardUtil.replaceSourceName(message, sourceObject.getName());
boolean result = true;
boolean doEffect = true;
// check if any opponent is willing to pay
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.canRespond() && !player.equals(controller) && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, message, source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, player.getId(), false, null)) {
if (!game.isSimulation()) {
game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
}
doEffect = false;
break;
}
}
}
// do the effects if nobody paid
if (doEffect) {
for (Effect effect : executingEffects) {
effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {
game.addEffect((ContinuousEffect) effect, source);
}
}
}
return result;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class ShowOfDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int highestPower = Integer.MIN_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (highestPower < permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = permanent;
} else if (highestPower == permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = null;
}
}
if (highestPower != Integer.MIN_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
effect.setTargetPointer(target);
effect.apply(game, source);
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(target);
game.addEffect(continuousEffect, source);
return true;
}
}
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class ShrivelingRotEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.isDiesEvent()) {
if (zEvent.getTarget().isCreature(game)) {
Effect effect = this.getEffects().get(0);
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
return true;
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class SoulshriekEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
Effect sacrifice = new SacrificeTargetEffect("Sacrifice that creature " + "at the beginning of the next end step", source.getControllerId());
sacrifice.setTargetPointer(new FixedTarget(permanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrifice), source);
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class SoulScourgeLeavesBattlefieldTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
String key = CardUtil.getCardZoneString("targetPlayer", this.getSourceId(), game, true);
Object object = game.getState().getValue(key);
if (object instanceof UUID) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget((UUID) object));
}
return true;
}
}
return false;
}
Aggregations