mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Prevent AI taking over if exception thrown while AI controller temporarily set
This commit is contained in:
@@ -2941,17 +2941,28 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
controllerCreator = ctrlr;
|
||||
controller = ctrlr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run a procedure using a different controller
|
||||
* Run a procedure using an AI controller
|
||||
* @param proc
|
||||
* @param tempController
|
||||
*/
|
||||
public void runWithController(Runnable proc, PlayerController tempController) {
|
||||
public void runAsAi(Runnable proc) {
|
||||
if (PlayerControllerAi.class.isInstance(controller)) {
|
||||
proc.run(); //can just run with current controller if it's an AI controller
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerController oldController = controller;
|
||||
controller = tempController;
|
||||
proc.run();
|
||||
controller = oldController;
|
||||
controller = new PlayerControllerAi(this.game, this, this.getOriginalLobbyPlayer());
|
||||
try {
|
||||
proc.run();
|
||||
controller = oldController;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
//ensure controller restored before throwing exception in case user chooses to continue
|
||||
controller = oldController;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ import forge.game.card.CardUtil;
|
||||
import forge.game.mana.ManaCostBeingPaid;
|
||||
import forge.game.player.HumanPlay;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerControllerAi;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.spellability.AbilityManaPart;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -49,11 +48,6 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
this.game = player.getGame();
|
||||
this.saPaidFor = saToPayFor;
|
||||
}
|
||||
|
||||
|
||||
public void runAsAi(Runnable proc) {
|
||||
this.player.runWithController(proc, new PlayerControllerAi(this.game, this.player, this.player.getOriginalLobbyPlayer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCardSelected(final Card card, final MouseEvent triggerEvent) {
|
||||
@@ -295,7 +289,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
ComputerUtilMana.payManaCost(manaCost, saPaidFor, player);
|
||||
}
|
||||
};
|
||||
runAsAi(proc);
|
||||
this.player.runAsAi(proc);
|
||||
this.showMessage();
|
||||
}
|
||||
}
|
||||
@@ -317,7 +311,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
return ComputerUtilMana.canPayManaCost(manaCost, saPaidFor, player);
|
||||
}
|
||||
};
|
||||
runAsAi(proc);
|
||||
this.player.runAsAi(proc);
|
||||
canPayManaCost = proc.getResult();
|
||||
}
|
||||
if (canPayManaCost) {
|
||||
|
||||
Reference in New Issue
Block a user