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

[MIRROR] Makes it EVEN EASIER to work with atom item interactions ft. "Leaf and Branch" & "Death to Chains" #2958

Merged
merged 1 commit into from
Apr 19, 2024
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
4 changes: 2 additions & 2 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var/list/modifiers = params2list(params)
var/is_right_clicking = LAZYACCESS(modifiers, RIGHT_CLICK)

var/item_interact_result = target.item_interaction(user, src, modifiers, is_right_clicking)
var/item_interact_result = target.base_item_interaction(user, src, modifiers)
if(item_interact_result & ITEM_INTERACT_SUCCESS)
return TRUE
if(item_interact_result & ITEM_INTERACT_BLOCKING)
Expand Down Expand Up @@ -159,7 +159,7 @@
return FALSE
return attacking_item.attack_atom(src, user, params)

/mob/living/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
/mob/living/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
// Surgery and such happens very high up in the interaction chain, before parent call
var/attempt_tending = item_tending(user, tool, modifiers)
if(attempt_tending & ITEM_INTERACT_ANY_BLOCKER)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/style/style_meter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
. = ..()
. += span_notice("You feel like a <b>multitool</b> could be used on this.")

/obj/item/style_meter/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/style_meter/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!istype(interacting_with, /obj/item/clothing/glasses))
return NONE

Expand Down
12 changes: 12 additions & 0 deletions code/datums/elements/ridable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,15 @@
to_chat(user, span_notice("You gently let go of [rider]."))
return
return rider

/obj/item/riding_offhand/interact_with_atom(atom/movable/interacting_with, mob/living/user, list/modifiers)
if(!istype(interacting_with) || !interacting_with.can_buckle)
return NONE
if(rider == user) // Piggyback user
return ITEM_INTERACT_BLOCKING

// Handles de-fireman carrying a mob and buckling them onto something (tables, etc)
var/mob/living/former_rider = rider
user.unbuckle_mob(former_rider)
former_rider.forceMove(get_turf(interacting_with))
return interacting_with.mouse_buckle_handling(former_rider, user) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING
34 changes: 29 additions & 5 deletions code/game/atom/atom_tool_acts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
* Handles non-combat iteractions of a tool on this atom,
* such as using a tool on a wall to deconstruct it,
* or scanning someone with a health analyzer
*
* This can be overridden to add custom item interactions to this atom
*
* Do not call this directly
*/
/atom/proc/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
/atom/proc/base_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
SHOULD_CALL_PARENT(TRUE)
PROTECTED_PROC(TRUE)

var/is_right_clicking = LAZYACCESS(modifiers, RIGHT_CLICK)
var/is_left_clicking = !is_right_clicking
var/early_sig_return = NONE
if(is_left_clicking)
Expand All @@ -24,6 +21,12 @@
if(early_sig_return)
return early_sig_return

var/self_interaction = is_left_clicking \
? item_interaction(user, tool, modifiers) \
: item_interaction_secondary(user, tool, modifiers)
if(self_interaction)
return self_interaction

var/interact_return = is_left_clicking \
? tool.interact_with_atom(src, user, modifiers) \
: tool.interact_with_atom_secondary(src, user, modifiers)
Expand Down Expand Up @@ -85,6 +88,27 @@
SEND_SIGNAL(tool, COMSIG_TOOL_ATOM_ACTED_SECONDARY(tool_type), src)
return act_result

/**
* Called when this atom has an item used on it.
* IE, a mob is clicking on this atom with an item.
*
* Return an ITEM_INTERACT_ flag in the event the interaction was handled, to cancel further interaction code.
* Return NONE to allow default interaction / tool handling.
*/
/atom/proc/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
return NONE

/**
* Called when this atom has an item used on it WITH RIGHT CLICK,
* IE, a mob is right clicking on this atom with an item.
* Default behavior has it run the same code as left click.
*
* Return an ITEM_INTERACT_ flag in the event the interaction was handled, to cancel further interaction code.
* Return NONE to allow default interaction / tool handling.
*/
/atom/proc/item_interaction_secondary(mob/living/user, obj/item/tool, list/modifiers)
return item_interaction(user, tool, modifiers)

