diff --git a/core/src/main/java/com/gdx/game/common/Constats.java b/core/src/main/java/com/gdx/game/common/Constats.java new file mode 100644 index 00000000..f64fc27a --- /dev/null +++ b/core/src/main/java/com/gdx/game/common/Constats.java @@ -0,0 +1,9 @@ +package com.gdx.game.common; + +public class Constats { + + public static final String FOE = "FOE"; + + public static final String COURTESY_PHRASES_PATH = "conversations/conversation_courtesy.json"; + +} diff --git a/core/src/main/java/com/gdx/game/dialog/ConversationGraph.java b/core/src/main/java/com/gdx/game/dialog/ConversationGraph.java index 6f697cbe..76a33601 100644 --- a/core/src/main/java/com/gdx/game/dialog/ConversationGraph.java +++ b/core/src/main/java/com/gdx/game/dialog/ConversationGraph.java @@ -120,4 +120,19 @@ public String toString() { return outputString.toString(); } + public Hashtable getConversations() { + return conversations; + } + + public Hashtable> getAssociatedChoices() { + return associatedChoices; + } + + public void setAssociatedChoices(Hashtable> associatedChoices) { + this.associatedChoices = associatedChoices; + } + + public void setCurrentConversationID(String currentConversationID) { + this.currentConversationID = currentConversationID; + } } diff --git a/core/src/main/java/com/gdx/game/dialog/ConversationUI.java b/core/src/main/java/com/gdx/game/dialog/ConversationUI.java index 31f29b5f..f51b1e48 100644 --- a/core/src/main/java/com/gdx/game/dialog/ConversationUI.java +++ b/core/src/main/java/com/gdx/game/dialog/ConversationUI.java @@ -17,6 +17,10 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Random; + +import static com.gdx.game.common.Constats.COURTESY_PHRASES_PATH; +import static com.gdx.game.common.Constats.FOE; public class ConversationUI extends Window { private static final Logger LOGGER = LoggerFactory.getLogger(ConversationUI.class); @@ -30,6 +34,8 @@ public class ConversationUI extends Window { private Json json; + private Random random = new Random(); + public ConversationUI() { super("dialog", ResourceManager.skin); @@ -98,15 +104,26 @@ public void loadConversation(EntityConfig entityConfig) { clearDialog(); - if (fullFilenamePath.isEmpty() || !Gdx.files.internal(fullFilenamePath).exists()) { - LOGGER.debug("Conversation file does not exist!"); + if(FOE.equalsIgnoreCase(entityConfig.getEntityStatus())){ + LOGGER.debug("The NPC is an Enemy"); return; } + if (fullFilenamePath.isEmpty() || !Gdx.files.internal(fullFilenamePath).exists()) { + fullFilenamePath = COURTESY_PHRASES_PATH; + } + currentEntityID = entityConfig.getEntityID(); this.getTitleLabel().setText(entityConfig.getEntityID()); ConversationGraph graph = json.fromJson(ConversationGraph.class, Gdx.files.internal(fullFilenamePath)); + + // if the npc has nothing to say, use a random courtesy phrases + if(graph.getCurrentConversationID() == null){ + int randomNumber = random.nextInt(graph.getConversations().size()) + 1; + graph.setCurrentConversationID(String.valueOf(randomNumber)); + } + setConversationGraph(graph); } diff --git a/core/src/main/java/com/gdx/game/screen/MenuScreen.java b/core/src/main/java/com/gdx/game/screen/MenuScreen.java index 2d9a8d38..bfbc705e 100644 --- a/core/src/main/java/com/gdx/game/screen/MenuScreen.java +++ b/core/src/main/java/com/gdx/game/screen/MenuScreen.java @@ -78,7 +78,11 @@ private void handleOptionButton() { optionButton.addListener(new ClickListener() { @Override public void clicked(InputEvent even, float x, float y) { - setScreenWithTransition((BaseScreen) gdxGame.getScreen(), new OptionScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), new ArrayList<>()); + setScreenWithTransition( + (BaseScreen) gdxGame.getScreen(), + new OptionScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), + new ArrayList<>() + ); } }); } @@ -90,7 +94,11 @@ private void handleNewButton() { newButton.addListener(new ClickListener() { @Override public void clicked(InputEvent even, float x, float y) { - setScreenWithTransition((BaseScreen) gdxGame.getScreen(), new MenuNewGameScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), new ArrayList<>()); + setScreenWithTransition( + (BaseScreen) gdxGame.getScreen(), + new MenuNewGameScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), + new ArrayList<>() + ); } }); } diff --git a/core/src/main/resources/conversations/conversation_courtesy.json b/core/src/main/resources/conversations/conversation_courtesy.json new file mode 100644 index 00000000..30e69e58 --- /dev/null +++ b/core/src/main/resources/conversations/conversation_courtesy.json @@ -0,0 +1,84 @@ +{ +conversations: { + 1: { + id: 1 + dialog: Hi. + } + 2: { + id: 2 + dialog: What a beautiful day! + } + 3: { + id: 3, + dialog: Greetings stranger. + } + 4: { + id: 4, + dialog: Well met traveler! + } + 5: { + id: 5, + dialog: May the winds guide you on your journey + } + 6: { + id: 6 + dialog: See you later traveler! + } +} + associatedChoices: { + 1: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ], + 2: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ], + 3: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ], + 4: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ], + 5: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ], + 6: [ + { + class: com.gdx.game.dialog.ConversationChoice + sourceId: 1 + destinationId: 7 + choicePhrase: "Bye." + conversationCommandEvent: EXIT_CONVERSATION + } + ] + } +} \ No newline at end of file