From 9dd28d5180c6115cddfcbe03d34b0742ee9f2bfd Mon Sep 17 00:00:00 2001 From: Rohesie Date: Wed, 30 Oct 2019 20:17:55 -0300 Subject: [PATCH] ID fix (#47387) --- code/__DEFINES/is_helpers.dm | 2 + code/game/machinery/computer/card.dm | 45 +++++++----- code/game/objects/items/cards_ids.dm | 8 +-- code/game/objects/items/devices/PDA/PDA.dm | 68 +++++++++++++------ code/game/objects/items/storage/wallets.dm | 15 ++++ code/modules/jobs/access.dm | 6 ++ .../mob/living/carbon/human/human_helpers.dm | 6 ++ code/modules/mob/mob.dm | 3 + .../computers/item/computer.dm | 15 ++++ .../modular_computers/hardware/card_slot.dm | 11 +++ 10 files changed, 139 insertions(+), 40 deletions(-) diff --git a/code/__DEFINES/is_helpers.dm b/code/__DEFINES/is_helpers.dm index 0e17b4d47bf..1827032d94e 100644 --- a/code/__DEFINES/is_helpers.dm +++ b/code/__DEFINES/is_helpers.dm @@ -163,6 +163,8 @@ GLOBAL_LIST_INIT(turfs_without_ground, typecacheof(list( #define isitem(A) (istype(A, /obj/item)) +#define isidcard(I) (istype(I, /obj/item/card/id)) + #define isstructure(A) (istype(A, /obj/structure)) #define ismachinery(A) (istype(A, /obj/machinery)) diff --git a/code/game/machinery/computer/card.dm b/code/game/machinery/computer/card.dm index a6dd90b968d..74e3ad47cc3 100644 --- a/code/game/machinery/computer/card.dm +++ b/code/game/machinery/computer/card.dm @@ -65,7 +65,7 @@ GLOBAL_VAR_INIT(time_last_changed_position, 0) . += "Alt-click to eject the ID card." /obj/machinery/computer/card/attackby(obj/I, mob/user, params) - if(istype(I, /obj/item/card/id)) + if(isidcard(I)) if(check_access(I) && !inserted_scan_id) if(id_insert(user, I, inserted_scan_id)) inserted_scan_id = I @@ -130,13 +130,26 @@ GLOBAL_VAR_INIT(time_last_changed_position, 0) return JOB_MAX_POSITIONS return JOB_DENIED -/obj/machinery/computer/card/proc/id_insert(mob/user, obj/item/card/id/I, target) - if(!user.transferItemToLoc(I, src)) + +/obj/machinery/computer/card/proc/id_insert(mob/user, obj/item/inserting_item, obj/item/target) + var/obj/item/card/id/card_to_insert = inserting_item + var/holder_item = FALSE + + if(!isidcard(card_to_insert)) + card_to_insert = inserting_item.RemoveID() + holder_item = TRUE + + if(!card_to_insert || !user.transferItemToLoc(card_to_insert, src)) return FALSE + if(target) - id_eject(user, target) - user.visible_message("[user] inserts \the [I] into \the [src].", \ - "You insert \the [I] into \the [src].") + if(holder_item && inserting_item.InsertID(target)) + playsound(src, 'sound/machines/terminal_insert_disc.ogg', 50, FALSE) + else + id_eject(user, target) + + user.visible_message("[user] inserts \the [card_to_insert] into \the [src].", + "You insert \the [card_to_insert] into \the [src].") playsound(src, 'sound/machines/terminal_insert_disc.ogg', 50, FALSE) updateUsrDialog() return TRUE @@ -359,11 +372,11 @@ GLOBAL_VAR_INIT(time_last_changed_position, 0) inserted_modify_id = null updateUsrDialog() return - var/mob/M = usr - if(M.get_idcard(TRUE)) - var/obj/item/card/id/I = M.get_idcard(TRUE) - if(id_insert(usr, I, inserted_modify_id)) - inserted_modify_id = I + if(usr.get_id_in_hand()) + var/obj/item/held_item = usr.get_active_held_item() + var/obj/item/card/id/id_to_insert = held_item.GetID() + if(id_insert(usr, held_item, inserted_modify_id)) + inserted_modify_id = id_to_insert updateUsrDialog() if ("inserted_scan_id") if(inserted_scan_id && !usr.get_active_held_item()) @@ -371,11 +384,11 @@ GLOBAL_VAR_INIT(time_last_changed_position, 0) inserted_scan_id = null updateUsrDialog() return - var/mob/M = usr - if(M.get_idcard(TRUE)) - var/obj/item/card/id/I = M.get_idcard(TRUE) - if(id_insert(usr, I, inserted_scan_id)) - inserted_scan_id = I + if(usr.get_id_in_hand()) + var/obj/item/held_item = usr.get_active_held_item() + var/obj/item/card/id/id_to_insert = held_item.GetID() + if(id_insert(usr, held_item, inserted_scan_id)) + inserted_scan_id = id_to_insert updateUsrDialog() if ("auth") if ((!( authenticated ) && (inserted_scan_id || issilicon(usr)) || mode)) diff --git a/code/game/objects/items/cards_ids.dm b/code/game/objects/items/cards_ids.dm index d5a02080737..4c67037673f 100644 --- a/code/game/objects/items/cards_ids.dm +++ b/code/game/objects/items/cards_ids.dm @@ -49,11 +49,6 @@ detail_overlay.color = detail_color add_overlay(detail_overlay) -/obj/item/proc/GetCard() - -/obj/item/card/data/GetCard() - return src - /obj/item/card/data/full_color desc = "A plastic magstripe card for simple and speedy data storage and transfer. This one has the entire card colored." icon_state = "data_2" @@ -299,6 +294,9 @@ /obj/item/card/id/GetID() return src +/obj/item/card/id/RemoveID() + return src + /obj/item/card/id/update_icon(blank=FALSE) cut_overlays() cached_flat_icon = null diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm index 6e7db944ab5..75e0dd2dca8 100644 --- a/code/game/objects/items/devices/PDA/PDA.dm +++ b/code/game/objects/items/devices/PDA/PDA.dm @@ -147,6 +147,18 @@ GLOBAL_LIST_EMPTY(PDAs) /obj/item/pda/GetID() return id +/obj/item/pda/RemoveID() + return do_remove_id() + +/obj/item/pda/InsertID(obj/item/inserting_item) + var/obj/item/card/inserting_id = inserting_item.RemoveID() + if(!inserting_id) + return + insert_id(inserting_id) + if(id == inserting_id) + return TRUE + return FALSE + /obj/item/pda/update_icon() cut_overlays() var/mutable_appearance/overlay = new() @@ -591,19 +603,29 @@ GLOBAL_LIST_EMPTY(PDAs) return /obj/item/pda/proc/remove_id() - if(issilicon(usr) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return + do_remove_id(usr) + + +/obj/item/pda/proc/do_remove_id(mob/user) + if(!id) + return + if(user) + user.put_in_hands(id) + to_chat(user, "You remove the ID from the [name].") + else + id.forceMove(get_turf(src)) + + . = id + id = null + update_icon() + + if(ishuman(loc)) + var/mob/living/carbon/human/H = loc + if(H.wear_id == src) + H.sec_hud_set_ID() - if (id) - usr.put_in_hands(id) - to_chat(usr, "You remove the ID from the [name].") - id = null - update_icon() - if(ishuman(loc)) - var/mob/living/carbon/human/H = loc - if(H.wear_id == src) - H.sec_hud_set_ID() /obj/item/pda/proc/msg_input(mob/living/U = usr) var/t = stripped_input(U, "Please enter message", name) @@ -791,20 +813,28 @@ GLOBAL_LIST_EMPTY(PDAs) if(istype(C)) I = C - if(I && I.registered_name) + if(I?.registered_name) if(!user.transferItemToLoc(I, src)) return FALSE - var/obj/old_id = id - id = I - if(ishuman(loc)) - var/mob/living/carbon/human/H = loc - if(H.wear_id == src) - H.sec_hud_set_ID() - if(old_id) - user.put_in_hands(old_id) + insert_id(I, user) update_icon() return TRUE + +/obj/item/pda/proc/insert_id(obj/item/card/id/inserting_id, mob/user) + var/obj/old_id = id + id = inserting_id + if(ishuman(loc)) + var/mob/living/carbon/human/human_wearer = loc + if(human_wearer.wear_id == src) + human_wearer.sec_hud_set_ID() + if(old_id) + if(user) + user.put_in_hands(old_id) + else + old_id.forceMove(get_turf(src)) + + // access to status display signals /obj/item/pda/attackby(obj/item/C, mob/user, params) if(istype(C, /obj/item/cartridge) && !cartridge) diff --git a/code/game/objects/items/storage/wallets.dm b/code/game/objects/items/storage/wallets.dm index fbb116e4240..3b0b9f35ba6 100644 --- a/code/game/objects/items/storage/wallets.dm +++ b/code/game/objects/items/storage/wallets.dm @@ -105,6 +105,21 @@ /obj/item/storage/wallet/GetID() return front_id +/obj/item/storage/wallet/RemoveID() + if(!front_id) + return + . = front_id + front_id.forceMove(get_turf(src)) + +/obj/item/storage/wallet/InsertID(obj/item/inserting_item) + var/obj/item/card/inserting_id = inserting_item.RemoveID() + if(!inserting_id) + return FALSE + attackby(inserting_id) + if(inserting_id in contents) + return TRUE + return FALSE + /obj/item/storage/wallet/GetAccess() if(LAZYLEN(combined_access)) return combined_access diff --git a/code/modules/jobs/access.dm b/code/modules/jobs/access.dm index ca4585a90bc..b31bb8eaae3 100644 --- a/code/modules/jobs/access.dm +++ b/code/modules/jobs/access.dm @@ -35,6 +35,12 @@ /obj/item/proc/GetID() return null +/obj/item/proc/RemoveID() + return null + +/obj/item/proc/InsertID() + return FALSE + /obj/proc/text2access(access_text) . = list() if(!access_text) diff --git a/code/modules/mob/living/carbon/human/human_helpers.dm b/code/modules/mob/living/carbon/human/human_helpers.dm index 9b203b75c0a..cf8544f3fd3 100644 --- a/code/modules/mob/living/carbon/human/human_helpers.dm +++ b/code/modules/mob/living/carbon/human/human_helpers.dm @@ -114,6 +114,12 @@ if(id_card) return id_card +/mob/living/carbon/human/get_id_in_hand() + var/obj/item/held_item = get_active_held_item() + if(!held_item) + return + return held_item.GetID() + /mob/living/carbon/human/IsAdvancedToolUser() if(HAS_TRAIT(src, TRAIT_MONKEYLIKE)) return FALSE diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index c3abb12a270..b1872173930 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -1117,6 +1117,9 @@ /mob/proc/get_idcard(hand_first) return +/mob/proc/get_id_in_hand() + return + /** * Get the mob VV dropdown extras */ diff --git a/code/modules/modular_computers/computers/item/computer.dm b/code/modules/modular_computers/computers/item/computer.dm index 36424d201cf..ccfddd3999e 100644 --- a/code/modules/modular_computers/computers/item/computer.dm +++ b/code/modules/modular_computers/computers/item/computer.dm @@ -157,6 +157,21 @@ return card_slot.GetID() return ..() +/obj/item/modular_computer/RemoveID() + var/obj/item/computer_hardware/card_slot/card_slot = all_components[MC_CARD] + if(!card_slot) + return + return card_slot.RemoveID() + +/obj/item/modular_computer/InsertID(obj/item/inserting_item) + var/obj/item/computer_hardware/card_slot/card_slot = all_components[MC_CARD] + if(!card_slot) + return FALSE + var/obj/item/card/inserting_id = inserting_item.RemoveID() + if(!inserting_id) + return FALSE + return card_slot.try_insert(inserting_id) + /obj/item/modular_computer/MouseDrop(obj/over_object, src_location, over_location) var/mob/M = usr if((!istype(over_object, /obj/screen)) && usr.canUseTopic(src, BE_CLOSE)) diff --git a/code/modules/modular_computers/hardware/card_slot.dm b/code/modules/modular_computers/hardware/card_slot.dm index 438e99bf569..18b423a42ea 100644 --- a/code/modules/modular_computers/hardware/card_slot.dm +++ b/code/modules/modular_computers/hardware/card_slot.dm @@ -36,6 +36,17 @@ return stored_card2 return ..() +/obj/item/computer_hardware/card_slot/RemoveID() + if(stored_card) + . = stored_card + if(!try_eject(1)) + return null + return + if(stored_card2) + . = stored_card2 + if(!try_eject(2)) + return null + /obj/item/computer_hardware/card_slot/on_install(obj/item/modular_computer/M, mob/living/user = null) M.add_verb(device_type)