From 9fe2c07a3f320a01348972acdd9ab42de863aec5 Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Tue, 29 Dec 2020 12:04:28 +0100 Subject: [PATCH] Quest has special dialogues now --- .../0/dialogues/map1/npc0/dialogue.txt | 3 + .../0/dialogues/map1/npc1/dialogue.txt | 3 + core/src/com/trs/main/InformationQuest.java | 28 ++++++++ core/src/com/trs/main/MovingNpc.java | 65 ++++++++++++++----- core/src/com/trs/main/Player.java | 21 +++--- 5 files changed, 94 insertions(+), 26 deletions(-) create mode 100644 core/assets/quests/informationQuests/0/dialogues/map1/npc0/dialogue.txt create mode 100644 core/assets/quests/informationQuests/0/dialogues/map1/npc1/dialogue.txt diff --git a/core/assets/quests/informationQuests/0/dialogues/map1/npc0/dialogue.txt b/core/assets/quests/informationQuests/0/dialogues/map1/npc0/dialogue.txt new file mode 100644 index 0000000..a86f7f4 --- /dev/null +++ b/core/assets/quests/informationQuests/0/dialogues/map1/npc0/dialogue.txt @@ -0,0 +1,3 @@ +nicenice +lol#-1 +lolol#-1 \ No newline at end of file diff --git a/core/assets/quests/informationQuests/0/dialogues/map1/npc1/dialogue.txt b/core/assets/quests/informationQuests/0/dialogues/map1/npc1/dialogue.txt new file mode 100644 index 0000000..e13d7a1 --- /dev/null +++ b/core/assets/quests/informationQuests/0/dialogues/map1/npc1/dialogue.txt @@ -0,0 +1,3 @@ +nivwenuveruivre +lol#-1 +lolol#-1 \ No newline at end of file diff --git a/core/src/com/trs/main/InformationQuest.java b/core/src/com/trs/main/InformationQuest.java index d58e047..b1e4ac4 100644 --- a/core/src/com/trs/main/InformationQuest.java +++ b/core/src/com/trs/main/InformationQuest.java @@ -53,6 +53,34 @@ public class InformationQuest extends Quest{ */ } + + boolean hasSpecialDialogue(int NpcId, int mapId){ + if(!rightOrderRequired){ + for(int i = 0; i < talked.length; i++){ + if(informationNpcId[i] == NpcId && informationNpcMapId[i] == mapId && !talked[i]){ + return true; + } + } + } + else{ + int nextToTalk = 0; + for(int i = 0; i < talked.length; i++){ + if(!talked[i]){ + nextToTalk = i; + break; + } + } + if(informationNpcId[nextToTalk] == NpcId && informationNpcMapId[nextToTalk] == mapId){ + return true; + } + } + return false; + } + + String getDialoguePath(int NpcId, int mapId){ + return "quests/informationQuests/"+questId+"/dialogues/map"+mapId+"/npc"+NpcId+"/dialogue.txt"; + } + @Override void updateQuest(Array actors) { if(!finished){ diff --git a/core/src/com/trs/main/MovingNpc.java b/core/src/com/trs/main/MovingNpc.java index 55d96ae..171a2cb 100644 --- a/core/src/com/trs/main/MovingNpc.java +++ b/core/src/com/trs/main/MovingNpc.java @@ -34,7 +34,10 @@ public class MovingNpc extends Actor{ boolean currentlyTalking; + boolean specialDialogue; + DialogueParser parser; + DialogueParser tempSpecialDialogueParser; Vector2 POI; @@ -47,7 +50,7 @@ public class MovingNpc extends Actor{ Texture t = new Texture(Gdx.files.internal("textureData/sprites/"+texture)); currentlyTalking = false; - + specialDialogue = false; animatedSprite = new AnimatedSprite(t, 64, 64, true); animatedSprite.setRow(0); collisionRect = new Rectangle(xPos + 16, yPos, 32, 48); @@ -62,6 +65,8 @@ public class MovingNpc extends Actor{ Dialogue nextDialogue = parser.firstDialogue(); this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + collisionRect = new Rectangle(xPos + 16, yPos, 32, 16); + setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight()); } @@ -70,10 +75,19 @@ public class MovingNpc extends Actor{ getStage().addActor(new Textbox(t, xPos, yPos)); } + public void startSpecialDialogue(String path, float xPos, float yPos){ + tempSpecialDialogueParser = new DialogueParser(path); + currentlyTalking = true; + specialDialogue = true; + Dialogue nextDialogue = tempSpecialDialogueParser.firstDialogue(); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + getStage().addActor(new Textbox(t, xPos, yPos)); + } + @Override protected void positionChanged() { animatedSprite.setSpritePosition((int)getX(), (int)getY()); - collisionRect = new Rectangle(getX() + 16, getY(), 32, 48); + collisionRect = new Rectangle(getX() + 16, getY(), 32, 16); super.positionChanged(); } @@ -83,18 +97,36 @@ public class MovingNpc extends Actor{ animatedSprite.setRow(facing); if(currentlyTalking) { - for(Actor a : getStage().getActors().toArray(Actor.class)) { + for(Actor a : getStage().getActors()) { if(a instanceof Textbox) { if(((Textbox) a).getState() == 2) { - int answer = ((Textbox) a).getSelectedAsw(); - Dialogue newDialogue = parser.nextDialogue(answer + 1); + if(!specialDialogue){ + int answer = ((Textbox) a).getSelectedAsw(); + Dialogue newDialogue = parser.nextDialogue(answer + 1); - if(newDialogue == null) { - currentlyTalking = false; - parser = new DialogueParser(dialoguePath); + if(newDialogue == null) { + currentlyTalking = false; + parser = new DialogueParser(dialoguePath); + } + else { + ((Textbox)a).update(newDialogue); + } } - else { - ((Textbox)a).update(newDialogue); + else{ + int answer = ((Textbox) a).getSelectedAsw(); + Dialogue newDialogue = tempSpecialDialogueParser.nextDialogue(answer + 1); + + if(newDialogue == null) { + currentlyTalking = false; + specialDialogue = false; + parser = new DialogueParser(dialoguePath); + Dialogue nextDialogue = parser.firstDialogue(); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + tempSpecialDialogueParser = null; + } + else { + ((Textbox)a).update(newDialogue); + } } } } @@ -177,20 +209,17 @@ public class MovingNpc extends Actor{ super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates. } - public boolean collidingWithMapCollisionObject(){ - boolean value = false; + public boolean collidingWithMapCollisionObject(){ for(Actor a : getStage().getActors()){ - if(a.getName().equals("mapobject")){ - //Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight()); + if(a instanceof MapCollisionObject){ Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight()); if(Intersector.overlaps(collisionRect, o)){ - value = true; - break; + return true; } } } - return value; - } + return false; + } public Textbox getTextbox(){ return t; diff --git a/core/src/com/trs/main/Player.java b/core/src/com/trs/main/Player.java index 63fedce..ab6dd72 100644 --- a/core/src/com/trs/main/Player.java +++ b/core/src/com/trs/main/Player.java @@ -45,13 +45,13 @@ public class Player extends Actor{ int[] n = {1, 1}; int[] m = {1, 0}; - quest = new InformationQuest(0, "Sprich mit Folgenden NPCs: (Id, mapId, schonGereded?) !Reihenfolge wichtig!", m, n, true); + quest = new InformationQuest(0, "Sprich mit Folgenden NPCs: (Id, mapId, schonGereded?) !Reihenfolge wichtig!", m, n, false); } @Override protected void positionChanged() { playerSprite.setSpritePosition((int)getX(), (int)getY()); - collisionRect = new Rectangle(getX() + 16, getY(), 32, 48); + collisionRect = new Rectangle(getX() + 16, getY(), 32, 16); super.positionChanged(); //To change body of generated methods, choose Tools | Templates. } @@ -90,9 +90,16 @@ public class Player extends Actor{ if(Gdx.input.isKeyJustPressed(Input.Keys.E)) { Actor a = collidingActor(); if(a != null) { - if(a instanceof MovingNpc){ + if(a instanceof MovingNpc){ Main.gamestate = 1; - ((MovingNpc)a).startDialogue(getX()+32, getY()+32); + if(quest instanceof InformationQuest){ + if(((InformationQuest)quest).hasSpecialDialogue(((MovingNpc) a).id, ((MovingNpc) a).mapId)){ + ((MovingNpc) a).startSpecialDialogue(((InformationQuest)quest).getDialoguePath(((MovingNpc) a).id, ((MovingNpc) a).mapId), getX()+32, getY()+32); + } + else{ + ((MovingNpc)a).startDialogue(getX()+32, getY()+32); + } + } movementX = 0; movementY = 0; } @@ -173,18 +180,16 @@ public class Player extends Actor{ } public boolean collidingWithMapCollisionObject(){ - boolean value = false; for(Actor a : getStage().getActors()){ if(a instanceof MapCollisionObject){ //Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight()); Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight()); if(Intersector.overlaps(collisionRect, o)){ - value = true; - break; + return true; } } } - return value; + return false; } public void velocity(float velocity){