diff --git a/2006Scape Server/plugins/plugin/area/alkharid/AlKharidDialogueButtons.kt b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidDialogueButtons.kt new file mode 100644 index 00000000..39c58ae3 --- /dev/null +++ b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidDialogueButtons.kt @@ -0,0 +1,87 @@ +package plugin.area.alkharid + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ButtonActionEvent +import com.rs2.game.players.Player +import plugin.area.alkharid.AlKharidGateUtil.DIALOGUE_ACTION_SUB_TOLL +import plugin.area.alkharid.AlKharidGateUtil.DIALOGUE_ACTION_TOLL +import plugin.area.alkharid.AlKharidGateUtil.isNearGate +import plugin.area.alkharid.AlKharidGateUtil.passThroughGate +import plugin.area.alkharid.AlKharidGateUtil.payToll + +@SubscribesTo(ButtonActionEvent::class) +class AlKharidDialogueButtons : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ButtonActionEvent) { + val action = player.dialogueAction + if (action != DIALOGUE_ACTION_TOLL && action != DIALOGUE_ACTION_SUB_TOLL) { + return + } + + val button = event.button + + if (action == DIALOGUE_ACTION_TOLL) { + when (button) { + // Option 1: "Okay, I'll pay." + 9167 -> { + if (!isNearGate(player)) { + player.packetSender.sendMessage("You need to be closer to the gate to use it.") + player.packetSender.closeAllWindows() + player.dialogueAction = 0 + return + } + if (player.payToll()) { + player.packetSender.sendMessage("You pay the border guard 10 coins.") + passThroughGate(player) + player.nextChat = 0 + } else { + player.dialogueHandler.sendPlayerChat("I haven't got that much.") + player.nextChat = 1028 // Guard: "Well, you can't come through here then." + } + player.dialogueAction = 0 + } + // Option 2: "Who does my money go to?" + 9168 -> { + player.dialogueHandler.sendPlayerChat("Who does my money go to?") + player.nextChat = 1023 + player.dialogueAction = 0 + } + // Option 3: "No thanks, I'll walk around." + 9169 -> { + player.dialogueHandler.sendPlayerChat("No thanks, I'll walk around.") + player.nextChat = 1029 // Guard: "Ok suit yourself." + player.dialogueAction = 0 + } + } + } else if (action == DIALOGUE_ACTION_SUB_TOLL) { + when (button) { + // Option 1: "Okay, I'll pay." + 9157 -> { + if (!isNearGate(player)) { + player.packetSender.sendMessage("You need to be closer to the gate to use it.") + player.packetSender.closeAllWindows() + player.dialogueAction = 0 + return + } + if (player.payToll()) { + player.packetSender.sendMessage("You pay the border guard 10 coins.") + passThroughGate(player) + player.nextChat = 0 + } else { + player.dialogueHandler.sendPlayerChat("I haven't got that much.") + player.nextChat = 1028 // Guard: "Well, you can't come through here then." + } + player.dialogueAction = 0 + } + // Option 2: "No thanks, I'll walk around." + 9158 -> { + player.dialogueHandler.sendPlayerChat("No thanks, I'll walk around.") + player.nextChat = 1029 // Guard: "Ok suit yourself." + player.dialogueAction = 0 + } + } + } + } +} diff --git a/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateFirstClick.kt b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateFirstClick.kt new file mode 100644 index 00000000..52b61ef9 --- /dev/null +++ b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateFirstClick.kt @@ -0,0 +1,36 @@ +package plugin.area.alkharid + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ObjectFirstClickEvent +import com.rs2.game.players.Player +import plugin.area.alkharid.AlKharidGateUtil.GATE_NORTH +import plugin.area.alkharid.AlKharidGateUtil.GATE_SOUTH +import plugin.area.alkharid.AlKharidGateUtil.hasCompletedPrinceAli +import plugin.area.alkharid.AlKharidGateUtil.isNearGate +import plugin.area.alkharid.AlKharidGateUtil.passThroughGate + +@SubscribesTo(ObjectFirstClickEvent::class) +class AlKharidGateFirstClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ObjectFirstClickEvent) { + val objectId = event.gameObject + if (objectId != GATE_NORTH && objectId != GATE_SOUTH) { + return + } + + if (!isNearGate(player)) { + player.packetSender.sendMessage("You need to be closer to the gate to use it.") + return + } + + if (player.hasCompletedPrinceAli()) { + player.packetSender.sendMessage("The guards recognize you as a friend of Al-Kharid and let you pass.") + passThroughGate(player) + return + } + + player.packetSender.sendMessage("You need to talk to the border guard.") + } +} diff --git a/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateUtil.kt b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateUtil.kt new file mode 100644 index 00000000..7c4ca2ca --- /dev/null +++ b/2006Scape Server/plugins/plugin/area/alkharid/AlKharidGateUtil.kt @@ -0,0 +1,119 @@ +package plugin.area.alkharid + +import com.rs2.event.CycleEvent +import com.rs2.event.CycleEventContainer +import com.rs2.event.CycleEventHandler +import com.rs2.game.content.StaticItemList +import com.rs2.game.content.StaticNpcList +import com.rs2.game.content.StaticObjectList +import com.rs2.game.content.music.sound.SoundList +import com.rs2.game.players.Player + +object AlKharidGateUtil { + + const val GATE_SOUTH = StaticObjectList.GATE_2882 + const val GATE_NORTH = StaticObjectList.GATE_2883 + const val BORDER_GUARD_1 = StaticNpcList.BORDER_GUARD + const val BORDER_GUARD_2 = StaticNpcList.BORDER_GUARD_926 + const val TOLL_COINS = 10 + const val COINS_ID = StaticItemList.COINS_995 + const val DIALOGUE_ACTION_TOLL = 502 + const val DIALOGUE_ACTION_SUB_TOLL = 508 + + fun Player.hasCompletedPrinceAli(): Boolean = this.princeAli >= 1 + + fun Player.hasTollCoins(): Boolean = this.itemAssistant.playerHasItem(COINS_ID, TOLL_COINS) + + fun Player.payToll(): Boolean { + if (!hasTollCoins()) return false + this.itemAssistant.deleteItem(COINS_ID, this.itemAssistant.getItemSlot(COINS_ID), TOLL_COINS) + return true + } + + fun isNearGate(player: Player): Boolean { + return (player.absX in 3266..3269) && (player.absY in 3225..3230) + } + + fun buildPathToGate(player: Player, movingEast: Boolean): List> { + val gateY = if (player.absY >= 3228) 3228 else 3227 + val entranceX = if (movingEast) 3267 else 3268 + val exitX = if (movingEast) 3268 else 3267 + val bypassX = if (movingEast) 3266 else 3269 + + val steps = mutableListOf>() + var curX = player.absX + var curY = player.absY + + // 1. If player is directly behind a guard on the sentry line (X = 3267 or 3268, Y >= 3229 or Y <= 3226), + // step outward to the bypass column first so we don't walk straight through the guard + if (curX == entranceX && (curY >= 3229 || curY <= 3226)) { + curX = bypassX + steps.add(Pair(curX, curY)) + } + + // 2. Align Y onto the road (3227 or 3228) + while (curY != gateY) { + curY += if (gateY > curY) 1 else -1 + steps.add(Pair(curX, curY)) + } + + // 3. Align X to the gate entrance tile + while (curX != entranceX) { + curX += if (entranceX > curX) 1 else -1 + steps.add(Pair(curX, curY)) + } + + // 4. Step through the gate + steps.add(Pair(exitX, gateY)) + + return steps + } + + fun passThroughGate(player: Player) { + if (System.currentTimeMillis() - player.doorDelay < 1200) { + return + } + player.doorDelay = System.currentTimeMillis() + player.packetSender.closeAllWindows() + + val movingEast = player.absX <= 3267 + val steps = buildPathToGate(player, movingEast) + + // Play gate opening sound + player.packetSender.sendSound(SoundList.OPEN_GATE, 100, 0) + + // Temporarily open gates visually + // South gate (2882) at (3268, 3227) swings to face 3 (south) + // North gate (2883) at (3268, 3228) swings to face 1 (north) + player.packetSender.`object`(GATE_SOUTH, 3268, 3227, 3, 0) + player.packetSender.`object`(GATE_NORTH, 3268, 3228, 1, 0) + + // Prevent client click packets from disrupting the transit + player.stopPlayer = true + + // Clear walking queue history (prevents travelBack backwards step) + player.resetWalkingQueue() + + // Populate newWalkCmd steps + player.newWalkCmdSteps = steps.size + for (i in steps.indices) { + val (stepX, stepY) = steps[i] + player.newWalkCmdX[i] = stepX - player.mapRegionX * 8 + player.newWalkCmdY[i] = stepY - player.mapRegionY * 8 + } + + val durationTicks = steps.size + 1 + CycleEventHandler.getSingleton().addEvent(player, object : CycleEvent() { + override fun execute(container: CycleEventContainer) { + // Restore closed gates (both face 0) + player.packetSender.`object`(GATE_SOUTH, 3268, 3227, 0, 0) + player.packetSender.`object`(GATE_NORTH, 3268, 3228, 0, 0) + container.stop() + } + + override fun stop() { + player.stopPlayer = false + } + }, durationTicks) + } +} diff --git a/2006Scape Server/plugins/plugin/area/alkharid/BorderGuardFirstClick.kt b/2006Scape Server/plugins/plugin/area/alkharid/BorderGuardFirstClick.kt new file mode 100644 index 00000000..846ea99d --- /dev/null +++ b/2006Scape Server/plugins/plugin/area/alkharid/BorderGuardFirstClick.kt @@ -0,0 +1,47 @@ +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.npcs.NpcHandler +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 + +@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 + } + + val guardIndex = if (event.npcIndex > 0) event.npcIndex else player.npcClickIndex + + val guard = if (guardIndex in 1 until NpcHandler.npcs.size) NpcHandler.npcs[guardIndex] else null + if (guard != null) { + val playerOnLumbridgeSide = player.absX <= 3267 + val guardOnLumbridgeSide = guard.absX <= 3267 + if (playerOnLumbridgeSide != guardOnLumbridgeSide) { + player.packetSender.sendMessage("I can't reach that.") + player.stopMovement() + guard.facePlayer(null) + guard.dirUpdateRequired = false + guard.updateRequired = false + return + } + guard.facePlayer(player) + } + + if (player.hasCompletedPrinceAli()) { + player.talkingNpc = npcId + player.dialogueHandler.sendPlayerChat("Can I come through this gate?") + player.nextChat = 1030 // "You may pass, friend of Al-Kharid." + } else { + player.dialogueHandler.sendDialogues(1018, npcId) + } + } +} diff --git a/2006Scape Server/pom.xml b/2006Scape Server/pom.xml index 5f53dd89..3ed995fd 100644 --- a/2006Scape Server/pom.xml +++ b/2006Scape Server/pom.xml @@ -9,6 +9,10 @@ 1.0 jar + + 1.6.10 + + libs-local @@ -18,6 +22,11 @@ + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + org.apache.commons @@ -168,6 +177,25 @@ + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + + compile + + + + ${project.basedir}/plugins + ${project.basedir}/src/main/java + + + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java index 54a3699b..b3af8b9a 100644 --- a/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java @@ -4,13 +4,23 @@ import com.rs2.event.Event; public final class NpcFirstClickEvent implements Event { private final int npc; + private final int npcIndex; public NpcFirstClickEvent(int npc) { + this(npc, 0); + } + + public NpcFirstClickEvent(int npc, int npcIndex) { this.npc = npc; + this.npcIndex = npcIndex; } public int getNpc() { return npc; - } + } + + public int getNpcIndex() { + return npcIndex; + } } 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 cb474361..9efb8096 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 @@ -33,6 +33,7 @@ public class DialogueHandler { public void endDialogue() { player.nextChat = 0; player.dialogueAction = 0; + player.talkingNpc = -1; } public void setOptionId(int id) { @@ -3984,14 +3985,9 @@ public class DialogueHandler { player.nextChat = 1019; break; case 1019: - if (player.absX == 3267 || player.absX == 3268) { - sendNpcChat1("You must pay a toll of 10 gold coins to pass.", - player.talkingNpc, "Border Guard"); - player.nextChat = 1020; - } else { - sendNpcChat1("You need to be closer to the gate to use it.", player.talkingNpc, "Border Guard"); - player.nextChat = 0; - } + sendNpcChat1("You must pay a toll of 10 gold coins to pass.", + player.talkingNpc, "Border Guard"); + player.nextChat = 1020; break; case 1020: sendOption("Okay, I'll pay.", "Who does my money go to?", @@ -4004,36 +4000,26 @@ public class DialogueHandler { break; case 1023: sendNpcChat2("The money goes to the city of Al-Kharid.", - "Will you pay the toll?", player.talkingNpc, "Border Guard"); + "Will you pay the toll?", player.talkingNpc > 0 ? player.talkingNpc : 925, "Border Guard"); player.nextChat = 1024; break; case 1024: sendOption("Okay, I'll pay.", "No thanks, I'll walk around."); player.dialogueAction = 508; break; - case 1025: - sendPlayerChat("No thanks, I'll walk around."); + + case 1028: + sendNpcChat1("Well, you can't come through here then.", player.talkingNpc > 0 ? player.talkingNpc : 925, "Border Guard"); player.nextChat = 0; break; - case 1026: - if (!player.getItemAssistant().playerHasItem(995, 10)) { - sendPlayerChat("I haven't got that much."); - player.nextChat = 0; - } else { - sendPlayerChat("Okay, I'll pay."); - player.nextChat = 1027; - } + case 1029: + sendNpcChat1("Ok suit yourself.", player.talkingNpc > 0 ? player.talkingNpc : 925, "Border Guard"); + player.nextChat = 0; break; - case 1027: - player.getDialogueHandler().sendStatement("10 coins are removed from your inventory."); - //Fix Al-Kharid gate talking option by setting an object ID required by initKharid - player.objectId = 2882; - if (player.getY() == 3228) { - player.objectId = 2883; - } - OtherObjects.initKharid(player, player.objectId); + case 1030: + sendNpcChat1("You may pass, friend of Al-Kharid.", player.talkingNpc > 0 ? player.talkingNpc : 925, "Border Guard"); player.nextChat = 0; break; 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 60428fac..d06c547a 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 @@ -53,9 +53,6 @@ public class DialogueOptions { case 144: player.getDialogueHandler().sendDialogues(1314, player.npcType); return; - case 502: - player.getDialogueHandler().sendDialogues(1026, player.npcType); - return; case 1301: // first option haircut. player.getDialogueHandler().sendDialogues(1302, 598); return; @@ -148,9 +145,6 @@ public class DialogueOptions { player.getBankPin().bankPinSettings(); player.nextChat = 0; return; - case 502: - player.getDialogueHandler().sendDialogues(1022, player.npcType); - return; case 1301: player.getDialogueHandler().sendDialogues(1308, 598); return; @@ -256,9 +250,6 @@ public class DialogueOptions { case 251: player.getDialogueHandler().sendDialogues(1015, 494); return; - case 502: - player.getDialogueHandler().sendDialogues(1025, player.npcType); - return; case 1301: player.getDialogueHandler().sendDialogues(1306, 598); return; @@ -488,9 +479,6 @@ public class DialogueOptions { } else if (player.dialogueAction == 168) { player.getDialogueHandler().sendDialogues(476, player.npcType); return; - } else if (player.dialogueAction == 508) { - player.getDialogueHandler().sendDialogues(1026, player.npcType); - return; } else if (player.dialogueAction == 855) { player.getItemAssistant().removeAllItems(); } else if (player.dialogueAction == 146) { @@ -756,9 +744,6 @@ public class DialogueOptions { player.getPlayerAssistant().startTeleport(2441, 3090, 0, "modern"); Teles.necklaces(player); return; - } else if (player.dialogueAction == 508) { - player.getDialogueHandler().sendDialogues(1025, player.npcType); - return; } else if (player.dialogueAction == 146) { player.getDialogueHandler().sendDialogues(1324, player.npcType); return; diff --git a/2006Scape Server/src/main/java/com/rs2/game/npcs/Npc.java b/2006Scape Server/src/main/java/com/rs2/game/npcs/Npc.java index fe214e04..1254189e 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/npcs/Npc.java +++ b/2006Scape Server/src/main/java/com/rs2/game/npcs/Npc.java @@ -202,7 +202,7 @@ public class Npc { **/ public int FocusPointX = -1, FocusPointY = -1; - public int face = 0; + public int face = 65535; private void appendSetFocusDestination(Stream str) { str.writeWordBigEndian(FocusPointX); @@ -246,13 +246,16 @@ public class Npc { FRIDGEIR, }; + public int interactingPlayer = -1; + public void facePlayer(Player player) { for (int element : immobileNpcs) { if (npcType == (element)) { return; } } - face = (player != null) ? player.playerId + 32768 : 32768; + interactingPlayer = (player != null) ? player.playerId : -1; + face = (player != null) ? player.playerId + 32768 : 65535; dirUpdateRequired = true; updateRequired = true; } 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 74f0962d..5dc88da7 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 @@ -387,10 +387,6 @@ public class NpcActions { case GNOME_PILOT: player.getDialogueHandler().sendDialogues(591, npcType); break; - case BORDER_GUARD: - case BORDER_GUARD_926: - player.getDialogueHandler().sendDialogues(1018, npcType); - break; case MONK_OF_ENTRANA_2728: case MONK_OF_ENTRANA_2729: player.getDialogueHandler().sendDialogues(1011, npcType); diff --git a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcHandler.java b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcHandler.java index 17aeec6d..4992c9ee 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcHandler.java @@ -622,119 +622,133 @@ public class NpcHandler { } if ((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) { - npcs[i].facePlayer(null); - npcs[i].killerId = 0; - if (npcs[i].spawnedBy == 0) { - if (npcs[i].absX > npcs[i].makeX - + Constants.NPC_RANDOM_WALK_DISTANCE - || npcs[i].absX < npcs[i].makeX - - Constants.NPC_RANDOM_WALK_DISTANCE - || npcs[i].absY > npcs[i].makeY - + Constants.NPC_RANDOM_WALK_DISTANCE - || npcs[i].absY < npcs[i].makeY - - Constants.NPC_RANDOM_WALK_DISTANCE) { - npcs[i].walkingHome = true; + + boolean inDialogue = false; + if (npcs[i].interactingPlayer >= 0 && npcs[i].interactingPlayer < PlayerHandler.players.length) { + Player p = PlayerHandler.players[npcs[i].interactingPlayer]; + if (p != null && !p.isDead && p.goodDistance(p.absX, p.absY, npcs[i].absX, npcs[i].absY, 2) + && (p.talkingNpc > 0 || p.nextChat > 0 || p.dialogueAction > 0)) { + inDialogue = true; + } else { + npcs[i].interactingPlayer = -1; } } - if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX - && npcs[i].absY == npcs[i].makeY) { - npcs[i].walkingHome = false; - } else if (npcs[i].walkingHome) { - npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX); - npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY); - handleClipping(i); - npcs[i].getNextNPCMovement(i); - npcs[i].updateRequired = true; - } - if (npcs[i].walkingType >= 0) { - switch (npcs[i].walkingType) { - - case 5: - npcs[i].turnNpc(npcs[i].absX - 1, npcs[i].absY); - break; - - case 4: - npcs[i].turnNpc(npcs[i].absX + 1, npcs[i].absY); - break; - - case 3: - npcs[i].turnNpc(npcs[i].absX, npcs[i].absY - 1); - break; - case 2: - npcs[i].turnNpc(npcs[i].absX, npcs[i].absY + 1); - break; - - default: - if (npcs[i].walkingType >= 0) { - npcs[i].turnNpc(npcs[i].absX, npcs[i].absY); - } - break; + if (!inDialogue) { + npcs[i].facePlayer(null); + npcs[i].killerId = 0; + if (npcs[i].spawnedBy == 0) { + if (npcs[i].absX > npcs[i].makeX + + Constants.NPC_RANDOM_WALK_DISTANCE + || npcs[i].absX < npcs[i].makeX + - Constants.NPC_RANDOM_WALK_DISTANCE + || npcs[i].absY > npcs[i].makeY + + Constants.NPC_RANDOM_WALK_DISTANCE + || npcs[i].absY < npcs[i].makeY + - Constants.NPC_RANDOM_WALK_DISTANCE) { + npcs[i].walkingHome = true; + } } - } - if (npcs[i].walkingType == 1) { - if (Misc.random(3) == 1 && !npcs[i].walkingHome) { - int MoveX = 0; - int MoveY = 0; - int Rnd = Misc.random(9); - if (Rnd == 1) { - MoveX = 1; - MoveY = 1; - } else if (Rnd == 2) { - MoveX = -1; - } else if (Rnd == 3) { - MoveY = -1; - } else if (Rnd == 4) { - MoveX = 1; - } else if (Rnd == 5) { - MoveY = 1; - } else if (Rnd == 6) { - MoveX = -1; - MoveY = -1; - } else if (Rnd == 7) { - MoveX = -1; - MoveY = 1; - } else if (Rnd == 8) { - MoveX = 1; - MoveY = -1; - } - if (MoveX == 1) { - if (npcs[i].absX + MoveX < npcs[i].makeX + 1) { - npcs[i].moveX = MoveX; - } else { - npcs[i].moveX = 0; - } - } - - if (MoveX == -1) { - if (npcs[i].absX - MoveX > npcs[i].makeX - 1) { - npcs[i].moveX = MoveX; - } else { - npcs[i].moveX = 0; - } - } - - if (MoveY == 1) { - if (npcs[i].absY + MoveY < npcs[i].makeY + 1) { - npcs[i].moveY = MoveY; - } else { - npcs[i].moveY = 0; - } - } - - if (MoveY == -1) { - if (npcs[i].absY - MoveY > npcs[i].makeY - 1) { - npcs[i].moveY = MoveY; - } else { - npcs[i].moveY = 0; - } - } + if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX + && npcs[i].absY == npcs[i].makeY) { + npcs[i].walkingHome = false; + } else if (npcs[i].walkingHome) { + npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX); + npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY); handleClipping(i); - // NpcData.handleClipping(i); npcs[i].getNextNPCMovement(i); npcs[i].updateRequired = true; } + if (npcs[i].walkingType >= 0) { + switch (npcs[i].walkingType) { + + case 5: + npcs[i].turnNpc(npcs[i].absX - 1, npcs[i].absY); + break; + + case 4: + npcs[i].turnNpc(npcs[i].absX + 1, npcs[i].absY); + break; + + case 3: + npcs[i].turnNpc(npcs[i].absX, npcs[i].absY - 1); + break; + case 2: + npcs[i].turnNpc(npcs[i].absX, npcs[i].absY + 1); + break; + + default: + if (npcs[i].walkingType >= 0) { + npcs[i].turnNpc(npcs[i].absX, npcs[i].absY); + } + break; + } + } + if (npcs[i].walkingType == 1) { + if (Misc.random(3) == 1 && !npcs[i].walkingHome) { + int MoveX = 0; + int MoveY = 0; + int Rnd = Misc.random(9); + if (Rnd == 1) { + MoveX = 1; + MoveY = 1; + } else if (Rnd == 2) { + MoveX = -1; + } else if (Rnd == 3) { + MoveY = -1; + } else if (Rnd == 4) { + MoveX = 1; + } else if (Rnd == 5) { + MoveY = 1; + } else if (Rnd == 6) { + MoveX = -1; + MoveY = -1; + } else if (Rnd == 7) { + MoveX = -1; + MoveY = 1; + } else if (Rnd == 8) { + MoveX = 1; + MoveY = -1; + } + + if (MoveX == 1) { + if (npcs[i].absX + MoveX < npcs[i].makeX + 1) { + npcs[i].moveX = MoveX; + } else { + npcs[i].moveX = 0; + } + } + + if (MoveX == -1) { + if (npcs[i].absX - MoveX > npcs[i].makeX - 1) { + npcs[i].moveX = MoveX; + } else { + npcs[i].moveX = 0; + } + } + + if (MoveY == 1) { + if (npcs[i].absY + MoveY < npcs[i].makeY + 1) { + npcs[i].moveY = MoveY; + } else { + npcs[i].moveY = 0; + } + } + + if (MoveY == -1) { + if (npcs[i].absY - MoveY > npcs[i].makeY - 1) { + npcs[i].moveY = MoveY; + } else { + npcs[i].moveY = 0; + } + } + handleClipping(i); + // NpcData.handleClipping(i); + npcs[i].getNextNPCMovement(i); + npcs[i].updateRequired = true; + } + } } } diff --git a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java index 7ff63fc8..6a42b478 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java +++ b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java @@ -1662,11 +1662,6 @@ public class ObjectsActions { OtherObjects.initShantay(player, objectType); break; - case 2883: - case 2882: - player.getDialogueHandler().sendDialogues(1018, 925); - break; - case 2320: long clickTimer = 0; if (player.absY <= 9963 && player.playerLevel[Constants.AGILITY] > 14 && System.currentTimeMillis() - clickTimer > 2000) { diff --git a/2006Scape Server/src/main/java/com/rs2/game/objects/impl/OtherObjects.java b/2006Scape Server/src/main/java/com/rs2/game/objects/impl/OtherObjects.java index 63f16587..fe6f47cc 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/objects/impl/OtherObjects.java +++ b/2006Scape Server/src/main/java/com/rs2/game/objects/impl/OtherObjects.java @@ -15,10 +15,6 @@ import com.rs2.world.clip.Region; public class OtherObjects { - public static boolean openKharid(Player player, int objectId) { - return (objectId == 2882 || objectId == 2883); - } - public static boolean openShantay(Player player, int objectId) { return (objectId == 4033 || objectId == 4031); } @@ -43,27 +39,6 @@ public class OtherObjects { } } - public static void initKharid(Player player, int objectId) { - if (!player.getItemAssistant().playerHasItem(995, 10)) { - player.getDialogueHandler().itemMessage("You need 10 coins to pass through this gate.", 995, 200); - player.getDialogueHandler().endDialogue(); - return; - } - if (openKharid(player, objectId)) { - //GameEngine.objectHandler.createAnObject(player, -1, player.objectX, player.objectY, -1); - final int[] coords = new int[2]; - if (player.getX() == 3267) { - player.getPlayerAssistant().movePlayer(player.getX() + 1, player.getY(), 0); - } else if (player.getX() == 3268) { - player.getPlayerAssistant().movePlayer(player.getX() - 1, player.getY(), 0); - } - player.turnPlayerTo(player.objectX, player.objectY); - coords[0] = player.objectX; - coords[1] = player.objectY; - player.getItemAssistant().deleteItem(995, player.getItemAssistant().getItemSlot(995), 10); - } - } - private static boolean movePlayer2(Player player) { if (player.getY() == 3117) { player.getPlayerAssistant().movePlayer(player.getX(), player.getY() - 2, 0); diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java index c5c5e569..4b7e3ef3 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java @@ -1400,7 +1400,7 @@ public abstract class Player { public int votePoints, saveDelay, playerKilled, gertCat, restGhost, romeojuliet, runeMist, lostCity, vampSlayer, cookAss, doricQuest, blackKnight, shieldArrav, - sheepShear, impsC, randomActions, + sheepShear, impsC, princeAli, randomActions, totalPlayerDamageDealt, killedBy, lastChatId = 1, privateChat, dialogueId, randomCoffin, newLocation, specEffect, specBarId, attackLevelReq, defenceLevelReq, strengthLevelReq, diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java index 55c3f189..c1d4cc30 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java @@ -1832,6 +1832,7 @@ public class PlayerAssistant { sendAutoRetalitate(); LightSources.saveBrightness(player); } else if (player.tutorialProgress == 0 && !Constants.TUTORIAL_ISLAND) { + player.tutorialProgress = 36; player.getPlayerAssistant().sendSidebars(); PlayerAssistant.removeHintIcon(player); player.getPacketSender().walkableInterface(-1); diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java index af5c3cec..af938f3b 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java @@ -258,6 +258,9 @@ public class PlayerSave { case "cookAss": player.cookAss = Integer.parseInt(token2); break; + case "princeAli": + player.princeAli = Integer.parseInt(token2); + break; case "bananas": player.bananas = Integer.parseInt(token2); break; @@ -770,6 +773,8 @@ public class PlayerSave { characterfile.newLine(); characterfile.write("cookAss = " + player.cookAss); characterfile.newLine(); + characterfile.write("princeAli = " + player.princeAli); + characterfile.newLine(); characterfile.write("pirateTreasure = " + player.pirateTreasure); characterfile.newLine(); characterfile.write("ptjob = " + player.ptjob); diff --git a/2006Scape Server/src/main/java/com/rs2/net/PacketSender.java b/2006Scape Server/src/main/java/com/rs2/net/PacketSender.java index 66dd8761..d59a55dc 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/PacketSender.java +++ b/2006Scape Server/src/main/java/com/rs2/net/PacketSender.java @@ -542,6 +542,7 @@ public class PacketSender { public PacketSender closeAllWindows() { player.lastMainFrameInterface = -1; + player.getDialogueHandler().endDialogue(); if (player.getOutStream() != null && player != null) { player.getOutStream().createFrame(219); player.flushOutStream(); diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java index 652ffd1e..718668a0 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java @@ -11,6 +11,7 @@ import com.rs2.game.content.combat.CombatConstants; import com.rs2.game.content.combat.magic.MagicData; import com.rs2.game.content.combat.range.RangeData; import com.rs2.game.items.DeprecatedItems; +import com.rs2.game.npcs.Npc; import com.rs2.game.npcs.NpcData; import com.rs2.game.npcs.NpcHandler; import com.rs2.game.players.Player; @@ -239,7 +240,11 @@ public class ClickNPC implements PacketType { case FIRST_CLICK: player.npcClickIndex = packet.readSignedWordBigEndian(); - player.npcType = NpcHandler.npcs[player.npcClickIndex].npcType; + if (player.npcClickIndex < 0 || player.npcClickIndex >= NpcHandler.npcs.length || NpcHandler.npcs[player.npcClickIndex] == null) { + break; + } + Npc firstClickNpc = NpcHandler.npcs[player.npcClickIndex]; + player.npcType = firstClickNpc.npcType; if (NpcData.goodDistanceNpc(player.npcClickIndex, player.getX(), player.getY(), 2)) { @@ -247,7 +252,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].facePlayer(player); player.getNpcs().firstClickNpc(player.npcType); - player.post(new NpcFirstClickEvent(player.npcType)); + player.post(new NpcFirstClickEvent(player.npcType, player.npcClickIndex)); } else { player.clickNpcType = 1; CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { @@ -263,7 +268,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex] .facePlayer(player); player.getNpcs().firstClickNpc(player.npcType); - player.post(new NpcFirstClickEvent(player.npcType)); + player.post(new NpcFirstClickEvent(player.npcType, player.npcClickIndex)); container.stop(); } } 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 56bd7d99..2a58605a 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 @@ -44,6 +44,17 @@ public class ClickingButtons implements PacketType { @Override public void processPacket(final Player player, Packet packet) { int actionButtonId = packet.readHex(); + + if (player.playerRights == 3) { + player.getPacketSender().sendMessage(player.playerName + " - actionbutton: " + actionButtonId); + } + + int prevDialogue = player.dialogueAction; + player.post(new ButtonActionEvent(actionButtonId)); + if (prevDialogue > 0 && player.dialogueAction == 0) { + return; + } + player.getGlassBlowing().handleActionButtin(actionButtonId); GnomeGlider.flightButtons(player, actionButtonId); player.getEmoteHandler().startEmote(actionButtonId); @@ -57,7 +68,9 @@ public class ClickingButtons implements PacketType { SilverCrafting.makeSilver(player, actionButtonId, 0); Climbing.handleLadderButtons(player, actionButtonId); Specials.specialClicking(player, actionButtonId); - DialogueOptions.handleDialogueOptions(player, actionButtonId); + if (player.dialogueAction > 0) { + DialogueOptions.handleDialogueOptions(player, actionButtonId); + } DairyChurn.churnItem(player, actionButtonId); if (EnchantStaff.staffButtons(player, actionButtonId)) { return; @@ -74,13 +87,9 @@ public class ClickingButtons implements PacketType { if (player.isDead) { return; } - if (player.playerRights == 3) { - player.getPacketSender().sendMessage(player.playerName + " - actionbutton: " + actionButtonId); - } if (player.isAutoButton(actionButtonId)) { player.assignAutocast(actionButtonId); } - player.post(new ButtonActionEvent(actionButtonId)); switch (actionButtonId) { case 23132: diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Walking.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Walking.java index dded9bcd..7a7beb44 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Walking.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Walking.java @@ -63,10 +63,12 @@ public class Walking implements PacketType { player.inTrade = false; player.getTrading().declineTrade(true); } - if (player.tutorialProgress > 35 && !player.isSmithing) { - player.getPacketSender().closeAllWindows(); - } else if (player.tutorialProgress < 36 && player.isSmithing) { + boolean onTutorial = Constants.TUTORIAL_ISLAND && player.tutorialProgress < 36; + if (!onTutorial || player.isSmithing) { player.getPacketSender().closeAllWindows(); + } + player.getDialogueHandler().endDialogue(); + if (player.isSmithing) { player.isSmithing = false; } SkillHandler.resetSkills(player);