mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 19:11:59 -08:00
Refactor DoIfCostPaid; Inform player on cost not paid. (#10942)
This commit is contained in:
parent
51d9d8d990
commit
aa71f0ba8a
1 changed files with 27 additions and 32 deletions
|
|
@ -100,39 +100,36 @@ public class DoIfCostPaid extends OneShotEffect {
|
|||
message = CardUtil.replaceSourceName(message, mageObject.getName());
|
||||
boolean result = true;
|
||||
Outcome payOutcome = executingEffects.getOutcome(source, this.outcome);
|
||||
if (cost.canPay(source, source, player.getId(), game)
|
||||
&& (!optional || player.chooseUse(payOutcome, message, source, game))) {
|
||||
boolean canPay = cost.canPay(source, source, player.getId(), game);
|
||||
boolean didPay = false;
|
||||
if (canPay && (!optional || player.chooseUse(payOutcome, message, source, game))) {
|
||||
cost.clearPaid();
|
||||
int bookmark = game.bookmarkState();
|
||||
if (cost.pay(source, game, source, player.getId(), false)) {
|
||||
didPay = true;
|
||||
game.informPlayers(player.getLogName() + " paid for " + mageObject.getLogName() + " - " + message);
|
||||
if (!executingEffects.isEmpty()) {
|
||||
for (Effect effect : executingEffects) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
if (effect instanceof OneShotEffect) {
|
||||
result &= effect.apply(game, source);
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) effect, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
result &= applyEffects(game, source, executingEffects);
|
||||
player.resetStoredBookmark(game); // otherwise you can e.g. undo card drawn with Mentor of the Meek
|
||||
} else {
|
||||
// Paying cost was cancels so try to undo payment so far
|
||||
player.restoreState(bookmark, DoIfCostPaid.class.getName(), game);
|
||||
if (!otherwiseEffects.isEmpty()) {
|
||||
for (Effect effect : otherwiseEffects) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
if (effect instanceof OneShotEffect) {
|
||||
result &= effect.apply(game, source);
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) effect, source);
|
||||
}
|
||||
}
|
||||
if (!didPay) {
|
||||
// Not leaking the information in the game log that the player could
|
||||
// not actually pay the cost, in case it is an hidden one.
|
||||
game.informPlayers(player.getLogName() + " did not pay for " + mageObject.getLogName() + " - " + message);
|
||||
result &= applyEffects(game, source, otherwiseEffects);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} else if (!otherwiseEffects.isEmpty()) {
|
||||
for (Effect effect : otherwiseEffects) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean applyEffects(Game game, Ability source, Effects effects) {
|
||||
boolean result = true;
|
||||
if (!effects.isEmpty()) {
|
||||
for (Effect effect : effects) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
if (effect instanceof OneShotEffect) {
|
||||
result &= effect.apply(game, source);
|
||||
|
|
@ -143,8 +140,6 @@ public class DoIfCostPaid extends OneShotEffect {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Player getPayingPlayer(Game game, Ability source) {
|
||||
return game.getPlayer(source.getControllerId());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue