mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
+ phase names for scripts
+ trying to collect used threads
This commit is contained in:
@@ -418,6 +418,7 @@ public enum FControl {
|
||||
|
||||
if( ev instanceof DuelFinishedEvent ) {
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
|
||||
getInputQueue().onGameOver();
|
||||
new ViewWinLose(game.getMatch());
|
||||
SOverlayUtils.showOverlay();
|
||||
} });
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
|
||||
sb.append("Priority: ").append(player).append("\n").append("\n");
|
||||
sb.append("Turn : ").append(ph.getPlayerTurn()).append("\n");
|
||||
sb.append("Phase: ").append(ph.getPhase().Name).append("\n");
|
||||
sb.append("Phase: ").append(ph.getPhase().NameForUi).append("\n");
|
||||
sb.append("Stack: ");
|
||||
if (!player.getGame().getStack().isEmpty()) {
|
||||
sb.append(player.getGame().getStack().size()).append(" to Resolve.");
|
||||
|
||||
@@ -35,7 +35,7 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
||||
/** Constant <code>serialVersionUID=3955194449319994301L</code>. */
|
||||
private static final long serialVersionUID = 3955194449319994301L;
|
||||
|
||||
private final BlockingDeque<Input> inputStack = new LinkedBlockingDeque<Input>();
|
||||
private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>();
|
||||
private final InputLockUI inputLock;
|
||||
|
||||
|
||||
@@ -43,21 +43,6 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
||||
inputLock = new InputLockUI(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Setter for the field <code>input</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param in
|
||||
* a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
private final void setInput(final Input in) {
|
||||
//System.out.println(in.getClass().getName());
|
||||
this.inputStack.push(in);
|
||||
// System.out.print("Current: " + input + "; Stack = " + inputStack);
|
||||
this.updateObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>input</code>.
|
||||
@@ -106,8 +91,19 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public void setInputAndWait(InputSynchronized input) {
|
||||
this.setInput(input);
|
||||
this.inputStack.push(input);
|
||||
this.updateObservers();
|
||||
|
||||
input.awaitLatchRelease();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*/
|
||||
public void onGameOver() {
|
||||
for(InputSynchronized inp : inputStack ) {
|
||||
inp.relaseLatchWhenGameIsOver();
|
||||
}
|
||||
}
|
||||
|
||||
} // InputControl
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package forge.control.input;
|
||||
|
||||
public interface InputSynchronized extends Input {
|
||||
|
||||
public void awaitLatchRelease();
|
||||
void awaitLatchRelease();
|
||||
void relaseLatchWhenGameIsOver();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
|
||||
}
|
||||
}
|
||||
|
||||
public final void relaseLatchWhenGameIsOver() {
|
||||
cdlDone.countDown();
|
||||
}
|
||||
|
||||
protected final void stop() {
|
||||
// ensure input won't accept any user actions.
|
||||
|
||||
@@ -86,26 +86,6 @@ public class AiController {
|
||||
game = game0;
|
||||
}
|
||||
|
||||
private final SpellAbility getSpellAbilityToPlay() {
|
||||
// if top of stack is owned by me
|
||||
if (!game.getStack().isEmpty() && game.getStack().peekAbility().getActivatingPlayer().equals(player)) {
|
||||
// probably should let my stuff resolve
|
||||
return null;
|
||||
}
|
||||
final List<Card> cards = getAvailableCards();
|
||||
|
||||
if ( !game.getStack().isEmpty() ) {
|
||||
SpellAbility counter = chooseCounterSpell(getPlayableCounters(cards));
|
||||
if( counter != null ) return counter;
|
||||
|
||||
SpellAbility counterETB = chooseSpellAbilyToPlay(this.getPossibleETBCounters(), false);
|
||||
if( counterETB != null )
|
||||
return counterETB;
|
||||
}
|
||||
|
||||
return chooseSpellAbilyToPlay(getSpellAbilities(cards), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getAvailableSpellAbilities.
|
||||
@@ -909,6 +889,26 @@ public class AiController {
|
||||
} while ( sa != null );
|
||||
}
|
||||
|
||||
private final SpellAbility getSpellAbilityToPlay() {
|
||||
// if top of stack is owned by me
|
||||
if (!game.getStack().isEmpty() && game.getStack().peekAbility().getActivatingPlayer().equals(player)) {
|
||||
// probably should let my stuff resolve
|
||||
return null;
|
||||
}
|
||||
final List<Card> cards = getAvailableCards();
|
||||
|
||||
if ( !game.getStack().isEmpty() ) {
|
||||
SpellAbility counter = chooseCounterSpell(getPlayableCounters(cards));
|
||||
if( counter != null ) return counter;
|
||||
|
||||
SpellAbility counterETB = chooseSpellAbilyToPlay(this.getPossibleETBCounters(), false);
|
||||
if( counterETB != null )
|
||||
return counterETB;
|
||||
}
|
||||
|
||||
return chooseSpellAbilyToPlay(getSpellAbilities(cards), true);
|
||||
}
|
||||
|
||||
public List<Card> chooseCardsToDelve(int colorlessCost, List<Card> grave) {
|
||||
List<Card> toExile = new ArrayList<Card>();
|
||||
int numToExile = Math.min(grave.size(), colorlessCost);
|
||||
|
||||
@@ -301,7 +301,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
game.getGameLog().add(GameEventType.TURN, "Turn " + this.turn + " (" + this.getPlayerTurn() + ")");
|
||||
}
|
||||
|
||||
game.getGameLog().add(GameEventType.PHASE, phaseType + Lang.getPossesive(this.getPlayerTurn().getName()) + " " + this.getPhase().Name);
|
||||
game.getGameLog().add(GameEventType.PHASE, phaseType + Lang.getPossesive(this.getPlayerTurn().getName()) + " " + this.getPhase().NameForUi);
|
||||
PhaseUtil.visuallyActivatePhase(this.getPlayerTurn(), this.getPhase());
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
if (this.isPlayerPriorityAllowed()) {
|
||||
// Run triggers if phase isn't being skipped
|
||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
||||
runParams.put("Phase", this.getPhase().Name);
|
||||
runParams.put("Phase", this.getPhase().NameForScripts);
|
||||
runParams.put("Player", this.getPlayerTurn());
|
||||
game.getTriggerHandler().runTrigger(TriggerType.Phase, runParams, false);
|
||||
}
|
||||
@@ -786,6 +786,8 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
System.out.print(" >>\n");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(FThreads.prependThreadId("Thread exited game loop due to ... " + ( game.isGameOver() ? "game over" : "interrupt" )));
|
||||
}
|
||||
|
||||
|
||||
@@ -875,7 +877,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public String debugPrintState(boolean hasPriority) {
|
||||
return String.format("%s's %s [%sP] %s", getPlayerTurn(), getPhase().Name, hasPriority ? "+" : "-", getPriorityPlayer());
|
||||
return String.format("%s's %s [%sP] %s", getPlayerTurn(), getPhase().NameForUi, hasPriority ? "+" : "-", getPriorityPlayer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ public enum PhaseType {
|
||||
UPKEEP("Upkeep"),
|
||||
DRAW("Draw"),
|
||||
MAIN1("Main1"),
|
||||
COMBAT_BEGIN("BeginCombat"),
|
||||
COMBAT_BEGIN("Begin Combat", "BeginCombat"),
|
||||
COMBAT_DECLARE_ATTACKERS("Declare Attackers"),
|
||||
COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY("Declare Attackers - Play Instants and Abilities"),
|
||||
COMBAT_DECLARE_BLOCKERS("Declare Blockers"),
|
||||
COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY("Declare Blockers - Play Instants and Abilities"),
|
||||
COMBAT_FIRST_STRIKE_DAMAGE("First Strike Damage"),
|
||||
COMBAT_DAMAGE("Combat Damage"),
|
||||
COMBAT_END("End Combat"),
|
||||
COMBAT_END("End Combat", "EndCombat"),
|
||||
MAIN2("Main2"),
|
||||
END_OF_TURN("End of Turn"),
|
||||
CLEANUP("Cleanup");
|
||||
@@ -35,10 +35,17 @@ public enum PhaseType {
|
||||
)
|
||||
);
|
||||
|
||||
public final String Name;
|
||||
public final String NameForUi;
|
||||
public final String NameForScripts;
|
||||
|
||||
private PhaseType(String name) {
|
||||
Name = name;
|
||||
this(name, name);
|
||||
}
|
||||
private PhaseType(String name, String name_for_scripts) {
|
||||
NameForUi = name;
|
||||
NameForScripts = name_for_scripts;
|
||||
}
|
||||
|
||||
|
||||
public final boolean isAfter(final PhaseType phase) {
|
||||
return ALL_PHASES.indexOf(this) > ALL_PHASES.indexOf(phase);
|
||||
@@ -61,7 +68,7 @@ public enum PhaseType {
|
||||
}
|
||||
final String valToCompate = value.trim();
|
||||
for (final PhaseType v : PhaseType.values()) {
|
||||
if (v.Name.compareToIgnoreCase(valToCompate) == 0) {
|
||||
if (v.NameForScripts.compareToIgnoreCase(valToCompate) == 0) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,8 @@ public class PlayerControllerAi extends PlayerController {
|
||||
|
||||
@Override
|
||||
public void takePriority() {
|
||||
if ( !game.isGameOver() )
|
||||
brains.onPriorityRecieved();
|
||||
// use separate thread for AI?
|
||||
brains.onPriorityRecieved();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user