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

Introduction of the assembly component and refactoring of pipeframe assemblies #15687

Merged
merged 11 commits into from
Sep 12, 2023
Merged
12 changes: 12 additions & 0 deletions code/datums/components/_component.dm
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ var/datum/signal_holder/global_signal_holder
return list()
return islist(components) ? components : list(components)

/**
* Calls RemoveComponent on all components of a given type that are attached to this datum
*
* Arguments:
* * c_type The component type path
*/

/datum/proc/RemoveComponentsOfType(c_type)
var/list/datum/component/component_to_remove_list = src.GetComponents(c_type)
for (var/datum/component/component_to_remove as anything in component_to_remove_list)
component_to_remove.RemoveComponent()

/**
* Creates an instance of `new_type` in the datum and attaches to it as parent
*
Expand Down
62 changes: 62 additions & 0 deletions code/datums/components/assembly_comp.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
TYPEINFO(/datum/component/assembly)
initialization_args = list(
ARG_INFO("to_combine_item", DATA_INPUT_TYPE, "path or list of items that will trigger this proc when used on. Can take tool-bitflags like TOOL_CUTTING."),
ARG_INFO("proc_to_call", DATA_INPUT_REF, "The proc reference that will be called when the item can be assembled"),
ARG_INFO("on_tool_attack", DATA_INPUT_BOOL, "Set this to TRUE if you want the component to fire if the construction should go two-ways.", FALSE),
)

///This component calls a procref with a assembly_information string on the atom it was added to when it gets attacked with an object specified in the to_combine_item
///This component can be used to get the convulent if-then-else trees of assemblies under control
///Make the proc you call on sucessfull assembly return TRUE. Else the attack will go through!

/datum/component/assembly
dupe_mode = COMPONENT_DUPE_ALLOWED //We want to have multiple differnt assembly types on an item for different assembly steps
///The item(s) that are used to combine with the atom this component is attached to
///use a tool-bitflags like TOOL_CUTTING, if you want to go with groups of tools
var/to_combine_item = null
ZeWaka marked this conversation as resolved.
Show resolved Hide resolved
///The Procref that will get called when the items are compatible
var/valid_assembly_proc = null



/datum/component/assembly/Initialize(var/required_item, var/called_proc, var/on_tool_attack = FALSE)
if(!src.parent || !required_item || !called_proc)
return COMPONENT_INCOMPATIBLE
. = ..()
src.to_combine_item = required_item
src.valid_assembly_proc = called_proc
RegisterSignal(src.parent, COMSIG_ATTACKBY, PROC_REF(attackby))
if(on_tool_attack)
RegisterSignal(src.parent, COMSIG_ITEM_ATTACKBY_PRE, PROC_REF(on_pre_attack))

/datum/component/assembly/UnregisterFromParent()
. = ..()
UnregisterSignal(src.parent, COMSIG_ITEM_ATTACKBY_PRE)
UnregisterSignal(src.parent, COMSIG_ATTACKBY)


/datum/component/assembly/proc/on_pre_attack(var/atom/affected_parent, var/atom/to_combine_atom, var/mob/user, var/damage)
return try_combination(to_combine_atom, user)

/datum/component/assembly/proc/attackby(var/atom/affected_parent, var/atom/to_combine_atom, var/mob/user, var/params, var/is_special)
return try_combination(to_combine_atom, user)

/datum/component/assembly/proc/try_combination(var/atom/checked_atom, var/mob/user)
var/is_combinable = FALSE
//if to_combine_item is a list, we look if we find the item in there
if (islist(src.to_combine_item))
var/list/combinable_items = src.to_combine_item
for(var/to_checked_type in combinable_items)
if(istype(checked_atom, to_checked_type))
is_combinable = TRUE
//if it is a number, it most likely is a bitflag we passed
else if (isnum_safe(src.to_combine_item))
if (istool(checked_atom, src.to_combine_item))
is_combinable = TRUE
else if (istype(checked_atom, src.to_combine_item))
is_combinable = TRUE

if(is_combinable)
//if the assembly is valid, we go and call the proc
//we need to return true so onattack does not trigger. Else we would still attack a completed assembly
return call(src.parent, src.valid_assembly_proc)(checked_atom, user)
21 changes: 0 additions & 21 deletions code/modules/medical/surgery_tools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -308,27 +308,6 @@ CONTAINS:
surgery_limb.surgery(src)
return

attackby(obj/item/W, mob/user)
..()

if (istype(W,/obj/item/pipebomb/frame))
var/obj/item/pipebomb/frame/F = W
if (F.state < 2)
user.show_text("This might work better if [F] was hollowed out.")
else if (F.state == 2)
user.show_text("You combine [F] and [src]. This looks pretty unsafe!")
user.u_equip(F)
user.u_equip(src)
playsound(src, 'sound/items/Deconstruct.ogg', 50, 1)
var/obj/item/gun/kinetic/zipgun/Z = new/obj/item/gun/kinetic/zipgun
user.put_in_hand_or_drop(Z)
qdel(F)
qdel(src)

else
user.show_text("You can't seem to combine these two items this way.")
return


// a mostly decorative thing from z2 areas I want to add to office closets
/obj/item/staple_gun/red
Expand Down