use of mage.abilities.effects.OneShotEffect in project mage by magefree.
the class DoIfClashWonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = getPayingPlayer(game, source);
MageObject mageObject = game.getObject(source.getSourceId());
if (player != null && mageObject != null) {
String message = null;
if (chooseUseText != null) {
message = chooseUseText;
message = CardUtil.replaceSourceName(message, mageObject.getLogName());
}
if (chooseUseText == null || player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
if (ClashEffect.getInstance().apply(game, source)) {
if (setTargetPointerToClashedOpponent) {
Object opponent = getValue("clashOpponent");
if (opponent instanceof Player) {
executingEffect.setTargetPointer(new FixedTarget(((Player) opponent).getId()));
}
} else {
executingEffect.setTargetPointer(this.targetPointer);
}
if (executingEffect instanceof OneShotEffect) {
return executingEffect.apply(game, source);
} else {
game.addEffect((ContinuousEffect) executingEffect, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.OneShotEffect in project mage by magefree.
the class DoUnlessAnyPlayerPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
Cost costToPay;
String costValueMessage;
if (controller != null && sourceObject != null) {
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message;
if (chooseUseText == null) {
String effectText = executingEffects.getText(source.getModes().getMode());
message = "Pay " + costValueMessage + " 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 player is willing to pay
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.canRespond() && costToPay.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
costToPay.clearPaid();
if (costToPay.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.OneShotEffect in project mage by magefree.
the class AbilityImpl method resolveMode.
private boolean resolveMode(Game game) {
boolean result = true;
for (Effect effect : getEffects()) {
if (game.inCheckPlayableState() && !(effect instanceof ManaEffect)) {
// Ignored non mana effects - see GameEvent.TAPPED_FOR_MANA
continue;
}
if (effect instanceof OneShotEffect) {
boolean effectResult = effect.apply(game, this);
result &= effectResult;
if (logger.isDebugEnabled()) {
if (this.getAbilityType() != AbilityType.MANA) {
if (!effectResult) {
if (this.getSourceId() != null) {
MageObject mageObject = game.getObject(this.getSourceId());
if (mageObject != null) {
logger.debug("AbilityImpl.resolve: object: " + mageObject.getName());
}
}
logger.debug("AbilityImpl.resolve: effect returned false -" + effect.getText(this.getModes().getMode()));
}
}
}
} else {
game.addEffect((ContinuousEffect) effect, this);
}
/**
* All restrained trigger events are fired now. To restrain the
* events is mainly neccessary because of the movement of multiple
* object at once. If the event is fired directly as one object
* moved, other objects are not already in the correct zone to check
* for their effects. (e.g. Valakut, the Molten Pinnacle)
*/
game.getState().handleSimultaneousEvent(game);
game.resetShortLivingLKI();
/**
* game.applyEffects() has to be done at least for every effect that
* moves cards/permanent between zones, or changes control of
* objects so Static effects work as intended if dependant from the
* moved objects zone it is in Otherwise for example were static
* abilities with replacement effects deactivated too late Example:
* {@link org.mage.test.cards.replacement.DryadMilitantTest#testDiesByDestroy testDiesByDestroy}
*/
game.applyEffects();
game.getState().getTriggers().checkStateTriggers(game);
}
return result;
}
Aggregations