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

Barrel/well interaction rework. #4660

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
A.AltClick(src)

/atom/proc/AltClick(var/mob/user)
if(try_handle_interactions(user, get_alt_interactions(user), user?.get_active_held_item()))
if(try_handle_interactions(user, get_alt_interactions(user), user?.get_active_held_item(), check_alt_interactions = TRUE))
return TRUE
if(user?.get_preference_value(/datum/client_preference/show_turf_contents) == PREF_ALT_CLICK)
. = show_atom_list_for_turf(user, get_turf(src))
Expand Down
5 changes: 5 additions & 0 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ avoid code duplication. This includes items that may sometimes act as a standard

// If TRUE, prevent afterattack from running.
/atom/proc/attackby(obj/item/used_item, mob/user, var/click_params)

if(try_handle_interactions(user, get_standard_interactions(user), user?.get_active_held_item(), check_alt_interactions = FALSE))
return TRUE

if(storage)
if(isrobot(user) && (used_item == user.get_active_held_item()))
return FALSE //Robots can't store their modules.
if(!storage.can_be_inserted(used_item, user, click_params = click_params))
return FALSE
used_item.add_fingerprint(user)
return storage.handle_item_insertion(user, used_item, click_params = click_params)

return FALSE

/atom/movable/attackby(obj/item/W, mob/user)
Expand Down
3 changes: 3 additions & 0 deletions code/_onclick/other_mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
if(handle_grab_interaction(user))
return TRUE

if(try_handle_interactions(user, get_standard_interactions(user), user?.get_active_held_item(), check_alt_interactions = FALSE))
return TRUE

if(!LAZYLEN(climbers) || (user in climbers) || !user.check_dexterity(DEXTERITY_HOLD_ITEM, silent = TRUE))
return FALSE

Expand Down
27 changes: 11 additions & 16 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@

to_chat(user, "[html_icon(src)] That's [f_name] [suffix]")
to_chat(user, desc)

var/list/alt_interactions = get_alt_interactions(user)
if(LAZYLEN(alt_interactions))
var/list/interaction_strings = list()
for(var/interaction_type as anything in alt_interactions)
var/decl/interaction_handler/interaction = GET_DECL(interaction_type)
if(interaction.examine_desc && (interaction.always_show_on_examine || interaction.is_possible(src, user, user?.get_active_held_item())))
interaction_strings += emote_replace_target_tokens(interaction.examine_desc, src)
if(length(interaction_strings))
to_chat(user, SPAN_INFO("Alt-click on \the [src] to [english_list(interaction_strings, and_text = " or ")]."))

RAISE_EVENT(/decl/observ/atom_examined, src, user, distance)
return TRUE

Expand Down Expand Up @@ -894,22 +905,6 @@
return check_loc
check_loc = check_loc.loc

/**
Get a list of alt interactions for a user from this atom.

- `user`: The mob that these alt interactions are for
- Return: A list containing the alt interactions
*/
/atom/proc/get_alt_interactions(var/mob/user)
SHOULD_CALL_PARENT(TRUE)
RETURN_TYPE(/list)
. = list()
if(storage)
. += /decl/interaction_handler/storage_open
if(reagents?.total_volume && ATOM_IS_OPEN_CONTAINER(src))
. += /decl/interaction_handler/wash_hands
. += /decl/interaction_handler/drink

/atom/proc/can_climb_from_below(var/mob/climber)
return FALSE

Expand Down
35 changes: 35 additions & 0 deletions code/game/atoms_interactions.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// List of interactions used in procs below.
var/global/list/_reagent_interactions = list(
/decl/interaction_handler/wash_hands,
/decl/interaction_handler/drink,
/decl/interaction_handler/dip_item,
/decl/interaction_handler/fill_from,
/decl/interaction_handler/empty_into
)

/**
Get a list of standard interactions (attack_hand and attackby) for a user from this atom.
At time of writing, these are really easy to have interfere with or be interfered with by
attack_hand() and attackby() overrides. Putting them on items us a bad idea due to pickup code.

- `user`: The mob that these interactions are for
- Return: A list containing the interactions
*/
/atom/proc/get_standard_interactions(var/mob/user)
SHOULD_CALL_PARENT(TRUE)
RETURN_TYPE(/list)
return null

/**
Get a list of alt interactions (alt-click) for a user from this atom.

- `user`: The mob that these alt interactions are for
- Return: A list containing the alt interactions
*/
/atom/proc/get_alt_interactions(var/mob/user)
SHOULD_CALL_PARENT(TRUE)
RETURN_TYPE(/list)
if(storage)
LAZYADD(., /decl/interaction_handler/storage_open)
if(reagents?.maximum_volume)
LAZYADD(., global._reagent_interactions)
8 changes: 8 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,11 @@
if(ATOM_IS_OPEN_CONTAINER(src))
return loc?.take_vaporized_reagent(reagent, amount)
return null

// TODO: make everything use this.
/atom/movable/proc/set_anchored(new_anchored)
SHOULD_CALL_PARENT(TRUE)
if(anchored != new_anchored)
anchored = new_anchored
return TRUE
return FALSE
2 changes: 2 additions & 0 deletions code/game/atoms_movable_interactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
name = "Examine"
expected_user_type = /mob
interaction_flags = 0
examine_desc = "examine $TARGET_THEM$"

