Skip to content

Commit

Permalink
[MIRROR] Replace attack() with use_before()
Browse files Browse the repository at this point in the history
Co-authored-by: emmanuelbassil <[email protected]>
  • Loading branch information
SierraHelper and emmanuelbassil authored Oct 18, 2023
1 parent 81d438e commit bda6eb2
Show file tree
Hide file tree
Showing 80 changed files with 230 additions and 346 deletions.
1 change: 0 additions & 1 deletion code/__defines/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define ITEM_FLAG_NOCUFFS FLAG(13) // Gloves that have this flag prevent cuffs being applied
#define ITEM_FLAG_CAN_HIDE_IN_SHOES FLAG(14) // Items that can be hidden in shoes that permit it
#define ITEM_FLAG_WASHER_ALLOWED FLAG(15) // Items that can be washed in washing machines
#define ITEM_FLAG_TRY_ATTACK FLAG(16) // Use the item's attack() when set before trying the receiver's resolve_attackby()

// Flags for pass_flags.
#define PASS_FLAG_TABLE FLAG(0)
Expand Down
2 changes: 1 addition & 1 deletion code/__defines/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
// Aura type options for `/mob/living/proc/aura_check()`.
/// Aura checks for projectile impacts. Generally called by `/obj/item/projectile/proc/attack_mob()`. Results in `/obj/aura/proc/aura_check_bullet()`.
#define AURA_TYPE_BULLET "Bullet"
/// Aura checks for physical weapon attacks. Generally called by `/obj/item/proc/attack()`. Results in `/obj/aura/proc/aura_check_weapon()`.
/// Aura checks for physical weapon attacks. Generally called by `/obj/item/proc/use_weapon()`. Results in `/obj/aura/proc/aura_check_weapon()`.
#define AURA_TYPE_WEAPON "Weapon"
/// Aura checks for thrown atom impacts. Generally called by `/mob/living/hitby()`. Results in `/obj/aura/proc/aura_check_thrown()`.
#define AURA_TYPE_THROWN "Thrown"
Expand Down
34 changes: 17 additions & 17 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ 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. This is generally called by `ClickOn()`.
*
* This passes down to `attack()`, `use_user()`, `use_grab()`, `use_weapon()`, `use_tool()`, `attackby()`, and
* `use_on()`, in that order, depending on item flags and user's intent.
* This passes down to `use_before()`, `use_weapon()`, `use_tool()`, `attackby()`, and then use_after() in that order,
* depending on item flags and user's intent.
* use_grab() is run in an override of resolve_attackby() processed at the grab's level, and is not part of this chain.
*
* **Parameters**:
* - `atom` - The atom that was clicked.
Expand All @@ -49,12 +50,9 @@ avoid code duplication. This includes items that may sometimes act as a standard
return FALSE
atom.pre_use_item(src, user, click_params)
var/use_call
if (HAS_FLAGS(item_flags, ITEM_FLAG_TRY_ATTACK))
use_call = "on"
. = use_on(atom, user, click_params)
if (!.)
use_call = "attack"
. = attack(atom, user)

use_call = "use"
. = use_before(atom, user, click_params)
if (!. && user.a_intent == I_HURT)
use_call = "weapon"
. = atom.use_weapon(src, user, click_params)
Expand All @@ -64,9 +62,9 @@ avoid code duplication. This includes items that may sometimes act as a standard
if (!.)
use_call = "attackby"
. = atom.attackby(src, user, click_params)
if (!. && !HAS_FLAGS(item_flags, ITEM_FLAG_TRY_ATTACK))
use_call = "on"
. = use_on(atom, user, click_params)
if (!.)
use_call = "use"
. = use_after(atom, user, click_params)
if (!.)
use_call = null
atom.post_use_item(src, user, ., use_call, click_params)
Expand Down Expand Up @@ -417,6 +415,8 @@ 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. This is generally called by the target's
* `resolve_attackby()` proc.
* Use it for item-level behavior you don't necessarily want running before use_tool/use_weapon.
* You will need to use type checks on atom/target on overrides; or else this will be called on anything you click.
*
* **Parameters**:
* - `target` - The atom that was clicked on.
Expand All @@ -425,22 +425,22 @@ avoid code duplication. This includes items that may sometimes act as a standard
*
* Returns boolean to indicate whether the use call was handled or not.
*/
/obj/item/proc/use_on(atom/target, mob/user, click_parameters)
/obj/item/proc/use_after(atom/target, mob/living/user, click_parameters)
return FALSE


