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]>
* @[Only registered and activated users can see links. ] 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
*
* @[Only registered and activated users can see links. ] spellbook
* If the change was a spellbook
*/
private void notifyChange(boolean spellbook) {
chatbox("Your " + (spellbook ? "spellbook" : "prayer book") + " has successfully been changed.");
}
}
Package: [Only registered and activated users can see links. ]
Dialogue.java [Only registered and activated users can see links. ]
DialogueManager.java [Only registered and activated users can see links. ]
[Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
------------------- [Only registered and activated users can see links. ]
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).
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?
[Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
------------------- [Only registered and activated users can see links. ]
OT: the lambda is pretty confusing and would send curious minds into a frenzy perhaps
It reads nicer in kotlin imo.
[Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
------------------- [Only registered and activated users can see links. ]
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.
* @[Only registered and activated users can see links. ] player
* the player
* @[Only registered and activated users can see links. ] 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)))
);
}
}
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.
* @[Only registered and activated users can see links. ] player
* the player
* @[Only registered and activated users can see links. ] 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.
[Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
------------------- [Only registered and activated users can see links. ]