package plugin.buttons.combat import com.rs2.Constants 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.content.combat.magic.MagicData import com.rs2.game.players.Player @SubscribesTo(ButtonActionEvent::class) class AutocastSpellSelectPlugin : EventSubscriber { override fun test(event: ButtonActionEvent) = SPELL_BY_BUTTON.containsKey(event.button) override fun subscribe(context: EventContext, player: Player, event: ButtonActionEvent) { if (player.isDead) return val spellIndex = SPELL_BY_BUTTON.getValue(event.button) val weapon = player.playerEquipment[player.playerWeapon] if (spellIndex in 32..47) { if (player.playerMagicBook != 1 || weapon != ANCIENT_STAFF) { player.packetSender.sendMessage("You can't autocast ancients without an ancient staff.") return } } else { if (player.playerMagicBook != 0) { return } if ((spellIndex == 27 || spellIndex == 25) && weapon != SLAYERS_STAFF) { return } } val requiredLevel = MagicData.MAGIC_SPELLS[spellIndex][1] if (player.playerLevel[Constants.MAGIC] < requiredLevel) { player.packetSender.sendMessage("You need a Magic level of $requiredLevel to cast this spell.") return } player.autocasting = true player.autocastId = spellIndex player.packetSender.sendConfig(108, 3) player.packetSender.sendConfig(43, -1) player.packetSender.setSidebarInterface(0, 328) player.packetSender.sendString(MagicData.getSpellName(spellIndex), 352, true) } private companion object { const val ANCIENT_STAFF = 4675 const val SLAYERS_STAFF = 4170 val SPELL_BY_BUTTON = mapOf( // Interface 1829 (Modern Combat Spells) 1830 to 0, 1831 to 1, 1832 to 2, 1833 to 3, 1834 to 4, 1835 to 5, 1836 to 6, 1837 to 7, 1838 to 8, 1839 to 9, 1840 to 10, 1841 to 11, 1842 to 12, 1843 to 13, 1844 to 14, 1845 to 15, // Interface 1689 (Ancient Magicks) 13189 to 32, 13241 to 33, 13147 to 34, 6162 to 35, 13215 to 36, 13267 to 37, 13167 to 38, 13125 to 39, 13202 to 40, 13254 to 41, 13158 to 42, 13114 to 43, 13228 to 44, 13280 to 45, 13178 to 46, 13136 to 47, // Interface 12050 (Slayer Staff) 12052 to 27, 12056 to 25, 12051 to 12, 12053 to 13, 12054 to 14, 12055 to 15, // Legacy / Custom Interface Fallback IDs 7038 to 0, 7039 to 1, 7040 to 2, 7041 to 3, 7042 to 4, 7043 to 5, 7044 to 6, 7045 to 7, 7046 to 8, 7047 to 9, 7048 to 10, 7049 to 11, 7050 to 12, 7051 to 13, 7052 to 14, 7053 to 15, 51133 to 32, 51185 to 33, 51091 to 34, 24018 to 35, 51159 to 36, 51211 to 37, 51111 to 38, 51069 to 39, 51146 to 40, 51198 to 41, 51102 to 42, 51058 to 43, 51172 to 44, 51224 to 45, 51122 to 46, 51080 to 47, 47019 to 27, 47020 to 25, 47021 to 12, 47022 to 13, 47023 to 14, 47024 to 15 ) } }