Files
Bubberstation/code/game/objects/items/devices/forcefieldprojector.dm
MrMelbert ff6b41aa07 Afterattack is dead, long live Afterattack (#83818)
## About The Pull Request

- Afterattack is a very simple proc now: All it does is this, and all
it's used for is for having a convenient place to put effects an item
does after a successful attack (IE, the attack was not blocked)


![image](https://github.com/tgstation/tgstation/assets/51863163/1e70f7be-0990-4827-a60a-0c9dd0e0ee49)

- An overwhelming majority of afterattack implementations have been
moved to `interact_with_atom` or the new `ranged_interact_with_atom`

I have manually tested many of the refactored procs but there was 200+
so it's kinda hard

## Why It's Good For The Game

Afterattack is one of the worst parts of the attack chain, as it
simultaneously serves as a way of doing random interactions NOT AT ALL
related to attacks (despite the name) while ALSO serving as the defacto
way to do a ranged interaction with an item

This means careless coders (most of them) may throw stuff in afterattack
without realizing how wide reaching it is, which causes bugs. By making
two well defined, separate procs for handing adjacent vs ranged
interactions, it becomes WAY WAY WAY more easy to develop for.

If you want to do something when you click on something else and you're
adjacent, use `interact_with_atom`
If you want to do something when you click on something else and you're
not adjacent, use 'ranged_interact_with_atom`

This does result in some instances of boilerplate as shown here:


![image](https://github.com/tgstation/tgstation/assets/51863163/a7e469dd-115e-4e5b-88e0-0c664619c878)

But I think it's acceptable, feel free to oppose if you don't I'm sure
we can think of another solution

~~Additionally it makes it easier to implement swing combat. That's a
bonus I guess~~

## Changelog

🆑 Melbert
refactor: Over 200 item interactions have been refactored to use a
newer, easier-to-use system. Report any oddities with using items on
other objects you may see (such as surgery, reagent containers like cups
and spray bottles, or construction devices), especially using something
at range (such as guns or chisels)
refactor: Item-On-Modsuit interactions have changed slightly. While on
combat mode, you will attempt to "use" the item on the suit instead of
inserting it into the suit's storage. This means being on combat mode
while the suit's panel is open will block you from inserting items
entirely via click (but other methods such as hotkey, clicking on the
storage boxes, and mousedrop will still work).
refactor: The detective's scanner will now be inserted into storage
items if clicked normally, and will scan the storage item if on combat
mode
/🆑
2024-06-11 21:58:09 -07:00

141 lines
5.4 KiB
Plaintext

/obj/item/forcefield_projector
name = "forcefield projector"
desc = "An experimental device that can create several forcefields at a distance."
icon = 'icons/obj/devices/tool.dmi'
icon_state = "signmaker_forcefield"
slot_flags = ITEM_SLOT_BELT
w_class = WEIGHT_CLASS_SMALL
item_flags = NOBLUDGEON
inhand_icon_state = "electronic"
worn_icon_state = "electronic"
lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi'
custom_materials = list(/datum/material/iron= SMALL_MATERIAL_AMOUNT * 2.5, /datum/material/glass= SMALL_MATERIAL_AMOUNT * 5)
var/max_shield_integrity = 250
var/shield_integrity = 250
var/max_fields = 3
var/list/current_fields
var/field_distance_limit = 7
/// Time it takes to materialize a forcefield.
var/creation_time = 1 SECONDS
/// Checks to make sure the projector isn't busy with making another forcefield.
var/force_proj_busy = FALSE
/obj/item/forcefield_projector/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
return interact_with_atom(interacting_with, user, modifiers)
/obj/item/forcefield_projector/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!check_allowed_items(interacting_with, not_inside = TRUE))
return NONE
if(istype(interacting_with, /obj/structure/projected_forcefield))
var/obj/structure/projected_forcefield/F = interacting_with
if(F.generator == src)
to_chat(user, span_notice("You deactivate [F]."))
qdel(F)
return ITEM_INTERACT_BLOCKING
var/turf/T = get_turf(interacting_with)
var/obj/structure/projected_forcefield/found_field = locate() in T
if(found_field)
to_chat(user, span_warning("There is already a forcefield in that location!"))
return ITEM_INTERACT_BLOCKING
if(T.density)
return ITEM_INTERACT_BLOCKING
if(get_dist(T,src) > field_distance_limit)
return ITEM_INTERACT_BLOCKING
if(get_turf(src) == T)
to_chat(user, span_warning("Target is too close, aborting!"))
return ITEM_INTERACT_BLOCKING
if(LAZYLEN(current_fields) >= max_fields)
to_chat(user, span_warning("[src] cannot sustain any more forcefields!"))
return ITEM_INTERACT_BLOCKING
if(force_proj_busy)
to_chat(user, span_notice("[src] is busy creating a forcefield."))
return ITEM_INTERACT_BLOCKING
playsound(loc, 'sound/machines/click.ogg', 20, TRUE)
if(creation_time)
force_proj_busy = TRUE
if(!do_after(user, creation_time, target = interacting_with))
force_proj_busy = FALSE
return ITEM_INTERACT_BLOCKING
force_proj_busy = FALSE
playsound(src,'sound/weapons/resonator_fire.ogg',50,TRUE)
user.visible_message(span_warning("[user] projects a forcefield!"),span_notice("You project a forcefield."))
var/obj/structure/projected_forcefield/F = new(T, src)
current_fields += F
user.changeNext_move(CLICK_CD_MELEE)
return ITEM_INTERACT_SUCCESS
/obj/item/forcefield_projector/attack_self(mob/user)
if(LAZYLEN(current_fields))
to_chat(user, span_notice("You deactivate [src], disabling all active forcefields."))
for(var/obj/structure/projected_forcefield/F in current_fields)
qdel(F)
/obj/item/forcefield_projector/examine(mob/user)
. = ..()
. += span_notice("It is currently sustaining [LAZYLEN(current_fields)]/[max_fields] fields, and it's [round((shield_integrity/max_shield_integrity)*100)]% charged.")
/obj/item/forcefield_projector/Initialize(mapload)
. = ..()
current_fields = list()
START_PROCESSING(SSobj, src)
/obj/item/forcefield_projector/Destroy()
STOP_PROCESSING(SSobj, src)
return ..()
/obj/item/forcefield_projector/process(seconds_per_tick)
if(!LAZYLEN(current_fields))
shield_integrity = min(shield_integrity + seconds_per_tick * 2, max_shield_integrity)
else
shield_integrity = max(shield_integrity - LAZYLEN(current_fields) * seconds_per_tick * 0.5, 0) //fields degrade slowly over time
for(var/obj/structure/projected_forcefield/F in current_fields)
if(shield_integrity <= 0 || get_dist(F,src) > field_distance_limit)
qdel(F)
/obj/structure/projected_forcefield
name = "forcefield"
desc = "A glowing barrier, generated by a projector nearby. It could be overloaded if hit enough times."
icon = 'icons/effects/effects.dmi'
icon_state = "forcefield"
layer = ABOVE_ALL_MOB_LAYER
plane = ABOVE_GAME_PLANE
anchored = TRUE
pass_flags_self = PASSGLASS
density = TRUE
mouse_opacity = MOUSE_OPACITY_OPAQUE
resistance_flags = INDESTRUCTIBLE
can_atmos_pass = ATMOS_PASS_DENSITY
armor_type = /datum/armor/structure_projected_forcefield
var/obj/item/forcefield_projector/generator
/datum/armor/structure_projected_forcefield
bullet = 25
laser = 50
energy = 50
bomb = 25
fire = 100
acid = 100
/obj/structure/projected_forcefield/Initialize(mapload, obj/item/forcefield_projector/origin)
. = ..()
generator = origin
/obj/structure/projected_forcefield/Destroy()
visible_message(span_warning("[src] flickers and disappears!"))
playsound(src,'sound/weapons/resonator_blast.ogg',25,TRUE)
if(generator)
generator.current_fields -= src
generator = null
return ..()
/obj/structure/projected_forcefield/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
playsound(loc, 'sound/weapons/egloves.ogg', 80, TRUE)
/obj/structure/projected_forcefield/take_damage(damage_amount, damage_type = BRUTE, damage_flag = 0, sound_effect = 1, attack_dir)
if(sound_effect)
play_attack_sound(damage_amount, damage_type, damage_flag)
if(generator)
generator.shield_integrity = max(generator.shield_integrity - damage_amount, 0)