mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-27 02:32:20 +00:00
* Adds support for self-filling reagent containers * Sets tool_behaviour on the default set of tools * Fixing merge conflicts * Refactors welder to use tool behaviour * The refactor: part I * The refactor: part II * Tool Refactor Part III: Revenge of the Maint * Tool Refactor Part IV: A New Hope * Tool Refactor Part V: The Oldcoder Strikes Back * Tool Refactor Part VI: Return of the Coder * VII * Holy shit, it compiles?! * Nannek I completed your TODO, you owe me ice cream * Tool helpers; telepad is compliant * Bugtest, Round 1: Fight Fuck refactoring disposals * Buggfixing, Round 2: Electric Boogaloo * Personal crafting uses tool behaviours now * Construction datums use new tool behaviours; better way of handling fueltank refuelling; more bugfixing * multitool_check_buffer change; removes some useless things in tool_helpers * proc name change * TRUE/FALSE changes * Bugfixing, Round 3: A Good Day To Bugfix Hard Fixes multiple issues raised by the testmerge * Minor style changes
61 lines
2.3 KiB
Plaintext
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(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=tool_check))
|
|
return
|
|
|
|
else
|
|
if(!do_after(user, delay, target=target, extra_checks=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(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())
|