//I would prefer to rename this attack_as_weapon(), but that would involve touching hundreds of files.
/**
* Called when a mob is clicked while the item is in the active hand and ITEM_FLAG_TRY_ATTACK is set. Generally called by the mob's `attackby()` proc.
* This is called before anything else if set correctly. Returns boolean to indicate whether the item usage was successful or not.
* Called when a mob is clicked while the item is in the active hand. This is usually called first by the mob's `resolve_attackby()` proc.
* Use this to set item-level overrides that you want running first. If you have an override you don't want running before use_tool and use_weapon, put it in use_after().
* You will need to use type checks on atom/target on overrides; or else this will be called on anything you click.
* If returns FALSE, the rest of the resolve_attackby() chain is called.
*
* **Parameters**:
* - `subject` - The mob that was clicked.
* - `target` - The atom that was clicked.
* - `user` - The mob that clicked the target.
* * - `click_parameters` - List of click parameters. See BYOND's `Click()` documentation.
*/
/obj/item/proc/attack(mob/living/subject, mob/living/user, click_parameters)
/obj/item/proc/use_before(atom/target, mob/living/user, click_parameters)
return FALSE


Expand Down
3 changes: 1 addition & 2 deletions code/game/gamemodes/cult/cult_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
edge = TRUE
sharp = TRUE
w_class = ITEM_SIZE_LARGE
item_flags = ITEM_FLAG_TRY_ATTACK
force = 30
throwforce = 10
hitsound = 'sound/weapons/bladeslice.ogg'
attack_verb = list("attacked", "slashed", "stabbed", "sliced", "tore", "ripped", "diced", "cut")

/obj/item/melee/cultblade/attack(mob/living/M, mob/living/user)
/obj/item/melee/cultblade/use_before(mob/living/M, mob/living/user)
. = FALSE
if (iscultist(user))
return FALSE
Expand Down
9 changes: 5 additions & 4 deletions code/game/gamemodes/cult/ritual.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
else
to_chat(user, "The scriptures of Nar-Sie, The One Who Sees, The Geometer of Blood. Contains the details of every ritual his followers could think of. Most of these are useless, though.")

/obj/item/book/tome/attack(mob/living/M, mob/living/user)
/obj/item/book/tome/use_before(mob/living/M, mob/living/user)
. = FALSE
if (!istype(M))
return FALSE
Expand All @@ -39,14 +39,15 @@
user.setClickCooldown(DEFAULT_QUICK_COOLDOWN)
return TRUE

/obj/item/book/tome/afterattack(atom/A, mob/user, proximity)
if(!proximity || !iscultist(user))
return
/obj/item/book/tome/use_after(atom/A, mob/user)
if(!iscultist(user))
return FALSE
if(A.reagents && A.reagents.has_reagent(/datum/reagent/water/holywater))
to_chat(user, SPAN_NOTICE("You unbless \the [A]."))
var/holy2water = A.reagents.get_reagent_amount(/datum/reagent/water/holywater)
A.reagents.del_reagent(/datum/reagent/water/holywater)
A.reagents.add_reagent(/datum/reagent/water, holy2water)
return TRUE

/mob/proc/make_rune(rune, cost = 5, tome_required = 0)
var/has_tome = !!IsHolding(/obj/item/book/tome)
Expand Down
3 changes: 1 addition & 2 deletions code/game/gamemodes/events/holidays/Christmas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
icon_state = "cracker"
desc = "Directions for use: Requires two people, one to pull each end."
var/cracked = 0
item_flags = ITEM_FLAG_TRY_ATTACK

/obj/item/toy/xmas_cracker/New()
..()

/obj/item/toy/xmas_cracker/attack(mob/target, mob/user)
/obj/item/toy/xmas_cracker/use_before(mob/target, mob/user)
. = FALSE
if (!cracked && istype(target,/mob/living/carbon/human) && (target.stat == CONSCIOUS) && !target.get_active_hand() )
target.visible_message(SPAN_NOTICE("[user] and [target] pop \an [src]! *pop*"), SPAN_NOTICE("You pull \an [src] with [target]! *pop*"), SPAN_NOTICE("You hear a *pop*."))
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/crayons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
qdel(src)
return

