Code:
package com.rs2.model;
/**
* A dialouge
*
* @author Ultimate
*/
public class Dialogue {
private int id;
public enum Type {
NPC, PLAYER
}
private Type type;
private int npcId;
private String[] line = new String[4];
private int emotion;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @return the type
*/
public Type getType() {
return type;
}
/**
* @return the npcId
*/
public int getNpcId() {
return npcId;
}
/**
* @return the lines
*/
public String getLine(int idx) {
return line[idx];
}
/**
* @return the emotion
*/
public int getEmotion() {
return emotion;
}
}
Code:
package com.rs2.world;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import com.rs2.GameEngine;
import com.rs2.model.Dialogue;
import com.rs2.model.player.Client;
import com.rs2.util.XStreamLoader;
/**
* Dialogue manager
*
* @author Ultimate
*/
public class DialogueManager {
public List<Dialogue> dialogue = null;
public DialogueManager() throws FileNotFoundException {
dialogue = new ArrayList<Dialogue>();
loadDialouges("./data/world/dialouges.xml");
}
@SuppressWarnings("unchecked")
public void loadDialouges(String url) throws FileNotFoundException {
dialogue.addAll((List<Dialogue>) XStreamLoader
.load(new FileInputStream(url)));
System.out.println("Loaded " + dialogue.size() + " dialouge.");
}
public void sendDialouge(Client c, int idx) {
Dialogue d = getDialouge(idx);
if (d.getType() == Dialogue.Type.NPC) {
c.getActionSender().sendFrame200(4901, d.getEmotion());
c.getActionSender().sendQuest(GameEngine.getNPCManager().getNPCDefinition(d.getNpcId()).getName(), 4902);
c.getActionSender().sendQuest(d.getLine(0), 4903);
c.getActionSender().sendQuest(d.getLine(1), 4904);
c.getActionSender().sendQuest(d.getLine(2), 4905);
c.getActionSender().sendQuest(d.getLine(3), 4906);
c.getActionSender().sendFrame75(d.getNpcId(), 4901);
c.getActionSender().sendFrame164(4900);
} else if (d.getType() == Dialogue.Type.PLAYER) {
c.getActionSender().sendFrame200(987, d.getEmotion());
c.getActionSender().sendQuest(c.getUsername(), 988);
c.getActionSender().sendQuest(d.getLine(0), 989);
c.getActionSender().sendQuest(d.getLine(1), 990);
c.getActionSender().sendQuest(d.getLine(2), 991);
c.getActionSender().sendQuest(d.getLine(3), 992);
c.getActionSender().sendFrame185(987);
c.getActionSender().sendFrame164(986);
}
}
public int getIndex(int idx) {
for (Dialogue d : dialogue) {
if (d.getId() == idx)
return dialogue.indexOf(d);
}
return -1;
}
public Dialogue getDialouge(int id) {
return dialogue.get(getIndex(id));
}
}
Code:
<!--
@author Dust Rip
Emotions
588 - Joyful/happy
589 - Speakingly calmly
590 - Calm talk
591 - Default speech
592 - Evil
593 - Evil continued
594 - Delighted evil
595 - Annoyed
596 - Distressed
597 - Distressed continued
598 - Almost crying
599 - Bows head while sad
600 - Talks and looks sleepy/drunk to left
601 - Talks and looks sleepy/drunk to right
602 - Sleepy or disinterested
603 - Tipping head as if sleepy.
604 - Plain evil (Grits teeth and moves eyebrows)
605 - Laughing or yawning
606 - Laughing or yawning for longer
607 - Laughing or yawning for longer
608 - Laughing or yawning
609 - Evil laugh then plain evil
610 - Slightly sad
611 - Quite sad
612 - On one hand...
613 - Close to crying
614 - Angry
615 - Angry
616 - Angry
617 - Angry
-->
<list>
<dialogue>
<id>0</id>
<type>NPC</type>
<npcId>945</npcId>
<line>
<string></string>
<string>Welcome to UltimateWorld!</string>
<string>Please do ::help if you are in need of any assistance.</string>
<string></string>
</line>
<emotion>588</emotion>
</dialogue>
</list>
Useage
Code:
Server.getDialogueManager().sendDialogue(client, idx);
EDIT:
For the XML part this will help out