mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-13 03:02:38 +00:00
## About The Pull Request It was trying to put items into a trash bag that doesn't have `CAN_BE_HIT` flag with an `attackby`. It now works for both the vacuum insert and the manual one. Fixes #84653 ## Why It's Good For The Game Bug fix. ## Changelog 🆑 fix: Janicart inserts items into the attached trash bag again (manual and vacuumed) /🆑
87 lines
2.3 KiB
Plaintext
87 lines
2.3 KiB
Plaintext
/**
|
|
* # Vacuum Component
|
|
*
|
|
* Adds a vacuum functionality to an atom, requires a trashbag to be linked
|
|
* using signals
|
|
*
|
|
*/
|
|
/datum/component/vacuum
|
|
/// The linked trash bag to vacuum trash into
|
|
var/obj/item/storage/bag/trash/vacuum_bag
|
|
|
|
/datum/component/vacuum/Initialize(obj/item/storage/bag/trash/connected_bag = null)
|
|
. = ..()
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
if (connected_bag)
|
|
attach_bag(null, connected_bag)
|
|
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(suck))
|
|
RegisterSignal(parent, COMSIG_VACUUM_BAG_ATTACH, PROC_REF(attach_bag))
|
|
RegisterSignal(parent, COMSIG_VACUUM_BAG_DETACH, PROC_REF(detach_bag))
|
|
|
|
/**
|
|
* Called when parent moves, deligates vacuuming functionality
|
|
*
|
|
* Arguments:
|
|
* * suckee - The source of the signal
|
|
*/
|
|
/datum/component/vacuum/proc/suck(datum/suckee)
|
|
SIGNAL_HANDLER
|
|
|
|
// get tile to suck on
|
|
var/atom/movable/AM = suckee
|
|
var/turf/tile = AM.loc
|
|
if (!isturf(tile))
|
|
return
|
|
|
|
// no bag attached, don't bother
|
|
if (!vacuum_bag)
|
|
return
|
|
|
|
// suck the things
|
|
INVOKE_ASYNC(src, PROC_REF(suck_items), tile)
|
|
|
|
/**
|
|
* Sucks up items as possible from a provided turf into the connected trash bag
|
|
*
|
|
* Arguments:
|
|
* * tile - The tile upon which to vacuum up items
|
|
*/
|
|
/datum/component/vacuum/proc/suck_items(turf/tile)
|
|
var/sucked = FALSE
|
|
for (var/potential_item in tile)
|
|
if (!isitem(potential_item))
|
|
continue
|
|
var/obj/item/item = potential_item
|
|
if (vacuum_bag.atom_storage.attempt_insert(item))
|
|
sucked = TRUE // track that we successfully sucked up something
|
|
|
|
// if we did indeed suck up something, play a funny noise
|
|
if (sucked)
|
|
playsound(parent, SFX_RUSTLE, 50, TRUE, -5)
|
|
|
|
/**
|
|
* Handler for when a new trash bag is attached
|
|
*
|
|
* Arguments:
|
|
* * source - The source of the signal
|
|
* * new_bag - The new bag being installed
|
|
*/
|
|
/datum/component/vacuum/proc/attach_bag(datum/source, obj/item/storage/bag/trash/new_bag)
|
|
SIGNAL_HANDLER
|
|
|
|
vacuum_bag = new_bag
|
|
RegisterSignal(new_bag, COMSIG_QDELETING, PROC_REF(detach_bag))
|
|
|
|
/**
|
|
* Handler for when a trash bag is detached
|
|
*
|
|
* Arguments:
|
|
* * source - The source of the signal
|
|
*/
|
|
/datum/component/vacuum/proc/detach_bag(datum/source)
|
|
SIGNAL_HANDLER
|
|
if (vacuum_bag) // null check to avoid runtime on bag being deleted then sending detach as a result from parent
|
|
UnregisterSignal(vacuum_bag, COMSIG_QDELETING)
|
|
vacuum_bag = null
|