Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public void actionPerformed(final ActionEvent e) {
if (matchUI == null) { return; }
StackItemView si = matchUI.getGameView().peekStack();
if (si != null && si.isAbility()) {
matchUI.getGameController().setShouldAutoYield(si.getKey(), true);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
matchUI.getGameController().setShouldAutoYield(si.getKey(), true, abilityScope);
int triggerID = si.getSourceTrigger();
if (si.isOptionalTrigger() && matchUI.isLocalPlayer(si.getActivatingPlayer())) {
matchUI.getGameController().setShouldAlwaysAcceptTrigger(triggerID);
Expand All @@ -177,7 +179,9 @@ public void actionPerformed(final ActionEvent e) {
if (matchUI == null) { return; }
StackItemView si = matchUI.getGameView().peekStack();
if (si != null && si.isAbility()) {
matchUI.getGameController().setShouldAutoYield(si.getKey(), true);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
matchUI.getGameController().setShouldAutoYield(si.getKey(), true, abilityScope);
int triggerID = si.getSourceTrigger();
if (si.isOptionalTrigger() && matchUI.isLocalPlayer(si.getActivatingPlayer())) {
matchUI.getGameController().setShouldAlwaysDeclineTrigger(triggerID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,12 @@ private void initializeSwitchStatesCombobox() {
}

private void initializeAutoYieldModeComboBox() {
final String[] elems = {ForgeConstants.AUTO_YIELD_PER_ABILITY, ForgeConstants.AUTO_YIELD_PER_CARD};
final String[] elems = {
ForgeConstants.AUTO_YIELD_PER_CARD,
ForgeConstants.AUTO_YIELD_PER_ABILITY,
ForgeConstants.AUTO_YIELD_PER_ABILITY_SESSION,
ForgeConstants.AUTO_YIELD_PER_ABILITY_INSTALL,
};
final FPref userSetting = FPref.UI_AUTO_YIELD_MODE;
final FComboBoxPanel<String> panel = this.view.getAutoYieldModeComboBoxPanel();
final FComboBox<String> comboBox = createComboBox(elems, userSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public VAutoYields(final CMatchUI matchUI) {
if (selected != null) {
autoYields.remove(selected);
btnRemove.setEnabled(autoYields.size() > 0);
matchUI.getGameController().setShouldAutoYield(selected, false);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
matchUI.getGameController().setShouldAutoYield(selected, false, abilityScope);
VAutoYields.this.revalidate();
lstAutoYields.repaint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ public AbilityMenu(){
jmiAutoYield.addActionListener(arg0 -> {
final String key = item.getKey();
final boolean autoYield = controller.getMatchUI().getGameController().shouldAutoYield(key);
controller.getMatchUI().getGameController().setShouldAutoYield(key, !autoYield);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
controller.getMatchUI().getGameController().setShouldAutoYield(key, !autoYield, abilityScope);
if (!autoYield && controller.getMatchUI().getGameView().peekStack() == item) {
//auto-pass priority if ability is on top of stack
controller.getMatchUI().getGameController().passPriority();
Expand Down
8 changes: 6 additions & 2 deletions forge-gui-mobile/src/forge/screens/match/MatchScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ public boolean keyDown(int keyCode) {
}

final String key = stackInstance.getKey();
controller.setShouldAutoYield(key, true);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
controller.setShouldAutoYield(key, true, abilityScope);
if (stackInstance.equals(gameView.peekStack())) {
//auto-pass priority if ability is on top of stack
controller.passPriority();
Expand Down Expand Up @@ -718,7 +720,9 @@ public boolean keyDown(int keyCode) {
}

final String key = stackInstance.getKey();
controller.setShouldAutoYield(key, true);
boolean abilityScope2 = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
controller.setShouldAutoYield(key, true, abilityScope2);
if (stackInstance.equals(gameView.peekStack())) {
//auto-pass priority if ability is on top of stack
controller.passPriority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ protected boolean allowDefaultItemWrap() {
String selected = lstAutoYields.getSelectedItem();
if (selected != null) {
lstAutoYields.removeItem(selected);
MatchController.instance.getGameController().setShouldAutoYield(selected, false);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
MatchController.instance.getGameController().setShouldAutoYield(selected, false, abilityScope);
setButtonEnabled(1, lstAutoYields.getCount() > 0);
lstAutoYields.cleanUpSelections();
VAutoYields.this.revalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public void setVisible(boolean b0) {
if (MatchController.instance.getGameView().peekStack() != null) {
final String key = MatchController.instance.getGameView().peekStack().getKey();
final boolean autoYield = MatchController.instance.getGameController().shouldAutoYield(key);
MatchController.instance.getGameController().setShouldAutoYield(key, !autoYield);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
MatchController.instance.getGameController().setShouldAutoYield(key, !autoYield, abilityScope);
if (!autoYield && MatchController.instance.getGameController().shouldAutoYield(key)) {
//auto-pass priority if ability is on top of stack
MatchController.instance.getGameController().passPriority();
Expand Down
4 changes: 3 additions & 1 deletion forge-gui-mobile/src/forge/screens/match/views/VStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ protected void buildMenu() {
final boolean autoYield = controller.shouldAutoYield(key);
addItem(new FCheckBoxMenuItem(Forge.getLocalizer().getMessage("cbpAutoYieldMode"), autoYield,
e -> {
controller.setShouldAutoYield(key, !autoYield);
boolean abilityScope = !forge.localinstance.properties.ForgeConstants.AUTO_YIELD_PER_CARD.equals(
forge.model.FModel.getPreferences().getPref(forge.localinstance.properties.ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
controller.setShouldAutoYield(key, !autoYield, abilityScope);
if (!autoYield && stackInstance.equals(gameView.peekStack())) {
//auto-pass priority if ability is on top of stack
controller.passPriority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ public void valueChanged(String newValue) {
lstSettings.addItem(new CustomSelectSetting(FPref.UI_AUTO_YIELD_MODE,
Forge.getLocalizer().getMessage("lblAutoYields"),
Forge.getLocalizer().getMessage("nlpAutoYieldMode"),
new String[] { ForgeConstants.AUTO_YIELD_PER_ABILITY, ForgeConstants.AUTO_YIELD_PER_CARD }), 1);
new String[] {
ForgeConstants.AUTO_YIELD_PER_CARD,
ForgeConstants.AUTO_YIELD_PER_ABILITY,
ForgeConstants.AUTO_YIELD_PER_ABILITY_SESSION,
ForgeConstants.AUTO_YIELD_PER_ABILITY_INSTALL,
}), 1);
lstSettings.addItem(new BooleanSetting(FPref.UI_ALLOW_ESC_TO_END_TURN,
Forge.getLocalizer().getMessage("cbEscapeEndsTurn"),
Forge.getLocalizer().getMessage("nlEscapeEndsTurn")), 1);
Expand Down
2 changes: 1 addition & 1 deletion forge-gui/res/languages/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ nlShowStormCount=When enabled, displays the current storm count in the prompt pa
nlRemindOnPriority=When enabled, flashes the player choice area upon receiving priority.
nlPreselectPrevAbOrder=When enabled, preselects the last defined simultaneous ability order in the ordering dialog.
nlpGraveyardOrdering=Determines when to let the player choose the order of cards simultaneously put in graveyard (never, always, or only when playing with cards for which it matters, for example, Volrath''s Shapeshifter).
nlpAutoYieldMode=Defines the granularity level of auto-yields (per unique ability or per unique card).
nlpAutoYieldMode=Auto-yield scope: per card (one game), or per ability (this match, this session, or all sessions).
RandomDeckGeneration=Random Deck Generation
nlRemoveSmall=Disables 1/1 and 0/X creatures in generated decks
nlSingletons=Disables non-land duplicates in generated decks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import forge.gui.events.*;
import forge.gui.interfaces.IGuiGame;
import forge.interfaces.IGameController;
import forge.localinstance.properties.ForgeConstants;
import forge.localinstance.properties.ForgePreferences;
import forge.localinstance.properties.ForgePreferences.FPref;
import forge.model.FModel;
Expand Down Expand Up @@ -388,10 +387,7 @@ public void endCurrentGame() {
ngg.shutdownForwarder();
}
humanController.getGui().setGameSpeed(PlaybackSpeed.NORMAL);
if (FModel.getPreferences().getPref(FPref.UI_AUTO_YIELD_MODE).equals(ForgeConstants.AUTO_YIELD_PER_CARD) || isMatchOver()) {
// when autoyielding per card, we need to clear auto yields between games since card IDs change
humanController.clearAutoYields();
}
humanController.clearAutoYields();

if (humanCount > 0) //conceded
humanController.getGui().afterGameEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public enum ProtocolMethod implements IHasForgeLog {
alphaStrike (Mode.CLIENT, Void.TYPE),
reorderHand (Mode.CLIENT, Void.TYPE, CardView.class, Integer.TYPE),
requestResync (Mode.CLIENT, Void.TYPE),
setShouldAutoYield (Mode.CLIENT, Void.TYPE, String.class, Boolean.TYPE),
setShouldAutoYield (Mode.CLIENT, Void.TYPE, String.class, Boolean.TYPE, Boolean.TYPE),
setShouldAlwaysAcceptTrigger (Mode.CLIENT, Void.TYPE, Integer.TYPE),
setShouldAlwaysDeclineTrigger (Mode.CLIENT, Void.TYPE, Integer.TYPE),
setShouldAlwaysAskTrigger (Mode.CLIENT, Void.TYPE, Integer.TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public void addLobbyListener(final ILobbyListener listener) {

void setGameControllers(final Iterable<PlayerView> myPlayers) {
for (final PlayerView p : myPlayers) {
clientGui.setOriginalGameController(p, new NetGameController(this));
NetGameController controller = new NetGameController(this);
clientGui.setOriginalGameController(p, controller);
controller.replayActiveYields();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package forge.gamemodes.net.client;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import forge.game.card.CardView;
import forge.game.player.PlayerView;
import forge.game.player.actions.PlayerAction;
Expand All @@ -15,20 +13,17 @@
import forge.localinstance.properties.ForgeConstants;
import forge.localinstance.properties.ForgePreferences;
import forge.model.FModel;
import forge.player.AutoYieldStore;
import forge.player.PersistentYieldStore;
import forge.util.ITriggerEvent;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class NetGameController implements IGameController {

private final GameProtocolSender sender;

// Local mirror of yield state for UI display
private final Set<String> autoYields = Sets.newHashSet();
private final Map<Integer, Boolean> triggersAlwaysAccept = Maps.newTreeMap();
private boolean disableAutoYields;
private final AutoYieldStore yieldStore = new AutoYieldStore();

public NetGameController(final IToServer server) {
this.sender = new GameProtocolSender(server);
Expand Down Expand Up @@ -139,76 +134,97 @@ public void requestResync() {
send(ProtocolMethod.requestResync);
}

private boolean activeModeIsInstall() {
return ForgeConstants.AUTO_YIELD_PER_ABILITY_INSTALL.equals(
FModel.getPreferences().getPref(ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
}

private boolean activeModeIsAbilityScope() {
return !ForgeConstants.AUTO_YIELD_PER_CARD.equals(
FModel.getPreferences().getPref(ForgePreferences.FPref.UI_AUTO_YIELD_MODE));
}

private AutoYieldStore.Tier activeTier() {
String mode = FModel.getPreferences().getPref(ForgePreferences.FPref.UI_AUTO_YIELD_MODE);
if (ForgeConstants.AUTO_YIELD_PER_CARD.equals(mode)) return AutoYieldStore.Tier.GAME;
if (ForgeConstants.AUTO_YIELD_PER_ABILITY_SESSION.equals(mode)) return AutoYieldStore.Tier.SESSION;
return AutoYieldStore.Tier.MATCH;
}

@Override
public boolean shouldAutoYield(final String key) {
String abilityKey = key.contains("): ") ? key.substring(key.indexOf("): ") + 3) : key;
boolean yieldPerAbility = FModel.getPreferences().getPref(ForgePreferences.FPref.UI_AUTO_YIELD_MODE)
.equals(ForgeConstants.AUTO_YIELD_PER_ABILITY);
return !disableAutoYields && autoYields.contains(yieldPerAbility ? abilityKey : key);
if (yieldStore.isDisabled()) return false;
if (activeModeIsInstall()) {
return PersistentYieldStore.get().contains(AutoYieldStore.abilitySuffix(key));
}
String storageKey = activeModeIsAbilityScope() ? AutoYieldStore.abilitySuffix(key) : key;
return yieldStore.shouldYield(activeTier(), storageKey);
}

@Override
public void setShouldAutoYield(final String key, final boolean autoYield) {
String abilityKey = key.contains("): ") ? key.substring(key.indexOf("): ") + 3) : key;
boolean yieldPerAbility = FModel.getPreferences().getPref(ForgePreferences.FPref.UI_AUTO_YIELD_MODE)
.equals(ForgeConstants.AUTO_YIELD_PER_ABILITY);
if (autoYield) {
autoYields.add(yieldPerAbility ? abilityKey : key);
public void setShouldAutoYield(final String key, final boolean autoYield, final boolean isAbilityScope) {
String storageKey = isAbilityScope ? AutoYieldStore.abilitySuffix(key) : key;
if (activeModeIsInstall()) {
PersistentYieldStore.get().setYield(storageKey, autoYield);
} else {
autoYields.remove(yieldPerAbility ? abilityKey : key);
yieldStore.setYield(activeTier(), storageKey, autoYield);
}
send(ProtocolMethod.setShouldAutoYield, key, autoYield);
send(ProtocolMethod.setShouldAutoYield, storageKey, autoYield, isAbilityScope);
}

@Override
public Iterable<String> getAutoYields() {
return autoYields;
return activeModeIsInstall()
? PersistentYieldStore.get().getYields()
: yieldStore.getYields(activeTier());
}

@Override
public void clearAutoYields() {
autoYields.clear();
triggersAlwaysAccept.clear();
// No-op locally: tier lifecycle is driven separately. Server-side mirror is cleared by HostedMatch.
}

@Override
public boolean getDisableAutoYields() {
return disableAutoYields;
}
public boolean getDisableAutoYields() { return yieldStore.isDisabled(); }

@Override
public void setDisableAutoYields(final boolean disable) {
disableAutoYields = disable;
}
public void setDisableAutoYields(final boolean disable) { yieldStore.setDisabled(disable); }

@Override
public boolean shouldAlwaysAcceptTrigger(final int trigger) {
return Boolean.TRUE.equals(triggersAlwaysAccept.get(trigger));
return yieldStore.getTriggerDecision(trigger) == AutoYieldStore.TriggerDecision.ACCEPT;
}

@Override
public boolean shouldAlwaysDeclineTrigger(final int trigger) {
return Boolean.FALSE.equals(triggersAlwaysAccept.get(trigger));
return yieldStore.getTriggerDecision(trigger) == AutoYieldStore.TriggerDecision.DECLINE;
}

@Override
public void setShouldAlwaysAcceptTrigger(final int trigger) {
triggersAlwaysAccept.put(trigger, Boolean.TRUE);
yieldStore.setTriggerDecision(trigger, AutoYieldStore.TriggerDecision.ACCEPT);
send(ProtocolMethod.setShouldAlwaysAcceptTrigger, trigger);
}

@Override
public void setShouldAlwaysDeclineTrigger(final int trigger) {
triggersAlwaysAccept.put(trigger, Boolean.FALSE);
yieldStore.setTriggerDecision(trigger, AutoYieldStore.TriggerDecision.DECLINE);
send(ProtocolMethod.setShouldAlwaysDeclineTrigger, trigger);
}

@Override
public void setShouldAlwaysAskTrigger(final int trigger) {
triggersAlwaysAccept.remove(trigger);
yieldStore.setTriggerDecision(trigger, AutoYieldStore.TriggerDecision.ASK);
send(ProtocolMethod.setShouldAlwaysAskTrigger, trigger);
}

public void replayActiveYields() {
boolean abilityScope = activeModeIsAbilityScope();
for (String key : getAutoYields()) {
send(ProtocolMethod.setShouldAutoYield, key, Boolean.TRUE, abilityScope);
}
}

private IMacroSystem macros;
@Override
public IMacroSystem macros() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,6 @@ public static LinkedHashMap<String, String> getAllLocalAddresses() {
result.putAll(sorted);
} catch (final SocketException e) {
netLog.error(e, "Failed to enumerate network interfaces");
if (result.isEmpty()) {
result.put("Default", routableAddress);
}
}

if (result.isEmpty()) {
Expand Down
Loading
Loading