From 0cd17c7932944df64773742f4ea57bc98f00ffa1 Mon Sep 17 00:00:00 2001 From: Kris Date: Sat, 14 Sep 2024 20:18:27 +0300 Subject: [PATCH] feat: add helper functions to get the indices of high resolution npcs This allows servers which relied on high resolution indices for mechanics such as aggression/hunt to continue using their old methods. --- .../game/outgoing/info/npcinfo/NpcInfo.kt | 29 ++++++ .../game/outgoing/info/npcinfo/NpcInfo.kt | 94 +++++++++++++++++++ .../game/outgoing/info/npcinfo/NpcInfo.kt | 94 +++++++++++++++++++ .../game/outgoing/info/npcinfo/NpcInfo.kt | 94 +++++++++++++++++++ .../game/outgoing/info/npcinfo/NpcInfo.kt | 94 +++++++++++++++++++ 5 files changed, 405 insertions(+) diff --git a/protocol/osrs-221/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/info/npcinfo/NpcInfo.kt b/protocol/osrs-221/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/info/npcinfo/NpcInfo.kt index 2f3711029..9b6e47c77 100644 --- a/protocol/osrs-221/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/info/npcinfo/NpcInfo.kt +++ b/protocol/osrs-221/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/info/npcinfo/NpcInfo.kt @@ -172,6 +172,35 @@ public class NpcInfo internal constructor( this.viewDistance = MAX_SMALL_PACKET_DISTANCE } + /** + * Gets the high resolution indices in a new arraylist of integers. + * The list is initialized to an initial capacity equal to the high resolution npc index count. + * @return the newly created arraylist of indices + */ + public fun getHighResolutionIndices(): ArrayList { + val collection = ArrayList(highResolutionNpcIndexCount) + for (i in 0.. appendHighResolutionIndices(collection: T): T where T : MutableCollection { + for (i in 0.. { + val details = getDetails(worldId) + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0..? { + val details = getDetailsOrNull(worldId) ?: return null + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0.. appendHighResolutionIndices( + worldId: Int, + collection: T, + throwExceptionIfNoWorld: Boolean = true, + ): T where T : MutableCollection { + val details = + if (throwExceptionIfNoWorld) { + getDetails(worldId) + } else { + getDetailsOrNull(worldId) ?: return collection + } + for (i in 0.. { + val details = getDetails(worldId) + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0..? { + val details = getDetailsOrNull(worldId) ?: return null + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0.. appendHighResolutionIndices( + worldId: Int, + collection: T, + throwExceptionIfNoWorld: Boolean = true, + ): T where T : MutableCollection { + val details = + if (throwExceptionIfNoWorld) { + getDetails(worldId) + } else { + getDetailsOrNull(worldId) ?: return collection + } + for (i in 0.. { + val details = getDetails(worldId) + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0..? { + val details = getDetailsOrNull(worldId) ?: return null + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0.. appendHighResolutionIndices( + worldId: Int, + collection: T, + throwExceptionIfNoWorld: Boolean = true, + ): T where T : MutableCollection { + val details = + if (throwExceptionIfNoWorld) { + getDetails(worldId) + } else { + getDetailsOrNull(worldId) ?: return collection + } + for (i in 0.. { + val details = getDetails(worldId) + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0..? { + val details = getDetailsOrNull(worldId) ?: return null + val collection = ArrayList(details.highResolutionNpcIndexCount) + for (i in 0.. appendHighResolutionIndices( + worldId: Int, + collection: T, + throwExceptionIfNoWorld: Boolean = true, + ): T where T : MutableCollection { + val details = + if (throwExceptionIfNoWorld) { + getDetails(worldId) + } else { + getDetailsOrNull(worldId) ?: return collection + } + for (i in 0..