/obj/item/pen/crayon/attack(mob/living/carbon/M as mob, mob/user as mob)
/obj/item/pen/crayon/use_before(mob/living/carbon/M as mob, mob/user as mob)
if(istype(M) && M == user)
to_chat(M, "You take a bite of the crayon and swallow it.")
M.adjust_nutrition(1)
Expand All @@ -121,7 +121,6 @@
to_chat(M, SPAN_WARNING("You ate your crayon!"))
qdel(src)
return TRUE
return ..()


/obj/random/crayon
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/auto_cpr.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
icon = 'icons/obj/auto_cpr.dmi'
icon_state = "pumper"
w_class = ITEM_SIZE_NORMAL
item_flags = ITEM_FLAG_TRY_ATTACK
origin_tech = list(TECH_MAGNET = 2, TECH_BIO = 2)
slot_flags = SLOT_OCLOTHING
var/last_pump
Expand All @@ -19,7 +18,7 @@
else
return FALSE

/obj/item/auto_cpr/attack(mob/living/carbon/human/M, mob/living/user)
/obj/item/auto_cpr/use_before(mob/living/carbon/human/M, mob/living/user)
. = FALSE
if (istype(M) && user.a_intent == I_HELP)
if (M.wear_suit)
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/dna_sampler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "dna sampler"
desc = "An all in one DNA sampling and sequencing device which can be used to deliver a genetic payload to a mimic cube. Requires a DNA sample from the target."
w_class = ITEM_SIZE_SMALL
item_flags = ITEM_FLAG_TRY_ATTACK
origin_tech = list(TECH_BIO = 5, TECH_MATERIAL = 2)
icon = 'icons/obj/tools/implanter.dmi'
icon_state = "dnainjector0"
Expand Down Expand Up @@ -35,7 +34,7 @@
src_species = ""
src_flavor = ""

/obj/item/device/dna_sampler/attack(mob/living/carbon/human/L, mob/user)
/obj/item/device/dna_sampler/use_before(mob/living/carbon/human/L, mob/user)
. = FALSE
if (istype(L) && L.can_inject(user, check_zone(user.zone_sel.selecting)))
if (loaded)
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/dociler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "dociler"
desc = "A complex single use recharging injector that spreads a complex neurological serum that makes animals docile and friendly. Somewhat."
w_class = ITEM_SIZE_NORMAL
item_flags = ITEM_FLAG_TRY_ATTACK
origin_tech = list(TECH_BIO = 5, TECH_MATERIAL = 2)
icon = 'icons/obj/tools/dociler.dmi'
icon_state = "animal_tagger1"
Expand Down Expand Up @@ -32,7 +31,7 @@
. = ..()
to_chat(user, SPAN_NOTICE("It is currently [loaded? "loaded": "recharging"]."))

/obj/item/device/dociler/attack(mob/living/L, mob/user)
/obj/item/device/dociler/use_before(mob/living/L, mob/user)
. = FALSE
if (!istype(L))
return FALSE
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/flash.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
throw_speed = 4
throw_range = 10
obj_flags = OBJ_FLAG_CONDUCTIBLE
item_flags = ITEM_FLAG_TRY_ATTACK
origin_tech = list(TECH_MAGNET = 2, TECH_COMBAT = 1)

var/times_used = 0 //Number of times it's been used.
Expand All @@ -36,7 +35,7 @@
times_used = max(0,round(times_used)) //sanity

//attack_as_weapon
/obj/item/device/flash/attack(mob/living/M, mob/living/user)
/obj/item/device/flash/use_before(mob/living/M, mob/living/user)
. = FALSE
if (!istype(M))
return FALSE
Expand Down
7 changes: 2 additions & 5 deletions code/game/objects/items/devices/flashlight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
item_state = "flashlight"
w_class = ITEM_SIZE_SMALL
obj_flags = OBJ_FLAG_CONDUCTIBLE
item_flags = ITEM_FLAG_TRY_ATTACK
slot_flags = SLOT_BELT

matter = list(MATERIAL_PLASTIC = 50, MATERIAL_GLASS = 20)
Expand Down Expand Up @@ -91,11 +90,9 @@
set_dir(new_dir)
update_light()

/obj/item/device/flashlight/attack(mob/living/M as mob, mob/living/user as mob)
. = FALSE
/obj/item/device/flashlight/use_after(mob/living/M as mob, mob/living/user as mob)
if (istype(M) && on && user.zone_sel.selecting == BP_EYES)

if((MUTATION_CLUMSY in user.mutations) && prob(50) || user.a_intent == I_HURT)
if((MUTATION_CLUMSY in user.mutations) && prob(50))
return M.use_weapon(src, user)

