From 9fdbc1b6e984e957c9d893a1c5c3263bfa2cedc7 Mon Sep 17 00:00:00 2001 From: Doubleumc Date: Mon, 13 Nov 2023 04:37:32 -0500 Subject: [PATCH] buffs are now SIGNALS, work with holders --- code/modules/vehicles/hardpoints/hardpoint.dm | 15 +++++++++------ .../vehicles/hardpoints/holder/holder.dm | 19 +++++++++++++++---- .../multitile/multitile_hardpoints.dm | 6 ------ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/code/modules/vehicles/hardpoints/hardpoint.dm b/code/modules/vehicles/hardpoints/hardpoint.dm index d9ca5bd38a..acdefca18f 100644 --- a/code/modules/vehicles/hardpoints/hardpoint.dm +++ b/code/modules/vehicles/hardpoints/hardpoint.dm @@ -193,15 +193,18 @@ /// Apply hardpoint effects to vehicle and self. /obj/item/hardpoint/proc/on_install(obj/vehicle/multitile/vehicle) + if(!vehicle) //in loose holder + return + RegisterSignal(vehicle, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES, PROC_REF(recalculate_hardpoint_bonuses)) apply_buff(vehicle) - recalculate_hardpoint_bonuses() - return /// Remove hardpoint effects from vehicle and self. /obj/item/hardpoint/proc/on_uninstall(obj/vehicle/multitile/vehicle) + if(!vehicle) //in loose holder + return + UnregisterSignal(vehicle, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES) remove_buff(vehicle) - recalculate_hardpoint_bonuses() - return + //resetting values like set_gun_config_values() would be tidy, but unnecessary as it gets recalc'd on install anyway /// Applying passive buffs like damage type resistance, speed, accuracy, cooldowns. /obj/item/hardpoint/proc/apply_buff(obj/vehicle/multitile/vehicle) @@ -214,7 +217,7 @@ for(var/type in buff_multipliers) vehicle.misc_multipliers[type] *= LAZYACCESS(buff_multipliers, type) buff_applied = TRUE - vehicle.on_modifiers_change() + SEND_SIGNAL(vehicle, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES) /// Removing passive buffs like damage type resistance, speed, accuracy, cooldowns. /obj/item/hardpoint/proc/remove_buff(obj/vehicle/multitile/vehicle) @@ -227,7 +230,7 @@ for(var/type in buff_multipliers) vehicle.misc_multipliers[type] *= 1 / LAZYACCESS(buff_multipliers, type) buff_applied = FALSE - vehicle.on_modifiers_change() + SEND_SIGNAL(vehicle, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES) /// Recalculates hardpoint values based on vehicle modifiers. /obj/item/hardpoint/proc/recalculate_hardpoint_bonuses() diff --git a/code/modules/vehicles/hardpoints/holder/holder.dm b/code/modules/vehicles/hardpoints/holder/holder.dm index 619bb649f5..fc8e849d10 100644 --- a/code/modules/vehicles/hardpoints/holder/holder.dm +++ b/code/modules/vehicles/hardpoints/holder/holder.dm @@ -43,10 +43,21 @@ for(var/obj/item/hardpoint/H in hardpoints) H.take_damage(damage) -/obj/item/hardpoint/holder/on_install(obj/vehicle/multitile/V) - for(var/obj/item/hardpoint/HP in hardpoints) - HP.owner = V - return +/obj/item/hardpoint/holder/on_install(obj/vehicle/multitile/vehicle) + ..() + if(!vehicle) //in loose holder + return + for(var/obj/item/hardpoint/hardpoint in hardpoints) + hardpoint.owner = vehicle + hardpoint.on_install(vehicle) + +/obj/item/hardpoint/holder/on_uninstall(obj/vehicle/multitile/vehicle) + if(!vehicle) //in loose holder + return + for(var/obj/item/hardpoint/hardpoint in hardpoints) + hardpoint.on_uninstall(vehicle) + hardpoint.owner = null + ..() /obj/item/hardpoint/holder/proc/can_install(obj/item/hardpoint/H) // Can only have 1 hardpoint of each slot type diff --git a/code/modules/vehicles/multitile/multitile_hardpoints.dm b/code/modules/vehicles/multitile/multitile_hardpoints.dm index ca03ec6dfd..a6014c6cf2 100644 --- a/code/modules/vehicles/multitile/multitile_hardpoints.dm +++ b/code/modules/vehicles/multitile/multitile_hardpoints.dm @@ -230,9 +230,3 @@ qdel(old) update_icon() - -/// Trigger vehicle hardpoints to update values based on new modifiers. -/obj/vehicle/multitile/proc/on_modifiers_change() //should this be a signal? - var/list/hardpoints = get_hardpoints_copy() //could be more selective with get_hardpoints_with_ammo(), as only autofire weapons need it - for(var/obj/item/hardpoint/hardpoint in hardpoints) - hardpoint.recalculate_hardpoint_bonuses()