Skip to content

Commit

Permalink
[MIRROR] Changes afterattacks to use_after
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelbassil authored and SierraHelper committed Nov 19, 2023
1 parent ee6b77b commit 4864c08
Show file tree
Hide file tree
Showing 73 changed files with 574 additions and 616 deletions.
2 changes: 1 addition & 1 deletion code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
The most common are:
* mob/UnarmedAttack(atom,adjacent) - used here only when adjacent, with no item in hand; in the case of humans, checks gloves
* atom/resolve_attackby(item,user) - used only when adjacent
* item/afterattack(atom,user,adjacent,params) - used both ranged and adjacent
* item/afterattack(atom,user,adjacent,params) - used for ranged; called when resolve_attackby returns FALSE.
* mob/RangedAttack(atom,params) - used only ranged, only used for tk and laser eyes but could be changed
*/
/mob/proc/ClickOn(atom/A, params)
Expand Down
3 changes: 1 addition & 2 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ avoid code duplication. This includes items that may sometimes act as a standard

/**
* Called when the item is in the active hand and another atom is clicked and `resolve_attackby()` returns FALSE. This is generally called by `ClickOn()`.
* Use this similar to how attack() is used; but for non-mob targets. Whenever you want specific behavior at the item level.
* Also works on ranged targets, unlike attack()
* Works on ranged targets, unlike resolve_attackby()
*
* **Parameters**:
* - `target` - The atom that was clicked on.
Expand Down
5 changes: 3 additions & 2 deletions code/game/gamemodes/cult/talisman.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
to_chat(user, "You see strange symbols on the paper. Are they supposed to mean something?")


/obj/item/paper/talisman/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
/obj/item/paper/talisman/use_after(atom/target, mob/living/user, click_parameters)
if (!can_invoke(target, user))
return
return TRUE

// Null rods block the talisman's effect but still consume it
var/obj/item/nullrod/nullrod = locate() in target
Expand All @@ -77,6 +77,7 @@
if (talisman_sound)
playsound(src, talisman_sound, 100, 1)
qdel(src)
return TRUE


/**
Expand Down
15 changes: 7 additions & 8 deletions code/game/machinery/atmoalter/clamp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,24 @@
icon_state = "pclamp0"
origin_tech = list(TECH_ENGINEERING = 4, TECH_MAGNET = 4)

/obj/item/clamp/afterattack(atom/A, mob/user as mob, proximity)
if(!proximity)
return

/obj/item/clamp/use_after(atom/A, mob/living/user, click_parameters)
if (istype(A, /obj/machinery/atmospherics/pipe/simple))
var/obj/machinery/atmospherics/pipe/simple/P = A
if (P.clamp)
to_chat(user, SPAN_WARNING("There is already \a [P.clamp] attached to \the [P]."))
return
return TRUE

to_chat(user, SPAN_NOTICE("You begin to attach \the [src] to \the [A]..."))
if (do_after(user, 3 SECONDS, A, DO_REPAIR_CONSTRUCT))
if (QDELETED(P))
return
return TRUE
if (P.clamp)
to_chat(user, SPAN_WARNING("There is already \a [P.clamp] attached to \the [P]."))
return
return TRUE
if(!user.unEquip(src))
return
return TRUE
to_chat(user, SPAN_NOTICE("You have attached \the [src] to \the [A]."))
new/obj/machinery/clamp(A.loc, A)
qdel(src)
return TRUE
else return FALSE
8 changes: 3 additions & 5 deletions code/game/machinery/pipe/construction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ Buildable meters
constructed_path = P.type

//called when a turf is attacked with a pipe item
/obj/item/pipe/afterattack(turf/simulated/floor/target, mob/user, proximity)
if(!proximity) return
if(istype(target))
/obj/item/pipe/use_after(atom/target, mob/living/user, click_parameters)
if (istype(target))
user.unEquip(src, target)
else
return ..()
return TRUE

/obj/item/pipe/rotate(mob/user)
. = ..()
Expand Down
16 changes: 6 additions & 10 deletions code/game/objects/effects/decals/contraband.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,22 @@
return ..()

//Places the poster on a wall
/obj/item/contraband/poster/afterattack(atom/A, mob/user, adjacent, clickparams)
if (!adjacent)
return

//must place on a wall and user must not be inside a closet/exosuit/whatever
var/turf/W = A
/obj/item/contraband/poster/use_after(turf/W, mob/living/user, click_parameters)
if(!isturf(W))
return
return FALSE

if (!W.is_wall() || !isturf(user.loc))
to_chat(user, SPAN_WARNING("You can't place this here!"))
return
return TRUE

var/placement_dir = get_dir(user, W)
if (!(placement_dir in GLOB.cardinal))
to_chat(user, SPAN_WARNING("You must stand directly in front of the wall you wish to place that on."))
return
return TRUE

if (ArePostersOnWall(W))
to_chat(user, SPAN_NOTICE("There is already a poster there!"))
return
return TRUE

user.visible_message(SPAN_NOTICE("\The [user] starts placing a poster on \the [W]."),SPAN_NOTICE("You start placing the poster on \the [W]."))

Expand All @@ -64,6 +59,7 @@
else
// We cannot rely on user being on the appropriate turf when placement fails
P.roll_and_drop(get_step(W, turn(placement_dir, 180)))
return TRUE

/obj/item/contraband/poster/proc/ArePostersOnWall(turf/W, placed_poster)
//just check if there is a poster on or adjacent to the wall
Expand Down
5 changes: 2 additions & 3 deletions code/game/objects/items/crayons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
shadeColour = input(user, "Please select the shade colour.", "Crayon colour") as color
return

/obj/item/pen/crayon/afterattack(atom/target, mob/user as mob, proximity)
if(!proximity) return
/obj/item/pen/crayon/use_after(atom/target, mob/user)
if(istype(target,/turf/simulated/floor))
var/drawtype = input("Choose what you'd like to draw.", "Crayon scribbles") in list("graffiti","rune","letter","arrow", "defector graffiti")
switch(drawtype)
Expand All @@ -108,7 +107,7 @@
if(!uses)
to_chat(user, SPAN_WARNING("You used up your crayon!"))
qdel(src)
return
return TRUE

/obj/item/pen/crayon/use_before(mob/living/carbon/M as mob, mob/user as mob)
if(istype(M) && M == user)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/devices/chameleonproj.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/obj/item/device/chameleon/attack_self()
toggle()

/obj/item/device/chameleon/afterattack(atom/target, mob/user , proximity)
if(!proximity) return
/obj/item/device/chameleon/use_after(atom/target, mob/living/user, click_parameters)
if(!active_dummy)
if(istype(target,/obj/item) && !istype(target, /obj/item/disk/nuclear))
playsound(get_turf(src), 'sound/weapons/flash.ogg', 100, 1, -6)
Expand All @@ -38,6 +37,7 @@
saved_icon = target.icon
saved_icon_state = target.icon_state
saved_overlays = target.overlays.Copy()
return TRUE

/obj/item/device/chameleon/proc/toggle()
if(!can_use || !saved_item) return
Expand Down
7 changes: 4 additions & 3 deletions code/game/objects/items/devices/flashlight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@
update_icon()
START_PROCESSING(SSobj, src)

/obj/item/device/flashlight/flare/afterattack(obj/O, mob/user, proximity)
if(proximity && istype(O) && on)
/obj/item/device/flashlight/flare/use_after(obj/O, mob/living/user)
if(istype(O) && on)
O.HandleObjectHeating(src, user, 500)
..()
return TRUE
return ..()

/obj/item/device/flashlight/flare/proc/activate(mob/user)
if(istype(user))
Expand Down
8 changes: 5 additions & 3 deletions code/game/objects/items/devices/inducer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
if(cell)
cell.emp_act(severity)

/obj/item/inducer/afterattack(obj/O, mob/living/carbon/user, proximity)
if (!proximity || user.a_intent == I_HURT || CannotUse(user) || !recharge(O, user))
return ..()
/obj/item/inducer/use_after(obj/O, mob/living/user, click_parameters)
if (!istype(O))
return FALSE
if (CannotUse(user) || !recharge(O, user))
return TRUE

/obj/item/inducer/proc/CannotUse(mob/user)
var/obj/item/cell/my_cell = get_cell()
Expand Down
23 changes: 11 additions & 12 deletions code/game/objects/items/devices/modkit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
/obj/item/clothing/suit/space/void
)

/obj/item/device/modkit/afterattack(obj/O, mob/user as mob, proximity)
if(!proximity)
return

/obj/item/device/modkit/use_after(obj/O, mob/living/user, click_parameters)
if (!target_species)
return //it shouldn't be null, okay?
return FALSE

if(!parts)
to_chat(user, SPAN_WARNING("This kit has no parts for this modification left."))
qdel(src)
return
return TRUE

var/allowed = 0
for (var/permitted_type in permitted_types)
Expand All @@ -35,22 +32,23 @@
var/obj/item/clothing/I = O
if (!istype(I) || !allowed)
to_chat(user, SPAN_NOTICE("[src] is unable to modify that."))
return
return TRUE

var/excluding = ("exclude" in I.species_restricted)
var/in_list = (target_species in I.species_restricted)
if (excluding ^ in_list)
to_chat(user, SPAN_NOTICE("[I] is already modified."))
return
return TRUE

if(!isturf(O.loc))
to_chat(user, SPAN_WARNING("[O] must be safely placed on the ground for modification."))
return
return TRUE

playsound(user.loc, 'sound/items/Screwdriver.ogg', 100, 1)

user.visible_message(SPAN_NOTICE("\The [user] opens \the [src] and modifies \the [O]."),SPAN_NOTICE("You open \the [src] and modify \the [O]."))

user.visible_message(
SPAN_NOTICE("\The [user] opens \the [src] and modifies \the [O]."),
SPAN_NOTICE("You open \the [src] and modify \the [O].")
)
I.refit_for_species(target_species)

if (istype(I, /obj/item/clothing/head/helmet))
Expand All @@ -60,6 +58,7 @@

if(!parts)
qdel(src)
return TRUE

/obj/item/device/modkit/examine(mob/user)
. = ..(user)
Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/items/devices/oxycandle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
..()
update_icon()

/obj/item/device/oxycandle/afterattack(obj/O, mob/user, proximity)
if(proximity && istype(O) && on)
/obj/item/device/oxycandle/use_after(obj/O, mob/living/user, click_parameters)
if(istype(O) && on)
O.HandleObjectHeating(src, user, 500)
..()
return TRUE

/obj/item/device/oxycandle/attack_self(mob/user)
if(!on)
Expand Down
7 changes: 3 additions & 4 deletions code/game/objects/items/devices/paint_sprayer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@
GLOB.module_deselected_event.unregister(user, src, /obj/item/device/paint_sprayer/proc/remove_click_handler)
GLOB.module_deactivated_event.unregister(user, src, /obj/item/device/paint_sprayer/proc/remove_click_handler)

/obj/item/device/paint_sprayer/afterattack(atom/A, mob/user, proximity, params)
if (!proximity)
return
apply_paint(A, user, params)
/obj/item/device/paint_sprayer/use_after(atom/target, mob/living/user, click_parameters)
apply_paint(target, user, click_parameters)
return TRUE

/obj/item/device/paint_sprayer/proc/pick_color(atom/A, mob/user)
if (!user.Adjacent(A) || user.incapacitated())
Expand Down
17 changes: 10 additions & 7 deletions code/game/objects/items/glassjar.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,34 @@
..()
update_icon()

/obj/item/glass_jar/afterattack(atom/A, mob/user, proximity)
if(!proximity || contains)
return
/obj/item/glass_jar/use_after(atom/A, mob/living/user, click_parameters)
if(contains)
to_chat(user, SPAN_WARNING("\The [src] is full and cannot accept further items."))
return TRUE

if(istype(A, /mob))
var/accept = 0
for(var/D in accept_mobs)
if(istype(A, D))
accept = 1
if(!accept)
to_chat(user, "[A] doesn't fit into \the [src].")
return
return TRUE
var/mob/L = A
user.visible_message(SPAN_NOTICE("[user] scoops [L] into \the [src]."), SPAN_NOTICE("You scoop [L] into \the [src]."))
L.forceMove(src)
contains = 2
update_icon()
return
else if(istype(A, /obj/spider/spiderling))
return TRUE

if (istype(A, /obj/spider/spiderling))
var/obj/spider/spiderling/S = A
user.visible_message(SPAN_NOTICE("[user] scoops [S] into \the [src]."), SPAN_NOTICE("You scoop [S] into \the [src]."))
S.forceMove(src)
STOP_PROCESSING(SSobj, S) // No growing inside jars
contains = 3
update_icon()
return
return TRUE

/obj/item/glass_jar/attack_self(mob/user)
switch(contains)
Expand Down
55 changes: 26 additions & 29 deletions code/game/objects/items/holosign_creator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,33 @@
signs.Cut()
. = ..()

/obj/item/holosign_creator/afterattack(atom/target, mob/user, flag)
. = ..()
if(flag)
var/turf/T = get_turf(target)
if(!T)
return // Some objs qdel on attackby (notably, holosigns), which happens before this.
var/obj/structure/holosign/H = locate(holosign_type) in T
if(H)
return
/obj/item/holosign_creator/use_after(atom/target, mob/living/user, click_parameters)
var/turf/T = get_turf(target)
if (!T) return FALSE
var/obj/structure/holosign/H = locate(holosign_type) in T
if (H) return FALSE

if (!is_blocked_turf(T, TRUE)) //can't put holograms on a tile that has dense stuff
if (holocreator_busy)
to_chat(user, SPAN_NOTICE("[src] is busy creating a hologram."))
return TRUE
if (length(signs) < max_signs)
playsound(src.loc, 'sound/machines/click.ogg', 20, 1)
if(creation_time)
holocreator_busy = TRUE
if(!do_after(user, creation_time, target, DO_BOTH_UNIQUE_ACT))
holocreator_busy = FALSE
return TRUE
holocreator_busy = FALSE
if(length(signs) >= max_signs)
return TRUE
if(is_blocked_turf(T, TRUE)) //don't try to sneak dense stuff on our tile during the wait.
return TRUE
H = new holosign_type(get_turf(target), src)
to_chat(user, SPAN_NOTICE("You create \a [H] with [src]."))
else
if(!is_blocked_turf(T, TRUE)) //can't put holograms on a tile that has dense stuff
if(holocreator_busy)
to_chat(user, SPAN_NOTICE("[src] is busy creating a hologram."))
return
if(length(signs) < max_signs)
playsound(src.loc, 'sound/machines/click.ogg', 20, 1)
if(creation_time)
holocreator_busy = TRUE
if(!do_after(user, creation_time, target, DO_BOTH_UNIQUE_ACT))
holocreator_busy = FALSE
return
holocreator_busy = FALSE
if(length(signs) >= max_signs)
return
if(is_blocked_turf(T, TRUE)) //don't try to sneak dense stuff on our tile during the wait.
return
H = new holosign_type(get_turf(target), src)
to_chat(user, SPAN_NOTICE("You create \a [H] with [src]."))
else
to_chat(user, SPAN_NOTICE("[src] is projecting at max capacity!"))
to_chat(user, SPAN_NOTICE("[src] is projecting at max capacity!"))
return TRUE

/obj/item/holosign_creator/attack_self(mob/user)
if(length(signs))
Expand Down
Loading

0 comments on commit 4864c08

Please sign in to comment.