Thread: Dialogue System

Results 1 to 9 of 9
  1. #1 Dialogue System 
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,819
    Thanks received
    1,767
    Rep Power
    2438
    Here's sample implementation:

    Code:
    package org.redrune.game.content.dialogue.impl.misc;
    
    import org.redrune.game.content.dialogue.Dialogue;
    import org.redrune.game.node.entity.player.Player;
    import org.redrune.game.node.entity.player.link.prayer.PrayerBook;
    import org.redrune.utility.rs.constant.MagicConstants.MagicBook;
    
    /**
     * @author Tyluur <[email protected]>
     *  @Since 8/9/2017
     */
    public class BookSwapDialogue extends Dialogue {
    	
    	@Override
    	public void constructMessages(Player player) {
    		options(DEFAULT_OPTION, new String[] { "Change spell book", "Change prayer book" }, () -> {
    			options("Select a book", new String[] { "Regular spells", "Ancient spells", "Lunar spells" }, () -> {
    				player.getCombatDefinitions().setSpellbook(MagicBook.REGULAR);
    				notifyChange(true);
    			}, () -> {
    				player.getCombatDefinitions().setSpellbook(MagicBook.ANCIENTS);
    				notifyChange(true);
    			}, () -> {
    				player.getCombatDefinitions().setSpellbook(MagicBook.LUNARS);
    				notifyChange(true);
    			});
    		}, () -> {
    			options("Select a book", new String[] { "Regular prayers", "Curse prayers" }, () -> {
    				player.getManager().getPrayers().setBook(PrayerBook.REGULAR);
    				notifyChange(false);
    			}, () -> {
    				player.getManager().getPrayers().setBook(PrayerBook.CURSES);
    				notifyChange(false);
    			});
    		});
    	}
    	
    	/**
    	 * Notifies the player of their change in books
    	 *
    	 *  @Param spellbook
    	 * 		If the change was a spellbook
    	 */
    	private void notifyChange(boolean spellbook) {
    		chatbox("Your " + (spellbook ? "spellbook" : "prayer book") + " has successfully been changed.");
    	}
    }
    Package: https://github.com/dusk-rs/redrune-6...ntent/dialogue

    Dialogue.java
    https://github.com/dusk-rs/redrune-6.../Dialogue.java

    DialogueManager.java
    https://github.com/dusk-rs/redrune-6...ueManager.java
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  2. #2  
    Extreme Donator

    JayArrowz's Avatar
    Join Date
    Sep 2008
    Posts
    104
    Thanks given
    99
    Thanks received
    107
    Rep Power
    810
    Decent start, but its pretty hard to see what lambda function is executed when the option is clicked

    I suggest you might want to combine the String & Function into one object then parse that .e.g. A new OptionsCallback class:

    Code:
    options(DEFAULT_OPTION, new OptionCallbacks[] { OptionCallbacks.create("Change spell book", this::changeSpellBook), OptionCallbacks.create("Change prayer book", this::changePrayerBook)});
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Registered Member

    Join Date
    Feb 2010
    Posts
    3,253
    Thanks given
    1,145
    Thanks received
    909
    Rep Power
    2081
    Are we having a dialogue system competition?

    We should totally do that. Host regular competitions on who can come up with the best way to solve a problem.

    I have not worked on a proper system for it yet, but i'm thinking when I get around to it I will put npc dialogue in json files and start the file name with the npc name mapped from the npc definitions (so man.json, etc).

    Precisely speaking, a dialogue is a conversation. So speaking about some things here in terms of dialogue is a little misleading. Player dialogue would be public chat.

    I'd check if the speaker was an instance of an entity to decide what model to send and then pull it from the definition mapping above.

    Dialogue is also quite a lot more complicated than many think because of factors like priority (not just in the action queue which is simple enough but in the decision of which dialogue to show based on quest stage etc).

    I think the lambda here is overly complicated and storing in Java unnecessary really, also a little intimidating and clunky for new users.

    I am absolutely anal about constants having precise terms, the whole 'case 320: etc' does my nut in, although I do see why you might do it for things that are very obvious (for example there's probably no point naming the logout button when all it does is call a method that tells it to logout, like no shit that's what it is).
    Reply With Quote  
     

  5. Thankful users:


  6. #4  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,819
    Thanks received
    1,767
    Rep Power
    2438
    Quote Originally Posted by Fire Cape View Post
    Are we having a dialogue system competition?

    We should totally do that. Host regular competitions on who can come up with the best way to solve a problem.

    I have not worked on a proper system for it yet, but i'm thinking when I get around to it I will put npc dialogue in json files and start the file name with the npc name mapped from the npc definitions (so man.json, etc).

    Precisely speaking, a dialogue is a conversation. So speaking about some things here in terms of dialogue is a little misleading. Player dialogue would be public chat.

    I'd check if the speaker was an instance of an entity to decide what model to send and then pull it from the definition mapping above.

    Dialogue is also quite a lot more complicated than many think because of factors like priority (not just in the action queue which is simple enough but in the decision of which dialogue to show based on quest stage etc).

    I think the lambda here is overly complicated and storing in Java unnecessary really, also a little intimidating and clunky for new users.

    I am absolutely anal about constants having precise terms, the whole 'case 320: etc' does my nut in, although I do see why you might do it for things that are very obvious (for example there's probably no point naming the logout button when all it does is call a method that tells it to logout, like no shit that's what it is).
    Let's make a competition out of it I guess?
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  7. #5  
    Registered Member
    Join Date
    Jan 2017
    Posts
    195
    Thanks given
    13
    Thanks received
    27
    Rep Power
    13
    just scrape all the dialogues from the wiki into a json file then read that

    https://oldschool.runescape.wiki/w/C...y:NPC_dialogue
    Reply With Quote  
     

  8. #6  
    Registered Member
    Melvin's Avatar
    Join Date
    Aug 2011
    Posts
    1,150
    Thanks given
    546
    Thanks received
    418
    Rep Power
    1561
    Quote Originally Posted by socklol View Post
    just scrape all the dialogues from the wiki into a json file then read that

    https://oldschool.runescape.wiki/w/C...y:NPC_dialogue
    come on..

    OT: the lambda is pretty confusing and would send curious minds into a frenzy perhaps


    A creative man is motivated by the desire to achieve, not by the desire to beat others.”


    ― Ayn Rand
    Reply With Quote  
     

  9. #7  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,819
    Thanks received
    1,767
    Rep Power
    2438
    Quote Originally Posted by Melvin View Post
    come on..

    OT: the lambda is pretty confusing and would send curious minds into a frenzy perhaps
    It reads nicer in kotlin imo.
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  10. #8  
    Endeavor

    Mikey`'s Avatar
    Join Date
    Dec 2007
    Posts
    4,434
    Thanks given
    715
    Thanks received
    1,435
    Rep Power
    1202
    If you're going to use java why not something like this

    Code:
    DialogueBuilder dialogue = new DialogueBuilder();
    dialogue.option(
    	new DialogueOption("Change magic book", () -> StaticCall::changeMagicBook),
    	new DialogueOption("Change spell book", () -> StaticCall::changeSpellBook)
    );
    player.start(dialogue);
    here you wouldn't have to create a new class implementation for every dialogue tree you build, plus it's more readable.

    here's another example from some stuff I wrote a couple of years ago
    Code:
    public class SelectGameModeDialogue extends DialogueBuilder {
    
        private static final int TUTORIAL_NPC = 30_306;
    
        private final Consumer<Player> selectionConsumer;
    
        /**
         * Create a new SelectGameModeDialogue.
         *   @Param player
         *          the player
         *   @Param selectionConsumer
         *          a consumer to be called when a game mode is selected.
         */
        public SelectGameModeDialogue(Player player, Consumer<Player> selectionConsumer) {
            super(player);
            this.selectionConsumer = selectionConsumer;
            option("Select Game Mode",
                    new DialogueOption("Standard", player1 -> select(player1, GameMode.NORMAL)),
                    new DialogueOption("Ironman", player1 -> select(player1, GameMode.IRONMAN)),
                    new DialogueOption("Hardcore Ironman", player1 -> select(player1, GameMode.HARDCORE_IRONMAN)),
                    new DialogueOption("Explain modes", player1 -> explain(player1)));
        }
    
        private void select(Player player, GameMode mode) {
            player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
                    .npc("You have selected to play the " + mode.toString() + " mode.", "Would you like to continue with this selection?")
                    .option(mode.toString() + "?",
                        new DialogueOption("Yes", player1 -> confirm(player, mode)),
                        new DialogueOption("No", player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
                    )
            );
        }
    
        private void confirm(Player player, GameMode mode) {
            player.closeDialogue();
            player.setGameMode(mode);
            InformationTab.updateGameMode(player);
            player.flag(UpdateFlags.UpdateFlag.APPEARANCE);
            if (selectionConsumer != null) {
                selectionConsumer.accept(player);
            }
        }
    
        private void explain(Player player) {
            player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
                .npc("Standard mode is the default mode.", "In standard mode all content is available to play freely.")
                .npc("Ironman mode is a restriction where you cannot", "receive items from other players and", "must be self sufficient.")
                .npc("Hardcore Ironman mode is the same as regular", "Ironman mode except when you die you will", "become a regular Ironman.")
                .continueAction(player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
            );
        }
    }
    Reply With Quote  
     

  11. Thankful users:


  12. #9  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,819
    Thanks received
    1,767
    Rep Power
    2438
    Quote Originally Posted by Mikey` View Post
    If you're going to use java why not something like this

    Code:
    DialogueBuilder dialogue = new DialogueBuilder();
    dialogue.option(
    	new DialogueOption("Change magic book", () -> StaticCall::changeMagicBook),
    	new DialogueOption("Change spell book", () -> StaticCall::changeSpellBook)
    );
    player.start(dialogue);
    here you wouldn't have to create a new class implementation for every dialogue tree you build, plus it's more readable.

    here's another example from some stuff I wrote a couple of years ago
    Code:
    public class SelectGameModeDialogue extends DialogueBuilder {
    
        private static final int TUTORIAL_NPC = 30_306;
    
        private final Consumer<Player> selectionConsumer;
    
        /**
         * Create a new SelectGameModeDialogue.
         *   @Param player
         *          the player
         *   @Param selectionConsumer
         *          a consumer to be called when a game mode is selected.
         */
        public SelectGameModeDialogue(Player player, Consumer<Player> selectionConsumer) {
            super(player);
            this.selectionConsumer = selectionConsumer;
            option("Select Game Mode",
                    new DialogueOption("Standard", player1 -> select(player1, GameMode.NORMAL)),
                    new DialogueOption("Ironman", player1 -> select(player1, GameMode.IRONMAN)),
                    new DialogueOption("Hardcore Ironman", player1 -> select(player1, GameMode.HARDCORE_IRONMAN)),
                    new DialogueOption("Explain modes", player1 -> explain(player1)));
        }
    
        private void select(Player player, GameMode mode) {
            player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
                    .npc("You have selected to play the " + mode.toString() + " mode.", "Would you like to continue with this selection?")
                    .option(mode.toString() + "?",
                        new DialogueOption("Yes", player1 -> confirm(player, mode)),
                        new DialogueOption("No", player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
                    )
            );
        }
    
        private void confirm(Player player, GameMode mode) {
            player.closeDialogue();
            player.setGameMode(mode);
            InformationTab.updateGameMode(player);
            player.flag(UpdateFlags.UpdateFlag.APPEARANCE);
            if (selectionConsumer != null) {
                selectionConsumer.accept(player);
            }
        }
    
        private void explain(Player player) {
            player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
                .npc("Standard mode is the default mode.", "In standard mode all content is available to play freely.")
                .npc("Ironman mode is a restriction where you cannot", "receive items from other players and", "must be self sufficient.")
                .npc("Hardcore Ironman mode is the same as regular", "Ironman mode except when you die you will", "become a regular Ironman.")
                .continueAction(player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
            );
        }
    }
    Yours is more readable, good stuff.
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    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

Similar Threads

  1. Dialogue System(Easy usage)
    By Nemmyz in forum Tutorials
    Replies: 46
    Last Post: 12-12-2010, 06:41 PM
  2. Dialogue System
    By Profesor Oak in forum Snippets
    Replies: 2
    Last Post: 03-11-2010, 02:49 AM
  3. My Improved Dialogue System
    By Vastiko in forum Snippets
    Replies: 6
    Last Post: 03-10-2010, 05:25 PM
  4. Dialogue System :)
    By Ultimate in forum Snippets
    Replies: 6
    Last Post: 09-12-2009, 10:28 PM
  5. Best Dialogue System{3x better than yours}
    By wizzyt21 in forum Tutorials
    Replies: 14
    Last Post: 11-28-2008, 12:41 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •