Astraeus Dialogue System Port (#512)

* - Marked As Deprecated
- Reorganized DialogueOptions.java so that option buttons are grouped with each interface
- Added temporary Dialogue Executor to make new Dialogue System function
- Remove Man, Woman, and Banker Dialogue and Dialogue Options

* - Refactored Dialogue.java into DialoguePacket.java
- Moved DialoguePacket.java into impl packets package
- Added Astraeus dialogue executor

* - Removed useless file
- Reorganized the Misc.java file

* - Ported Astraeus Dialogue System
- Rewrote Man, Woman, and Banker Dialogues
- Added line splitter in AstraeusDialogueFactory.java

* - Renamed Astraeus* classes to *Plugin
- Fixed an issue where the Dialogue Option buttons were not executed through the Kotlin file

(cherry picked from commit 6deaa4162a)
This commit is contained in:
Qweqker
2021-10-31 01:53:15 +00:00
committed by Dark98
parent 3aaf413bc7
commit 8ee88848a3
20 changed files with 1773 additions and 7967 deletions
@@ -0,0 +1,14 @@
package com.rs2.game.dialogues;
import java.util.function.Consumer;
/**
* The chain-able interface that allows implementing dialogue factories the ability to chain
* together.
*
* @author Vult-R
*/
public interface ChainablePlugin extends Consumer<DialogueFactoryPlugin> {
}
@@ -4,7 +4,12 @@ package com.rs2.game.dialogues;
* ChatEmotes.java
* @author Andrew (Mr Extremez)
*/
/**
* Contains a List of Chat Head Emotes NPCs and Players can use during Dialogues
* @Deprecated Consider using {@link ExpressionPlugin} instead to add Chat Head Animations to Dialogues.
*
*/
@Deprecated
public enum ChatEmotes {
HAPPY_JOYFUL(588),
@@ -1,20 +0,0 @@
package com.rs2.game.dialogues;
import com.rs2.game.players.Player;
import com.rs2.net.packets.PacketType;
/**
* Dialogue
**/
public class Dialogue implements PacketType {
@Override
public void processPacket(Player c, int packetType, int packetSize) {
if (c.nextChat > 0) {
c.getDialogueHandler().sendDialogues(c.nextChat, c.talkingNpc);
} else {
c.getDialogueHandler().sendDialogues(0, -1);
}
}
}
@@ -0,0 +1,741 @@
package com.rs2.game.dialogues;
import com.rs2.GameConstants;
import com.rs2.game.npcs.NpcHandler;
import com.rs2.game.players.Player;
import com.rs2.util.LoggerUtils;
import com.rs2.util.Misc;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Represents a factory class that contains important functions for building dialogues.
*
* @author Vult-R <https://github.com/Vult-R>
*
* Ported by Qweqker
*/
public final class DialogueFactoryPlugin {
/**
* The single logger for this class.
*/
private static final Logger logger = LoggerUtils.getLogger(DialogueFactoryPlugin.class);
/**
* The queue of dialogues in this factory.
*/
private final Queue<ChainablePlugin> chain = new ArrayDeque<>();
/**
* The approximate maximum characters that can be fit onto a dialogue line in the interface
*
* Defined for use in the dialogue line splitting code
*/
private static final int MAXIMUM_CHARACTERS_PER_LINE = 52;
/**
* The maximum length for any dialogue
*
* Because each line can fit approximately 52 characters, we'll set the maximum
* to 260 characters to accommodate for five lines of dialogue. It can be adjusted later if needed.
*/
private static final int MAXIMUM_LENGTH = 260;
/**
* The player who owns this factory.
*/
private final Player player;
/**
* The flag that denotes dialogue is active.
*/
private boolean active;
/**
* The next action in the dialogue chain.
*/
private Optional<Runnable> nextAction = Optional.empty();
/**
* Creates a new {@link DialogueFactoryPlugin}.
*
* @param player The player who owns this factory.
*/
public DialogueFactoryPlugin(Player player) {
this.player = player;
}
/**
* Sends a player a dialogue.
*
* @param dialogue The dialogue to sent.
*/
public final DialogueFactoryPlugin sendDialogue(DialoguePlugin dialogue) {
clear(); // Clear dialogue queue before starting new one. Hacky, but it works for this base
player.setDialogue(Optional.of(dialogue));
dialogue.sendDialogues(this);
return this;
}
/**
* Sets an {@code action} so this action can be executed after dialogues are done.
*
* @param action The action to set.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin onAction(Runnable action) {
setNextAction(Optional.of(action));
return this;
}
/**
* Accepts the next dialogue in the chain.
*
* @return The instance of this factory.
*/
public DialogueFactoryPlugin onNext() {
if (getChain().peek() != null) {
ChainablePlugin chain = getChain().poll();
chain.accept(this);
} else {
player.getPacketSender().sendClearScreen();
}
return this;
}
/**
* Executes an {@code option} for a {@code player}.
*
* @param type The type of option.
*
* @param option The option to execute.
*/
public final void executeOption(int type, Optional<OptionDialoguePlugin> option) {
option.ifPresent($it -> $it.getActions().get(type).run());
execute();
}
/**
* Clears the current dialogue {@code chain}.
*
* @return The instance of this factory.
*/
public void clear() {
chain.clear();
nextAction = Optional.empty();
player.setDialogue(Optional.empty());
player.setOptionDialogue(Optional.empty());
setActive(false);
}
/**
* Appends a {@code chain} to this factory.
*
* @return The instance of this factory.
*/
private final DialogueFactoryPlugin append(ChainablePlugin chain) {
this.chain.add(chain);
return this;
}
/**
* Retrieves the next dialogue in the chain and executes it.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin execute() {
// check to see if there are anymore dialogues.
if (getChain().peek() != null) {
// there is so, grab the next dialogue.
ChainablePlugin entry = getChain().poll();
// is this an option dialogue?
if (entry instanceof OptionDialoguePlugin) {
OptionDialoguePlugin option = (OptionDialoguePlugin) entry;
player.setOptionDialogue(Optional.of(option));
}
setActive(true);
// whatever dialogue it is, accept it.
entry.accept(this);
} else {
// there are no dialogues in this chain.
// is there an action?
if (getNextAction().isPresent()) {
// there is so, execute it.
getNextAction().ifPresent($it -> $it.run());
// we just used this action so empty it so it can't be used again.
setNextAction(Optional.empty());
return this;
}
setActive(false);
// there are no more dialogues, so clear the screen.
player.getPacketSender().sendClearScreen();
}
return this;
}
/**
* Retrieves the next dialogue in the chain and executes it.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin executeNoClose() {
// check to see if there are anymore dialogues.
if (getChain().peek() != null) {
// there is so, grab the next dialogue.
ChainablePlugin entry = getChain().poll();
// is this an option dialogue?
if (entry instanceof OptionDialoguePlugin) {
OptionDialoguePlugin option = (OptionDialoguePlugin) entry;
player.setOptionDialogue(Optional.of(option));
}
setActive(true);
// whatever dialogue it is, accept it.
entry.accept(this);
} else {
// there are no dialogues in this chain.
// is there an action?
if (getNextAction().isPresent()) {
// there is so, execute it.
getNextAction().ifPresent($it -> $it.run());
// we just used this action so empty it so it can't be used again.
setNextAction(Optional.empty());
return this;
}
setActive(false);
}
return this;
}
/**
* Replaces keywords with their translated values in an existing dialogue text.
*
* @param line The line to check for a keyword.
*/
private final String appendKeywords(String line) {
// If the line contains #username, replace with a formatted player name.
if (line.contains("<username>")) {
line = line.replaceAll("<username>", Misc.formatPlayerName((player.playerName)));
}
if (line.contains("<servername>")) {
line = line.replaceAll("<servername>", GameConstants.SERVER_NAME);
}
return line;
}
/**
* Appends a {@link PlayerDialoguePlugin} to the current dialogue chain.
*
* @param lines The dialogue of the player talking.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendPlayerChat(String... lines) {
return append(new PlayerDialoguePlugin(lines));
}
/**
* Appends a {@link PlayerDialoguePlugin} to the current dialogue chain.
*
* @param lines The dialogue of the player talking.
*
* @param expression The expression of this dialogue.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendPlayerChat(ExpressionPlugin expression, String... lines) {
return append(new PlayerDialoguePlugin(expression, lines));
}
/**
* Sends a dialogue with a player talking.
*
* @param dialogue The player dialogue.
*
* @return The instance of this factory.
*/
final DialogueFactoryPlugin sendPlayerChat(PlayerDialoguePlugin dialogue) {
ExpressionPlugin expression = dialogue.getExpression();
String[] lines = dialogue.getLines();
validateLength(lines);
lines = splitLines(lines);
switch (lines.length) {
case 1:
player.getPacketSender().sendDialogueAnimation(969, expression.getId());
player.getPacketSender().sendString(Misc.formatPlayerName(player.playerName), 970);
player.getPacketSender().sendString(appendKeywords(lines[0]), 971);
player.getPacketSender().sendPlayerDialogueHead(969);
player.getPacketSender().sendChatInterface(968);
break;
case 2:
player.getPacketSender().sendDialogueAnimation(974, expression.getId());
player.getPacketSender().sendString(Misc.formatPlayerName(player.playerName), 975);
player.getPacketSender().sendString(appendKeywords(lines[0]), 976);
player.getPacketSender().sendString(appendKeywords(lines[1]), 977);
player.getPacketSender().sendPlayerDialogueHead(974);
player.getPacketSender().sendChatInterface(973);
break;
case 3:
player.getPacketSender().sendDialogueAnimation(980, expression.getId());
player.getPacketSender().sendString(Misc.formatPlayerName(player.playerName), 981);
player.getPacketSender().sendString(appendKeywords(lines[0]), 982);
player.getPacketSender().sendString(appendKeywords(lines[1]), 983);
player.getPacketSender().sendString(appendKeywords(lines[2]), 984);
player.getPacketSender().sendPlayerDialogueHead(980);
player.getPacketSender().sendChatInterface(979);
break;
case 4:
player.getPacketSender().sendDialogueAnimation(987, expression.getId());
player.getPacketSender().sendString(Misc.formatPlayerName(player.playerName), 988);
player.getPacketSender().sendString(appendKeywords(lines[0]), 989);
player.getPacketSender().sendString(appendKeywords(lines[1]), 990);
player.getPacketSender().sendString(appendKeywords(lines[2]), 991);
player.getPacketSender().sendString(appendKeywords(lines[3]), 992);
player.getPacketSender().sendPlayerDialogueHead(987);
player.getPacketSender().sendChatInterface(986);
break;
default:
logger.log(Level.SEVERE, String.format("Invalid player dialogue line length: %s", lines.length));
break;
}
return this;
}
/**
* Appends an npc dialogue.
*
* @param lines The text of this dialogue.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendNPCChat(String... lines) {
return append(new NPCDialogue(lines));
}
/**
* Appends an {@link NPCDialogue} to the current dialogue chain.
*
* @param expression The expression of this npc.
*
* @param lines The text of this dialogue.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendNPCChat(ExpressionPlugin expression, String... lines) {
return append(new NPCDialogue(expression, lines));
}
/**
* Appends an {@link NPCDialogue} to the current dialogue chain.
*
* @param id The id of this npc.
*
* @param lines The text of this dialogue.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendNPCChat(int id, String... lines) {
return append(new NPCDialogue(id, ExpressionPlugin.DEFAULT, lines));
}
/**
* Appends an {@link NPCDialogue} to the current dialogue chain.
*
* @param id The id of this npc.
*
* @param expression The expression of this npc.
*
* @param lines The text of this dialogue.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendNPCChat(int id, ExpressionPlugin expression, String... lines) {
return append(new NPCDialogue(id, expression, lines));
}
/**
* Sends a dialogue with a npc talking.
*
* @param dialogue The dialogue.
*
* @return The instance of this factory.
*/
final DialogueFactoryPlugin sendNPCChat(NPCDialogue dialogue) {
ExpressionPlugin expression = dialogue.getExpression();
String[] lines = dialogue.getLines();
validateLength(lines);
lines = splitLines(lines);
final String npcName = NpcHandler.getNpcListName(player.npcType).replaceAll("_", " ");
if (npcName == null) {
return this;
}
switch (lines.length) {
case 1:
player.getPacketSender().sendDialogueAnimation(4883, expression.getId());
player.getPacketSender().sendString(npcName, 4884);
player.getPacketSender().sendString(appendKeywords(lines[0]), 4885);
player.getPacketSender().sendNPCDialogueHead(player.npcType, 4883);
player.getPacketSender().sendChatInterface(4882);
break;
case 2:
player.getPacketSender().sendDialogueAnimation(4888, expression.getId());
player.getPacketSender().sendString(npcName, 4889);
player.getPacketSender().sendString(appendKeywords(lines[0]), 4890);
player.getPacketSender().sendString(appendKeywords(lines[1]), 4891);
player.getPacketSender().sendNPCDialogueHead(player.npcType, 4888);
player.getPacketSender().sendChatInterface(4887);
break;
case 3:
player.getPacketSender().sendDialogueAnimation(4894, expression.getId());
player.getPacketSender().sendString(npcName, 4895);
player.getPacketSender().sendString(appendKeywords(lines[0]), 4896);
player.getPacketSender().sendString(appendKeywords(lines[1]), 4897);
player.getPacketSender().sendString(appendKeywords(lines[2]), 4898);
player.getPacketSender().sendNPCDialogueHead(player.npcType, 4894);
player.getPacketSender().sendChatInterface(4893);
break;
case 4:
player.getPacketSender().sendDialogueAnimation(4901, expression.getId());
player.getPacketSender().sendString(npcName, 4902);
player.getPacketSender().sendString(appendKeywords(lines[0]), 4903);
player.getPacketSender().sendString(appendKeywords(lines[1]), 4904);
player.getPacketSender().sendString(appendKeywords(lines[2]), 4905);
player.getPacketSender().sendString(appendKeywords(lines[3]), 4906);
player.getPacketSender().sendNPCDialogueHead(player.npcType, 4901);
player.getPacketSender().sendChatInterface(4900);
break;
default:
logger.log(Level.SEVERE,
String.format("Invalid npc dialogue line length: %s", lines.length));
break;
}
return this;
}
/**
* Appends the {@link OptionDialoguePlugin} onto the current dialogue chain.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*/
public final DialogueFactoryPlugin sendOption(String option1, Runnable action1, String option2,
Runnable action2) {
return append(new OptionDialoguePlugin(option1, action1, option2, action2));
}
/**
* Appends the {@link OptionDialoguePlugin} onto the current dialogue chain.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*/
public final DialogueFactoryPlugin sendOption(String option1, Runnable action1, String option2,
Runnable action2, String option3, Runnable action3) {
return append(new OptionDialoguePlugin(option1, action1, option2, action2, option3, action3));
}
/**
* Appends the {@link OptionDialoguePlugin} onto the current dialogue chain.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*
* @param option4 The text for the four option.
*
* @param action4 The action for the four action.
*/
public final DialogueFactoryPlugin sendOption(String option1, Runnable action1, String option2,
Runnable action2, String option3, Runnable action3, String option4, Runnable action4) {
return append(
new OptionDialoguePlugin(option1, action1, option2, action2, option3, action3, option4, action4));
}
/**
* Appends the {@link OptionDialoguePlugin} onto the current dialogue chain.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*
* @param option4 The text for the four option.
*
* @param action4 The action for the four action.
*
* @param option5 The text for the fifth option.
*
* @param action5 The action for the fifth action.
*/
public final DialogueFactoryPlugin sendOption(String option1, Runnable action1, String option2,
Runnable action2, String option3, Runnable action3, String option4, Runnable action4,
String option5, Runnable action5) {
return append(new OptionDialoguePlugin(option1, action1, option2, action2, option3, action3, option4,
action4, option5, action5));
}
/**
* Sends a dialogue with options.
*
* @param dialogue The dialogue.
*
* @return The instance of this factory.
*/
final DialogueFactoryPlugin sendOption(OptionDialoguePlugin dialogue) {
String[] options = dialogue.getLines();
validateLength(options);
switch (options.length) {
case 2:
player.getPacketSender().sendString("Select an Option", 2460);
player.getPacketSender().sendString(options[0], 2461);
player.getPacketSender().sendString(options[1], 2462);
player.getPacketSender().sendChatInterface(2459);
return this;
case 3:
player.getPacketSender().sendString("Select an Option", 2470);
player.getPacketSender().sendString(options[0], 2471);
player.getPacketSender().sendString(options[1], 2472);
player.getPacketSender().sendString(options[2], 2473);
player.getPacketSender().sendChatInterface(2469);
return this;
case 4:
player.getPacketSender().sendString("Select an Option", 2481);
player.getPacketSender().sendString(options[0], 2482);
player.getPacketSender().sendString(options[1], 2483);
player.getPacketSender().sendString(options[2], 2484);
player.getPacketSender().sendString(options[3], 2485);
player.getPacketSender().sendChatInterface(2480);
return this;
case 5:
player.getPacketSender().sendString("Select an Option", 2493);
player.getPacketSender().sendString(options[0], 2494);
player.getPacketSender().sendString(options[1], 2495);
player.getPacketSender().sendString(options[2], 2496);
player.getPacketSender().sendString(options[3], 2497);
player.getPacketSender().sendString(options[4], 2498);
player.getPacketSender().sendChatInterface(2492);
return this;
}
return this;
}
/**
* Appends a {@link StatementDialoguePlugin} to the current dialogue chain.
*
* @param lines The text for this statement.
*
* @return The instance of this factory.
*/
public final DialogueFactoryPlugin sendStatement(String... lines) {
append(new StatementDialoguePlugin(lines));
return this;
}
/**
* Sends a player a statement dialogue.
*
* @param dialogue The statement dialogue.
*/
final DialogueFactoryPlugin sendStatement(StatementDialoguePlugin dialogue) {
String[] lines = dialogue.getLines();
validateLength(lines);
lines = splitLines(lines);
switch (lines.length) {
case 1:
player.getPacketSender().sendString(dialogue.getLines()[0], 357);
player.getPacketSender().sendString("Click here to continue", 358);
player.getPacketSender().sendChatInterface(356);
break;
case 2:
player.getPacketSender().sendString(dialogue.getLines()[0], 360);
player.getPacketSender().sendString(dialogue.getLines()[1], 361);
player.getPacketSender().sendString("Click here to continue", 362);
player.getPacketSender().sendChatInterface(359);
break;
case 3:
player.getPacketSender().sendString(dialogue.getLines()[0], 364);
player.getPacketSender().sendString(dialogue.getLines()[1], 365);
player.getPacketSender().sendString(dialogue.getLines()[2], 366);
player.getPacketSender().sendString("Click here to continue", 367);
player.getPacketSender().sendChatInterface(363);
break;
case 4:
player.getPacketSender().sendString(dialogue.getLines()[0], 369);
player.getPacketSender().sendString(dialogue.getLines()[1], 370);
player.getPacketSender().sendString(dialogue.getLines()[2], 371);
player.getPacketSender().sendString(dialogue.getLines()[3], 372);
player.getPacketSender().sendString("Click here to continue", 373);
player.getPacketSender().sendChatInterface(368);
break;
case 5:
player.getPacketSender().sendString(dialogue.getLines()[0], 375);
player.getPacketSender().sendString(dialogue.getLines()[1], 376);
player.getPacketSender().sendString(dialogue.getLines()[2], 377);
player.getPacketSender().sendString(dialogue.getLines()[3], 378);
player.getPacketSender().sendString(dialogue.getLines()[4], 379);
player.getPacketSender().sendString("Click here to continue", 380);
player.getPacketSender().sendChatInterface(374);
default:
logger.log(Level.SEVERE, String.format("Invalid statement dialogue line length: %s",
dialogue.getLines().length));
break;
}
return this;
}
/**
* The method that validates the length of {@code text}.
*
* @param text the text that will be validated.
* @throws IllegalStateException if any lines of the text exceed a certain length.
*/
private final void validateLength(String... text) {
if (Arrays.stream(text).filter(Objects::nonNull).anyMatch(s -> s.length() > MAXIMUM_LENGTH)) {
throw new IllegalStateException(
"Dialogue length too long, maximum length is: " + MAXIMUM_LENGTH);
}
}
/**
* The method that splits the length of {@code text}.
*
* @param text the text that will be split.
* @throws IllegalStateException if the calculated number of lines exceeds 4.
* @return text if the line is detected to already be split.
* @return splittext the text formatted into lines that fit into the dialogue interface
*/
private final String[] splitLines(String... text) {
if(text.length > 1){
logger.log(Level.INFO, "Detected more than 1 Dialogue line. Assuming Dialogues have been split already.");
return text;
}
int characters = text[0].length();
String[] words = text[0].split(" ");
double lines = Math.ceil(characters / MAXIMUM_CHARACTERS_PER_LINE) + 1;
if(lines > 4){
throw new IllegalStateException(
"Calculated Line Split Exceeds 4 Lines.");
}
ArrayList<String> splitText = new ArrayList<>();
int index = 0;
// Begin Splitting Lines
for(int i = 0; i < lines; i++) {
int length = 0;
StringBuilder line = new StringBuilder();
while (length <= MAXIMUM_CHARACTERS_PER_LINE && !(index == words.length)) {
String currentWord = "";
try {
currentWord = words[index];
if (length + (currentWord.length() + 1) <= MAXIMUM_CHARACTERS_PER_LINE) {
currentWord += " ";
} else {
currentWord += "";
}
} catch (Exception e) {
logger.log(Level.INFO, e.toString());
}
length += currentWord.length();
if (length <= MAXIMUM_CHARACTERS_PER_LINE) {
line.append(currentWord);
index++;
}
}
splitText.add(line.toString());
}
return splitText.toArray(new String[0]);
}
// Delombok'd Code Below
public Queue<ChainablePlugin> getChain() {
return this.chain;
}
public Player getPlayer() {
return this.player;
}
public boolean isActive() {
return this.active;
}
public Optional<Runnable> getNextAction() {
return this.nextAction;
}
public void setActive(boolean active) {
this.active = active;
}
public void setNextAction(Optional<Runnable> nextAction) {
this.nextAction = nextAction;
}
}
@@ -8,7 +8,6 @@ import com.rs2.game.content.quests.QuestAssistant;
import com.rs2.game.content.quests.QuestRewards;
import com.rs2.game.content.randomevents.FreakyForester;
import com.rs2.game.content.randomevents.RandomEventHandler;
import com.rs2.game.content.skills.SkillHandler;
import com.rs2.game.content.skills.farming.Farmers;
import com.rs2.game.content.skills.slayer.Slayer;
import com.rs2.game.content.traveling.CarpetTravel;
@@ -22,6 +21,12 @@ import com.rs2.game.players.PlayerAssistant;
import com.rs2.game.shops.Shops.Shop;
import com.rs2.util.Misc;
/**
* Handles Dialogues between NPCs and Players
* @Deprecated Consider using {@link DialogueFactoryPlugin} instead to implement dialogues.
*
*/
@Deprecated
public class DialogueHandler {
private final Player player;
@@ -3942,32 +3947,9 @@ public class DialogueHandler {
"Tzhaar-Mej-Tal");
player.nextChat = 0;
break;
/** Bank Settings **/
case 1013:
if (SkillHandler.isSkilling(player)) {
return;
}
sendNpcChat1("Good day. How may I help you?", player.talkingNpc, "Banker");
player.nextChat = 1014;
break;
case 1014:// bank open done, this place done, settings done, to do
// delete pin
sendOption("I'd like to access my bank account, please.", "I'd like to check my my P I N settings.", "What is this place?");
player.dialogueAction = 251;
break;
/** What is this place? **/
case 1015:
sendPlayerChat("What is this place?");
player.nextChat = 1016;
break;
case 1016:
sendNpcChat2("This is the bank of " + GameConstants.SERVER_NAME + ".", "We have many branches in many towns.", player.talkingNpc, "Banker");
player.nextChat = 0;
break;
/**
* Note on P I N. In order to check your "Pin Settings. You must have
* enter your Bank Pin first
* BANK P I N Setting
* Note on P I N. In order to check your P I N Settings. You must enter your Bank Pin first
**/
/** I don't know option for Bank Pin **/
case 1017:
@@ -7472,28 +7454,8 @@ public class DialogueHandler {
case 3868:
player.getDialogueHandler().sendNpcChat(player.talkingNpc, ChatEmotes.HAPPY_JOYFUL, "Enjoy your stay here. May it be spiritually uplifting!");
player.getDialogueHandler().endDialogue();
break;
case 3869:
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Hello, how's it going?");
player.nextChat = 3870;
break;
case 3870:
player.getDialogueHandler().sendNpcChat(player.talkingNpc, ChatEmotes.HAPPY_JOYFUL, "I'm fine how are you?");
player.nextChat = 3871;
break;
case 3871:
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Very well thank you.");
player.getDialogueHandler().endDialogue();
break;
case 3872:
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Hello, how's it going?");
player.nextChat = 3873;
break;
case 3873:
player.getDialogueHandler().sendNpcChat(player.talkingNpc, ChatEmotes.HAPPY_JOYFUL, "Hello there! Nice weather we've been having.");
player.getDialogueHandler().endDialogue();
break;
//holiday events (easter)
//holiday events (easter)
case 6000:
player.getDialogueHandler().sendNpcChat(player.talkingNpc, ChatEmotes.DISTRESSED, "Oh dear... What am I going to do?");
player.nextChat = 6001;
@@ -0,0 +1,37 @@
package com.rs2.game.dialogues;
import com.google.common.collect.ImmutableList;
/**
* Represents an abstract dialogue, in which extending classes will be able to construct and send
* dialogues to a player.
*
* @author Vult-R
*/
public abstract class DialoguePlugin {
/**
* The action buttons responsible for dialogues.
*/
public static final ImmutableList<Integer> DIALOGUE_BUTTONS = ImmutableList.of(9157, 9167, 9178, 9190,
9158, 9168, 9179, 9191, 9169, 9180, 9192, 9181, 9193, 9194);
/**
* Sends a player a dialogue.
*
* @param factory The factory for this dialogue.
*/
public abstract void sendDialogues(DialogueFactoryPlugin factory);
/**
* Checks if the button triggered is an optional dialogue button.
*
* @param button The index of the button being checked.
*
* @return The result of the operation.
*/
public static final boolean isDialogueButton(int button) {
return DIALOGUE_BUTTONS.stream().anyMatch(search -> search == button);
}
}
@@ -0,0 +1,74 @@
package com.rs2.game.dialogues;
/*
* Copyright (c) 2010-2011 Graham Edgecombe Copyright (c) 2011-2016 Major <major.emrs@gmail.com> and
* other apollo contributors
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without
* fee is hereby granted, provided that the above copyright notice and this permission notice appear
* in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
/**
* Represents the expressions of entities for dialogue.
*
* @author Vult-R
*/
public enum ExpressionPlugin {
HAPPY(588),
ANXIOUS(589),
CALM_TALK(590),
DEFAULT(591),
EVIL(592),
BAD(593),
WICKED(594),
ANNOYED(595),
DISTRESSED(596),
AFFLICTED(597),
DRUNK_LEFT(600),
DRUNK_RIGHT(601),
NOT_INTERESTED(602),
SLEEPY(603),
PLAIN_EVIL(604),
LAUGH(605),
SNIGGER(606),
HAVE_FUN(607),
GUFFAW(608),
EVIL_LAUGH_SHORT(609),
SLIGHTLY_SAD(610),
SAD(599),
VERY_SAD(611),
ON_ONE_HAND(612),
ALMOST_CRYING(598),
NEARLY_CRYING(613),
ANGRY(614),
FURIOUS(615),
ENRAGED(616),
MAD(617);
/**
* The id for this expression.
*/
private final int id;
/**
* Creates a new {@link ExpressionPlugin}.
*
* @param expression The id for this expression.
*/
private ExpressionPlugin(int expression) {
this.id = expression;
}
// Delombok'd Code Below
public int getId() {
return this.id;
}
}
@@ -0,0 +1,122 @@
package com.rs2.game.dialogues;
/**
* The {@link ChainablePlugin} implementation that represents dialogue in which an NPC is talking.
*
* @author Vult-R
*/
public final class NPCDialogue implements ChainablePlugin {
/**
* The id of this npc.
*/
private int id = -1;
/**
* The expression of this NPC.
*/
private final ExpressionPlugin expression;
/**
* The text for this dialogue.
*/
private final String[] lines;
/**
* Creates a new {@link NPCDialogue}
*
* @param lines The text for this dialogue.
*/
public NPCDialogue(String... lines) {
this(ExpressionPlugin.DEFAULT, lines);
}
/**
* Creates a new {@link NPCDialogue}
*
* @param expression The expression of this npc.
*
* @param lines The text for this dialogue.
*/
public NPCDialogue(ExpressionPlugin expression, String... lines) {
this.expression = expression;
this.lines = lines;
}
/**
* Creates a new {@link NPCDialogue}
*
* @param id The id of this npc.
*
* @param lines The text for this dialogue.
*/
public NPCDialogue(int id, String... lines) {
this(id, ExpressionPlugin.DEFAULT, lines);
}
/**
* Creates a new {@link NPCDialogue}
*
* @param id The id of this npc.
*
* @param expression The expression of this npc.
*
* @param lines The text for this dialogue.
*/
public NPCDialogue(int id, ExpressionPlugin expression, String... lines) {
this.id = id;
this.expression = expression;
this.lines = lines;
}
@Override
public void accept(DialogueFactoryPlugin factory) {
factory.sendNPCChat(this);
}
public int getId() {
return this.id;
}
public ExpressionPlugin getExpression() {
return this.expression;
}
// Delombok'd Code Below
public String[] getLines() {
return this.lines;
}
public void setId(int id) {
this.id = id;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof NPCDialogue)) return false;
final NPCDialogue other = (NPCDialogue) o;
if (this.getId() != other.getId()) return false;
final Object this$expression = this.getExpression();
final Object other$expression = other.getExpression();
if (this$expression == null ? other$expression != null : !this$expression.equals(other$expression))
return false;
if (!java.util.Arrays.deepEquals(this.getLines(), other.getLines())) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getId();
final Object $expression = this.getExpression();
result = result * PRIME + ($expression == null ? 43 : $expression.hashCode());
result = result * PRIME + java.util.Arrays.deepHashCode(this.getLines());
return result;
}
public String toString() {
return "AstraeusNPCDialogue(id=" + this.getId() + ", expression=" + this.getExpression() + ", lines=" + java.util.Arrays.deepToString(this.getLines()) + ")";
}
}
@@ -0,0 +1,163 @@
package com.rs2.game.dialogues;
import java.util.ArrayList;
import java.util.List;
/**
* The {@link ChainablePlugin} implementation that represents a dialogue in which options are given to the
* player.
*
* @author Vult-R
*/
public final class OptionDialoguePlugin implements ChainablePlugin {
/**
* The text for this dialogue.
*/
private final String[] lines;
/**
* The list of actions for this dialogue.
*/
private final List<Runnable> actions = new ArrayList<>();
/**
* Creates a new {@link OptionDialoguePlugin}.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*/
public OptionDialoguePlugin(String option1, Runnable action1, String option2, Runnable action2) {
lines = new String[] {option1, option2};
actions.add(action1);
actions.add(action2);
}
/**
* Creates a new {@link OptionDialoguePlugin}.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*/
public OptionDialoguePlugin(String option1, Runnable action1, String option2, Runnable action2,
String option3, Runnable action3) {
lines = new String[] {option1, option2, option3};
actions.add(action1);
actions.add(action2);
actions.add(action3);
}
/**
* Creates a new {@link OptionDialoguePlugin}.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*
* @param option4 The text for the four option.
*
* @param action4 The action for the four action.
*/
public OptionDialoguePlugin(String option1, Runnable action1, String option2, Runnable action2,
String option3, Runnable action3, String option4, Runnable action4) {
lines = new String[] {option1, option2, option3, option4};
actions.add(action1);
actions.add(action2);
actions.add(action3);
actions.add(action4);
}
/**
* Creates a new {@link OptionDialoguePlugin}.
*
* @param option1 The text for the first option.
*
* @param action1 The action for the first action.
*
* @param option2 The text for the second option.
*
* @param action2 The action for the second action.
*
* @param option3 The text for the third option.
*
* @param action3 The action for the third action.
*
* @param option4 The text for the four option.
*
* @param action4 The action for the four action.
*
* @param option5 The text for the fifth option.
*
* @param action5 The action for the fifth action.
*/
public OptionDialoguePlugin(String option1, Runnable action1, String option2, Runnable action2,
String option3, Runnable action3, String option4, Runnable action4, String option5,
Runnable action5) {
lines = new String[] {option1, option2, option3, option4, option5};
actions.add(action1);
actions.add(action2);
actions.add(action3);
actions.add(action4);
actions.add(action5);
}
@Override
public void accept(DialogueFactoryPlugin factory) {
factory.sendOption(this);
}
// Delombok'd code below
public String[] getLines() {
return this.lines;
}
public List<Runnable> getActions() {
return this.actions;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof OptionDialoguePlugin)) return false;
final OptionDialoguePlugin other = (OptionDialoguePlugin) o;
if (!java.util.Arrays.deepEquals(this.getLines(), other.getLines())) return false;
final Object this$actions = this.getActions();
final Object other$actions = other.getActions();
if (this$actions == null ? other$actions != null : !this$actions.equals(other$actions)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + java.util.Arrays.deepHashCode(this.getLines());
final Object $actions = this.getActions();
result = result * PRIME + ($actions == null ? 43 : $actions.hashCode());
return result;
}
public String toString() {
return "AstraeusOptionDialogue(lines=" + java.util.Arrays.deepToString(this.getLines()) + ", actions=" + this.getActions() + ")";
}
}
@@ -0,0 +1,84 @@
package com.rs2.game.dialogues;
/**
* A {@link ChainablePlugin} implementation that represents a player talking.
*
* @author Vult-R
*/
public class PlayerDialoguePlugin implements ChainablePlugin {
/**
* The expression of this player.
*/
private final ExpressionPlugin expression;
/**
* The text for this dialogue.
*/
private final String[] lines;
/**
* Creates a new {@link PlayerDialoguePlugin} with a default expression of {@code DEFAULT}.
*
* @param lines The text for this dialogue.
*/
public PlayerDialoguePlugin(String... lines) {
this(ExpressionPlugin.DEFAULT, lines);
}
/**
* Creates a new {@link PlayerDialoguePlugin}.
*
* @param expression The expression for this dialogue.
*
* @param lines The text for this dialogue.
*/
public PlayerDialoguePlugin(ExpressionPlugin expression, String... lines) {
this.expression = expression;
this.lines = lines;
}
@Override
public void accept(DialogueFactoryPlugin factory) {
factory.sendPlayerChat(this);
}
public ExpressionPlugin getExpression() {
return this.expression;
}
// Delombok'd Code Below
public String[] getLines() {
return this.lines;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof PlayerDialoguePlugin)) return false;
final PlayerDialoguePlugin other = (PlayerDialoguePlugin) o;
if (!other.canEqual((Object) this)) return false;
final Object this$expression = this.getExpression();
final Object other$expression = other.getExpression();
if (this$expression == null ? other$expression != null : !this$expression.equals(other$expression))
return false;
if (!java.util.Arrays.deepEquals(this.getLines(), other.getLines())) return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof PlayerDialoguePlugin;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $expression = this.getExpression();
result = result * PRIME + ($expression == null ? 43 : $expression.hashCode());
result = result * PRIME + java.util.Arrays.deepHashCode(this.getLines());
return result;
}
public String toString() {
return "PlayerDialoguePlugin(expression=" + this.getExpression() + ", lines=" + java.util.Arrays.deepToString(this.getLines()) + ")";
}
}
@@ -0,0 +1,60 @@
package com.rs2.game.dialogues;
/**
* The {@link ChainablePlugin} implementation that represents a dialogue with a single statement; which
* has no models on the dialogue.
*
* @author Vult-R
*/
public class StatementDialoguePlugin implements ChainablePlugin {
/**
* The text for this dialogue.
*/
private final String[] lines;
/**
* Creates a new {@link StatementDialoguePlugin}.
*
* @param lines The text for this dialogue.
*/
public StatementDialoguePlugin(String... lines) {
this.lines = lines;
}
@Override
public void accept(DialogueFactoryPlugin factory) {
factory.sendStatement(this);
}
// Delombok'd code below
public String[] getLines() {
return this.lines;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof StatementDialoguePlugin)) return false;
final StatementDialoguePlugin other = (StatementDialoguePlugin) o;
if (!other.canEqual((Object) this)) return false;
if (!java.util.Arrays.deepEquals(this.getLines(), other.getLines())) return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof StatementDialoguePlugin;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + java.util.Arrays.deepHashCode(this.getLines());
return result;
}
public String toString() {
return "AstraeusStatementDialogue(lines=" + java.util.Arrays.deepToString(this.getLines()) + ")";
}
}