Skip to content

Commit

Permalink
Dungeon improves:
Browse files Browse the repository at this point in the history
* Dungeons: added dungeon name hint to room's game log and choices (part of #12274);
* GUI, game: added card popup hints support in feedback panel (yes/no choices);
* Images: fixed miss images for dungeons in command zone, game logs and choice dialogs;
  • Loading branch information
JayDi85 committed Sep 19, 2024
1 parent cd51954 commit b40e722
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import mage.client.cards.VirtualCardInfo;
import mage.client.dialog.PreferencesDialog;
import mage.client.game.GamePanel;
import mage.game.command.Dungeon;
import mage.game.command.Plane;
import mage.util.CardUtil;
import mage.util.GameLog;
import mage.view.CardView;
import mage.view.DungeonView;
import mage.view.PlaneView;

import javax.swing.*;
Expand Down Expand Up @@ -156,7 +158,7 @@ private void addHyperlinkHandlers() {
// show real object by priority (workable card hints and actual info)
CardView cardView = needCard;

// if no game object found then show default card
// if no game object found then show default card/object
if (cardView == null) {
CardInfo card = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
if (card != null) {
Expand All @@ -172,6 +174,14 @@ private void addHyperlinkHandlers() {
}
}

// dungeon
if (cardView == null) {
Dungeon dungeon = Dungeon.createDungeon(cardName, false);
if (dungeon != null) {
cardView = new CardView(new DungeonView(dungeon));
}
}

// TODO: add other objects like dungeon, emblem, commander

if (cardView != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void choiceHintShow(int modelIndex) {
cardInfo.init(item.getHint(), this.bigCard, this.gameId);
} else if (item.getHintType() == ChoiceHintType.CARD_DUNGEON) {
// as card name
CardView cardView = new CardView(new DungeonView(Dungeon.createDungeon(item.getHint())));
CardView cardView = new CardView(new DungeonView(Dungeon.createDungeon(item.getHint(), true)));
cardInfo.init(cardView, this.bigCard, this.gameId);
} else if (item.getHintType() == ChoiceHintType.GAME_OBJECT) {
// as object
Expand Down
5 changes: 3 additions & 2 deletions Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.cards.BigCard;
import mage.client.chat.ChatPanelBasic;
import mage.client.dialog.MageDialog;
import mage.client.util.audio.AudioManager;
Expand Down Expand Up @@ -56,9 +57,9 @@ public FeedbackPanel() {
customInitComponents();
}

public void init(UUID gameId) {
public void init(UUID gameId, BigCard bigCard) {
this.gameId = gameId;
helper.init(gameId);
helper.init(gameId, bigCard);
setGUISize();
}

Expand Down
23 changes: 16 additions & 7 deletions Mage.Client/src/main/java/mage/client/game/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,20 @@ private void prepareAllCardsIndex() {
player.getGraveyard().values().forEach(c -> this.allCardsIndex.put(c.getId(), c));
Optional.ofNullable(player.getTopCard()).ifPresent(c -> this.allCardsIndex.put(c.getId(), c));
// TODO: add support of dungeon, emblem all another non-card objects
// commanders and custom emblems
player.getCommandObjectList()
.stream()
.filter(c -> c instanceof CardView)
.map(c -> (CardView) c)
.forEach(c -> this.allCardsIndex.put(c.getId(), c));
.forEach(object -> {
if (object instanceof CardView) {
// commanders and custom emblems
this.allCardsIndex.put(object.getId(), (CardView) object);
} else if (object instanceof DungeonView) {
// dungeons
this.allCardsIndex.put(object.getId(), new CardView((DungeonView) object));
} else {
// TODO: enable after all view types added here?
//throw new IllegalArgumentException("Unsupported object type: " + object.getName() + " - " + object.getClass().getSimpleName());
}
});
});
}

Expand Down Expand Up @@ -808,7 +817,7 @@ public synchronized void showGame(UUID currentTableId, UUID parentTableId, UUID
this.gamePane = gamePane;
this.playerId = playerId;
MageFrame.addGame(gameId, this);
this.feedbackPanel.init(gameId);
this.feedbackPanel.init(gameId, bigCard);
this.feedbackPanel.clear();
this.abilityPicker.init(gameId, bigCard);
this.btnConcede.setVisible(true);
Expand Down Expand Up @@ -851,7 +860,7 @@ public synchronized void watchGame(UUID currentTableId, UUID parentTableId, UUID
this.gamePane = gamePane;
this.playerId = null;
MageFrame.addGame(gameId, this);
this.feedbackPanel.init(gameId);
this.feedbackPanel.init(gameId, bigCard);
this.feedbackPanel.clear();

this.btnConcede.setVisible(false);
Expand Down Expand Up @@ -886,7 +895,7 @@ public synchronized void replayGame(UUID gameId) {
this.gameId = gameId;
this.playerId = null;
MageFrame.addGame(gameId, this);
this.feedbackPanel.init(gameId);
this.feedbackPanel.init(gameId, bigCard);
this.feedbackPanel.clear();
this.btnConcede.setVisible(false);
this.btnSkipToNextTurn.setVisible(false);
Expand Down
4 changes: 3 additions & 1 deletion Mage.Client/src/main/java/mage/client/game/HelperPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mage.client.game;

import mage.client.SessionHandler;
import mage.client.cards.BigCard;
import mage.client.components.MageTextArea;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
Expand Down Expand Up @@ -89,8 +90,9 @@ public HelperPanel() {
initComponents();
}

public void init(UUID gameId) {
public void init(UUID gameId, BigCard bigCard) {
this.gameId = gameId;
this.dialogTextArea.setGameData(gameId, bigCard);
}

public void changeGUISize() {
Expand Down
18 changes: 12 additions & 6 deletions Mage.Common/src/main/java/mage/view/CardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ public CardView(EmblemView emblem) {
this.displayName = name;
this.displayFullName = name;
this.rules = new ArrayList<>(emblem.getRules());
// emblem images are always with common (black) symbol

// image - emblem are always with common (black) symbol
this.frameStyle = FrameStyle.M15_NORMAL;
this.expansionSetCode = emblem.getExpansionSetCode();
this.cardNumber = emblem.getCardNumber();
Expand All @@ -901,12 +902,13 @@ public CardView(DungeonView dungeon) {
this.displayName = name;
this.displayFullName = name;
this.rules = new ArrayList<>(dungeon.getRules());
// emblem images are always with common (black) symbol
this.frameStyle = FrameStyle.M15_NORMAL;

// image
this.frameStyle = FrameStyle.M15_NORMAL; // TODO: needs in full art? Test dungeon choose dialog
this.expansionSetCode = dungeon.getExpansionSetCode();
this.cardNumber = "";
this.imageFileName = "";
this.imageNumber = 0;
this.imageFileName = dungeon.getImageFileName();
this.imageNumber = dungeon.getImageNumber();
this.rarity = Rarity.SPECIAL;

this.playableStats = dungeon.playableStats.copy();
Expand All @@ -923,7 +925,8 @@ public CardView(PlaneView plane) {
this.displayName = name;
this.displayFullName = name;
this.rules = new ArrayList<>(plane.getRules());
// Display the plane in landscape (similar to Fused cards)

// image - display the plane in landscape (similar to Fused cards)
this.rotate = true;
this.frameStyle = FrameStyle.M15_NORMAL;
this.expansionSetCode = plane.getExpansionSetCode();
Expand All @@ -947,13 +950,16 @@ public CardView(Designation designation, StackAbility stackAbility) {
this.displayFullName = name;
this.rules = new ArrayList<>();
this.rules.add(stackAbility.getRule(designation.getName()));

// image
this.frameStyle = FrameStyle.M15_NORMAL;
this.cardNumber = designation.getCardNumber();
this.expansionSetCode = designation.getExpansionSetCode();
this.cardNumber = "";
this.imageFileName = "";
this.imageNumber = 0;
this.rarity = Rarity.SPECIAL;

// no playable/chooseable marks for designations
}

Expand Down
11 changes: 10 additions & 1 deletion Mage/src/main/java/mage/game/GameImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ private TheRingEmblem getOrCreateTheRing(UUID playerId) {
return emblem;
}
TheRingEmblem newEmblem = new TheRingEmblem(playerId);

// TODO: add image info

state.addCommandObject(newEmblem);
return newEmblem;
}
Expand Down Expand Up @@ -1971,7 +1974,9 @@ public void addEmblem(Emblem emblem, MageObject sourceObject, UUID toPlayerId) {
ability.setSourceId(newEmblem.getId());
}

state.addCommandObject(newEmblem); // TODO: generate image for emblem here?
// image info setup in setSourceObject

state.addCommandObject(newEmblem);
}

/**
Expand Down Expand Up @@ -1999,6 +2004,9 @@ public boolean addPlane(Plane plane, UUID toPlayerId) {
for (Ability ability : newPlane.getAbilities()) {
ability.setSourceId(newPlane.getId());
}

// image info setup in setSourceObject

state.addCommandObject(newPlane);
informPlayers("You have planeswalked to " + newPlane.getLogName());

Expand All @@ -2020,6 +2028,7 @@ public void addCommander(Commander commander) {
@Override
public Dungeon addDungeon(Dungeon dungeon, UUID playerId) {
dungeon.setControllerId(playerId);
dungeon.setSourceObject();
state.addCommandObject(dungeon);
return dungeon;
}
Expand Down
36 changes: 31 additions & 5 deletions Mage/src/main/java/mage/game/command/Dungeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import mage.abilities.effects.Effect;
import mage.abilities.hint.HintUtils;
import mage.cards.FrameStyle;
import mage.cards.repository.TokenInfo;
import mage.cards.repository.TokenRepository;
import mage.choices.Choice;
import mage.choices.ChoiceHintType;
import mage.choices.ChoiceImpl;
Expand Down Expand Up @@ -87,14 +89,19 @@ public void addRoom(DungeonRoom room) {
}

public void moveToNextRoom(UUID playerId, Game game) {
Dungeon dungeon = game.getPlayerDungeon(playerId);
if (dungeon == null) {
return;
}

if (currentRoom == null) {
currentRoom = dungeonRooms.get(0);
} else {
currentRoom = currentRoom.chooseNextRoom(playerId, game);
}
Player player = game.getPlayer(getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " has entered " + currentRoom.getName());
game.informPlayers(player.getLogName() + " has entered " + currentRoom.getName() + " (dungeon: " + dungeon.getLogName() + ")");
}
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.ROOM_ENTERED, currentRoom.getId(), null, playerId
Expand Down Expand Up @@ -139,14 +146,14 @@ public static Dungeon selectDungeon(UUID playerId, Game game) {
choice.setChoices(dungeonNames);
player.choose(Outcome.Neutral, choice, game);
if (choice.getChoice() != null) {
return createDungeon(choice.getChoice());
return createDungeon(choice.getChoice(), true);
} else {
// on disconnect
return createDungeon("Tomb of Annihilation");
return createDungeon("Tomb of Annihilation", true);
}
}

public static Dungeon createDungeon(String name) {
public static Dungeon createDungeon(String name, boolean isNameMustExists) {
switch (name) {
case "Tomb of Annihilation":
return new TombOfAnnihilationDungeon();
Expand All @@ -155,7 +162,26 @@ public static Dungeon createDungeon(String name) {
case "Dungeon of the Mad Mage":
return new DungeonOfTheMadMageDungeon();
default:
throw new UnsupportedOperationException("A dungeon should have been chosen");
if (isNameMustExists) {
throw new UnsupportedOperationException("A dungeon should have been chosen");
} else {
return null;
}
}
}

public void setSourceObject() {
// choose set code due source
TokenInfo foundInfo = TokenRepository.instance.findPreferredTokenInfoForClass(this.getClass().getName(), null);
if (foundInfo != null) {
this.setExpansionSetCode(foundInfo.getSetCode());
this.setUsesVariousArt(false);
this.setCardNumber("");
this.setImageFileName(""); // use default
this.setImageNumber(foundInfo.getImageNumber());
} else {
// how-to fix: add dungeon to the tokens-database
throw new IllegalArgumentException("Wrong code usage: can't find token info for the dungeon: " + this.getClass().getName());
}
}

Expand Down
9 changes: 7 additions & 2 deletions Mage/src/main/java/mage/game/command/DungeonRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ List<DungeonRoom> getNextRooms() {
}

public DungeonRoom chooseNextRoom(UUID playerId, Game game) {
Dungeon dungeon = game.getPlayerDungeon(playerId);
if (dungeon == null) {
return null;
}

switch (nextRooms.size()) {
case 0:
return null;
Expand All @@ -90,8 +95,8 @@ public DungeonRoom chooseNextRoom(UUID playerId, Game game) {
return null;
}
return player.chooseUse(
Outcome.Neutral, "Choose which room to go to",
null, room1.name, room2.name, null, game
Outcome.Neutral, "Choose which room to go to in",
"dungeon: " + dungeon.getLogName(), room1.name, room2.name, null, game
) ? room1 : room2;
default:
throw new UnsupportedOperationException("there shouldn't be more than two rooms to go to");
Expand Down

0 comments on commit b40e722

Please sign in to comment.