Files
Bubberstation/code/modules/paperwork/clipboard.dm
John Willard 1880003270 Reworks silicon/ai access checking & fixes some ui_act's (#84964)
## About The Pull Request

Currently to check for Silicon access, we do:
``if is silicon or is admin ghost or has unlimited silicon privileges or
has machine remote in hand``
What has unlimited silicon privileges? Bots, Drones, and admin ghosts.
To check for AI access, it just checks for AI instead of silicon, and
doesnt check for unlimited silicon privileges.

This was kinda silly, so I thought I should make this a little easier to
understand.
Now all silicon/ai traits come from ``AI_ACCESS_TRAIT`` or
``SILICON_ACCESS_TRAIT``. I made a single exception to keep Admin ghost,
since now instead of being a var on the client, we moved it to using the
same trait but giving it to the client instead, but since we have to
keep parity with previous functionality (admins can spawn in and not
have this on, it only works while as a ghost), I kept previous checks as
well.

No more type checks, removes a silly var on the mob level and another on
the client.

Now while I was doing this, I found a lot of tgui's ``ui_act`` still
uses ``usr`` and the wrong args, so I fixed those wherever I saw them,
and used a mass replace for the args.

Other changes:

- machinery's ``ui_act`` from
https://github.com/tgstation/tgstation/pull/81250 had ``isAI`` replaced
with ``HAS_AI_ACCESS``, this has been reverted. Machine wands and admin
ghosts no longer get kicked off things not on cameras. This was my
fault, I overlooked this when adding Human AI.
- Human AI's wand gives AI control as long as it's in your hand, you can
swap to your offhand. I hope this doesn't end up going horribly,
otherwise I'll revert this part. It should let human AIs not have their
UI closed on them when swapping to eat food or use their door wand or
whatnot.
- Bots previously had special checks to scan reagents and be
unobservant, I replaced this with giving them the trait. I also fixed an
instance of unobservant not being used, so now statues don't affect the
basic creature, whatever that is.

## Why It's Good For The Game

This is an easier to understand way of handling silicon access and makes
these mobs more consistent between eachother.
Other than what I've mentioned above, this should have no impact on
gameplay itself.

## Changelog

🆑
fix: Statues don't count as eyes to creatures.
fix: Human AIs and Admin ghosts no longer get kicked off of machines
that aren't on cameranets.
/🆑
2024-08-19 10:43:45 +00:00

213 lines
5.8 KiB
Plaintext

