Code:
package net.iClarity.content;
import net.iClarity.model.Player;
import net.iClarity.util.misc;
/**
* Stores and handles NPC/Player dialogues.
* @author Primadude.
*/
public class Dialogue {
/**
* The player object.
*/
Player player;
/**
* Head animation constant.
* Value for the index in the dialogueData array.
*/
private final int HEAD_ANIM = 1;
/**
* Dialogue type constant.
* Value for the index in the dialogueData array.
*/
private final int DIALOGUE_TYPE = 2;
/**
* Dialogue line 1 constant.
* Value for the index in the dialogueData array.
*/
private final int LINE_1 = 3;
/**
* Dialogue line 2 constant.
* Value for the index in the dialogueData array.
*/
private final int LINE_2 = 4;
/**
* Dialogue line 3 constant.
* Value for the index in the dialogueData array.
*/
private final int LINE_3 = 5;
/**
* Dialogue line 4 constant.
* Value for the index in the dialogueData array.
*/
private final int LINE_4 = 6;
/**
* Array to store dialogue data.
* <dialogueID, head animation ID, type of dialogue, dialogue text>.
*/
private Object[][] dialogueData = {
{1, 591, "NPC", "Good day, how can I help you?"},
{2, -1, "OPTION", "I'd like to access my bank account, please.", "I'd like to check my PIN settings"},
{3, 591, "NPC", "Do you want to buy some runes?"},
{4, -1, "OPTION", "Yes Please!", "Oh it's a rune shop. No thank you, then."},
{5, 591, "PLAYER", "Oh it's a rune shop. No thank you, then."},
{6, 591, "NPC", "Well, if you find somone who does want runes, please", "send them my way."}
};
/**
* Gets the player.
* @return The player object.
*/
public Player getPlayer() {
return player;
}
/**
* Initializes the player object.
* @param player The player that this class is applied to.
*/
public Dialogue(Player player) {
this.player = player;
}
/**
* Shows the correct dialogue for the player's dialogue ID.
*/
public void showDialogue() {
int dialogueIndex = 0;
for (int i = 0; i < dialogueData.length; i++) {
if (getPlayer().dialogueID == dialogueData[i][0]) {
dialogueIndex = i;
}
}
if (dialogueIndex == 0) {
return;
}
if (dialogueData[dialogueIndex][2].equals("OPTION")) {
if (dialogueData[dialogueIndex].length == 5) {
showChatboxOptions((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2]);
} else if (dialogueData[dialogueIndex].length == 6) {
showChatboxOptions((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3]);
} else if (dialogueData[dialogueIndex].length == 7) {
showChatboxOptions((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3],
(String)dialogueData[dialogueIndex][LINE_4]);
}
} else if (dialogueData[dialogueIndex][2].equals("PLAYER")) {
if (dialogueData[dialogueIndex].length == 4) {
showPlayerDialogue((String)dialogueData[dialogueIndex][LINE_1],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 5) {
showPlayerDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 6) {
showPlayerDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 7) {
showPlayerDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3],
(String)dialogueData[dialogueIndex][LINE_4],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
}
} else if (dialogueData[dialogueIndex][2].equals("NPC")) {
if (dialogueData[dialogueIndex].length == 4) {
showNPCDialogue((String)dialogueData[dialogueIndex][LINE_1],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 5) {
showNPCDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 6) {
showNPCDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
} else if (dialogueData[dialogueIndex].length == 7) {
showNPCDialogue((String)dialogueData[dialogueIndex][LINE_1],
(String)dialogueData[dialogueIndex][LINE_2],
(String)dialogueData[dialogueIndex][LINE_3],
(String)dialogueData[dialogueIndex][LINE_4],
(Integer)dialogueData[dialogueIndex][HEAD_ANIM]);
}
}
}
/**
* Show 2 options in the chatbox.
* @param option1 The first option.
* @param option2 The second option.
*/
public void showChatboxOptions(String option1, String option2) {
getPlayer().getActionSender().sendFrame171(1, 2465);
getPlayer().getActionSender().sendFrame171(0, 2468);
getPlayer().getActionSender().setTextOnInterface("Select an Option", 2460);
getPlayer().getActionSender().setTextOnInterface(option1, 2461);
getPlayer().getActionSender().setTextOnInterface(option2, 2462);
getPlayer().getActionSender().setChatBoxInterface(2459);
}
/**
* Show 3 options in the chatbox.
* @param option1 The first option.
* @param option2 The second option.
* @param option2 The third option.
*/
public void showChatboxOptions(String option1, String option2, String option3) {
getPlayer().getActionSender().setTextOnInterface("Select an Option", 2470);
getPlayer().getActionSender().setTextOnInterface(option1, 2471);
getPlayer().getActionSender().setTextOnInterface(option2, 2472);
getPlayer().getActionSender().setTextOnInterface(option3, 2473);
getPlayer().getActionSender().setChatBoxInterface(2469);
}
/**
* Show 4 options in the chatbox.
* @param option1 The first option.
* @param option2 The second option.
* @param option2 The third option.
* @param option4 The fourth option.
*/
public void showChatboxOptions(String option1, String option2, String option3, String option4) {
getPlayer().getActionSender().setTextOnInterface("Select an Option", 2481);
getPlayer().getActionSender().setTextOnInterface(option1, 2482);
getPlayer().getActionSender().setTextOnInterface(option2, 2483);
getPlayer().getActionSender().setTextOnInterface(option3, 2484);
getPlayer().getActionSender().setTextOnInterface(option4, 2485);
getPlayer().getActionSender().setChatBoxInterface(2480);
}
/**
* Show a single lined NPC dialogue.
* @param line1 The line of text for the npc to say.
* @param faceAnim The animation for the npc's head to display.
*/
public void showNPCDialogue(String line1, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(4883, faceAnim);
getPlayer().getActionSender().setTextOnInterface(getPlayer().getEngine().getNpcHandler().getNpcName(getPlayer().npcTalkToType), 4884);
getPlayer().getActionSender().setTextOnInterface(line1, 4885);
getPlayer().getActionSender().setNpcHeadOnInterface(getPlayer().npcTalkToType, 4883);
getPlayer().getActionSender().setChatBoxInterface(4882);
getPlayer().sendNpcDialogue = true;
}
/**
* Show an NPC dialogue with 2 lines of dialogue.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param faceAnim The animation for the npc's head to display.
*/
public void showNPCDialogue(String line1, String line2, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(4888, faceAnim);
getPlayer().getActionSender().setTextOnInterface(getPlayer().getEngine().getNpcHandler().getNpcName(getPlayer().npcTalkToType), 4889);
getPlayer().getActionSender().setTextOnInterface(line1, 4890);
getPlayer().getActionSender().setTextOnInterface(line2, 4891);
getPlayer().getActionSender().setNpcHeadOnInterface(getPlayer().npcTalkToType, 4888);
getPlayer().getActionSender().setChatBoxInterface(4887);
getPlayer().sendNpcDialogue = true;
}
/**
* Show an NPC dialogue with 3 lines of dialogue.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param line3 The third line of text.
* @param faceAnim The animation for the npc's head to display.
*/
public void showNPCDialogue(String line1, String line2, String line3, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(4894, faceAnim);
getPlayer().getActionSender().setTextOnInterface(getPlayer().getEngine().getNpcHandler().getNpcName(getPlayer().npcTalkToType), 4895);
getPlayer().getActionSender().setTextOnInterface(line1, 4896);
getPlayer().getActionSender().setTextOnInterface(line2, 4897);
getPlayer().getActionSender().setTextOnInterface(line3, 4898);
getPlayer().getActionSender().setNpcHeadOnInterface(getPlayer().npcTalkToType, 4894);
getPlayer().getActionSender().setChatBoxInterface(4893);
getPlayer().sendNpcDialogue = true;
}
/**
* Show an NPC dialogue with 4 lines of dialogue.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param line3 The third line of text.
* @param line4 The fourth line of text.
* @param faceAnim The animation for the npc's head to display.
*/
public void showNPCDialogue(String line1, String line2, String line3, String line4, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(4901, faceAnim);
getPlayer().getActionSender().setTextOnInterface(getPlayer().getEngine().getNpcHandler().getNpcName(getPlayer().npcTalkToType), 4902);
getPlayer().getActionSender().setTextOnInterface(line1, 4903);
getPlayer().getActionSender().setTextOnInterface(line2, 4904);
getPlayer().getActionSender().setTextOnInterface(line3, 4905);
getPlayer().getActionSender().setTextOnInterface(line4, 4906);
getPlayer().getActionSender().setNpcHeadOnInterface(getPlayer().npcTalkToType, 4901);
getPlayer().getActionSender().setChatBoxInterface(4900);
getPlayer().sendNpcDialogue = true;
}
/**
* Show a single lined Player dialogue.
* @param line1 The line of text.
* @param faceAnim The animation for the player's head to display.
*/
public void showPlayerDialogue(String line1, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(969, faceAnim);
getPlayer().getActionSender().setTextOnInterface(misc.optimizeText(getPlayer().playerName.replaceAll("_", " ")), 970);
getPlayer().getActionSender().setTextOnInterface(line1, 971);
getPlayer().getActionSender().setPlayerHeadOnInterface(969);
getPlayer().getActionSender().setChatBoxInterface(968);
getPlayer().sendNpcDialogue = true;
}
/**
* Show a Player dialogue with two lines of text.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param faceAnim The animation for the player's head to display.
*/
public void showPlayerDialogue(String line1, String line2, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(974, faceAnim);
getPlayer().getActionSender().setTextOnInterface(misc.optimizeText(getPlayer().playerName.replaceAll("_", " ")), 975);
getPlayer().getActionSender().setTextOnInterface(line1, 976);
getPlayer().getActionSender().setTextOnInterface(line2, 977);
getPlayer().getActionSender().setPlayerHeadOnInterface(974);
getPlayer().getActionSender().setChatBoxInterface(973);
getPlayer().sendNpcDialogue = true;
}
/**
* Show a Player dialogue with three lines of text.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param line3 The third line of text.
* @param faceAnim The animation for the player's head to display.
*/
public void showPlayerDialogue(String line1, String line2, String line3, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(980, faceAnim);
getPlayer().getActionSender().setTextOnInterface(misc.optimizeText(getPlayer().playerName.replaceAll("_", " ")), 981);
getPlayer().getActionSender().setTextOnInterface(line1, 982);
getPlayer().getActionSender().setTextOnInterface(line2, 983);
getPlayer().getActionSender().setTextOnInterface(line3, 984);
getPlayer().getActionSender().setPlayerHeadOnInterface(980);
getPlayer().getActionSender().setChatBoxInterface(979);
getPlayer().sendNpcDialogue = true;
}
/**
* Show a Player dialogue with four lines of text.
* @param line1 The first line of text.
* @param line2 The second line of text.
* @param line3 The third line of text.
* @param line4 The fourth line of text.
* @param faceAnim The animation for the player's head to display.
*/
public void showPlayerDialogue(String line1, String line2, String line3, String line4, int faceAnim) {
getPlayer().getActionSender().setAnimOnInterface(987, faceAnim);
getPlayer().getActionSender().setTextOnInterface(misc.optimizeText(getPlayer().playerName.replaceAll("_", " ")), 988);
getPlayer().getActionSender().setTextOnInterface(line1, 989);
getPlayer().getActionSender().setTextOnInterface(line2, 990);
getPlayer().getActionSender().setTextOnInterface(line3, 991);
getPlayer().getActionSender().setTextOnInterface(line4, 992);
getPlayer().getActionSender().setPlayerHeadOnInterface(987);
getPlayer().getActionSender().setChatBoxInterface(986);
getPlayer().sendNpcDialogue = true;
}
}