Thread: Dialogue System :)

Results 1 to 7 of 7
  1. #1 Dialogue System :) 
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    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

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    jabbah
    Guest
    wow, nice.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    May 2008
    Posts
    140
    Thanks given
    39
    Thanks received
    13
    Rep Power
    176
    w00t w00t xstream

    i am so in with xstream

    thank you by the way for making the thread, helped alot.
    Reply With Quote  
     

  4. #4  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Quote Originally Posted by 'Alpha View Post
    w00t w00t xstream

    i am so in with xstream

    thank you by the way for making the thread, helped alot.
    NP mate and yh, XSTREAM FTW!
    Reply With Quote  
     

  5. #5  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    bumpp
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Jul 2008
    Posts
    1,043
    Thanks given
    209
    Thanks received
    46
    Rep Power
    0
    Thanks Ultimate gonna surely use! you saved me a lot of time
    Reply With Quote  
     

  7. #7  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    No problem dude
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •