From 3c61ba69f3e09ff9ad0c459ff5127ee49b122518 Mon Sep 17 00:00:00 2001
From: Dark98 <darkaidz98@gmail.com>
Date: Wed, 15 Dec 2021 02:08:54 +0000
Subject: [PATCH] Small Update

* Disabled The Old Dialogue System
* Converted CooksAssistant/Lumbridge Cook Dialogue
* Only Show Log Info For New Dialogue System When Server Is In Debug Mode
---
 .../quests/cooksassistant/FirstClick.kt       |  26 +++
 .../dialogue/LumbridgeCookDialogue.kt         | 151 ++++++++++++++++++
 .../game/dialogues/DialogueFactoryPlugin.java |   4 +-
 .../rs2/game/dialogues/DialogueHandler.java   | 134 ----------------
 .../rs2/game/dialogues/DialogueOptions.java   |  18 ---
 .../java/com/rs2/game/npcs/NpcActions.java    |  12 --
 .../rs2/net/packets/impl/ClickingButtons.java |   2 +-
 .../rs2/net/packets/impl/DialoguePacket.java  |   4 +-
 8 files changed, 183 insertions(+), 168 deletions(-)
 create mode 100644 2006Scape Server/plugins/plugin/quests/cooksassistant/FirstClick.kt
 create mode 100644 2006Scape Server/plugins/plugin/quests/cooksassistant/dialogue/LumbridgeCookDialogue.kt

