mirror of
https://github.com/fulpstation/fulpstation.git
synced 2025-12-10 18:11:47 +00:00
Adds a new element, Self-Knockback. (#47938)
* Adds a new element, Self-Knockback. * Squashes a potential edgecase runtime in projectile_selfknockback before it can even happen. * Allows item_selfknockback to interact with dense turfs now. * Made self-knockback utilize the Element Bespoke flag to allow custom force and speed values on attachment. * fixes newline issue, adds a usage comment. * fixes the newline issue in self-knockback for real this time, thanks TortoiseGit. * i swear on god almighty if this doesn't fix the newline issue, i'll eat a shoe. * Testing newline lint
This commit is contained in:
committed by
Emmett Gaines
parent
f910ebad5d
commit
db878e848b
@@ -306,6 +306,7 @@
|
||||
// /obj/projectile signals (sent to the firer)
|
||||
#define COMSIG_PROJECTILE_ON_HIT "projectile_on_hit" // from base of /obj/projectile/proc/on_hit(): (atom/movable/firer, atom/target, Angle)
|
||||
#define COMSIG_PROJECTILE_BEFORE_FIRE "projectile_before_fire" // from base of /obj/projectile/proc/fire(): (obj/projectile, atom/original_target)
|
||||
#define COMSIG_PROJECTILE_FIRE "projectile_fire" // from the base of /obj/projectile/proc/fire(): ()
|
||||
#define COMSIG_PROJECTILE_PREHIT "com_proj_prehit" // sent to targets during the process_hit proc of projectiles
|
||||
|
||||
// /obj/mecha signals
|
||||
|
||||
60
code/datums/elements/selfknockback.dm
Normal file
60
code/datums/elements/selfknockback.dm
Normal file
@@ -0,0 +1,60 @@
|
||||
/datum/element/selfknockback
|
||||
element_flags = ELEMENT_BESPOKE
|
||||
id_arg_index = 2
|
||||
var/override_throw_val
|
||||
var/override_speed_val
|
||||
|
||||
/* Adds the ability to put recoil on various things, throwing the user back proportional to the force and speed set.
|
||||
Important note: Force/Throw_Amount, is how far you want to throw a user. By default, it is calculated based on damage below.
|
||||
Speed_Amount, is a measure of how long it will take a user to get thrown to the target. By default, it is calculated by
|
||||
clamping the Knockback_Force value below. */
|
||||
/datum/element/selfknockback/Attach(datum/target, throw_amount, speed_amount)
|
||||
. = ..()
|
||||
if(isitem(target))
|
||||
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, .proc/Item_SelfKnockback)
|
||||
else if(isprojectile(target))
|
||||
RegisterSignal(target, COMSIG_PROJECTILE_FIRE, .proc/Projectile_SelfKnockback)
|
||||
else
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
|
||||
override_throw_val = throw_amount
|
||||
override_speed_val = speed_amount
|
||||
|
||||
/datum/element/selfknockback/Detach(datum/source, force)
|
||||
. = ..()
|
||||
UnregisterSignal(source, list(COMSIG_ITEM_AFTERATTACK, COMSIG_PROJECTILE_FIRE))
|
||||
|
||||
/datum/element/selfknockback/proc/Get_Knockback_Force(default_force)
|
||||
if(override_throw_val)
|
||||
return override_throw_val
|
||||
else
|
||||
return default_force
|
||||
|
||||
/datum/element/selfknockback/proc/Get_Knockback_Speed(default_speed)
|
||||
if(override_speed_val)
|
||||
return override_speed_val
|
||||
else
|
||||
return default_speed
|
||||
|
||||
/datum/element/selfknockback/proc/Item_SelfKnockback(obj/item/I, atom/attacktarget, mob/usertarget, proximity_flag)
|
||||
if(isturf(attacktarget) && !attacktarget.density)
|
||||
return
|
||||
if(proximity_flag || (get_dist(attacktarget, usertarget) <= I.reach))
|
||||
var/knockback_force = Get_Knockback_Force(CLAMP(CEILING((I.force / 10), 1), 1, 5))
|
||||
var/knockback_speed = Get_Knockback_Speed(CLAMP(knockback_force, 1, 5))
|
||||
|
||||
var/target_angle = Get_Angle(attacktarget, usertarget)
|
||||
var/move_target = get_ranged_target_turf(usertarget, angle2dir(target_angle), knockback_force)
|
||||
usertarget.throw_at(move_target, knockback_force, knockback_speed)
|
||||
usertarget.visible_message("<span class='warning'>[usertarget] gets thrown back by the force of \the [I] impacting \the [attacktarget]!</span>", "<span class='warning'>The force of \the [I] impacting \the [attacktarget] sends you flying!</span>")
|
||||
|
||||
/datum/element/selfknockback/proc/Projectile_SelfKnockback(obj/projectile/P)
|
||||
if(!P.firer)
|
||||
return
|
||||
|
||||
var/knockback_force = Get_Knockback_Force(CLAMP(CEILING((P.damage / 10), 1), 1, 5))
|
||||
var/knockback_speed = Get_Knockback_Speed(CLAMP(knockback_force, 1, 5))
|
||||
|
||||
var/atom/movable/knockback_target = P.firer
|
||||
var/move_target = get_edge_target_turf(knockback_target, angle2dir(P.original_angle+180))
|
||||
knockback_target.throw_at(move_target, knockback_force, knockback_speed)
|
||||
@@ -392,6 +392,7 @@
|
||||
trajectory = new(starting.x, starting.y, starting.z, pixel_x, pixel_y, Angle, SSprojectiles.global_pixel_speed)
|
||||
last_projectile_move = world.time
|
||||
fired = TRUE
|
||||
SEND_SIGNAL(src, COMSIG_PROJECTILE_FIRE)
|
||||
if(hitscan)
|
||||
process_hitscan()
|
||||
if(!(datum_flags & DF_ISPROCESSING))
|
||||
|
||||
@@ -512,6 +512,7 @@
|
||||
#include "code\datums\elements\digitalcamo.dm"
|
||||
#include "code\datums\elements\earhealing.dm"
|
||||
#include "code\datums\elements\firestacker.dm"
|
||||
#include "code\datums\elements\selfknockback.dm"
|
||||
#include "code\datums\elements\snail_crawl.dm"
|
||||
#include "code\datums\helper_datums\events.dm"
|
||||
#include "code\datums\helper_datums\getrev.dm"
|
||||
|
||||
Reference in New Issue
Block a user