Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helmet Light fixes #492

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 49 additions & 159 deletions code/modules/clothing/head/helmet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,90 +15,49 @@

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)
AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HEAD)


/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 <b>unscrewed</b> from [src].")
else if(can_flashlight)
. += "It has a mounting point for a <b>seclite</b>."


/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))


/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

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/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
/obj/item/clothing/head/helmet/alt
name = "bulletproof helmet"
desc = "A bulletproof combat helmet that excels in protecting the wearer against traditional projectile weaponry and explosives to a minor extent."
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
supports_variations_flags = CLOTHING_TESHARI_VARIATION | CLOTHING_VOX_VARIATION

/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."
Expand All @@ -108,14 +67,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"
Expand Down Expand Up @@ -161,20 +117,27 @@
supports_variations_flags = CLOTHING_TESHARI_VARIATION | CLOTHING_VOX_VARIATION

/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]."))

user.update_worn_head()
if(iscarbon(user))
var/mob/living/carbon/C = user
C.head_update(src, forced = 1)
. = ..()
if(.)
return
if(!can_toggle)
return

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_worn_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"
Expand Down Expand Up @@ -532,76 +495,3 @@
if(magnification)
visible_message(span_warning("[src] falls off of [magnification]'s head as it changes shape!"))
magnification.dropItemToGround(src)

/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_worn_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()
10 changes: 7 additions & 3 deletions code/modules/mob/living/carbon/human/monkey/monkey.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +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_REF(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


/mob/living/carbon/human/species/monkey/punpun //except for a few special persistence features, pun pun is just a normal monkey
Expand Down
Loading