diff --git a/2006Scape Server/plugins/plugin/quests/cooksassistant/FirstClick.kt b/2006Scape Server/plugins/plugin/quests/cooksassistant/FirstClick.kt
new file mode 100644
index 00000000..c86a7d78
--- /dev/null
+++ b/2006Scape Server/plugins/plugin/quests/cooksassistant/FirstClick.kt	
@@ -0,0 +1,26 @@
+package plugin.quests.cooksassistant
+
+import com.rs2.event.EventContext
+import com.rs2.event.EventSubscriber
+import com.rs2.event.SubscribesTo
+import com.rs2.event.impl.NpcFirstClickEvent
+import com.rs2.game.players.Player
+import plugin.quests.cooksassistant.dialogue.LumbridgeCookDialogue
+
+
+@SubscribesTo(NpcFirstClickEvent::class)
+class FirstClick : EventSubscriber<NpcFirstClickEvent> {
+
+	override fun subscribe(context: EventContext, player: Player, event: NpcFirstClickEvent) {
+
+		when(event.npc) {
+			//Lumbridge Cook (278)
+			278 -> {
+				if (player.playerRights >= 3) {
+					player.packetSender.sendMessage("[click= npc], [type = first/quest], [id= ${event.npc}], [Type= ${event.npc}]")
+				}
+				player.dialogueFactory.sendDialogue(LumbridgeCookDialogue())
+			}
+		}
+	}
+}
\ No newline at end of file
diff --git a/2006Scape Server/plugins/plugin/quests/cooksassistant/dialogue/LumbridgeCookDialogue.kt b/2006Scape Server/plugins/plugin/quests/cooksassistant/dialogue/LumbridgeCookDialogue.kt
new file mode 100644
index 00000000..e05cc15b
--- /dev/null
+++ b/2006Scape Server/plugins/plugin/quests/cooksassistant/dialogue/LumbridgeCookDialogue.kt	
@@ -0,0 +1,151 @@
+package plugin.quests.cooksassistant.dialogue
+
+import com.rs2.game.content.quests.QuestAssistant
+import com.rs2.game.content.quests.QuestRewards
+import com.rs2.game.dialogues.DialogueFactoryPlugin
+import com.rs2.game.dialogues.DialoguePlugin
+import com.rs2.game.dialogues.ExpressionPlugin
+
+/**
+ * The Dialogue For The Lumbridge Castle Cook/Cooks Assistant Quest
+ */
+class LumbridgeCookDialogue : DialoguePlugin() {
+
+    override fun sendDialogues(factory: DialogueFactoryPlugin) {
+        if (factory.player.cookAss == 0) {
+            factory
+                .sendNPCChat(ExpressionPlugin.ANXIOUS, "What am I to do?")
+                .sendOption("What's wrong?", {
+                    factory
+                        .onAction {
+                            factory
+                                .sendPlayerChat("What's wrong?")
+                                .sendNPCChat(
+                                    "Oh dear, oh dear, oh dear, I'm in a terrible terrible",
+                                    "mess! It's the Duke's birthday today, and I should be",
+                                    "making him a lovely big birthday cake!"
+                                )
+                                .sendNPCChat(
+                                    "I've forgotten to buy the ingredients. I'll never get",
+                                    "them in time now. He'll sack me! What will I do? I have",
+                                    "four children and a goat to look after. Would you help",
+                                    "me? Please?"
+                                )
+                                .sendOption("I'm always happy to help a cook in distress", {
+                                    factory.onAction {
+                                        factory
+                                            .sendPlayerChat("Yes, I'll help you.")
+                                            .sendNPCChat(
+                                                "Oh thank you, thank you. I need milk, an egg, and",
+                                                "flour. I'd be very grateful if you can get them for me."
+                                            )
+                                            .sendPlayerChat("So where do I find these ingredients then?")
+                                            .sendNPCChat(
+                                                "You can find flour in any of the shops here.",
+                                                "You can find eggs by killing chickens.",
+                                                "You can find milk by using a bucket on a cow"
+                                            )
+                                            .execute()
+                                            .player.cookAss = 1
+                                        QuestAssistant.sendStages(factory.player)
+                                    }
+                                },
+                                    "I can't right now, Maybe later.", {
+                                        factory.onAction {
+                                            factory
+                                                .sendPlayerChat("I can't right now, Maybe later.")
+                                                .sendNPCChat("Oh please! Hurry then!")
+                                                .execute()
+                                        }
+
+                                    })
+                        }
+                }, "Can you cook me a cake?", {
+                    factory
+                        .onAction {
+                            factory
+                                .sendNPCChat("Does it look like I have the time?")
+                                .execute()
+                        }
+                }, "You don't look very happy.", {
+                    factory
+                        .sendPlayerChat(ExpressionPlugin.ANXIOUS, "You don't look so happy.")
+                        .sendNPCChat(
+                            "Oh dear, oh dear, oh dear, I'm in a terrible terrible",
+                            "mess! It's the Duke's birthday today, and I should be",
+                            "making him a lovely big birthday cake!"
+                        )
+                        .sendNPCChat(
+                            "I've forgotten to buy the ingredients. I'll never get",
+                            "them in time now. He'll sack me! What will I do? I have",
+                            "four children and a goat to look after. Would you help",
+                            "me? Please?"
+                        )
+                        .sendOption("I'm always happy to help a cook in distress", {
+                            factory.onAction {
+                                factory
+                                    .sendPlayerChat("Yes, I'll help you.")
+                                    .sendNPCChat(
+                                        "Oh thank you, thank you. I need milk, an egg, and",
+                                        "flour. I'd be very grateful if you can get them for me."
+                                    )
+                                    .sendPlayerChat("So where do I find these ingredients then?")
+                                    .sendNPCChat(
+                                        "You can find flour in any of the shops here.",
+                                        "You can find eggs by killing chickens.",
+                                        "You can find milk by using a bucket on a cow"
+                                    )
+                                    .execute()
+                                    .player.cookAss = 1
+                                QuestAssistant.sendStages(factory.player)
+                            }
+                        },
+                            "I can't right now, Maybe later.", {
+                                factory.onAction {
+                                    factory
+                                        .sendPlayerChat("I can't right now, Maybe later.")
+                                        .sendNPCChat("Oh please! Hurry then!")
+                                        .execute()
+                                }
+
+                            })
+                }, "Nice hat.") {
+                    factory
+                        .sendNPCChat("I don't have time for your jibber-jabber!")
+                }
+                .execute()
+        } else if(factory.player.cookAss == 1) {
+            factory
+                .sendNPCChat("How are you getting on with finding the ingredients?")
+            if (factory.player.itemAssistant.playerHasItem(1944, 1)
+                && factory.player.itemAssistant.playerHasItem(1927, 1)
+                && factory.player.itemAssistant.playerHasItem(1933, 1)
+            ) {
+                factory.sendPlayerChat("Here's all the items!")
+                factory.player.itemAssistant.deleteItem(1944, 1)
+                factory.player.itemAssistant.deleteItem(1927, 1)
+                factory.player.itemAssistant.deleteItem(1933, 1)
+                factory.player.cookAss = 2
+                factory.sendNPCChat("You brought me everything I need! I'm saved!", "Thank you!")
+                    .sendPlayerChat("So do I get to go to the Duke's Party?")
+                    .sendNPCChat("I'm afraid not, only the big cheeses get to dine with the", "Duke.")
+                    .sendPlayerChat("Well, maybe one day I'll be important enough to sit on", "the Duke's table")
+                    .sendNPCChat("Maybe, but I won't be holding my breath.")
+                QuestRewards.cookReward(factory.player)
+            } else {
+                factory.sendPlayerChat("I don't have all the items yet.")
+                    .sendNPCChat("Oh please! Hurry then!")
+                    .execute()
+            }
+        } else if(factory.player.cookAss == 2) {
+            factory
+                .sendPlayerChat("So do I get to go to the Duke's Party?")
+                .sendNPCChat("I'm afraid not, only the big cheeses get to dine with the", "Duke.")
+                .sendPlayerChat("Well, maybe one day I'll be important enough to sit on", "the Duke's table")
+                .sendNPCChat("Maybe, but I won't be holding my breath.")
+            QuestRewards.cookReward(factory.player)
+        } else if(factory.player.cookAss == 3) {
+            factory.sendNPCChat("Thanks for helping me out friend!")
+        }
+    }
+}
\ No newline at end of file
diff --git a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueFactoryPlugin.java b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueFactoryPlugin.java
index 373e2d64..05097c30 100644
--- a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueFactoryPlugin.java	
+++ b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueFactoryPlugin.java	
@@ -670,7 +670,9 @@ public final class DialogueFactoryPlugin {
     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.");
+            if(GameConstants.SERVER_DEBUG) {
+                logger.log(Level.INFO, "Detected more than 1 Dialogue line. Assuming Dialogues have been split already.");
+            }
             return text;
         }
         int characters = text[0].length();
