Files
Paradise/code/game/objects/items/tools/tool_behaviour.dm
larentoun 7daf219ec0 More Crowbar Acts (#24986)
* crowbar acts part 1

* livings checked

* convert istypes to tool behaviour

* solars

* use tool_volume

* Update code/modules/research/server.dm

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Signed-off-by: larentoun <31931237+larentoun@users.noreply.github.com>

* Update code/modules/power/generators/portable generators/pacman.dm

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Signed-off-by: larentoun <31931237+larentoun@users.noreply.github.com>

* return

* return returns

* Update code/modules/mob/living/simple_animal/bot/mulebot.dm

Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>
Signed-off-by: larentoun <31931237+larentoun@users.noreply.github.com>

* Update code/game/objects/structures/janicart.dm

Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>
Signed-off-by: larentoun <31931237+larentoun@users.noreply.github.com>

---------

Signed-off-by: larentoun <31931237+larentoun@users.noreply.github.com>
Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>
2024-05-01 10:37:08 +00:00

67 lines
2.4 KiB
Plaintext

/**
* Called when a mob tries to use the item as a tool.
* Handles most checks.
*/
/obj/item/proc/use_tool(atom/target, mob/living/user, delay, amount=0, volume=0, datum/callback/extra_checks)
// No delay means there is no start message, and no reason to call tool_start_check before use_tool.
// Run the start check here so we wouldn't have to call it manually.
target.add_fingerprint(user)
if(!tool_start_check(target, user, amount) && !delay)
return
delay *= toolspeed
// Play tool sound at the beginning of tool usage.
play_tool_sound(target, volume)
if(delay)
// Create a callback with checks that would be called every tick by do_after.
var/datum/callback/tool_check = CALLBACK(src, PROC_REF(tool_check_callback), user, target, amount, extra_checks)
if(ismob(target))
if(!do_mob(user, target, delay, extra_checks = list(tool_check)))
return
else
if(!do_after(user, delay, target=target, extra_checks = list(tool_check)))
return
else
// Invoke the extra checks once, just in case.
if(extra_checks && !extra_checks.Invoke())
return
// Use tool's fuel, stack sheets or charges if amount is set.
if(amount && !use(amount))
return
// Play tool sound at the end of tool usage,
// but only if the delay between the beginning and the end is not too small
if(delay >= MIN_TOOL_SOUND_DELAY)
play_tool_sound(target, volume)
return TRUE
// Called before use_tool if there is a delay, or by use_tool if there isn't.
// Only ever used by welding tools and stacks, so it's not added on any other use_tool checks.
/obj/item/proc/tool_start_check(atom/target, mob/living/user, amount=0)
return tool_use_check(user, amount)
// A check called by tool_start_check once, and by use_tool on every tick of delay.
/obj/item/proc/tool_use_check(mob/living/user, amount, silent = FALSE)
return !amount
/obj/item/proc/play_tool_sound(atom/target, volume = tool_volume)
if(target && usesound && volume)
var/played_sound = usesound
if(islist(usesound))
played_sound = pick(usesound)
playsound(target, played_sound, volume, 1)
// Used in a callback that is passed by use_tool into do_after call. Do not override, do not call manually.
/obj/item/proc/tool_check_callback(mob/living/user, atom/target, amount, datum/callback/extra_checks)
if(!tool_use_check(user, amount))
return TRUE
if(extra_checks && !extra_checks.Invoke())
return TRUE
return FALSE