-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathrepacking.dm
More file actions
101 lines (79 loc) · 4.28 KB
/
repacking.dm
File metadata and controls
101 lines (79 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// An element that allows objects to be right clicked and turned into another item after a delay
/datum/element/repackable
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// The path to spawn when the repacking operation is complete
var/item_to_pack_into
/// How long will repacking the attachee take
var/repacking_time
/// Do we tell objects destroyed that we disassembled them?
var/disassemble_objects
///are we a generic repack?
var/generic_repack
/datum/element/repackable/Attach(datum/target, item_to_pack_into = /obj/item/flatpacked_machine, repacking_time = 1 SECONDS, disassemble_objects = TRUE, generic_repack = FALSE)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE
if(generic_repack && !ispath(item_to_pack_into, /obj/item/flatpacked_machine/generic))
return ELEMENT_INCOMPATIBLE
src.item_to_pack_into = item_to_pack_into
src.repacking_time = repacking_time
src.disassemble_objects = disassemble_objects
src.generic_repack = generic_repack
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(examine))
RegisterSignal(target, COMSIG_ATOM_ATTACK_HAND_SECONDARY, PROC_REF(on_right_click))
RegisterSignal(target, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, PROC_REF(on_requesting_context_from_item))
/datum/element/repackable/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_ATOM_EXAMINE)
UnregisterSignal(target, COMSIG_ATOM_ATTACK_HAND_SECONDARY)
UnregisterSignal(target, list(COMSIG_ATOM_ATTACKBY, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM))
/datum/element/repackable/proc/examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("It can be <b>repacked</b> with <b>right click</b>.")
/// Checks if the user can actually interact with the structures in question, then invokes the proc to make it repack
/datum/element/repackable/proc/on_right_click(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.can_perform_action(source, NEED_DEXTERITY))
return
INVOKE_ASYNC(src, PROC_REF(repack), source, user)
return COMPONENT_CANCEL_ATTACK_CHAIN
/// Removes the element target and spawns a new one of whatever item_to_pack_into is
/datum/element/repackable/proc/repack(atom/source, mob/user)
source.balloon_alert_to_viewers("repacking...")
if(!do_after(user, repacking_time, target = source))
return
playsound(source, 'sound/items/ratchet.ogg', 50, TRUE)
if(hascall(source, "prepare_for_packing"))
call(source, "prepare_for_packing")()
else if(hascall(source, "build_packed_material_cache"))
call(source, "build_packed_material_cache")()
var/obj/item/new_pack
if(generic_repack)
var/obj/item/flatpacked_machine/generic/new_generic_pack = new item_to_pack_into(source.drop_location())
new_pack = new_generic_pack
new_generic_pack.type_to_deploy = source.type
new_generic_pack.after_set()
else
new_pack = new item_to_pack_into(source.drop_location())
if(new_pack && ("imported_designs" in source.vars) && ("imported_designs" in new_pack.vars))
var/list/imported_designs = source.vars["imported_designs"]
new_pack.vars["imported_designs"] = islist(imported_designs) ? imported_designs.Copy() : list()
if(new_pack && ("unlocked_techfab_departments" in source.vars) && ("unlocked_techfab_departments" in new_pack.vars))
var/list/unlocked_techfab_departments = source.vars["unlocked_techfab_departments"]
new_pack.vars["unlocked_techfab_departments"] = islist(unlocked_techfab_departments) ? unlocked_techfab_departments.Copy() : list()
if(new_pack && ("lathe_recipe_set" in source.vars) && ("lathe_recipe_set" in new_pack.vars))
new_pack.vars["lathe_recipe_set"] = source.vars["lathe_recipe_set"]
if(new_pack && ("packed_materials" in source.vars) && ("packed_materials" in new_pack.vars))
var/list/packed_materials = source.vars["packed_materials"]
new_pack.vars["packed_materials"] = islist(packed_materials) ? packed_materials.Copy() : list()
if(new_pack && hascall(source, "transfer_contents_to_packed_item"))
call(source, "transfer_contents_to_packed_item")(new_pack)
qdel(source)
/// Adds screen context for hovering over the repackable items with your mouse
/datum/element/repackable/proc/on_requesting_context_from_item(atom/source, list/context, obj/item/held_item, mob/user)
SIGNAL_HANDLER
if(isnull(held_item))
context[SCREENTIP_CONTEXT_RMB] = "Repack"
. = CONTEXTUAL_SCREENTIP_SET
return NONE