mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Player belongs to game, it cannot have references to any concrete PlayerController
This commit is contained in:
@@ -2941,28 +2941,21 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
controllerCreator = ctrlr;
|
||||
controller = ctrlr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run a procedure using an AI controller
|
||||
* Run a procedure using a different controller
|
||||
* @param proc
|
||||
* @param tempController
|
||||
*/
|
||||
public void runAsAi(Runnable proc) {
|
||||
if (controller instanceof PlayerControllerAi) {
|
||||
proc.run(); //can just run with current controller if it's an AI controller
|
||||
return;
|
||||
}
|
||||
|
||||
public void runWithController(Runnable proc, PlayerController tempController) {
|
||||
|
||||
PlayerController oldController = controller;
|
||||
controller = new PlayerControllerAi(this.game, this, this.getOriginalLobbyPlayer());
|
||||
controller = tempController;
|
||||
try {
|
||||
proc.run();
|
||||
} finally {
|
||||
controller = oldController;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
//ensure controller restored before throwing exception in case user chooses to continue
|
||||
controller = oldController;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
@@ -48,6 +49,11 @@ 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) {
|
||||
@@ -289,7 +295,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
ComputerUtilMana.payManaCost(manaCost, saPaidFor, player);
|
||||
}
|
||||
};
|
||||
this.player.runAsAi(proc);
|
||||
runAsAi(proc);
|
||||
this.showMessage();
|
||||
}
|
||||
}
|
||||
@@ -311,7 +317,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
return ComputerUtilMana.canPayManaCost(manaCost, saPaidFor, player);
|
||||
}
|
||||
};
|
||||
this.player.runAsAi(proc);
|
||||
runAsAi(proc);
|
||||
canPayManaCost = proc.getResult();
|
||||
}
|
||||
if (canPayManaCost) {
|
||||
|
||||
Reference in New Issue
Block a user