Skip to content
Open
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
16 changes: 16 additions & 0 deletions forge-core/src/main/java/forge/deck/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ public PaperCard removeCardName(String name) {
return null;
}

/**
* Removes a card from any section it's found in, prioritizing the sideboard over other sections.
*/
public void removeAnteCard(PaperCard card) {
if (has(DeckSection.Sideboard) && get(DeckSection.Sideboard).contains(card)) {
get(DeckSection.Sideboard).remove(card);
return;
}
for (CardPool pool : parts.values()) {
if(pool.contains(card)) {
pool.remove(card);
return;
}
}
}

// will return new if it was absent
public CardPool getOrCreate(DeckSection deckSection) {
CardPool p = get(deckSection);
Expand Down
14 changes: 12 additions & 2 deletions forge-game/src/main/java/forge/game/GameOutcome.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ public AnteResult() {
}

public void addWon(List<PaperCard> cards) {
this.wonCards.addAll(cards);
for(PaperCard c : cards) {
if(lostCards.contains(c))
lostCards.remove(c);
else
wonCards.add(c);
}
}

public void addLost(List<PaperCard> cards) {
this.lostCards.addAll(cards);
for(PaperCard c : cards) {
if(wonCards.contains(c))
wonCards.remove(c);
else
lostCards.add(c);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions forge-game/src/main/java/forge/game/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,16 @@ private void executeOwnershipChanges(Game lastGame) {
}
}

public GameOutcome.AnteResult getAnteResult(RegisteredPlayer player) {
GameOutcome.AnteResult out = new GameOutcome.AnteResult();
for (GameOutcome outcome : gameOutcomes.values()) {
GameOutcome.AnteResult gameAnte = outcome.getAnteResult(player);
out.addWon(gameAnte.wonCards);
out.addLost(gameAnte.lostCards);
}
return out;
}

/**
* Fire only the events after they became real for gamestate and won't get replaced.<br>
* The events are sent to UI, log and sound system. Network listeners are under development.
Expand Down
35 changes: 17 additions & 18 deletions forge-gui-mobile/src/forge/Forge.java
Original file line number Diff line number Diff line change
Expand Up @@ -1196,24 +1196,10 @@ public boolean keyDown(int keyCode) {
shiftKeyDown = true;
}

// Cursor keys emulate swipe gestures
// First we touch the screen and later swipe (fling) in the direction of the key pressed
if (keyCode == Keys.LEFT) {
touchDown(0, 0, 0, 0);
return fling(1000, 0);
}
if (keyCode == Keys.RIGHT) {
touchDown(0, 0, 0, 0);
return fling(-1000, 0);
}
if (keyCode == Keys.UP) {
touchDown(0, 0, 0, 0);
return fling(0, -1000);
}
if (keyCode == Keys.DOWN) {
touchDown(0, 0, 0, 0);
return fling(0, 1000);
}
if (keyCode == Keys.LEFT || keyCode == Keys.RIGHT || keyCode == Keys.UP || keyCode == Keys.DOWN)
if(emulateSwipe(keyCode))
return true;

if (keyCode == Keys.BACK) {
if ((destroyThis && !isMobileAdventureMode) || (splashScreen != null && splashScreen.isShowModeSelector()))
exitAnimation(false);
Expand All @@ -1237,6 +1223,19 @@ else if (onHomeScreen() && isLandscapeMode())
return keyInputAdapter.keyDown(keyCode);
}

private boolean emulateSwipe (int keyCode) {
// Cursor keys emulate swipe gestures
// First we touch the screen and later swipe (fling) in the direction of the key pressed
touchDown(0, 0, 0, 0);
return switch (keyCode) {
case Keys.LEFT -> fling(1000, 0);
case Keys.RIGHT -> fling(-1000, 0);
case Keys.UP -> fling(0, -1000);
case Keys.DOWN -> fling(0, 1000);
default -> false;
};
}

@Override
public boolean keyUp(int keyCode) {
keyTyped = false; //reset on keyUp
Expand Down
26 changes: 20 additions & 6 deletions forge-gui-mobile/src/forge/adventure/scene/DuelScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,28 @@ public void GameEnd() {
}

// Mostly for ante handling, but also blacker lotus
GameOutcome.AnteResult anteResult = hostedMatch.getGame().getOutcome().getAnteResult(humanPlayer);
GameOutcome.AnteResult anteResult = hostedMatch.getAnteResult(humanPlayer);
if (anteResult != null) {
for (PaperCard card : anteResult.wonCards) {
Current.player().addCard(card);
if (eventData != null) {
//In an event. Apply the ante result to the current event deck.
eventData.registeredDeck.getOrCreate(DeckSection.Sideboard).add(anteResult.wonCards);
if(eventData.draftedDeck != null)
eventData.draftedDeck.getOrCreate(DeckSection.Sideboard).add(anteResult.wonCards);
for(PaperCard card : anteResult.lostCards) {
eventData.registeredDeck.removeAnteCard(card);
if(eventData.draftedDeck != null)
eventData.draftedDeck.removeAnteCard(card);
}
//Could also add the cards to the opponent's pool, but their games aren't simulated and they never edit their decks.
}
for (PaperCard card : anteResult.lostCards) {
// We could clean this up by trying to combine all the lostCards into a mapping, but good enough for now
Current.player().removeLostCardFromPools(card);
else {
for (PaperCard card : anteResult.wonCards) {
Current.player().addCard(card);
}
for (PaperCard card : anteResult.lostCards) {
// We could clean this up by trying to combine all the lostCards into a mapping, but good enough for now
Current.player().removeLostCardFromPools(card);
}
}
}
} catch (Exception e) {
Expand Down
4 changes: 3 additions & 1 deletion forge-gui-mobile/src/forge/itemmanager/ItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1238,10 +1238,12 @@ public boolean keyDown(int keyCode) {

boolean usingListView = currentView == listView;
switch(keyCode) {
case(Input.Keys.DPAD_RIGHT):
case Input.Keys.DPAD_RIGHT:
case Input.Keys.PAGE_DOWN:
setSelectedIndexRelative(usingListView ? 10 : 1);
return true;
case Input.Keys.DPAD_LEFT:
case Input.Keys.PAGE_UP:
setSelectedIndexRelative(usingListView ? -10 : -1);
return true;
case Input.Keys.DPAD_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ public boolean isMatchOver() {
return isMatchOver;
}

public GameOutcome.AnteResult getAnteResult(RegisteredPlayer player) {
return match.getAnteResult(player);
}

private final class MatchUiEventVisitor extends IGameEventVisitor.Base<Void> implements IUiEventVisitor<Void> {
@Override
public Void visit(final UiEventBlockerAssigned event) {
Expand Down