diff --git a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java
index c407658a..ee17a0e2 100644
--- a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java	
+++ b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java	
@@ -317,140 +317,6 @@ public class DialogueHandler {
 				player.nextChat = 0;
 				player.ptjob = 2;
 				break;
-			case 50:
-				sendNpcChat1("What am I to do?", player.talkingNpc, "Cook");
-				player.nextChat = 51;
-				break;
-			case 51:
-				sendOption("What's wrong?", "Can you cook me a cake?",
-						"You don't look very happy.", "Nice hat.");
-				player.dialogueAction = 52;
-				break;
-			case 52:
-				sendPlayerChat("What's wrong?");
-				player.nextChat = 54;
-				break;
-			case 54:
-				sendNpcChat3(
-						"Oh dear, oh dear, oh dear, I'm in a terrible terrible",
-						"mess! It's the Duke's birthday today, and I should be",
-						"making him a lovely big birthday cake!",
-						player.talkingNpc, "Cook");
-				player.nextChat = 55;
-				break;
-			case 55:
-				sendNpcChat4(
-						"I've forgotten to buy the ingredients. I'll never get",
-						"them in time now. He'll sack me! What will I do? I have",
-						"four children and a goat to look after. Would you help",
-						"me? Please?", player.talkingNpc, "Cook");
-				player.nextChat = 56;
-				break;
-			case 56:
-				sendOption("I'm always happy to help a cook in distress.",
-						"I can't right now, Maybe later.");
-				player.dialogueAction = 57;
-				break;
-			case 57:
-				sendPlayerChat("Yes, I'll help you.");// 9157
-				player.nextChat = 60;
-				break;
-			case 58:
-				sendPlayerChat("I can't right now, Maybe later.");// 9158
-				player.nextChat = 59;
-				break;
-			case 59:
-				sendNpcChat1("Oh please! Hurry then!", player.talkingNpc, "Cook");
-				player.nextChat = 0;
-				break;
-			case 60:
-				sendNpcChat2("Oh thank you, thank you. I need milk, an egg, and",
-						"flour. I'd be very grateful if you can get them for me.",
-						player.talkingNpc, "Cook");
-				player.cookAss = 1;
-				QuestAssistant.sendStages(player);
-				player.nextChat = 61;
-				break;
-			case 61:
-				sendPlayerChat("So where do I find these ingredients then?");
-				player.nextChat = 62;
-				break;
-			case 62:
-				sendNpcChat3("You can find flour in any of the shops here.",
-						"You can find eggs by killing chickens.",
-						"You can find milk by using a bucket on a cow",
-						player.talkingNpc, "Cook");
-				player.nextChat = 0;
-				break;
-			case 63:
-				sendNpcChat1("I don't have time for your jibber-jabber!",
-						player.talkingNpc, "Cook");
-				player.nextChat = 0;
-				break;
-			case 64:
-				sendNpcChat1("Does it look like I have the time?",
-						player.talkingNpc, "Cook");
-				player.nextChat = 0;
-				break;
-			case 65:
-				sendPlayerChat("You don't look so happy.");
-				player.nextChat = 54;
-				break;
-			case 66:
-				sendNpcChat1(
-						"How are you getting on with finding the ingredients?",
-						player.talkingNpc, "Cook");
-				player.nextChat = 67;
-				break;
-			case 67:
-				if (player.getItemAssistant().playerHasItem(1944, 1)
-						&& player.getItemAssistant().playerHasItem(1927, 1)
-						&& player.getItemAssistant().playerHasItem(1933, 1)) {
-					sendPlayerChat("Here's all the items!");
-					player.nextChat = 68;
-				} else {
-					sendPlayerChat("I don't have all the items yet.");
-					player.nextChat = 59;
-				}
-				break;
-			case 68:
-				player.getItemAssistant().deleteItem(1944, 1);
-				player.getItemAssistant().deleteItem(1927, 1);
-				player.getItemAssistant().deleteItem(1933, 1);
-				player.cookAss = 2;
-				sendNpcChat2("You brought me everything I need! I'm saved!",
-						"Thank you!", player.talkingNpc, "Cook");
-				player.nextChat = 69;
-				break;
-			case 69:
-				sendPlayerChat("So do I get to go to the Duke's Party?");
-				player.nextChat = 70;
-				break;
-			case 70:
-				sendNpcChat2(
-						"I'm afraid not, only the big cheeses get to dine with the",
-						"Duke.", player.talkingNpc, "Cook");
-				player.nextChat = 72;
-				break;
-			case 72:
-				sendPlayerChat(
-						"Well, maybe one day I'll be important enough to sit on",
-						"the Duke's table");
-				player.nextChat = 74;
-				break;
-			case 74:
-				sendNpcChat1("Maybe, but I won't be holding my breath.",
-						player.talkingNpc, "Cook");
-				player.nextChat = 75;
-				break;
-			case 75:
-				QuestRewards.cookReward(player);
-				break;
-			case 76:
-				sendNpcChat1("Thanks for helping me out friend!",
-						player.talkingNpc, "Cook");
-				player.nextChat = 0;
-				break;
 			case 84:
 				sendNpcChat1("How are you getting on finding all my supplies",
 						player.talkingNpc, "Doric");
diff --git a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueOptions.java b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueOptions.java
index 089eda23..b7f78279 100644
--- a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueOptions.java	
+++ b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueOptions.java	
@@ -393,9 +393,6 @@ public class DialogueOptions {
 			} else if (player.dialogueAction == 56) {
 				player.getDialogueHandler().sendDialogues(96, player.npcType);
 				return;
-			} else if (player.dialogueAction == 57) {
-				player.getDialogueHandler().sendDialogues(57, player.npcType);
-				return;
 			} else if (player.dialogueAction == 3222) {
 				player.getBarrows().checkCoffins();
 				player.getPacketSender().closeAllWindows();
@@ -692,9 +689,6 @@ public class DialogueOptions {
 			} else if (player.dialogueAction == 74) {
 				player.getDialogueHandler().sendDialogues(535, player.npcType);
 				return;
-			} else if (player.dialogueAction == 57) {
-				player.getDialogueHandler().sendDialogues(58, player.npcType);
-				return;
 			} else if (player.dialogueAction == 62) {
 				player.getDialogueHandler().sendDialogues(309, player.npcType);
 				return;
@@ -944,9 +938,6 @@ public class DialogueOptions {
 			if (player.dialogueAction == 113) {
 				player.getDialogueHandler().sendDialogues(3540, player.npcType);
 			}
-			if (player.dialogueAction == 52) {
-				player.getDialogueHandler().sendDialogues(52, player.npcType);
-			}
 			if (player.dialogueAction == 1000) {
 				player.getDialogueHandler().sendDialogues(3524,player.npcType);
 			}
@@ -1017,9 +1008,6 @@ public class DialogueOptions {
 				player.getPlayerAssistant().gloryTeleport(3293, 3174, 0, "modern");
 				Teles.necklaces(player);
 			}
-			if (player.dialogueAction == 52) {
-				player.getDialogueHandler().sendDialogues(64, player.npcType);
-			}
 			if (player.dialogueAction == 1000) {
 				player.getDialogueHandler().sendDialogues(3523, player.npcType);
 			}
@@ -1093,9 +1081,6 @@ public class DialogueOptions {
 				player.getPlayerAssistant().gloryTeleport(2911, 3152, 0, "modern");
 				Teles.necklaces(player);
 			}
-			if (player.dialogueAction == 52) {
-				player.getDialogueHandler().sendDialogues(65, player.npcType);
-			}
 			if (player.dialogueAction == 1000) {
 				player.getDialogueHandler().sendDialogues(3523,player.npcType);
 			}
@@ -1154,9 +1139,6 @@ public class DialogueOptions {
 				player.getPlayerAssistant().gloryTeleport(3103, 3249, 0, "modern");
 				Teles.necklaces(player);
 			}
-			if (player.dialogueAction == 52) {
-				player.getDialogueHandler().sendDialogues(63, player.npcType);
-			}
 			if (player.dialogueAction == 1000) {
 				player.getDialogueHandler().sendDialogues(3523, player.npcType);
 			}
diff --git a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java
index 5ad15959..43fbad49 100644
--- a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java	
+++ b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java	
@@ -724,18 +724,6 @@ public class NpcActions {
 			}
 			break;
 
-		case 278:
-			if (player.cookAss == 0) {
-				player.getDialogueHandler().sendDialogues(50, npcType);
-			} else if (player.cookAss == 1) {
-				player.getDialogueHandler().sendDialogues(67, npcType);
-			} else if (player.cookAss == 2) {
-				player.getDialogueHandler().sendDialogues(69, npcType);
-			} else if (player.cookAss == 3) {
-				player.getDialogueHandler().sendDialogues(76, npcType);
-			}
-			break;
-
 		case 608:
 			if (player.blackKnight == 0 && player.questPoints >= 12) {
 				player.getDialogueHandler().sendDialogues(3902, npcType);
diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java
index 50228c2e..32413f7f 100644
--- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java	
+++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java	
@@ -59,7 +59,7 @@ public class ClickingButtons implements PacketType {
 		SilverCrafting.makeSilver(player, actionButtonId, 0);
 		Climbing.handleLadderButtons(player, actionButtonId);
 		Specials.specialClicking(player, actionButtonId);
-		DialogueOptions.handleDialogueOptions(player, actionButtonId);
+		//DialogueOptions.handleDialogueOptions(player, actionButtonId);
 		DairyChurn.churnItem(player, actionButtonId);
 		if (EnchantStaff.staffButtons(player, actionButtonId)) {
 			return;
diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/DialoguePacket.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/DialoguePacket.java
index 12c3b34a..8275c44e 100644
--- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/DialoguePacket.java	
+++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/DialoguePacket.java	
@@ -16,11 +16,11 @@ public class DialoguePacket implements PacketType {
 			 to the new system. Expect to see flickering in some Astraeus Dialogues as the old
 			 dialogue handler activates before it.
 		 */
-		if (player.nextChat > 0) {
+		/*if (player.nextChat > 0) {
 			player.getDialogueHandler().sendDialogues(player.nextChat, player.talkingNpc);
 		} else {
 			player.getDialogueHandler().sendDialogues(0, -1);
-		}
+		}*/
 
 		// New Dialogue System
 		player.getDialogueFactory().execute();
-- 
GitLab