Files
Bubberstation/code/game/objects/items/stacks/wrap.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

211 lines
6.7 KiB
Plaintext

/*
* Wrapping Paper
*/
/obj/item/stack/wrapping_paper
name = "wrapping paper"
desc = "Wrap packages with this festive paper to make gifts."
icon = 'icons/obj/stack_objects.dmi'
icon_state = "wrap_paper"
inhand_icon_state = "wrap_paper"
greyscale_config = /datum/greyscale_config/wrap_paper
item_flags = NOBLUDGEON
amount = 25
max_amount = 25
resistance_flags = FLAMMABLE
merge_type = /obj/item/stack/wrapping_paper
singular_name = "wrapping paper"
/obj/item/stack/wrapping_paper/Initialize(mapload)
. = ..()
if(!greyscale_colors)
//Generate random valid colors for paper and ribbon
var/generated_base_color = "#" + random_color()
var/generated_ribbon_color = "#" + random_color()
var/list/base_hsv = rgb2hsv(generated_base_color)
var/list/ribbon_hsv = rgb2hsv(generated_ribbon_color)
//If colors are too dark, set to original colors
if(base_hsv[3] < 50)
generated_base_color = COLOR_VIBRANT_LIME
if(ribbon_hsv[3] < 50)
generated_ribbon_color = COLOR_RED
//Set layers to these colors, base then ribbon
set_greyscale(colors = list(generated_base_color, generated_ribbon_color))
/obj/item/stack/wrapping_paper/click_alt(mob/user)
var/new_base = input(user, "", "Select a base color", color) as color
var/new_ribbon = input(user, "", "Select a ribbon color", color) as color
if(!new_base || !new_ribbon)
return CLICK_ACTION_BLOCKING
set_greyscale(colors = list(new_base, new_ribbon))
return CLICK_ACTION_SUCCESS
//preset wrapping paper meant to fill the original color configuration
/obj/item/stack/wrapping_paper/xmas
greyscale_colors = "#00FF00#FF0000"
/obj/item/stack/wrapping_paper/use(used, transfer, check = TRUE)
var/turf/T = get_turf(src)
. = ..()
if(QDELETED(src) && !transfer)
new /obj/item/c_tube(T)
/obj/item/stack/wrapping_paper/small
desc = "Wrap packages with this festive paper to make gifts. This roll looks a bit skimpy."
amount = 10
merge_type = /obj/item/stack/wrapping_paper/small
/*
* Package Wrap
*/
/obj/item/stack/package_wrap
name = "package wrapper"
singular_name = "wrapping sheet"
desc = "You can use this to wrap items in."
icon = 'icons/obj/stack_objects.dmi'
icon_state = "deliveryPaper"
item_flags = NOBLUDGEON
amount = 25
max_amount = 25
resistance_flags = FLAMMABLE
grind_results = list(/datum/reagent/cellulose = 5)
merge_type = /obj/item/stack/package_wrap
/obj/item/stack/package_wrap/suicide_act(mob/living/user)
user.visible_message(span_suicide("[user] begins wrapping [user.p_them()]self in \the [src]! It looks like [user.p_theyre()] trying to commit suicide!"))
if(use(3))
var/obj/item/delivery/big/parcel = new(get_turf(user.loc))
parcel.base_icon_state = "deliverypackage5"
parcel.update_icon()
user.forceMove(parcel)
parcel.add_fingerprint(user)
return OXYLOSS
else
balloon_alert(user, "not enough paper!")
return SHAME
/obj/item/proc/can_be_package_wrapped() //can the item be wrapped with package wrapper into a delivery package
return TRUE
/obj/item/storage/can_be_package_wrapped()
return FALSE
/obj/item/storage/box/can_be_package_wrapped()
return TRUE
/obj/item/delivery/can_be_package_wrapped()
return FALSE
/obj/item/stack/package_wrap/storage_insert_on_interaction(datum/storage, atom/storage_holder, mob/user)
if(isitem(storage_holder))
// Don't insert if the target can be wrapped
var/obj/item/item = storage_holder
return !item.can_be_package_wrapped()
return TRUE
/obj/item/stack/package_wrap/interact_with_atom(obj/interacting_with, mob/living/user, list/modifiers)
if(!isobj(interacting_with))
return NONE
if(interacting_with.anchored)
return NONE
if(isitem(interacting_with))
var/obj/item/item = interacting_with
if(!item.can_be_package_wrapped())
balloon_alert(user, "can't be wrapped!")
return ITEM_INTERACT_BLOCKING
if(user.is_holding(item))
if(!user.dropItemToGround(item))
return ITEM_INTERACT_BLOCKING
else if(!isturf(item.loc))
return ITEM_INTERACT_BLOCKING
if(use(1))
var/obj/item/delivery/small/parcel = new(get_turf(item.loc))
if(user.Adjacent(item))
parcel.add_fingerprint(user)
item.add_fingerprint(user)
user.put_in_hands(parcel)
item.forceMove(parcel)
var/size = round(item.w_class)
parcel.name = "[weight_class_to_text(size)] parcel"
parcel.update_weight_class(size)
size = min(size, 5)
parcel.base_icon_state = "deliverypackage[size]"
parcel.update_icon()
else
return ITEM_INTERACT_BLOCKING
else if(istype(interacting_with, /obj/structure/closet))
var/obj/structure/closet/closet = interacting_with
if(closet.opened)
balloon_alert(user, "can't wrap while open!")
return ITEM_INTERACT_BLOCKING
if(!closet.delivery_icon) //no delivery icon means unwrappable closet (e.g. body bags)
balloon_alert(user, "can't wrap!")
return ITEM_INTERACT_BLOCKING
if(use(3))
var/obj/item/delivery/big/parcel = new(get_turf(closet.loc))
parcel.base_icon_state = closet.delivery_icon
parcel.update_icon()
parcel.drag_slowdown = closet.drag_slowdown
closet.forceMove(parcel)
parcel.add_fingerprint(user)
closet.add_fingerprint(user)
else
balloon_alert(user, "not enough paper!")
return ITEM_INTERACT_BLOCKING
else if(istype(interacting_with, /obj/machinery/portable_atmospherics))
var/obj/machinery/portable_atmospherics/portable_atmospherics = interacting_with
if(portable_atmospherics.anchored)
balloon_alert(user, "can't wrap while anchored!")
return ITEM_INTERACT_BLOCKING
if(use(3))
var/obj/item/delivery/big/parcel = new(get_turf(portable_atmospherics.loc))
parcel.base_icon_state = "deliverybox"
parcel.update_icon()
parcel.drag_slowdown = portable_atmospherics.drag_slowdown
portable_atmospherics.forceMove(parcel)
parcel.add_fingerprint(user)
portable_atmospherics.add_fingerprint(user)
else
balloon_alert(user, "not enough paper!")
return ITEM_INTERACT_BLOCKING
else
balloon_alert(user, "can't wrap!")
return ITEM_INTERACT_BLOCKING
user.visible_message(span_notice("[user] wraps [interacting_with]."))
user.log_message("has used [name] on [key_name(interacting_with)]", LOG_ATTACK, color="blue")
return ITEM_INTERACT_SUCCESS
/obj/item/stack/package_wrap/use(used, transfer = FALSE, check = TRUE)
var/turf/T = get_turf(src)
. = ..()
if(QDELETED(src) && !transfer)
new /obj/item/c_tube(T)
/obj/item/stack/package_wrap/small
desc = "You can use this to wrap items in. This roll looks a bit skimpy."
w_class = WEIGHT_CLASS_SMALL
amount = 5
merge_type = /obj/item/stack/package_wrap/small
/obj/item/c_tube
name = "cardboard tube"
desc = "A tube... of cardboard."
icon = 'icons/obj/stack_objects.dmi'
icon_state = "c_tube"
inhand_icon_state = "c_tube"
throwforce = 0
w_class = WEIGHT_CLASS_TINY
throw_speed = 3
throw_range = 5