package plugin.area.alkharid 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.area.alkharid.AlKharidGateUtil.BORDER_GUARD_1 import plugin.area.alkharid.AlKharidGateUtil.BORDER_GUARD_2 import plugin.area.alkharid.AlKharidGateUtil.hasCompletedPrinceAli import plugin.area.alkharid.AlKharidGateUtil.isNearGate import plugin.area.alkharid.AlKharidGateUtil.passThroughGate import plugin.area.alkharid.AlKharidGateUtil.payToll @SubscribesTo(NpcFirstClickEvent::class) class BorderGuardFirstClick : EventSubscriber { override fun subscribe(context: EventContext, player: Player, event: NpcFirstClickEvent) { val npcId = event.npc if (npcId != BORDER_GUARD_1 && npcId != BORDER_GUARD_2) { return } if (player.hasCompletedPrinceAli()) { player.talkingNpc = npcId player.dialogueFactory.clear() player.dialogueFactory .sendPlayerChat("Can I come through this gate?") .sendNpcChat(npcId, "You may pass, friend of Al-Kharid.") .execute() } else { startTollDialogue(player, npcId) } } private fun startTollDialogue(player: Player, npcId: Int) { val dialogue = player.dialogueFactory dialogue.clear() player.talkingNpc = npcId dialogue.sendPlayerChat("Can I come through this gate?") .sendNpcChat(npcId, "You must pay a toll of 10 gold coins to pass.") .sendOption( "Okay, I'll pay.", { payToll(player, npcId) }, "Who does my money go to?", { dialogue.sendPlayerChat("Who does my money go to?") .sendNpcChat(npcId, "The money goes to the city of Al-Kharid.", "Will you pay the toll?") .sendOption( "Okay, I'll pay.", { payToll(player, npcId) }, "No thanks, I'll walk around.", { declineToll(player, npcId) } ) }, "No thanks, I'll walk around.", { declineToll(player, npcId) } ) .execute() } private fun payToll(player: Player, npcId: Int) { if (!isNearGate(player)) { player.packetSender.sendMessage("You need to be closer to the gate to use it.") player.packetSender.closeAllWindows() return } if (player.payToll()) { player.packetSender.sendMessage("You pay the border guard 10 coins.") passThroughGate(player) } else { player.dialogueFactory.sendPlayerChat("I haven't got that much.") .sendNpcChat(npcId, "Well, you can't come through here then.") } } private fun declineToll(player: Player, npcId: Int) { player.dialogueFactory.sendPlayerChat("No thanks, I'll walk around.") .sendNpcChat(npcId, "Ok suit yourself.") } }