/**
* Called when this item is being used to interact with an atom,
* IE, a mob is clicking on an atom with this item.
Expand Down
11 changes: 6 additions & 5 deletions code/game/machinery/_machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,14 @@
return
update_last_used(user)

/obj/machinery/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
/obj/machinery/base_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(SEND_SIGNAL(user, COMSIG_TRY_USE_MACHINE, src) & COMPONENT_CANT_USE_MACHINE_TOOLS)
return ITEM_INTERACT_ANY_BLOCKER
return ITEM_INTERACT_BLOCKING

. = ..()
if(. & ITEM_INTERACT_BLOCKING)
return
update_last_used(user)
if(.)
update_last_used(user)
return .

/obj/machinery/_try_interact(mob/user)
if((interaction_flags_machine & INTERACT_MACHINE_WIRES_IF_OPEN) && panel_open && (attempt_wire_interaction(user) == WIRE_INTERACTION_BLOCK))
Expand Down
10 changes: 3 additions & 7 deletions code/game/machinery/computer/arcade/_arcade.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
///Like prize pool, it must be a list of the prize and the weight of being selected.
var/list/prize_override

/obj/machinery/computer/arcade/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .

/obj/machinery/computer/arcade/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(istype(tool, /obj/item/stack/arcadeticket))
var/obj/item/stack/arcadeticket/tickets = tool
if(!tickets.use(2))
Expand Down Expand Up @@ -44,6 +40,8 @@
reset_cabinet(user)
return ITEM_INTERACT_SUCCESS

return NONE

/obj/machinery/computer/arcade/screwdriver_act(mob/living/user, obj/item/I)
//you can't stop playing when you start.
if(obj_flags & EMAGGED)
Expand Down Expand Up @@ -100,5 +98,3 @@
var/atom/movable/the_prize = new prizeselect(get_turf(src))
playsound(src, 'sound/machines/machine_vend.ogg', 50, TRUE, extrarange = -3)
visible_message(span_notice("[src] dispenses [the_prize]!"), span_notice("You hear a chime and a clunk."))


2 changes: 1 addition & 1 deletion code/game/machinery/computer/buildandrepair.dm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@

return FALSE

/obj/structure/frame/computer/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
/obj/structure/frame/computer/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .
Expand Down
9 changes: 2 additions & 7 deletions code/game/machinery/constructable_frame.dm
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,10 @@
return ITEM_INTERACT_BLOCKING
return .

/obj/structure/frame/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .

/obj/structure/frame/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(istype(tool, /obj/item/circuitboard)) // Install board will fail if passed an invalid circuitboard and give feedback
return install_board(user, tool, by_hand = TRUE) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING

return .
return NONE

/**
* Installs the passed circuit board into the frame
Expand Down
15 changes: 11 additions & 4 deletions code/game/machinery/machine_frame.dm
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
balloon_alert(user, "can't add that!")
return FALSE

/obj/structure/frame/machine/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
/obj/structure/frame/machine/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .
Expand All @@ -416,11 +416,18 @@
if(istype(tool, /obj/item/storage/part_replacer))
return install_parts_from_part_replacer(user, tool) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING

if(!user.combat_mode)
return add_part(user, tool) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING

return .

// Override of base_item_interaction so we only try to add parts to the frame AFTER running item_interaction and all the tool_acts
/obj/structure/frame/machine/base_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .
if(user.combat_mode)
return NONE

return add_part(user, tool) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING

/**
* Attempt to finalize the construction of the frame into a machine
* as according to our circuit and parts
Expand Down
40 changes: 23 additions & 17 deletions code/game/machinery/slotmachine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -94,50 +94,56 @@
return ..()


/obj/machinery/computer/slot_machine/item_interaction(mob/living/user, obj/item/inserted, list/modifiers, is_right_clicking)
/obj/machinery/computer/slot_machine/item_interaction(mob/living/user, obj/item/inserted, list/modifiers)
if(istype(inserted, /obj/item/coin))
var/obj/item/coin/inserted_coin = inserted
if(paymode == COIN)
if(prob(2))
if(!user.transferItemToLoc(inserted_coin, drop_location(), silent = FALSE))
return
return ITEM_INTERACT_BLOCKING
inserted_coin.throw_at(user, 3, 10)
if(prob(10))
balance = max(balance - SPIN_PRICE, 0)
to_chat(user, span_warning("[src] spits your coin back out!"))

return ITEM_INTERACT_BLOCKING
else
if(!user.temporarilyRemoveItemFromInventory(inserted_coin))
return
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "coin insterted")
balance += inserted_coin.value
qdel(inserted_coin)
return ITEM_INTERACT_SUCCESS
else
balloon_alert(user, "holochips only!")
return ITEM_INTERACT_BLOCKING

else if(istype(inserted, /obj/item/holochip))
if(istype(inserted, /obj/item/holochip))
if(paymode == HOLOCHIP)
var/obj/item/holochip/inserted_chip = inserted
if(!user.temporarilyRemoveItemFromInventory(inserted_chip))
return
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "[inserted_chip.credits] credit[inserted_chip.credits == 1 ? "" : "s"] inserted")
balance += inserted_chip.credits
qdel(inserted_chip)
return ITEM_INTERACT_SUCCESS
else
balloon_alert(user, "coins only!")
return ITEM_INTERACT_BLOCKING

else if(inserted.tool_behaviour == TOOL_MULTITOOL)
if(balance > 0)
visible_message("<b>[src]</b> says, 'ERROR! Please empty the machine balance before altering paymode'") //Prevents converting coins into holocredits and vice versa
else
if(paymode == HOLOCHIP)
paymode = COIN
balloon_alert(user, "now using coins")
else
paymode = HOLOCHIP
balloon_alert(user, "now using holochips")
return NONE

/obj/machinery/computer/slot_machine/multitool_act(mob/living/user, obj/item/tool)
if(balance > 0)
visible_message("<b>[src]</b> says, 'ERROR! Please empty the machine balance before altering paymode'") //Prevents converting coins into holocredits and vice versa
return ITEM_INTERACT_BLOCKING

if(paymode == HOLOCHIP)
paymode = COIN
balloon_alert(user, "now using coins")
else
return ..()
paymode = HOLOCHIP
balloon_alert(user, "now using holochips")
return ITEM_INTERACT_SUCCESS

/obj/machinery/computer/slot_machine/emag_act(mob/user, obj/item/card/emag/emag_card)
if(obj_flags & EMAGGED)
Expand Down
12 changes: 0 additions & 12 deletions code/game/objects/buckling.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
if(user_unbuckle_mob(buckled_mobs[1],user))
return TRUE

/atom/movable/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
if(!can_buckle || !istype(tool, /obj/item/riding_offhand) || !user.Adjacent(src))
return ..()

var/obj/item/riding_offhand/riding_item = tool
var/mob/living/carried_mob = riding_item.rider
if(carried_mob == user) //Piggyback user.
return ITEM_INTERACT_BLOCKING
user.unbuckle_mob(carried_mob)
carried_mob.forceMove(get_turf(src))
return mouse_buckle_handling(carried_mob, user) ? ITEM_INTERACT_SUCCESS: ITEM_INTERACT_BLOCKING

//literally just the above extension of attack_hand(), but for silicons instead (with an adjacency check, since attack_robot() being called doesn't mean that you're adjacent to something)
/atom/movable/attack_robot(mob/living/user)
. = ..()
Expand Down
9 changes: 3 additions & 6 deletions code/game/objects/items/devices/laserpointer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@
diode = null
return TRUE

/obj/item/laser_pointer/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
. = ..()
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .
/obj/item/laser_pointer/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(isnull(crystal_lens))
return .
return NONE
if(tool_behaviour != TOOL_WIRECUTTER && tool_behaviour != TOOL_HEMOSTAT)
return .
return NONE
tool.play_tool_sound(src)
balloon_alert(user, "removed crystal lens")
crystal_lens.forceMove(drop_location())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT*2)
custom_price = PAYCHECK_COMMAND

/obj/item/autopsy_scanner/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/autopsy_scanner/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE
if(!user.can_read(src) || user.is_blind())
Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/items/devices/scanners/health_analyzer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
if(SCANMODE_WOUND)
to_chat(user, span_notice("You switch the health analyzer to report extra info on wounds."))

/obj/item/healthanalyzer/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/healthanalyzer/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE
if(!user.can_read(src)) //NOVA EDIT CHANGE - Blind People Can Analyze Again- ORIGINAL: if(!user.can_read(src) || user.is_blind())
Expand Down Expand Up @@ -89,7 +89,7 @@

add_fingerprint(user)

/obj/item/healthanalyzer/interact_with_atom_secondary(atom/interacting_with, mob/living/user)
/obj/item/healthanalyzer/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE
if(!user.can_read(src)) // NOVA EDIT CHANGE - Blind people can analyze again - ORIGINAL: if(!user.can_read(src) || user.is_blind())
Expand Down Expand Up @@ -596,7 +596,7 @@
/obj/item/healthanalyzer/simple/proc/violence_damage(mob/living/user)
user.adjustBruteLoss(4)

/obj/item/healthanalyzer/simple/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/healthanalyzer/simple/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE
if(!user.can_read(src)) //NOVA EDIT CHANGE - Blind People Can Analyze Again - ORIGINAL: if(!user.can_read(src) || user.is_blind())
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/devices/scanners/sequence_scanner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if(LAZYLEN(genetic_makeup_buffer) > 0)
. += span_notice("It has the genetic makeup of \"[genetic_makeup_buffer["name"]]\" stored inside its buffer")

/obj/item/sequence_scanner/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/sequence_scanner/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE

Expand All @@ -46,7 +46,7 @@
user.visible_message(span_notice("[user] fails to analyze [interacting_with]'s genetic sequence."), span_warning("[interacting_with] has no readable genetic sequence!"))
return ITEM_INTERACT_BLOCKING

/obj/item/sequence_scanner/interact_with_atom_secondary(atom/interacting_with, mob/living/user)
/obj/item/sequence_scanner/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE

Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/scanners/slime_scanner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
throw_range = 7
custom_materials = list(/datum/material/iron=SMALL_MATERIAL_AMOUNT*0.30, /datum/material/glass=SMALL_MATERIAL_AMOUNT * 0.20)

/obj/item/slime_scanner/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/slime_scanner/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isliving(interacting_with))
return NONE
if(!user.can_read(src)) //NOVA EDIT CHANGE - Blind People Can Analyze Again - ORIGINAL : if(!user.can_read(src) || user.is_blind())
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/traitordevices.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ effective or pretty fucking useless.
var/intensity = 10 // how much damage the radiation does
var/wavelength = 10 // time it takes for the radiation to kick in, in seconds

/obj/item/healthanalyzer/rad_laser/interact_with_atom(atom/interacting_with, mob/living/user)
/obj/item/healthanalyzer/rad_laser/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!stealth || !irradiate)
. = ..()

Expand Down
Loading
Loading