/decl/interaction_handler/look/invoked(atom/target, mob/user, obj/item/prop)
target.examine(user, get_dist(user, target))
Expand All @@ -22,6 +23,7 @@
name = "Grab"
expected_target_type = /atom/movable
interaction_flags = INTERACTION_NEEDS_PHYSICAL_INTERACTION | INTERACTION_NEEDS_TURF
examine_desc = "grab $TARGET_THEM$"

/decl/interaction_handler/grab/is_possible(atom/movable/target, mob/user, obj/item/prop)
return ..() && !target.anchored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@
name = "Eject Card"
icon = 'icons/screen/radial.dmi'
icon_state = "radial_eject_id"
expected_component_type = /obj/item/stock_parts/item_holder/card_reader
expected_component_type = /obj/item/stock_parts/item_holder/card_reader
examine_desc = "eject an inserted ID card"
3 changes: 2 additions & 1 deletion code/game/machinery/_machines_base/stock_parts/cupholder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@

/decl/interaction_handler/remove_held_item/cup
name = "Remove Cup"
expected_component_type = /obj/item/stock_parts/item_holder/cupholder
expected_component_type = /obj/item/stock_parts/item_holder/cupholder
examine_desc = "remove a cup"
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@

/decl/interaction_handler/remove_held_item/disk
name = "Eject Disk"
expected_component_type = /obj/item/stock_parts/item_holder/disk_reader
expected_component_type = /obj/item/stock_parts/item_holder/disk_reader
examine_desc = "remove a disk"
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
name = "Eject Item"
icon = 'icons/screen/radial.dmi'
icon_state = "radial_eject"
examine_desc = "eject an item"
var/obj/item/stock_parts/item_holder/expected_component_type

/decl/interaction_handler/remove_held_item/validate()
Expand Down
2 changes: 2 additions & 0 deletions code/game/machinery/washing_machine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
/decl/interaction_handler/start_washer
name = "Start washer"
expected_target_type = /obj/machinery/washing_machine
examine_desc = "start a wash cycle"

/decl/interaction_handler/start_washer/is_possible(obj/machinery/washing_machine/washer, mob/user)
. = ..()
Expand All @@ -263,6 +264,7 @@
/decl/interaction_handler/toggle_open/washing_machine
name = "Toggle detergent port"
expected_target_type = /obj/machinery/washing_machine
examine_desc = "open the detergent port"

/decl/interaction_handler/toggle_open/washing_machine/invoked(atom/target, mob/user, obj/item/prop)
var/obj/machinery/washing_machine/washer = target
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/_objs_interactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/decl/interaction_handler/rotate
name = "Rotate"
expected_target_type = /obj
examine_desc = "rotate $TARGET_THEM$"

/decl/interaction_handler/rotate/is_possible(atom/target, mob/user, obj/item/prop)
. = ..()
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/_item_interactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
name = "Open Storage"
expected_target_type = /atom
incapacitation_flags = INCAPACITATION_DISRUPTED
examine_desc = "open $TARGET_THEIR$ storage"

/decl/interaction_handler/storage_open/is_possible(atom/target, mob/user, obj/item/prop)
. = ..() && (ishuman(user) || isrobot(user) || issmall(user)) && target?.storage
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/_item_reagents.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/obj/item/proc/standard_dispenser_refill(var/mob/user, var/obj/structure/reagent_dispensers/target, skip_container_check = FALSE) // This goes into afterattack
/obj/item/proc/standard_dispenser_refill(mob/user, obj/structure/reagent_dispensers/target, skip_container_check = FALSE) // This goes into afterattack
if(!istype(target) || (!skip_container_check && (target.atom_flags & ATOM_FLAG_OPEN_CONTAINER)))
return FALSE

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/blades/folding.dm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
name = "Adjust Folding Knife"
expected_target_type = /obj/item/bladed/folding
interaction_flags = INTERACTION_NEEDS_INVENTORY | INTERACTION_NEEDS_PHYSICAL_INTERACTION
examine_desc = "adjust $TARGET_THEM$"

/decl/interaction_handler/folding_knife/is_possible(atom/target, mob/user)
. = ..()
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/devices/gps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ var/global/list/all_gps_units = list()
/decl/interaction_handler/gps_toggle
name = "Toggle Tracking"
expected_target_type = /obj/item/gps
examine_desc = "toggle GPS tracking"

/decl/interaction_handler/gps_toggle/invoked(atom/target, mob/user, obj/item/prop)
var/obj/item/gps/G = target
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/devices/paint_sprayer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
name = "Change Color Preset"
expected_target_type = /obj/item/paint_sprayer
interaction_flags = INTERACTION_NEEDS_PHYSICAL_INTERACTION | INTERACTION_NEEDS_INVENTORY
examine_desc = "change the color preset"

/decl/interaction_handler/paint_sprayer_colour/invoked(atom/target, mob/user, obj/item/prop)
var/obj/item/paint_sprayer/sprayer = target
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/weapons/storage/wallets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

/decl/interaction_handler/remove_id/wallet
expected_target_type = /obj/item/wallet
examine_desc = "remove an ID card"

/decl/interaction_handler/remove_id/wallet/is_possible(atom/target, mob/user, obj/item/prop)
. = ..() && ishuman(user)
Expand Down
Loading