/**
* Clipboard
*/
/obj/item/clipboard
name = "clipboard"
icon = 'icons/obj/service/bureaucracy.dmi'
icon_state = "clipboard"
inhand_icon_state = "clipboard"
worn_icon_state = "clipboard"
throwforce = 0
w_class = WEIGHT_CLASS_SMALL
throw_speed = 3
throw_range = 7
slot_flags = ITEM_SLOT_BELT
resistance_flags = FLAMMABLE
unique_reskin = list(
"Brown" = "clipboard",
"Black" = "clipboard_black",
"White" = "clipboard_white",
)
/// The stored pen
var/obj/item/pen/pen
/// Is the pen integrated?
var/integrated_pen = FALSE
/**
* Weakref of the topmost piece of paper
*
* This is used for the paper displayed on the clipboard's icon
* and it is the one attacked, when attacking the clipboard.
* (As you can't organise contents directly in BYOND)
*/
var/datum/weakref/toppaper_ref
/obj/item/clipboard/suicide_act(mob/living/carbon/user)
user.visible_message(span_suicide("[user] begins putting [user.p_their()] head into the clip of \the [src]! It looks like [user.p_theyre()] trying to commit suicide!"))
return BRUTELOSS //The clipboard's clip is very strong. Industrial duty. Can kill a man easily.
/obj/item/clipboard/Initialize(mapload)
update_appearance()
. = ..()
/obj/item/clipboard/Destroy()
QDEL_NULL(pen)
return ..()
/obj/item/clipboard/examine()
. = ..()
if(!integrated_pen && pen)
. += span_notice("Alt-click to remove [pen].")
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
if(toppaper)
. += span_notice("Right-click to remove [toppaper].")
/// Take out the topmost paper
/obj/item/clipboard/proc/remove_paper(obj/item/paper/paper, mob/user)
if(!istype(paper))
return
paper.forceMove(user.loc)
user.put_in_hands(paper)
to_chat(user, span_notice("You remove [paper] from [src]."))
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
if(paper == toppaper)
UnregisterSignal(toppaper, COMSIG_ATOM_UPDATED_ICON)
toppaper_ref = null
var/obj/item/paper/newtop = locate(/obj/item/paper) in src
if(newtop && (newtop != paper))
toppaper_ref = WEAKREF(newtop)
else
toppaper_ref = null
update_icon()
/obj/item/clipboard/proc/remove_pen(mob/user)
pen.forceMove(user.loc)
user.put_in_hands(pen)
to_chat(user, span_notice("You remove [pen] from [src]."))
pen = null
update_icon()
/obj/item/clipboard/click_alt(mob/user)
if(isnull(pen))
return CLICK_ACTION_BLOCKING
if(integrated_pen)
to_chat(user, span_warning("You can't seem to find a way to remove [src]'s [pen]."))
return CLICK_ACTION_BLOCKING
remove_pen(user)
return CLICK_ACTION_SUCCESS
/obj/item/clipboard/update_overlays()
. = ..()
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
if(toppaper)
. += toppaper.icon_state
. += toppaper.overlays
if(pen)
. += "clipboard_pen"
. += "clipboard_over"
/obj/item/clipboard/attack_hand(mob/user, list/modifiers)
if(LAZYACCESS(modifiers, RIGHT_CLICK))
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
remove_paper(toppaper, user)
return TRUE
. = ..()
/obj/item/clipboard/attackby(obj/item/weapon, mob/user, params)
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
if(istype(weapon, /obj/item/paper))
//Add paper into the clipboard
if(!user.transferItemToLoc(weapon, src))
return
if(toppaper)
UnregisterSignal(toppaper, COMSIG_ATOM_UPDATED_ICON)
RegisterSignal(weapon, COMSIG_ATOM_UPDATED_ICON, PROC_REF(on_top_paper_change))
toppaper_ref = WEAKREF(weapon)
to_chat(user, span_notice("You clip [weapon] onto [src]."))
else if(istype(weapon, /obj/item/pen) && !pen)
//Add a pen into the clipboard, attack (write) if there is already one
if(!usr.transferItemToLoc(weapon, src))
return
pen = weapon
to_chat(usr, span_notice("You slot [weapon] into [src]."))
else if(toppaper)
toppaper.attackby(user.get_active_held_item(), user)
update_appearance()
/obj/item/clipboard/attack_self(mob/user)
add_fingerprint(usr)
ui_interact(user)
return
/obj/item/clipboard/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Clipboard")
ui.open()
/obj/item/clipboard/ui_data(mob/user)
// prepare data for TGUI
var/list/data = list()
data["pen"] = "[pen]"
data["integrated_pen"] = integrated_pen
var/obj/item/paper/toppaper = toppaper_ref?.resolve()
data["top_paper"] = "[toppaper]"
data["top_paper_ref"] = "[REF(toppaper)]"
data["paper"] = list()
data["paper_ref"] = list()
for(var/obj/item/paper/paper in src)
if(paper == toppaper)
continue
data["paper"] += "[paper]"
data["paper_ref"] += "[REF(paper)]"
return data
/obj/item/clipboard/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
if(usr.stat != CONSCIOUS || HAS_TRAIT(usr, TRAIT_HANDS_BLOCKED))
return
switch(action)
// Take the pen out
if("remove_pen")
if(pen)
if(!integrated_pen)
remove_pen(usr)
else
to_chat(usr, span_warning("You can't seem to find a way to remove [src]'s [pen]."))
. = TRUE
// Take paper out
if("remove_paper")
var/obj/item/paper/paper = locate(params["ref"]) in src
if(istype(paper))
remove_paper(paper, usr)
. = TRUE
// Look at (or edit) the paper
if("edit_paper")
var/obj/item/paper/paper = locate(params["ref"]) in src
if(istype(paper))
paper.ui_interact(usr)
update_icon()
. = TRUE
// Move paper to the top
if("move_top_paper")
var/obj/item/paper/paper = locate(params["ref"]) in src
if(istype(paper))
toppaper_ref = WEAKREF(paper)
to_chat(usr, span_notice("You move [paper] to the top."))
update_icon()
. = TRUE
// Rename the paper (it's a verb)
if("rename_paper")
var/obj/item/paper/paper = locate(params["ref"]) in src
if(istype(paper))
paper.rename()
update_icon()
. = TRUE
/**
* This is a simple proc to handle calling update_icon() upon receiving the top paper's `COMSIG_ATOM_UPDATE_APPEARANCE`.
*/
/obj/item/clipboard/proc/on_top_paper_change()
SIGNAL_HANDLER
update_appearance()