Files
Paradise/code/game/objects/items/tools/tool_behaviour.dm
SteelSlayer 74d0e6523b Fixes welders blinding you when you repair robo-limbs and cyborgs (#12988)
* Fixes welders blinding you while repairing your own robo-limbs

* gives tool_start_check() a target argument

* flash be gone

* CRLF to LF

* adds trailing newlines because travis wants them I guess

Co-authored-by: SteelSlayer <SteelSlayer@users.noreply.github.com>
2020-06-26 01:18:13 -06:00

61 lines
2.3 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/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)
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)
return tool_use_check(user, amount) && (extra_checks && !extra_checks.Invoke())