package plugin.quests.cooksassistant import com.rs2.Constants 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.content.StaticItemList.BUCKET_OF_MILK import com.rs2.game.content.StaticItemList.EGG import com.rs2.game.content.StaticItemList.POT_OF_FLOUR import com.rs2.game.content.StaticNpcList.COOK import com.rs2.game.content.quests.QuestAssistant import com.rs2.game.content.quests.QuestRewards import com.rs2.game.players.Player import plugin.quests.cooksassistant.CooksAssistantConstants.GAVE_EGG_KEY import plugin.quests.cooksassistant.CooksAssistantConstants.GAVE_FLOUR_KEY import plugin.quests.cooksassistant.CooksAssistantConstants.GAVE_MILK_KEY import plugin.quests.cooksassistant.CooksAssistantConstants.ITEMS_GIVEN_KEY import plugin.quests.cooksassistant.CooksAssistantConstants.PLUGIN_ID import plugin.quests.cooksassistant.CooksAssistantConstants.STAGE_COMPLETE import plugin.quests.cooksassistant.CooksAssistantConstants.STAGE_IN_PROGRESS import plugin.quests.cooksassistant.CooksAssistantConstants.STAGE_NOT_STARTED @SubscribesTo(NpcFirstClickEvent::class) class CooksAssistantNpcPlugin : EventSubscriber { override fun test(event: NpcFirstClickEvent) = event.npc == COOK override fun subscribe(context: EventContext, player: Player, event: NpcFirstClickEvent) { player.talkingNpc = event.npc when (player.pluginData.getInt(PLUGIN_ID, QuestAssistant.STAGE_KEY, STAGE_NOT_STARTED)) { STAGE_NOT_STARTED -> startQuest(player, event.npc) STAGE_IN_PROGRESS -> { if (player.pluginData.getInt(PLUGIN_ID, ITEMS_GIVEN_KEY, 0) == 1) { finishQuestDialogue(player, event.npc) } else { checkIngredients(player, event.npc) } } STAGE_COMPLETE -> { val dialogue = player.dialogueFactory dialogue.clear() dialogue.sendNpcChat(event.npc, "Hello friend, how is the adventuring going?") .sendPlayerChat("I am getting strong and mighty. Grrr.") .sendNpcChat(event.npc, "Glad to hear it.") .execute() } } } private fun startQuest(player: Player, npc: Int) { val dialogue = player.dialogueFactory dialogue.clear() dialogue.sendNpcChat(npc, "What am I to do?") .sendOption( "What's wrong?", { dialogue.clear() dialogue.sendPlayerChat("What's wrong?") .sendNpcChat( npc, "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( npc, "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.", { acceptQuest(player, npc) }, "I can't right now, Maybe later.", { declineQuest(dialogue, npc) } ) }, "Can you cook me a cake?", { dialogue.clear() dialogue.sendNpcChat(npc, "Does it look like I have the time?") }, "You don't look very happy.", { dialogue.clear() dialogue.sendPlayerChat("You don't look so happy.") .sendNpcChat( npc, "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( npc, "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.", { acceptQuest(player, npc) }, "I can't right now, Maybe later.", { declineQuest(dialogue, npc) } ) }, "Nice hat.", { dialogue.clear() dialogue.sendNpcChat(npc, "I don't have time for your jibber-jabber!") } ).execute() } private fun acceptQuest(player: Player, npc: Int) { val dialogue = player.dialogueFactory dialogue.clear() player.pluginData.putInt(PLUGIN_ID, QuestAssistant.STAGE_KEY, STAGE_IN_PROGRESS) QuestAssistant.sendStages(player) dialogue.sendPlayerChat("I'm always happy to help a cook in distress.") .sendNpcChat( npc, "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( npc, "You'll find a windmill north-west of here to make flour,", "a chicken farm across the river to the east for eggs,", "and dairy cows in the field just east of the castle." ) } private fun declineQuest(dialogue: com.rs2.game.dialogues.factory.DialogueFactory, npc: Int) { dialogue.clear() dialogue.sendPlayerChat("I can't right now, Maybe later.") .sendNpcChat(npc, "Fine. I always knew you Adventurer types were callous", "beasts. Go on your merry way!") } private fun checkIngredients(player: Player, npc: Int) { val dialogue = player.dialogueFactory dialogue.clear() var gaveMilk = player.pluginData.getInt(PLUGIN_ID, GAVE_MILK_KEY, 0) == 1 var gaveFlour = player.pluginData.getInt(PLUGIN_ID, GAVE_FLOUR_KEY, 0) == 1 var gaveEgg = player.pluginData.getInt(PLUGIN_ID, GAVE_EGG_KEY, 0) == 1 val hasMilk = !gaveMilk && player.itemAssistant.playerHasItem(BUCKET_OF_MILK, 1) val hasFlour = !gaveFlour && player.itemAssistant.playerHasItem(POT_OF_FLOUR, 1) val hasEgg = !gaveEgg && player.itemAssistant.playerHasItem(EGG, 1) dialogue.sendNpcChat(npc, "How are you getting on with finding the ingredients?") if (!hasMilk && !hasFlour && !hasEgg) { dialogue.sendPlayerChat("I haven't got any of them yet, I'm still looking.") .sendNpcChat(npc, "Please get the ingredients quickly. I'm running out of", "time! The Duke will throw me into the streets!") .execute() return } if (hasMilk) { dialogue.sendPlayerChat("Here's a bucket of milk.") player.itemAssistant.deleteItem(BUCKET_OF_MILK, 1) player.pluginData.putInt(PLUGIN_ID, GAVE_MILK_KEY, 1) gaveMilk = true } if (hasFlour) { dialogue.sendPlayerChat("Here's a pot of flour.") player.itemAssistant.deleteItem(POT_OF_FLOUR, 1) player.pluginData.putInt(PLUGIN_ID, GAVE_FLOUR_KEY, 1) gaveFlour = true } if (hasEgg) { dialogue.sendPlayerChat("Here's an egg.") player.itemAssistant.deleteItem(EGG, 1) player.pluginData.putInt(PLUGIN_ID, GAVE_EGG_KEY, 1) gaveEgg = true } if (gaveMilk && gaveFlour && gaveEgg) { player.pluginData.putInt(PLUGIN_ID, ITEMS_GIVEN_KEY, 1) dialogue.onAction { showCompletionDialogue(player, npc) }.execute() } else { val missing = mutableListOf() if (!gaveMilk) missing.add("a bucket of milk") if (!gaveFlour) missing.add("a pot of flour") if (!gaveEgg) missing.add("an egg") dialogue.sendNpcChat( npc, "Thanks for the ingredients you have got so far.", "Please get the rest quickly! I still need ${missing.joinToString(" and ")}." ).execute() } } private fun finishQuestDialogue(player: Player, npc: Int) { showCompletionDialogue(player, npc, showThanks = false) } private fun showCompletionDialogue(player: Player, npc: Int, showThanks: Boolean = true) { val dialogue = player.dialogueFactory dialogue.clear() if (showThanks) { dialogue.sendNpcChat(npc, "You've brought me everything I need! I am saved!", "Thank you!") } dialogue.sendPlayerChat("So do I get to go to the Duke's Party?") .sendNpcChat(npc, "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(npc, "Maybe, but I won't be holding my breath.") .onAction { reward(player) } .execute() } private fun reward(player: Player) { player.pluginData.putInt(PLUGIN_ID, QuestAssistant.STAGE_KEY, STAGE_COMPLETE) player.pluginData.putInt(PLUGIN_ID, ITEMS_GIVEN_KEY, 0) QuestRewards.questReward( player, "Cook's Assistant", "1 Quest Point", "300 Cooking XP", "Permission to use the", "Cook's range", "", "", 326 ) player.playerAssistant.addSkillXP(300.0, Constants.COOKING) player.questPoints++ QuestAssistant.sendStages(player) } }