var/mob/living/carbon/human/H = M
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/holowarrant.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
throw_speed = 4
throw_range = 10
obj_flags = OBJ_FLAG_CONDUCTIBLE
item_flags = ITEM_FLAG_TRY_ATTACK
slot_flags = SLOT_BELT
req_access = list(list(access_heads, access_security))
var/datum/computer_file/data/warrant/active
Expand Down Expand Up @@ -82,7 +81,7 @@


//hit other people with it
/obj/item/device/holowarrant/attack(mob/living/carbon/M as mob, mob/living/carbon/user as mob)
/obj/item/device/holowarrant/use_before(mob/living/carbon/M as mob, mob/living/carbon/user as mob)
. = FALSE
if(istype(M))
user.visible_message(SPAN_NOTICE("[user] holds up a warrant projector and shows the contents to [M]."), \
Expand Down
25 changes: 7 additions & 18 deletions code/game/objects/items/stacks/medical.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
amount = 5
max_amount = 5
w_class = ITEM_SIZE_SMALL
item_flags = ITEM_FLAG_TRY_ATTACK
throw_speed = 4
throw_range = 20

Expand All @@ -25,8 +24,7 @@
else
. = TRUE

/obj/item/stack/medical/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/use_after(mob/living/carbon/M, mob/user)
if (!istype(M))
return FALSE

Expand Down Expand Up @@ -77,8 +75,7 @@
apply_sounds = list('sound/effects/rip1.ogg','sound/effects/rip2.ogg')
amount = 10

/obj/item/stack/medical/bruise_pack/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/bruise_pack/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

Expand Down Expand Up @@ -137,8 +134,7 @@
animal_heal = 4
apply_sounds = list('sound/effects/ointment.ogg')

/obj/item/stack/medical/ointment/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/ointment/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

Expand Down Expand Up @@ -173,14 +169,10 @@
apply_sounds = list('sound/effects/rip1.ogg','sound/effects/rip2.ogg','sound/effects/tape.ogg')
amount = 10

/obj/item/stack/medical/advanced/bruise_pack/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/advanced/bruise_pack/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

if (check_possible_surgeries(M, user))
return FALSE

var/turf/T = get_turf(M)
if (locate(/obj/machinery/optable, T) && user.a_intent == I_HELP)
return FALSE
Expand Down Expand Up @@ -239,8 +231,7 @@
apply_sounds = list('sound/effects/ointment.ogg')


/obj/item/stack/medical/advanced/ointment/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/advanced/ointment/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

Expand Down Expand Up @@ -278,8 +269,7 @@
can_treat_robots = TRUE
var/list/splintable_organs = list(BP_L_ARM, BP_R_ARM, BP_L_LEG, BP_R_LEG, BP_L_HAND, BP_R_HAND, BP_L_FOOT, BP_R_FOOT) //List of organs you can splint, natch.

/obj/item/stack/medical/splint/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/splint/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

Expand Down Expand Up @@ -360,8 +350,7 @@
return TRUE


/obj/item/stack/medical/resin/attack(mob/living/carbon/M, mob/user)
. = FALSE
/obj/item/stack/medical/resin/use_after(mob/living/carbon/M, mob/user)
if (..())
return TRUE

Expand Down
6 changes: 1 addition & 5 deletions code/game/objects/items/stacks/nanopaste.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
icon = 'icons/obj/medical.dmi'
icon_state = "nanopaste"
origin_tech = list(TECH_MATERIAL = 4, TECH_ENGINEERING = 3)
item_flags = ITEM_FLAG_TRY_ATTACK
amount = 10


/obj/item/stack/nanopaste/attack(mob/living/M as mob, mob/user as mob)
. = FALSE
/obj/item/stack/nanopaste/use_after(mob/living/M as mob, mob/user as mob)
if (!istype(M) || !istype(user))
return FALSE
if (istype(M,/mob/living/silicon/robot)) //Repairing cyborgs
Expand All @@ -30,8 +28,6 @@
if (istype(M,/mob/living/carbon/human)) //Repairing robolimbs
var/mob/living/carbon/human/H = M
var/obj/item/organ/external/S = H.get_organ(user.zone_sel.selecting)
if (check_possible_surgeries(M, user))
return FALSE

if(!S)
to_chat(user, SPAN_WARNING("\The [M] is missing that body part."))
Expand Down
Loading

0 comments on commit bda6eb2

Please sign in to comment.