Skip to content

Commit

Permalink
do_after_mob
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsar-Salat committed Mar 26, 2024
1 parent 02f22a7 commit d2106ee
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 76 deletions.
70 changes: 0 additions & 70 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -353,76 +353,6 @@ GLOBAL_LIST_EMPTY(species_list)
. = 1
return

///Timed action involving at least one mob user and a list of targets.
/proc/do_after_mob(mob/user, list/targets, time = 3 SECONDS, uninterruptible = FALSE, progress = TRUE, datum/callback/extra_checks)
if(!user)
return FALSE
if(!islist(targets))
targets = list(targets)
if(!length(targets))
return FALSE

for(var/i in targets)
var/mob/living/target = i
if(INTERACTING_WITH(user, target))
to_chat(user, "<span class='warning'>You're already interacting with [target]!</span>")
return


var/user_loc = user.loc

var/drifting = FALSE
if(!user.Process_Spacemove(0) && user.inertia_dir)
drifting = TRUE

var/list/originalloc = list()
for(var/atom/target in targets)
originalloc[target] = target.loc
LAZYADD(user.do_afters, target)
LAZYADD(target.targeted_by, user)

var/holding = user.get_active_held_item()
var/datum/progressbar/progbar
if(progress)
progbar = new(user, time, targets[1])

var/endtime = world.time + time
var/starttime = world.time
. = TRUE
mainloop:
while(world.time < endtime)
stoplag(1)

if(QDELETED(user))
. = FALSE
break

if(!QDELETED(progbar))
progbar.update(world.time - starttime)

if(QDELETED(user) || !targets)
. = FALSE
break
if(uninterruptible)
continue

if(drifting && !user.inertia_dir)
drifting = FALSE
user_loc = user.loc

for(var/atom/target in targets)
if((!drifting && user_loc != user.loc) || QDELETED(target) || originalloc[target] != target.loc || user.get_active_held_item() != holding || user.incapacitated() || (extra_checks && !extra_checks.Invoke()))
. = FALSE
break mainloop
if(!QDELETED(progbar))
progbar.end_progress()

for(var/thing in targets)
var/atom/target = thing
if(!QDELETED(target))
LAZYREMOVE(user.do_afters, target)
LAZYREMOVE(target.targeted_by, user)

/proc/is_species(A, species_datum)
. = FALSE
if(ishuman(A))
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/survery_handheld.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
src_turf.visible_message("<span class='warning'>Warning: unable to locate valuable information in current sector.</span>")
break

if(!do_after_mob(user, list(src), survey_delay / penalty))
if(!do_after(user, list(src), survey_delay / penalty))
flick(icon_state + "-corrupted", src)
playsound(src, 'sound/machines/buzz-sigh.ogg', 20)
src_turf.visible_message("<span class='warning'>Warning: results corrupted. Please try again.</span>")
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/crates_lockers/closets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"<span class='warning'>You [actuallyismob ? "try to ":""]stuff [O] into [src].</span>", \
"<span class='hear'>You hear clanging.</span>")
if(actuallyismob)
if(do_after_mob(user, targets, 40))
if(do_after(user, 40, targets))
user.visible_message(
"<span class='notice'>[user] stuffs [O] into [src].</span>", \
"<span class='notice'>You stuff [O] into [src].</span>", \
Expand Down
4 changes: 2 additions & 2 deletions code/modules/overmap/helm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@
return

to_chat(user, "<span class='warning'>You begin to manually override the local database...</span>")
if(!do_after_mob(user, list(src), 2 SECONDS))
if(!do_after(user, 2 SECONDS, list(src)))
return COMPONENT_BLOCK_TOOL_ATTACK

priority_announce("Illegal access to local ship database detected.", sender_override="[src.name]", zlevel=virtual_z())
if(!do_after_mob(user, list(src), 10 SECONDS))
if(!do_after(user, 10 SECONDS, list(src)))
return COMPONENT_BLOCK_TOOL_ATTACK

say("Warning, database corruption present, resetting local database state.")
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/boxes_magazines/_box_magazine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
if(istype(attacking_obj, /obj/item/ammo_box))
var/obj/item/ammo_box/attacking_box = attacking_obj
for(var/obj/item/ammo_casing/casing_to_insert in attacking_box.stored_ammo)
if(!((instant_load && attacking_box.instant_load) || (stored_ammo.len >= max_ammo) || do_after_mob(user, list(attacking_box), 1 SECONDS)))
if(!((instant_load && attacking_box.instant_load) || (stored_ammo.len >= max_ammo) || do_after(user, 1 SECONDS, list(attacking_box))))
break
var/did_load = give_round(casing_to_insert, replace_spent)
if(!did_load)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
var/list/ammo_list_no_empty = ammo_list(FALSE)
listclearnulls(ammo_list_no_empty)
for(var/obj/item/ammo_casing/casing_to_insert in attacking_box.stored_ammo)
if(!((instant_load && attacking_box.instant_load) || (ammo_list_no_empty.len >= max_ammo) || do_after_mob(user, list(attacking_box), 1 SECONDS))) //stupid work around for revolvers
if(!((instant_load && attacking_box.instant_load) || (ammo_list_no_empty.len >= max_ammo) || do_after(user, 1 SECONDS, list(attacking_box)))) //stupid work around for revolvers
break
var/did_load = give_round(casing_to_insert, replace_spent)
if(!did_load)
Expand Down

0 comments on commit d2106ee

Please sign in to comment.