From e5915846fafd591b917f47dca6a58324bf3815e3 Mon Sep 17 00:00:00 2001
From: DGamerL <108773801+DGamerL@users.noreply.github.com>
Date: Mon, 8 Jul 2024 15:03:32 +0200
Subject: [PATCH] Changes energy sword sharpening to use signals (#26157)
* We love signals in this household
* This isn't needed
* Coconut review
* Update code/game/objects/items/weapons/melee/energy_melee_weapons.dm
Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
* Adds handler
---------
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
---
.../items/weapons/melee/energy_melee_weapons.dm | 14 ++++++++++++++
code/game/objects/items/weapons/whetstone.dm | 11 +----------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/code/game/objects/items/weapons/melee/energy_melee_weapons.dm b/code/game/objects/items/weapons/melee/energy_melee_weapons.dm
index e047ea965b6..811a2f58c21 100644
--- a/code/game/objects/items/weapons/melee/energy_melee_weapons.dm
+++ b/code/game/objects/items/weapons/melee/energy_melee_weapons.dm
@@ -26,6 +26,11 @@
. = ..()
force_off = initial(force) //We want to check this only when initializing, not when swapping, so sharpening works.
throwforce_off = initial(throwforce)
+ RegisterSignal(src, COMSIG_ITEM_SHARPEN_ACT, PROC_REF(try_sharpen))
+
+/obj/item/melee/energy/Destroy()
+ UnregisterSignal(src, COMSIG_ITEM_SHARPEN_ACT)
+ return ..()
/obj/item/melee/energy/attack(mob/living/target, mob/living/carbon/human/user)
var/nemesis_faction = FALSE
@@ -88,6 +93,15 @@
/obj/item/melee/energy/get_heat()
return active * 3500
+/obj/item/melee/energy/proc/try_sharpen(obj/item/item, amount, max_amount)
+ SIGNAL_HANDLER // COMSIG_ITEM_SHARPEN_ACT
+ if(force_on > initial(force_on) || force_on >= max_amount)
+ return COMPONENT_BLOCK_SHARPEN_MAXED
+ throwforce_on = clamp(throwforce_on + amount, 0, max_amount)
+ throwforce_off = clamp(throwforce_off + amount, 0, max_amount)
+ force_on = clamp(force_on + amount, 0, max_amount)
+ force_off = clamp(force_off + amount, 0, max_amount)
+
/obj/item/melee/energy/axe
name = "energy axe"
desc = "An energised battle axe."
diff --git a/code/game/objects/items/weapons/whetstone.dm b/code/game/objects/items/weapons/whetstone.dm
index c4b7f7a6e5b..7c21ddda9c8 100644
--- a/code/game/objects/items/weapons/whetstone.dm
+++ b/code/game/objects/items/weapons/whetstone.dm
@@ -31,15 +31,6 @@
if((signal_out & COMPONENT_BLOCK_SHARPEN_ALREADY) || (I.force > initial(I.force) && !(signal_out & COMPONENT_SHARPEN_APPLIED))) //No sharpening stuff twice
to_chat(user, "[I] has already been refined before. It cannot be sharpened further!")
return
- if(istype(I, /obj/item/melee/energy))
- var/obj/item/melee/energy/E = I
- if(E.force_on > initial(E.force_on))
- to_chat(user, "[E] is much too powerful to sharpen further!")
- return
- E.throwforce_on = clamp(E.throwforce_on + increment, 0, max)
- E.throwforce_off = clamp(E.throwforce_off + increment, 0, max)
- E.force_on = clamp(E.force_on + increment, 0, max)
- E.force_off = clamp(E.force_off + increment, 0, max)
if(!(signal_out & COMPONENT_SHARPEN_APPLIED)) //If the item has a relevant component and COMPONENT_BLOCK_SHARPEN_APPLIED is returned, the item only gets the throw force increase
I.force = clamp(I.force + increment, 0, max)
@@ -49,7 +40,7 @@
set_sharpness(TRUE)
I.throwforce = clamp(I.throwforce + increment, 0, max)
I.name = "[prefix] [I.name]"
- playsound(get_turf(src), usesound, 50, 1)
+ playsound(get_turf(src), usesound, 50, TRUE)
name = "worn out [name]"
desc = "[desc] At least, it used to."
used = TRUE