From 3c8b666b352b0e64b27dd381d1d68e7f0fa1ce57 Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Thu, 9 Jun 2022 23:34:24 -0500 Subject: [PATCH] Refactors Gunlight / Helmetlight to be a component (#67517) Atomized from the proc holder PR Refactors gunlight / helmet light to be a component. They just copy+pasted code between each other and it was really annoying. I was working on fixes for the proc holder PR and noticed this (had to make the same fix for two things). Moved Mind Monkey Helmet to its own file Balloon alerts for seclite attachment / removal One may be able to genericize this even further and put the bayonet behavior on this as well. Future idea. Why It's Good For The Game Cleaner, less copy pasted code. Changelog cl Melbert refactor: Gunlight / Helmetlight behavior is now a component. qol: Gunlight / Helmetlight now uses balloon alerts. /cl --- code/__DEFINES/dcs/signals/signals_object.dm | 6 + code/datums/action.dm | 3 + code/datums/components/seclight_attachable.dm | 295 ++++++++++++++++ code/game/objects/items.dm | 3 + code/modules/clothing/head/helmet.dm | 322 +++--------------- .../clothing/head/mind_monkey_helmet.dm | 109 ++++++ .../mob/living/carbon/human/monkey/monkey.dm | 9 +- code/modules/projectiles/gun.dm | 143 +------- code/modules/projectiles/guns/energy.dm | 9 +- .../projectiles/guns/energy/energy_gun.dm | 34 +- .../guns/energy/kinetic_accelerator.dm | 10 +- code/modules/projectiles/guns/energy/laser.dm | 12 +- .../projectiles/guns/energy/mounted.dm | 8 +- code/modules/projectiles/guns/energy/pulse.dm | 10 +- .../projectiles/guns/energy/special.dm | 17 +- code/modules/projectiles/guns/energy/stun.dm | 14 +- tgstation.dme | 2 + 17 files changed, 563 insertions(+), 443 deletions(-) create mode 100644 code/datums/components/seclight_attachable.dm create mode 100644 code/modules/clothing/head/mind_monkey_helmet.dm diff --git a/code/__DEFINES/dcs/signals/signals_object.dm b/code/__DEFINES/dcs/signals/signals_object.dm index eb95a016d78..f9b34717406 100644 --- a/code/__DEFINES/dcs/signals/signals_object.dm +++ b/code/__DEFINES/dcs/signals/signals_object.dm @@ -116,6 +116,12 @@ #define COMSIG_ITEM_DROPPED "item_drop" ///from base of obj/item/pickup(): (/mob/taker) #define COMSIG_ITEM_PICKUP "item_pickup" + +/// Sebt from obj/item/ui_action_click(): (mob/user, datum/action) +#define COMSIG_ITEM_UI_ACTION_CLICK "item_action_click" + /// Return to prevent the default behavior (attack_selfing) from ocurring. + #define COMPONENT_ACTION_HANDLED (1<<0) + ///from base of mob/living/carbon/attacked_by(): (mob/living/carbon/target, mob/living/user, hit_zone) #define COMSIG_ITEM_ATTACK_ZONE "item_attack_zone" ///from base of obj/item/hit_reaction(): (list/args) diff --git a/code/datums/action.dm b/code/datums/action.dm index d56c2371782..85899857516 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -436,6 +436,9 @@ /datum/action/item_action/toggle_helmet name = "Toggle Helmet" +/datum/action/item_action/toggle_seclight + name = "Toggle Seclight" + /datum/action/item_action/toggle_jetpack name = "Toggle Jetpack" diff --git a/code/datums/components/seclight_attachable.dm b/code/datums/components/seclight_attachable.dm new file mode 100644 index 00000000000..ec408401a5c --- /dev/null +++ b/code/datums/components/seclight_attachable.dm @@ -0,0 +1,295 @@ +/** + * Component which allows you to attach a seclight to an item, + * be it a piece of clothing or a tool. + */ +/datum/component/seclite_attachable + dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS + /// Whether we can remove the light with a screwdriver or not. + var/is_light_removable = TRUE + /// If passed, we wil simply update our item's icon_state when a light is attached. + /// Formatted as parent_base_state-[light_icon-state]-"on" + var/light_icon_state + /// If passed, we will add overlays to the item when a light is attached. + /// This is the icon file it grabs the overlay from. + var/light_overlay_icon + /// The state to take from the light overlay icon if supplied. + var/light_overlay + /// The X offset of our overlay if supplied. + var/overlay_x = 0 + /// The Y offset of our overlay if supplied. + var/overlay_y = 0 + + // Internal vars. + /// A reference to the actual light that's attached. + var/obj/item/flashlight/seclite/light + /// A weakref to the item action we add with the light. + var/datum/weakref/toggle_action_ref + /// Static typecache of all lights we consider seclites (all lights we can attach). + var/static/list/valid_lights = typecacheof(list(/obj/item/flashlight/seclite)) + +/datum/component/seclite_attachable/Initialize( + obj/item/flashlight/seclite/starting_light, + is_light_removable = TRUE, + light_icon_state, + light_overlay_icon, + light_overlay, + overlay_x = 0, + overlay_y = 0, +) + + if(!isitem(parent)) + return COMPONENT_INCOMPATIBLE + + src.is_light_removable = is_light_removable + src.light_icon_state = light_icon_state + src.light_overlay_icon = light_overlay_icon + src.light_overlay = light_overlay + src.overlay_x = overlay_x + src.overlay_y = overlay_y + + if(istype(starting_light)) + add_light(starting_light) + +/datum/component/seclite_attachable/Destroy(force, silent) + if(light) + remove_light() + return ..() + +// Inheriting component allows lights to be added externally to things which already have a mount. +/datum/component/seclite_attachable/InheritComponent( + datum/component/seclite_attachable/new_component, + original, + obj/item/flashlight/seclite/starting_light, + is_light_removable = TRUE, + light_icon_state, + light_overlay_icon, + light_overlay, + overlay_x, + overlay_y, +) + + if(!original) + return + + src.is_light_removable = is_light_removable + + // For the rest of these arguments, default to what already exists + if(light_icon_state) + src.light_icon_state = light_icon_state + if(light_overlay_icon) + src.light_overlay_icon = light_overlay_icon + if(light_overlay) + src.light_overlay = light_overlay + if(overlay_x) + src.overlay_x = overlay_x + if(overlay_x) + src.overlay_y = overlay_y + + if(istype(starting_light)) + add_light(starting_light) + +/datum/component/seclite_attachable/RegisterWithParent() + RegisterSignal(parent, COMSIG_ATOM_DESTRUCTION, .proc/on_parent_deconstructed) + RegisterSignal(parent, COMSIG_ATOM_EXITED, .proc/on_light_exit) + RegisterSignal(parent, COMSIG_ATOM_TOOL_ACT(TOOL_SCREWDRIVER), .proc/on_screwdriver) + RegisterSignal(parent, COMSIG_ATOM_UPDATE_ICON_STATE, .proc/on_update_icon_state) + RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, .proc/on_update_overlays) + RegisterSignal(parent, COMSIG_ITEM_UI_ACTION_CLICK, .proc/on_action_click) + RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/on_attackby) + RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/on_examine) + RegisterSignal(parent, COMSIG_PARENT_QDELETING, .proc/on_parent_deleted) + +/datum/component/seclite_attachable/UnregisterFromParent() + UnregisterSignal(parent, list( + COMSIG_ATOM_DESTRUCTION, + COMSIG_ATOM_EXITED, + COMSIG_ATOM_TOOL_ACT(TOOL_SCREWDRIVER), + COMSIG_ATOM_UPDATE_ICON_STATE, + COMSIG_ATOM_UPDATE_OVERLAYS, + COMSIG_ITEM_UI_ACTION_CLICK, + COMSIG_PARENT_ATTACKBY, + COMSIG_PARENT_EXAMINE, + COMSIG_PARENT_QDELETING, + )) + +/// Sets a new light as our current light for our parent. +/datum/component/seclite_attachable/proc/add_light(obj/item/flashlight/new_light, mob/attacher) + if(light) + CRASH("[type] tried to add a new light when it already had one.") + + light = new_light + + light.set_light_flags(light.light_flags | LIGHT_ATTACHED) + // We may already exist within in our parent's contents... But if we don't move it over now + if(light.loc != parent) + light.forceMove(parent) + + // We already have an action for the light for some reason? Clean it up + if(toggle_action_ref?.resolve()) + stack_trace("[type] - add_light had an existing toggle action when add_light was called.") + QDEL_NULL(toggle_action_ref) + + // Make a new toggle light item action for our parent + var/obj/item/item_parent = parent + var/datum/action/item_action/toggle_seclight/toggle_action = new(item_parent) + toggle_action_ref = WEAKREF(toggle_action) + if(attacher && item_parent.loc == attacher) + toggle_action.Grant(attacher) + + update_light() + +/// Removes the current light from our parent. +/datum/component/seclite_attachable/proc/remove_light() + // Our action may be linked to our parent, + // but it's really sourced from our light. Get rid of it. + QDEL_NULL(toggle_action_ref) + + // It is possible the light was removed by being deleted. + if(!QDELETED(light)) + UnregisterSignal(light, COMSIG_PARENT_QDELETING) + light.set_light_flags(light.light_flags & ~LIGHT_ATTACHED) + light.update_brightness() + + light = null + update_light() + +/// Toggles the light within on or off. +/// Returns TRUE if there is a light inside, FALSE otherwise. +/datum/component/seclite_attachable/proc/toggle_light(mob/user) + if(!light) + return FALSE + + light.on = !light.on + light.update_brightness() + if(user) + user.balloon_alert(user, "[light.name] toggled [light.on ? "on":"off"]") + + playsound(light, 'sound/weapons/empty.ogg', 100, TRUE) + update_light() + return TRUE + +/// Called after the a light is added, removed, or toggles. +/// Ensures all of our appearances look correct for the new light state. +/datum/component/seclite_attachable/proc/update_light() + var/obj/item/item_parent = parent + item_parent.update_appearance() + item_parent.update_action_buttons() + +/// Signal proc for [COMSIG_ATOM_EXITED] that handles our light being removed or deleted from our parent. +/datum/component/seclite_attachable/proc/on_light_exit(obj/item/source, atom/movable/gone, direction) + SIGNAL_HANDLER + + if(gone == light) + remove_light() + +/// Signal proc for [COMSIG_ATOM_DESTRUCTION] that drops our light to the ground if our parent is deconstructed. +/datum/component/seclite_attachable/proc/on_parent_deconstructed(obj/item/source, disassembled) + SIGNAL_HANDLER + + light.forceMove(source.drop_location()) + +/// Signal proc for [COMSIG_PARENT_QDELETING] that deletes our light if our parent is deleted. +/datum/component/seclite_attachable/proc/on_parent_deleted(obj/item/source) + SIGNAL_HANDLER + + QDEL_NULL(light) + +/// Signal proc for [COMSIG_ITEM_UI_ACTION_CLICK] that toggles our light on and off if our action button is clicked. +/datum/component/seclite_attachable/proc/on_action_click(obj/item/source, mob/user, datum/action) + SIGNAL_HANDLER + + // This isn't OUR action specifically, we don't care. + if(!IS_WEAKREF_OF(action, toggle_action_ref)) + return + + // Toggle light fails = no light attached = shouldn't be possible + if(!toggle_light(user)) + CRASH("[type] - on_action_click somehow both HAD AN ACTION and also HAD A TRIGGERABLE ACTION, without having an attached light.") + + return COMPONENT_ACTION_HANDLED + +/// Signal proc for [COMSIG_PARENT_ATTACKBY] that allows a user to attach a seclite by hitting our parent with it. +/datum/component/seclite_attachable/proc/on_attackby(obj/item/source, obj/item/attacking_item, mob/attacker, params) + SIGNAL_HANDLER + + if(!is_type_in_typecache(attacking_item, valid_lights)) + return + + if(light) + source.balloon_alert(attacker, "already has \a [light]!") + return + + if(!attacker.transferItemToLoc(attacking_item, source)) + return + + add_light(attacking_item, attacker) + source.balloon_alert(attacker, "attached [attacking_item]") + return COMPONENT_NO_AFTERATTACK + +/// Signal proc for [COMSIG_ATOM_TOOL_ACT] via [TOOL_SCREWDRIVER] that removes any attached seclite. +/datum/component/seclite_attachable/proc/on_screwdriver(obj/item/source, mob/user, obj/item/tool) + SIGNAL_HANDLER + + if(!light || !is_light_removable) + return + + INVOKE_ASYNC(src, .proc/unscrew_light, source, user, tool) + return COMPONENT_BLOCK_TOOL_ATTACK + +/// Invoked asyncronously from [proc/on_screwdriver]. Handles removing the light from our parent. +/datum/component/seclite_attachable/proc/unscrew_light(obj/item/source, mob/user, obj/item/tool) + tool?.play_tool_sound(source) + source.balloon_alert(user, "unscrewed [light]") + + var/obj/item/flashlight/seclite/to_remove = light + + // The forcemove here will call exited on the light, and automatically update our references / etc + to_remove.forceMove(source.drop_location()) + if(source.Adjacent(user) && !issilicon(user)) + user.put_in_hands(to_remove) + +/// Signal proc for [COMSIG_PARENT_EXAMINE] that shows our item can have / does have a seclite attached. +/datum/component/seclite_attachable/proc/on_examine(obj/item/source, mob/examiner, list/examine_list) + SIGNAL_HANDLER + + if(light) + examine_list += "It has \a [light] [is_light_removable ? "mounted on it with a few screws" : "permanently mounted on it"]." + else + examine_list += "It has a mounting point for a seclite." + +/// Signal proc for [COMSIG_ATOM_UPDATE_OVERLAYS] that updates our parent with our seclite overlays, if we have some. +/datum/component/seclite_attachable/proc/on_update_overlays(obj/item/source, list/overlays) + SIGNAL_HANDLER + + // No overlays to add, no reason to run + if(!light_overlay || !light_overlay_icon) + return + // No light, nothing to add + if(!light) + return + + var/overlay_state = "[light_overlay][light.on ? "_on":""]" + var/mutable_appearance/flashlight_overlay = mutable_appearance(light_overlay_icon, overlay_state) + flashlight_overlay.pixel_x = overlay_x + flashlight_overlay.pixel_y = overlay_y + overlays += flashlight_overlay + +/// Signal proc for [COMSIG_ATOM_UPDATE_ICON_STATE] that updates our parent's icon state, if we have one. +/datum/component/seclite_attachable/proc/on_update_icon_state(obj/item/source) + SIGNAL_HANDLER + + // No icon state to set, no reason to run + if(!light_icon_state) + return + + // Get the "base icon state" to work on + var/base_state = source.base_icon_state || initial(source.icon_state) + // Updates our icon state based on our light state. + if(light) + source.icon_state = "[base_state]-[light_icon_state][light.on ? "-on":""]" + + // Reset their icon state when if we've got no light. + else if(source.icon_state != base_state) + // Yes, this might mess with other icon state alterations, + // but that's the downside of using icon states over overlays. + source.icon_state = base_state diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index cf18d34f47f..184f885da75 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -688,6 +688,9 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e *Checks before we get to here are: mob is alive, mob is not restrained, stunned, asleep, resting, laying, item is on the mob. */ /obj/item/proc/ui_action_click(mob/user, actiontype) + if(SEND_SIGNAL(src, COMSIG_ITEM_UI_ACTION_CLICK, user, actiontype) & COMPONENT_ACTION_HANDLED) + return + attack_self(user) ///This proc determines if and at what an object will reflect energy projectiles if it's in l_hand,r_hand or wear_suit diff --git a/code/modules/clothing/head/helmet.dm b/code/modules/clothing/head/helmet.dm index c3e6e6e3e86..09c710a3bd6 100644 --- a/code/modules/clothing/head/helmet.dm +++ b/code/modules/clothing/head/helmet.dm @@ -15,77 +15,38 @@ dog_fashion = /datum/dog_fashion/head/helmet - var/can_flashlight = FALSE //if a flashlight can be mounted. if it has a flashlight and this is false, it is permanently attached. - var/obj/item/flashlight/seclite/attached_light - var/datum/action/item_action/toggle_helmet_flashlight/alight - /obj/item/clothing/head/helmet/Initialize(mapload) . = ..() - if(attached_light) - alight = new(src) - - -/obj/item/clothing/head/helmet/Destroy() - var/obj/item/flashlight/seclite/old_light = set_attached_light(null) - if(old_light) - qdel(old_light) - return ..() - - -/obj/item/clothing/head/helmet/examine(mob/user) - . = ..() - if(attached_light) - . += "It has \a [attached_light] [can_flashlight ? "" : "permanently "]mounted on it." - if(can_flashlight) - . += span_info("[attached_light] looks like it can be unscrewed from [src].") - else if(can_flashlight) - . += "It has a mounting point for a seclite." - - -/obj/item/clothing/head/helmet/handle_atom_del(atom/A) - if(A == attached_light) - set_attached_light(null) - update_helmlight() - update_appearance() - QDEL_NULL(alight) - qdel(A) - return ..() - - -///Called when attached_light value changes. -/obj/item/clothing/head/helmet/proc/set_attached_light(obj/item/flashlight/seclite/new_attached_light) - if(attached_light == new_attached_light) - return - . = attached_light - attached_light = new_attached_light - if(attached_light) - attached_light.set_light_flags(attached_light.light_flags | LIGHT_ATTACHED) - if(attached_light.loc != src) - attached_light.forceMove(src) - else if(.) - var/obj/item/flashlight/seclite/old_attached_light = . - old_attached_light.set_light_flags(old_attached_light.light_flags & ~LIGHT_ATTACHED) - if(old_attached_light.loc == src) - old_attached_light.forceMove(get_turf(src)) - + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/clothing/head/helmet/sec - can_flashlight = TRUE -/obj/item/clothing/head/helmet/sec/attackby(obj/item/I, mob/user, params) - if(issignaler(I)) - var/obj/item/assembly/signaler/S = I - if(attached_light) //Has a flashlight. Player must remove it, else it will be lost forever. - to_chat(user, span_warning("The mounted flashlight is in the way, remove it first!")) - return +/obj/item/clothing/head/helmet/sec/Initialize(mapload) + . = ..() + AddComponent(/datum/component/seclite_attachable, light_icon_state = "flight") + +/obj/item/clothing/head/helmet/sec/attackby(obj/item/attacking_item, mob/user, params) + if(issignaler(attacking_item)) + var/obj/item/assembly/signaler/attached_signaler = attacking_item + // There's a flashlight in us. Remove it first, or it'll be lost forever! + var/obj/item/flashlight/seclite/blocking_us = locate() in src + if(blocking_us) + to_chat(user, span_warning("[blocking_us] is in the way, remove it first!")) + return TRUE + + if(!attached_signaler.secured) + to_chat(user, span_warning("Secure [attached_signaler] first!")) + return TRUE + + to_chat(user, span_notice("You add [attached_signaler] to [src].")) + + qdel(attached_signaler) + var/obj/item/bot_assembly/secbot/secbot_frame = new(loc) + user.put_in_hands(secbot_frame) + + qdel(src) + return TRUE - if(S.secured) - qdel(S) - var/obj/item/bot_assembly/secbot/A = new - user.put_in_hands(A) - to_chat(user, span_notice("You add the signaler to the helmet.")) - qdel(src) - return return ..() /obj/item/clothing/head/helmet/alt @@ -94,9 +55,12 @@ icon_state = "helmetalt" inhand_icon_state = "helmetalt" armor = list(MELEE = 15, BULLET = 60, LASER = 10, ENERGY = 10, BOMB = 40, BIO = 0, FIRE = 50, ACID = 50, WOUND = 5) - can_flashlight = TRUE dog_fashion = null +/obj/item/clothing/head/helmet/alt/Initialize(mapload) + . = ..() + AddComponent(/datum/component/seclite_attachable, light_icon_state = "flight") + /obj/item/clothing/head/helmet/marine name = "tactical combat helmet" desc = "A tactical black helmet, sealed from outside hazards with a plate of glass and not much else." @@ -106,14 +70,11 @@ min_cold_protection_temperature = SPACE_HELM_MIN_TEMP_PROTECT clothing_flags = STOPSPRESSUREDAMAGE | PLASMAMAN_HELMET_EXEMPT resistance_flags = FIRE_PROOF | ACID_PROOF - can_flashlight = TRUE dog_fashion = null /obj/item/clothing/head/helmet/marine/Initialize(mapload) - set_attached_light(new /obj/item/flashlight/seclite) - update_helmlight() - update_appearance() . = ..() + AddComponent(/datum/component/seclite_attachable, starting_light = new /obj/item/flashlight/seclite(src), light_icon_state = "flight") /obj/item/clothing/head/helmet/marine/security name = "marine heavy helmet" @@ -158,20 +119,27 @@ dog_fashion = null /obj/item/clothing/head/helmet/attack_self(mob/user) - if(can_toggle && !user.incapacitated()) - if(world.time > cooldown + toggle_cooldown) - cooldown = world.time - up = !up - flags_1 ^= visor_flags - flags_inv ^= visor_flags_inv - flags_cover ^= visor_flags_cover - icon_state = "[initial(icon_state)][up ? "up" : ""]" - to_chat(user, span_notice("[up ? alt_toggle_message : toggle_message] \the [src].")) + . = ..() + if(.) + return + if(!can_toggle) + return - user.update_inv_head() - if(iscarbon(user)) - var/mob/living/carbon/C = user - C.head_update(src, forced = 1) + if(user.incapacitated() || world.time <= cooldown + toggle_cooldown) + return + + cooldown = world.time + up = !up + flags_1 ^= visor_flags + flags_inv ^= visor_flags_inv + flags_cover ^= visor_flags_cover + icon_state = "[initial(icon_state)][up ? "up" : ""]" + to_chat(user, span_notice("[up ? alt_toggle_message : toggle_message] \the [src].")) + + user.update_inv_head() + if(iscarbon(user)) + var/mob/living/carbon/carbon_user = user + carbon_user.head_update(src, forced = TRUE) /obj/item/clothing/head/helmet/justice name = "helmet of justice" @@ -405,191 +373,3 @@ material_flags = MATERIAL_EFFECTS | MATERIAL_COLOR | MATERIAL_AFFECT_STATISTICS //Can change color and add prefix flags_inv = HIDEMASK|HIDEEARS|HIDEEYES|HIDEFACE|HIDEHAIR|HIDESNOUT flags_cover = HEADCOVERSEYES | HEADCOVERSMOUTH - -//monkey sentience caps - -/obj/item/clothing/head/helmet/monkey_sentience - name = "monkey mind magnification helmet" - desc = "A fragile, circuitry embedded helmet for boosting the intelligence of a monkey to a higher level. You see several warning labels..." - - icon_state = "monkeymind" - inhand_icon_state = "monkeymind" - strip_delay = 100 - var/mob/living/carbon/human/magnification = null ///if the helmet is on a valid target (just works like a normal helmet if not (cargo please stop)) - var/polling = FALSE///if the helmet is currently polling for targets (special code for removal) - var/light_colors = 1 ///which icon state color this is (red, blue, yellow) - -/obj/item/clothing/head/helmet/monkey_sentience/Initialize(mapload) - . = ..() - light_colors = rand(1,3) - update_appearance() - -/obj/item/clothing/head/helmet/monkey_sentience/examine(mob/user) - . = ..() - . += span_boldwarning("---WARNING: REMOVAL OF HELMET ON SUBJECT MAY LEAD TO:---") - . += span_warning("BLOOD RAGE") - . += span_warning("BRAIN DEATH") - . += span_warning("PRIMAL GENE ACTIVATION") - . += span_warning("GENETIC MAKEUP MASS SUSCEPTIBILITY") - . += span_boldnotice("Ask your CMO if mind magnification is right for you.") - -/obj/item/clothing/head/helmet/monkey_sentience/update_icon_state() - . = ..() - icon_state = "[initial(icon_state)][light_colors][magnification ? "up" : null]" - -/obj/item/clothing/head/helmet/monkey_sentience/equipped(mob/user, slot) - . = ..() - if(slot != ITEM_SLOT_HEAD) - return - if(!ismonkey(user) || user.ckey) - var/mob/living/something = user - to_chat(something, span_boldnotice("You feel a stabbing pain in the back of your head for a moment.")) - something.apply_damage(5,BRUTE,BODY_ZONE_HEAD,FALSE,FALSE,FALSE) //notably: no damage resist (it's in your helmet), no damage spread (it's in your helmet) - playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) - return - if(!(GLOB.ghost_role_flags & GHOSTROLE_STATION_SENTIENCE)) - say("ERROR: Central Command has temporarily outlawed monkey sentience helmets in this sector. NEAREST LAWFUL SECTOR: 2.537 million light years away.") - return - magnification = user //this polls ghosts - visible_message(span_warning("[src] powers up!")) - playsound(src, 'sound/machines/ping.ogg', 30, TRUE) - RegisterSignal(magnification, COMSIG_SPECIES_LOSS, .proc/make_fall_off) - polling = TRUE - var/list/candidates = poll_candidates_for_mob("Do you want to play as a mind magnified monkey?", ROLE_SENTIENCE, ROLE_SENTIENCE, 5 SECONDS, magnification, POLL_IGNORE_SENTIENCE_POTION) - polling = FALSE - if(!magnification) - return - if(!candidates.len) - UnregisterSignal(magnification, COMSIG_SPECIES_LOSS) - magnification = null - visible_message(span_notice("[src] falls silent and drops on the floor. Maybe you should try again later?")) - playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) - user.dropItemToGround(src) - return - var/mob/picked = pick(candidates) - magnification.key = picked.key - playsound(src, 'sound/machines/microwave/microwave-end.ogg', 100, FALSE) - to_chat(magnification, span_notice("You're a mind magnified monkey! Protect your helmet with your life- if you lose it, your sentience goes with it!")) - var/policy = get_policy(ROLE_MONKEY_HELMET) - if(policy) - to_chat(magnification, policy) - icon_state = "[icon_state]up" - -/obj/item/clothing/head/helmet/monkey_sentience/Destroy() - disconnect() - return ..() - -/obj/item/clothing/head/helmet/monkey_sentience/proc/disconnect() - if(!magnification) //not put on a viable head - return - if(!polling)//put on a viable head, but taken off after polling finished. - if(magnification.client) - to_chat(magnification, span_userdanger("You feel your flicker of sentience ripped away from you, as everything becomes dim...")) - magnification.ghostize(FALSE) - if(prob(10)) - switch(rand(1,4)) - if(1) //blood rage - magnification.ai_controller.blackboard[BB_MONKEY_AGGRESSIVE] = TRUE - if(2) //brain death - magnification.apply_damage(500,BRAIN,BODY_ZONE_HEAD,FALSE,FALSE,FALSE) - if(3) //primal gene (gorilla) - magnification.gorillize() - if(4) //genetic mass susceptibility (gib) - magnification.gib() - //either used up correctly or taken off before polling finished (punish this by destroying the helmet) - UnregisterSignal(magnification, COMSIG_SPECIES_LOSS) - playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) - playsound(src, SFX_SPARKS, 100, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) - visible_message(span_warning("[src] fizzles and breaks apart!")) - magnification = null - new /obj/effect/decal/cleanable/ash/crematorium(drop_location()) //just in case they're in a locker or other containers it needs to use crematorium ash, see the path itself for an explanation - -/obj/item/clothing/head/helmet/monkey_sentience/dropped(mob/user) - . = ..() - if(magnification || polling) - qdel(src)//runs disconnect code - -/obj/item/clothing/head/helmet/monkey_sentience/proc/make_fall_off() - SIGNAL_HANDLER - if(magnification) - visible_message(span_warning("[src] falls off of [magnification]'s head as it changes shape!")) - magnification.dropItemToGround(src) - -//LightToggle - -/obj/item/clothing/head/helmet/ComponentInitialize() - . = ..() - AddElement(/datum/element/update_icon_updates_onmob) - -/obj/item/clothing/head/helmet/update_icon_state() - if(attached_light) - var/state = "[initial(icon_state)]" - if(attached_light.on) - state += "-flight-on" //"helmet-flight-on" // "helmet-cam-flight-on" - else - state += "-flight" //etc. - icon_state = state - return ..() - -/obj/item/clothing/head/helmet/ui_action_click(mob/user, action) - if(istype(action, alight)) - toggle_helmlight() - else - ..() - -/obj/item/clothing/head/helmet/attackby(obj/item/I, mob/user, params) - if(istype(I, /obj/item/flashlight/seclite)) - var/obj/item/flashlight/seclite/S = I - if(can_flashlight && !attached_light) - if(!user.transferItemToLoc(S, src)) - return - to_chat(user, span_notice("You click [S] into place on [src].")) - set_attached_light(S) - update_appearance() - update_helmlight() - alight = new(src) - if(loc == user) - alight.Grant(user) - return - return ..() - -/obj/item/clothing/head/helmet/screwdriver_act(mob/living/user, obj/item/I) - . = ..() - if(can_flashlight && attached_light) //if it has a light but can_flashlight is false, the light is permanently attached. - I.play_tool_sound(src) - to_chat(user, span_notice("You unscrew [attached_light] from [src].")) - attached_light.forceMove(drop_location()) - if(Adjacent(user) && !issilicon(user)) - user.put_in_hands(attached_light) - - var/obj/item/flashlight/removed_light = set_attached_light(null) - update_helmlight() - removed_light.update_brightness(user) - update_appearance() - user.update_inv_head() - QDEL_NULL(alight) - return TRUE - -/obj/item/clothing/head/helmet/proc/toggle_helmlight() - set name = "Toggle Helmetlight" - set category = "Object" - set desc = "Click to toggle your helmet's attached flashlight." - - if(!attached_light) - return - - var/mob/user = usr - if(user.incapacitated()) - return - attached_light.on = !attached_light.on - attached_light.update_brightness() - to_chat(user, span_notice("You toggle the helmet light [attached_light.on ? "on":"off"].")) - - playsound(user, 'sound/weapons/empty.ogg', 100, TRUE) - update_helmlight() - -/obj/item/clothing/head/helmet/proc/update_helmlight() - if(attached_light) - update_appearance() - - update_action_buttons() diff --git a/code/modules/clothing/head/mind_monkey_helmet.dm b/code/modules/clothing/head/mind_monkey_helmet.dm new file mode 100644 index 00000000000..6534cdbc128 --- /dev/null +++ b/code/modules/clothing/head/mind_monkey_helmet.dm @@ -0,0 +1,109 @@ + +//monkey sentience caps + +/obj/item/clothing/head/helmet/monkey_sentience + name = "monkey mind magnification helmet" + desc = "A fragile, circuitry embedded helmet for boosting the intelligence of a monkey to a higher level. You see several warning labels..." + + icon_state = "monkeymind" + inhand_icon_state = "monkeymind" + strip_delay = 100 + var/mob/living/carbon/human/magnification = null ///if the helmet is on a valid target (just works like a normal helmet if not (cargo please stop)) + var/polling = FALSE///if the helmet is currently polling for targets (special code for removal) + var/light_colors = 1 ///which icon state color this is (red, blue, yellow) + +/obj/item/clothing/head/helmet/monkey_sentience/Initialize(mapload) + . = ..() + light_colors = rand(1,3) + update_appearance() + +/obj/item/clothing/head/helmet/monkey_sentience/examine(mob/user) + . = ..() + . += span_boldwarning("---WARNING: REMOVAL OF HELMET ON SUBJECT MAY LEAD TO:---") + . += span_warning("BLOOD RAGE") + . += span_warning("BRAIN DEATH") + . += span_warning("PRIMAL GENE ACTIVATION") + . += span_warning("GENETIC MAKEUP MASS SUSCEPTIBILITY") + . += span_boldnotice("Ask your CMO if mind magnification is right for you.") + +/obj/item/clothing/head/helmet/monkey_sentience/update_icon_state() + . = ..() + icon_state = "[initial(icon_state)][light_colors][magnification ? "up" : null]" + +/obj/item/clothing/head/helmet/monkey_sentience/equipped(mob/user, slot) + . = ..() + if(slot != ITEM_SLOT_HEAD) + return + if(!ismonkey(user) || user.ckey) + var/mob/living/something = user + to_chat(something, span_boldnotice("You feel a stabbing pain in the back of your head for a moment.")) + something.apply_damage(5,BRUTE,BODY_ZONE_HEAD,FALSE,FALSE,FALSE) //notably: no damage resist (it's in your helmet), no damage spread (it's in your helmet) + playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) + return + if(!(GLOB.ghost_role_flags & GHOSTROLE_STATION_SENTIENCE)) + say("ERROR: Central Command has temporarily outlawed monkey sentience helmets in this sector. NEAREST LAWFUL SECTOR: 2.537 million light years away.") + return + magnification = user //this polls ghosts + visible_message(span_warning("[src] powers up!")) + playsound(src, 'sound/machines/ping.ogg', 30, TRUE) + RegisterSignal(magnification, COMSIG_SPECIES_LOSS, .proc/make_fall_off) + polling = TRUE + var/list/candidates = poll_candidates_for_mob("Do you want to play as a mind magnified monkey?", ROLE_SENTIENCE, ROLE_SENTIENCE, 5 SECONDS, magnification, POLL_IGNORE_SENTIENCE_POTION) + polling = FALSE + if(!magnification) + return + if(!candidates.len) + UnregisterSignal(magnification, COMSIG_SPECIES_LOSS) + magnification = null + visible_message(span_notice("[src] falls silent and drops on the floor. Maybe you should try again later?")) + playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) + user.dropItemToGround(src) + return + var/mob/picked = pick(candidates) + magnification.key = picked.key + playsound(src, 'sound/machines/microwave/microwave-end.ogg', 100, FALSE) + to_chat(magnification, span_notice("You're a mind magnified monkey! Protect your helmet with your life- if you lose it, your sentience goes with it!")) + var/policy = get_policy(ROLE_MONKEY_HELMET) + if(policy) + to_chat(magnification, policy) + icon_state = "[icon_state]up" + +/obj/item/clothing/head/helmet/monkey_sentience/Destroy() + disconnect() + return ..() + +/obj/item/clothing/head/helmet/monkey_sentience/proc/disconnect() + if(!magnification) //not put on a viable head + return + if(!polling)//put on a viable head, but taken off after polling finished. + if(magnification.client) + to_chat(magnification, span_userdanger("You feel your flicker of sentience ripped away from you, as everything becomes dim...")) + magnification.ghostize(FALSE) + if(prob(10)) + switch(rand(1,4)) + if(1) //blood rage + magnification.ai_controller.blackboard[BB_MONKEY_AGGRESSIVE] = TRUE + if(2) //brain death + magnification.apply_damage(500,BRAIN,BODY_ZONE_HEAD,FALSE,FALSE,FALSE) + if(3) //primal gene (gorilla) + magnification.gorillize() + if(4) //genetic mass susceptibility (gib) + magnification.gib() + //either used up correctly or taken off before polling finished (punish this by destroying the helmet) + UnregisterSignal(magnification, COMSIG_SPECIES_LOSS) + playsound(src, 'sound/machines/buzz-sigh.ogg', 30, TRUE) + playsound(src, SFX_SPARKS, 100, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) + visible_message(span_warning("[src] fizzles and breaks apart!")) + magnification = null + new /obj/effect/decal/cleanable/ash/crematorium(drop_location()) //just in case they're in a locker or other containers it needs to use crematorium ash, see the path itself for an explanation + +/obj/item/clothing/head/helmet/monkey_sentience/dropped(mob/user) + . = ..() + if(magnification || polling) + qdel(src)//runs disconnect code + +/obj/item/clothing/head/helmet/monkey_sentience/proc/make_fall_off() + SIGNAL_HANDLER + if(magnification) + visible_message(span_warning("[src] falls off of [magnification]'s head as it changes shape!")) + magnification.dropItemToGround(src) diff --git a/code/modules/mob/living/carbon/human/monkey/monkey.dm b/code/modules/mob/living/carbon/human/monkey/monkey.dm index a4ce98269e5..b0cccf6618d 100644 --- a/code/modules/mob/living/carbon/human/monkey/monkey.dm +++ b/code/modules/mob/living/carbon/human/monkey/monkey.dm @@ -24,10 +24,13 @@ /mob/living/carbon/human/species/monkey/angry/Initialize(mapload) . = ..() if(prob(10)) - var/obj/item/clothing/head/helmet/justice/escape/helmet = new(src) - equip_to_slot_or_del(helmet,ITEM_SLOT_HEAD) - helmet.attack_self(src) // todo encapsulate toggle + INVOKE_ASYNC(src, .proc/give_ape_escape_helmet) +/// Gives our funny monkey an Ape Escape hat reference +/mob/living/carbon/human/species/monkey/angry/proc/give_ape_escape_helmet() + var/obj/item/clothing/head/helmet/justice/escape/helmet = new(src) + equip_to_slot_or_del(helmet, ITEM_SLOT_HEAD) + helmet.attack_self(src) // todo encapsulate toggle GLOBAL_DATUM(the_one_and_only_punpun, /mob/living/carbon/human/species/monkey/punpun) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index e3c7e979717..21bf6948854 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -56,10 +56,6 @@ var/obj/item/firing_pin/pin = /obj/item/firing_pin //standard firing pin for most guns /// True if a gun dosen't need a pin, mostly used for abstract guns like tentacles and meathooks var/pinless = FALSE - var/can_flashlight = FALSE //if a flashlight can be added or removed if it already has one. - var/obj/item/flashlight/seclite/gun_light - var/datum/action/item_action/toggle_gunlight/alight - var/gunlight_state = "flight" var/can_bayonet = FALSE //if a bayonet can be added or removed if it already has one. var/obj/item/knife/bayonet @@ -68,8 +64,6 @@ var/ammo_x_offset = 0 //used for positioning ammo count overlay on sprite var/ammo_y_offset = 0 - var/flight_x_offset = 0 - var/flight_y_offset = 0 var/pb_knockback = 0 @@ -77,14 +71,12 @@ . = ..() if(pin) pin = new pin(src) - if(gun_light) - alight = new(src) + + add_seclight_point() /obj/item/gun/Destroy() if(isobj(pin)) //Can still be the initial path, then we skip QDEL_NULL(pin) - if(gun_light) - QDEL_NULL(gun_light) if(bayonet) QDEL_NULL(bayonet) if(chambered) //Not all guns are chambered (EMP'ed energy guns etc) @@ -93,6 +85,12 @@ QDEL_NULL(suppressed) return ..() +/// Handles adding [the seclite mount component][/datum/component/seclite_attachable] to the gun. +/// If the gun shouldn't have a seclight mount, override this with a return. +/// Or, if a child of a gun with a seclite mount has slightly different behavior or icons, extend this. +/obj/item/gun/proc/add_seclight_point() + return + /obj/item/gun/handle_atom_del(atom/A) if(A == pin) pin = null @@ -101,8 +99,6 @@ update_appearance() if(A == bayonet) clear_bayonet() - if(A == gun_light) - clear_gunlight() if(A == suppressed) clear_suppressor() return ..() @@ -123,13 +119,6 @@ else . += "It doesn't have a firing pin installed, and won't fire." - if(gun_light) - . += "It has \a [gun_light] [can_flashlight ? "" : "permanently "]mounted on it." - if(can_flashlight) //if it has a light and this is false, the light is permanent. - . += span_info("[gun_light] looks like it can be unscrewed from [src].") - else if(can_flashlight) - . += "It has a mounting point for a seclite." - if(bayonet) . += "It has \a [bayonet] [can_bayonet ? "" : "permanently "]affixed to it." if(can_bayonet) //if it has a bayonet and this is false, the bayonet is permanent. @@ -417,19 +406,7 @@ /obj/item/gun/attackby(obj/item/I, mob/living/user, params) if(user.combat_mode) return ..() - else if(istype(I, /obj/item/flashlight/seclite)) - if(!can_flashlight) - return ..() - var/obj/item/flashlight/seclite/S = I - if(!gun_light) - if(!user.transferItemToLoc(I, src)) - return - to_chat(user, span_notice("You click [S] into place on [src].")) - set_gun_light(S) - update_gunlight() - alight = new(src) - if(loc == user) - alight.Grant(user) + else if(istype(I, /obj/item/knife)) var/obj/item/knife/K = I if(!can_bayonet || !K.bayonet || bayonet) //ensure the gun has an attachment point available, and that the knife is compatible with it. @@ -449,20 +426,9 @@ return if(!user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if((can_flashlight && gun_light) && (can_bayonet && bayonet)) //give them a choice instead of removing both - var/list/possible_items = list(gun_light, bayonet) - var/obj/item/item_to_remove = tgui_input_list(user, "Attachment to remove", "Attachment Removal", sort_names(possible_items)) - if(isnull(item_to_remove)) - return - if(!user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) - return - return remove_gun_attachment(user, I, item_to_remove) - else if(gun_light && can_flashlight) //if it has a gun_light and can_flashlight is false, the flashlight is permanently attached. - return remove_gun_attachment(user, I, gun_light, "unscrewed") - - else if(bayonet && can_bayonet) //if it has a bayonet, and the bayonet can be removed - return remove_gun_attachment(user, I, bayonet, "unfix") + if(bayonet && can_bayonet) //if it has a bayonet, and the bayonet can be removed + return remove_bayonet(user, I) else if(pin && user.is_holding(src)) user.visible_message(span_warning("[user] attempts to remove [pin] from [src] with [I]."), @@ -509,19 +475,15 @@ QDEL_NULL(pin) return TRUE -/obj/item/gun/proc/remove_gun_attachment(mob/living/user, obj/item/tool_item, obj/item/item_to_remove, removal_verb) - if(tool_item) - tool_item.play_tool_sound(src) - to_chat(user, span_notice("You [removal_verb ? removal_verb : "remove"] [item_to_remove] from [src].")) - item_to_remove.forceMove(drop_location()) +/obj/item/gun/proc/remove_bayonet(mob/living/user, obj/item/tool_item) + tool_item?.play_tool_sound(src) + to_chat(user, span_notice("You unfix [bayonet] from [src].")) + bayonet.forceMove(drop_location()) if(Adjacent(user) && !issilicon(user)) - user.put_in_hands(item_to_remove) + user.put_in_hands(bayonet) - if(item_to_remove == bayonet) - return clear_bayonet() - else if(item_to_remove == gun_light) - return clear_gunlight() + return clear_bayonet() /obj/item/gun/proc/clear_bayonet() if(!bayonet) @@ -530,79 +492,8 @@ update_appearance() return TRUE -/obj/item/gun/proc/clear_gunlight() - if(!gun_light) - return - var/obj/item/flashlight/seclite/removed_light = gun_light - set_gun_light(null) - update_gunlight() - removed_light.update_brightness() - QDEL_NULL(alight) - return TRUE - - -/** - * Swaps the gun's seclight, dropping the old seclight if it has not been qdel'd. - * - * Returns the former gun_light that has now been replaced by this proc. - * Arguments: - * * new_light - The new light to attach to the weapon. Can be null, which will mean the old light is removed with no replacement. - */ -/obj/item/gun/proc/set_gun_light(obj/item/flashlight/seclite/new_light) - // Doesn't look like this should ever happen? We're replacing our old light with our old light? - if(gun_light == new_light) - CRASH("Tried to set a new gun light when the old gun light was also the new gun light.") - - . = gun_light - - // If there's an old gun light that isn't being QDELETED, detatch and drop it to the floor. - if(!QDELETED(gun_light)) - gun_light.set_light_flags(gun_light.light_flags & ~LIGHT_ATTACHED) - if(gun_light.loc == src) - gun_light.forceMove(get_turf(src)) - - // If there's a new gun light to be added, attach and move it to the gun. - if(new_light) - new_light.set_light_flags(new_light.light_flags | LIGHT_ATTACHED) - if(new_light.loc != src) - new_light.forceMove(src) - - gun_light = new_light - -/obj/item/gun/ui_action_click(mob/user, actiontype) - if(istype(actiontype, alight)) - toggle_gunlight() - else - ..() - -/obj/item/gun/proc/toggle_gunlight() - if(!gun_light) - return - - var/mob/living/carbon/human/user = usr - gun_light.on = !gun_light.on - gun_light.update_brightness() - to_chat(user, span_notice("You toggle the gunlight [gun_light.on ? "on":"off"].")) - - playsound(user, 'sound/weapons/empty.ogg', 100, TRUE) - update_gunlight() - -/obj/item/gun/proc/update_gunlight() - update_appearance() - update_action_buttons() - /obj/item/gun/update_overlays() . = ..() - if(gun_light) - var/mutable_appearance/flashlight_overlay - var/state = "[gunlight_state][gun_light.on? "_on":""]" //Generic state. - if(gun_light.icon_state in icon_states('icons/obj/guns/flashlights.dmi')) //Snowflake state? - state = gun_light.icon_state - flashlight_overlay = mutable_appearance('icons/obj/guns/flashlights.dmi', state) - flashlight_overlay.pixel_x = flight_x_offset - flashlight_overlay.pixel_y = flight_y_offset - . += flashlight_overlay - if(bayonet) var/mutable_appearance/knife_overlay var/state = "bayonet" //Generic state. diff --git a/code/modules/projectiles/guns/energy.dm b/code/modules/projectiles/guns/energy.dm index 5d959c5265b..570d5cc1106 100644 --- a/code/modules/projectiles/guns/energy.dm +++ b/code/modules/projectiles/guns/energy.dm @@ -59,6 +59,7 @@ START_PROCESSING(SSobj, src) update_appearance() RegisterSignal(src, COMSIG_ITEM_RECHARGED, .proc/instant_recharge) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/gun/energy/add_weapon_description() AddElement(/datum/element/weapon_description, attached_proc = .proc/add_notes_energy) @@ -92,10 +93,6 @@ return readout.Join("\n") // Sending over the singular string, rather than the whole list -/obj/item/gun/energy/ComponentInitialize() - . = ..() - AddElement(/datum/element/update_icon_updates_onmob) - /obj/item/gun/energy/proc/update_ammo_types() var/obj/item/ammo_casing/energy/shot for (var/i in 1 to ammo_type.len) @@ -214,8 +211,8 @@ if(modifystate) var/obj/item/ammo_casing/energy/shot = ammo_type[select] if(single_shot_type_overlay) - . += "[icon_state]_[shot.select_name]" - overlay_icon_state += "_[shot.select_name]" + . += "[icon_state]_[initial(shot.select_name)]" + overlay_icon_state += "_[initial(shot.select_name)]" var/ratio = get_charge_ratio() if(ratio == 0 && display_empty) diff --git a/code/modules/projectiles/guns/energy/energy_gun.dm b/code/modules/projectiles/guns/energy/energy_gun.dm index 6e2f701bd94..110d4d6ef61 100644 --- a/code/modules/projectiles/guns/energy/energy_gun.dm +++ b/code/modules/projectiles/guns/energy/energy_gun.dm @@ -6,12 +6,16 @@ inhand_icon_state = null //so the human update icon uses the icon_state instead. ammo_type = list(/obj/item/ammo_casing/energy/disabler, /obj/item/ammo_casing/energy/laser) modifystate = TRUE - can_flashlight = TRUE ammo_x_offset = 3 - flight_x_offset = 15 - flight_y_offset = 10 dual_wield_spread = 60 +/obj/item/gun/energy/e_gun/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 15, \ + overlay_y = 10) + /obj/item/gun/energy/e_gun/mini name = "miniature energy gun" desc = "A small, pistol-sized energy gun with a built-in flashlight. It has two settings: disable and kill." @@ -21,15 +25,17 @@ cell_type = /obj/item/stock_parts/cell/mini_egun ammo_x_offset = 2 charge_sections = 3 - can_flashlight = FALSE // Can't attach or detach the flashlight, and override it's icon update - gunlight_state = "mini-light" - flight_x_offset = 19 - flight_y_offset = 13 single_shot_type_overlay = FALSE -/obj/item/gun/energy/e_gun/mini/Initialize(mapload) - set_gun_light(new /obj/item/flashlight/seclite(src)) - return ..() +/obj/item/gun/energy/e_gun/mini/add_seclight_point() + // The mini energy gun's light comes attached but is unremovable. + AddComponent(/datum/component/seclite_attachable, \ + starting_light = new /obj/item/flashlight/seclite(src), \ + is_light_removable = FALSE, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "mini-light", \ + overlay_x = 19, \ + overlay_y = 13) /obj/item/gun/energy/e_gun/stun name = "tactical energy gun" @@ -74,9 +80,11 @@ ammo_type = list(/obj/item/ammo_casing/energy/net, /obj/item/ammo_casing/energy/trap) modifystate = FALSE w_class = WEIGHT_CLASS_NORMAL - can_flashlight = FALSE ammo_x_offset = 1 +/obj/item/gun/energy/e_gun/dragnet/add_seclight_point() + return + /obj/item/gun/energy/e_gun/dragnet/snare name = "Energy Snare Launcher" desc = "Fires an energy snare that slows the target down." @@ -91,10 +99,12 @@ w_class = WEIGHT_CLASS_HUGE ammo_type = list(/obj/item/ammo_casing/energy/electrode, /obj/item/ammo_casing/energy/laser) weapon_weight = WEAPON_HEAVY - can_flashlight = FALSE trigger_guard = TRIGGER_GUARD_NONE ammo_x_offset = 2 +/obj/item/gun/energy/e_gun/turret/add_seclight_point() + return + /obj/item/gun/energy/e_gun/nuclear name = "advanced energy gun" desc = "An energy gun with an experimental miniaturized nuclear reactor that automatically charges the internal power cell." diff --git a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm index a6e73985001..eb07b8b1728 100644 --- a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm +++ b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm @@ -8,9 +8,6 @@ item_flags = NONE obj_flags = UNIQUE_RENAME weapon_weight = WEAPON_LIGHT - can_flashlight = TRUE - flight_x_offset = 15 - flight_y_offset = 9 can_bayonet = TRUE knife_x_offset = 20 knife_y_offset = 12 @@ -18,6 +15,13 @@ var/max_mod_capacity = 100 var/list/modkits = list() +/obj/item/gun/energy/recharge/kinetic_accelerator/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 15, \ + overlay_y = 9) + /obj/item/gun/energy/recharge/kinetic_accelerator/examine(mob/user) . = ..() if(max_mod_capacity) diff --git a/code/modules/projectiles/guns/energy/laser.dm b/code/modules/projectiles/guns/energy/laser.dm index 3f401dda4b7..447c65e17ee 100644 --- a/code/modules/projectiles/guns/energy/laser.dm +++ b/code/modules/projectiles/guns/energy/laser.dm @@ -163,19 +163,23 @@ ammo_type = list(/obj/item/ammo_casing/energy/nanite) shaded_charge = TRUE ammo_x_offset = 1 - can_flashlight = TRUE - flight_x_offset = 15 - flight_y_offset = 9 can_bayonet = TRUE knife_x_offset = 19 knife_y_offset = 13 w_class = WEIGHT_CLASS_NORMAL dual_wield_spread = 10 //as intended by the coders -/obj/item/gun/energy/laser/thermal/ComponentInitialize() +/obj/item/gun/energy/laser/thermal/Initialize(mapload) . = ..() AddElement(/datum/element/empprotection, EMP_PROTECT_SELF|EMP_PROTECT_CONTENTS) +/obj/item/gun/energy/laser/thermal/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 15, \ + overlay_y = 9) + /obj/item/gun/energy/laser/thermal/inferno //the magma gun name = "inferno pistol" desc = "A modified handcannon with a self-replicating reserve of decommissioned weaponized nanites. Spit globs of molten angry robots into the bad guys. While it doesn't manipulate temperature in of itself, it does cause an violent eruption in anyone who is severely cold." diff --git a/code/modules/projectiles/guns/energy/mounted.dm b/code/modules/projectiles/guns/energy/mounted.dm index c6d8df7321f..c553d4edbb6 100644 --- a/code/modules/projectiles/guns/energy/mounted.dm +++ b/code/modules/projectiles/guns/energy/mounted.dm @@ -7,11 +7,10 @@ display_empty = FALSE force = 5 selfcharge = 1 - can_flashlight = FALSE trigger_guard = TRIGGER_GUARD_ALLOW_ALL // Has no trigger at all, uses neural signals instead -/obj/item/gun/energy/e_gun/advtaser/mounted/dropped()//if somebody manages to drop this somehow... - ..() +/obj/item/gun/energy/e_gun/advtaser/mounted/add_seclight_point() + return /obj/item/gun/energy/laser/mounted name = "mounted laser" @@ -23,9 +22,6 @@ selfcharge = 1 trigger_guard = TRIGGER_GUARD_ALLOW_ALL -/obj/item/gun/energy/laser/mounted/dropped() - ..() - /obj/item/gun/energy/laser/mounted/augment icon = 'icons/obj/surgery.dmi' icon_state = "arm_laser" diff --git a/code/modules/projectiles/guns/energy/pulse.dm b/code/modules/projectiles/guns/energy/pulse.dm index 9f90b69da74..d53edc8a52d 100644 --- a/code/modules/projectiles/guns/energy/pulse.dm +++ b/code/modules/projectiles/guns/energy/pulse.dm @@ -40,9 +40,13 @@ worn_icon_state = "gun" inhand_icon_state = null cell_type = "/obj/item/stock_parts/cell/pulse/carbine" - can_flashlight = TRUE - flight_x_offset = 18 - flight_y_offset = 12 + +/obj/item/gun/energy/pulse/carbine/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 18, \ + overlay_y = 12) /obj/item/gun/energy/pulse/carbine/loyalpin pin = /obj/item/firing_pin/implant/mindshield diff --git a/code/modules/projectiles/guns/energy/special.dm b/code/modules/projectiles/guns/energy/special.dm index 663d9319804..a96b5f40283 100644 --- a/code/modules/projectiles/guns/energy/special.dm +++ b/code/modules/projectiles/guns/energy/special.dm @@ -5,13 +5,17 @@ inhand_icon_state = null //so the human update icon uses the icon_state instead. worn_icon_state = null shaded_charge = TRUE - can_flashlight = TRUE w_class = WEIGHT_CLASS_HUGE flags_1 = CONDUCT_1 slot_flags = ITEM_SLOT_BACK ammo_type = list(/obj/item/ammo_casing/energy/ion) - flight_x_offset = 17 - flight_y_offset = 9 + +/obj/item/gun/energy/ionrifle/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 17, \ + overlay_y = 9) /obj/item/gun/energy/ionrifle/emp_act(severity) return @@ -22,8 +26,11 @@ icon_state = "ioncarbine" w_class = WEIGHT_CLASS_BULKY slot_flags = ITEM_SLOT_BELT - flight_x_offset = 18 - flight_y_offset = 11 + +/obj/item/gun/energy/ionrifle/carbine/add_seclight_point() + . = ..() + // We use the same overlay as the parent, so we can just let the component inherit the correct offsets here + AddComponent(/datum/component/seclite_attachable, overlay_x = 18, overlay_y = 11) /obj/item/gun/energy/decloner name = "biological demolecularisor" diff --git a/code/modules/projectiles/guns/energy/stun.dm b/code/modules/projectiles/guns/energy/stun.dm index ae5f1a4131a..627c8b5e893 100644 --- a/code/modules/projectiles/guns/energy/stun.dm +++ b/code/modules/projectiles/guns/energy/stun.dm @@ -16,10 +16,12 @@ /obj/item/gun/energy/e_gun/advtaser/cyborg name = "cyborg taser" desc = "An integrated hybrid taser that draws directly from a cyborg's power cell. The weapon contains a limiter to prevent the cyborg's power cell from overheating." - can_flashlight = FALSE can_charge = FALSE use_cyborg_cell = TRUE +/obj/item/gun/energy/e_gun/advtaser/cyborg/add_seclight_point() + return + /obj/item/gun/energy/e_gun/advtaser/cyborg/emp_act() return @@ -30,9 +32,13 @@ inhand_icon_state = null ammo_type = list(/obj/item/ammo_casing/energy/disabler) ammo_x_offset = 2 - can_flashlight = TRUE - flight_x_offset = 15 - flight_y_offset = 10 + +/obj/item/gun/energy/disabler/add_seclight_point() + AddComponent(/datum/component/seclite_attachable, \ + light_overlay_icon = 'icons/obj/guns/flashlights.dmi', \ + light_overlay = "flight", \ + overlay_x = 15, \ + overlay_y = 10) /obj/item/gun/energy/disabler/cyborg name = "cyborg disabler" diff --git a/tgstation.dme b/tgstation.dme index 0d701f5dcca..5727cb5a503 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -800,6 +800,7 @@ #include "code\datums\components\rot.dm" #include "code\datums\components\rotation.dm" #include "code\datums\components\scope.dm" +#include "code\datums\components\seclight_attachable.dm" #include "code\datums\components\shell.dm" #include "code\datums\components\shielded.dm" #include "code\datums\components\shrink.dm" @@ -2642,6 +2643,7 @@ #include "code\modules\clothing\head\helmet.dm" #include "code\modules\clothing\head\jobs.dm" #include "code\modules\clothing\head\justice.dm" +#include "code\modules\clothing\head\mind_monkey_helmet.dm" #include "code\modules\clothing\head\moth.dm" #include "code\modules\clothing\head\papersack.dm" #include "code\modules\clothing\head\pirate.dm"