From 60f32629c2639ea1875b474766081f885a9f4efd Mon Sep 17 00:00:00 2001 From: ceikry Date: Fri, 2 Jul 2021 10:24:37 -0500 Subject: [PATCH] Fixed an exploit related to magic. --- .../combat/equipment/WeaponInterface.java | 1 + .../node/entity/combat/CombatSwingHandler.kt | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/core/game/node/entity/combat/equipment/WeaponInterface.java b/Server/src/main/java/core/game/node/entity/combat/equipment/WeaponInterface.java index a969f72be..78c7bdf86 100644 --- a/Server/src/main/java/core/game/node/entity/combat/equipment/WeaponInterface.java +++ b/Server/src/main/java/core/game/node/entity/combat/equipment/WeaponInterface.java @@ -464,6 +464,7 @@ public final class WeaponInterface extends Component { Component component = new Component(id); component.getDefinition().setTabIndex(0); component.getDefinition().setType(InterfaceType.TAB); + player.setAttribute("autocast_component",component); player.getInterfaceManager().openTab(component); } diff --git a/Server/src/main/kotlin/rs09/game/node/entity/combat/CombatSwingHandler.kt b/Server/src/main/kotlin/rs09/game/node/entity/combat/CombatSwingHandler.kt index 1b1d5edd9..146453e8d 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/combat/CombatSwingHandler.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/combat/CombatSwingHandler.kt @@ -1,5 +1,6 @@ package rs09.game.node.entity.combat +import core.game.component.Component import core.game.container.Container import core.game.container.impl.EquipmentContainer import core.game.node.Node @@ -7,8 +8,7 @@ import core.game.node.entity.Entity import core.game.node.entity.combat.BattleState import core.game.node.entity.combat.CombatStyle import core.game.node.entity.combat.InteractionType -import core.game.node.entity.combat.equipment.ArmourSet -import core.game.node.entity.combat.equipment.DegradableEquipment +import core.game.node.entity.combat.equipment.* import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.entity.player.link.audio.Audio @@ -219,6 +219,20 @@ abstract class CombatSwingHandler(var type: CombatStyle?) { * @return `True` if so. */ open fun isAttackable(entity: Entity, victim: Entity): InteractionType? { + val comp = entity.getAttribute("autocast_component",null) as Component? + if((comp != null || type == CombatStyle.MAGIC) && (entity.properties.autocastSpell == null || entity.properties.autocastSpell.spellId == 0) && entity is Player){ + val weapEx = entity.getExtension(WeaponInterface::class.java) as WeaponInterface? + if(comp != null){ + entity.interfaceManager.close(comp) + entity.interfaceManager.openTab(weapEx) + entity.properties.combatPulse.stop() + entity.attack(victim) + entity.removeAttribute("autocast_component") + } + weapEx?.setAttackStyle(1) + weapEx?.updateInterface() + entity.debug("Adjusting attack style") + } if (entity.location == victim.location) { return if (entity.index < victim.index && victim.properties.combatPulse.getVictim() === entity) { InteractionType.STILL_INTERACT