Files
Bubberstation/code/datums/components/gps.dm
MrMelbert c92d338dad Refactors chameleon actions, Adds chameleon outfit saving, Adds chameleon scanner (#77140)
## About The Pull Request

- Refactors chameleon actions a good bit, reducing a lot of the
boilerplate copied around chameleon items.
- I noticed that the EMP comsig completely disregarded any EMP
protection the mob might have. I split the comsig into
`COMSIG_ATOM_PRE_EMP_ACT` and `COMSIG_ATOM_EMP_ACT` - the former now
used to aggregate protection flags and the latter to actually do EMP
stuff.
- As a result of above, this fixes a few oversights in which things
using `COMSIG_ATOM_EMP_ACT` disregarded EMP protection.

- Adds Chameleon Outfit saving. 
- RMB clicking the "Select Chameleon Outfit" will now save your current
chameleon setup as a custom outfit. They become selectable as any other
outfit afterwards.
- Because it might be *too* easy to bamboozle people / might make people
think you're a ling, I added a slight "animation" to swapping whole
chameleon outfits. It's less than a second long.

- Adds the Chameleon Scanner.
- The chameleon scanner is, surprise, a chameleon item that can disguise
as small gadgets or items (toys, cameras, analyzers, etc).
- On LMB, the chameleon scanner will copy the outfit of the target to a
custom outfit slot, allowing you to mimic them entirely without going
through all the menus.
- RMB does the same, but instantly equips the disguise you select in
addition to saving it to a slot.

## Why It's Good For The Game

Right now traitor stealth is very capable but cumbersome, which makes it
much less appealing than just running and gunning.

One big problem with it is that the chameleon kit is rather time
consuming to use. You have to sort through hundreds of items for each of
your chameleon items to find exactly the one you need.

These items seek to amend that time gate, allowing for much quicker
swapping between disguises or picking up the disguise of someone you
kill to replace them like a pseudo-changeling.

## Changelog

🆑 Melbert
refactor: Refactored chameleon actions a fair bit
add: Adds outfit saving to chameleon clothes. RMB the "chameleon outfit"
action to save your current chameleon setup for quick swapping.
add: Swapping between chameleon outfits now has a slight "animation"
associated, to distinguish traitors from lings slightly.
add: Adds a new chameleon item, the "Chameleon Scanner". Use it on other
crewmembers to stealthily save their current outfit as a custom outfit
to use later. And of course, it's chameleon too.
fix: Ethereals, the DNA lock mod, GPSs, and storage items now respect
EMP protection
/🆑
2023-07-29 15:39:06 -06:00

183 lines
5.5 KiB
Plaintext

///Global GPS_list. All GPS components get saved in here for easy reference.
GLOBAL_LIST_EMPTY(GPS_list)
///GPS component. Atoms that have this show up on gps. Pretty simple stuff.
/datum/component/gps
var/gpstag = "COM0"
var/tracking = TRUE
var/emped = FALSE
/datum/component/gps/Initialize(_gpstag = "COM0")
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
gpstag = _gpstag
GLOB.GPS_list += src
/datum/component/gps/Destroy()
GLOB.GPS_list -= src
return ..()
/datum/component/gps/kheiral_cuffs
/datum/component/gps/kheiral_cuffs/Initialize(_gpstag = "COM0")
. = ..()
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(deactivate_kheiral_cuffs))
/datum/component/gps/kheiral_cuffs/proc/deactivate_kheiral_cuffs(datum/source)
SIGNAL_HANDLER
qdel(src)
///GPS component subtype. Only gps/item's can be used to open the UI.
/datum/component/gps/item
var/updating = TRUE //Automatic updating of GPS list. Can be set to manual by user.
var/global_mode = TRUE //If disabled, only GPS signals of the same Z level are shown
/// UI state of GPS, altering when it can be used.
var/datum/ui_state/state = null
/datum/component/gps/item/Initialize(_gpstag = "COM0", emp_proof = FALSE, state = null, overlay_state = "working")
. = ..()
if(. == COMPONENT_INCOMPATIBLE || !isitem(parent))
return COMPONENT_INCOMPATIBLE
if(isnull(state))
state = GLOB.default_state
src.state = state
var/atom/A = parent
if(overlay_state)
A.add_overlay(overlay_state)
A.name = "[initial(A.name)] ([gpstag])"
RegisterSignal(parent, COMSIG_ITEM_ATTACK_SELF, PROC_REF(interact))
if(!emp_proof)
RegisterSignal(parent, COMSIG_ATOM_EMP_ACT, PROC_REF(on_emp_act))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_CLICK_ALT, PROC_REF(on_AltClick))
///Called on COMSIG_ITEM_ATTACK_SELF
/datum/component/gps/item/proc/interact(datum/source, mob/user)
SIGNAL_HANDLER
if(user)
INVOKE_ASYNC(src, PROC_REF(ui_interact), user)
///Called on COMSIG_ATOM_EXAMINE
/datum/component/gps/item/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("Alt-click to switch it [tracking ? "off":"on"].")
///Called on COMSIG_ATOM_EMP_ACT
/datum/component/gps/item/proc/on_emp_act(datum/source, severity, protection)
SIGNAL_HANDLER
if(protection & EMP_PROTECT_SELF)
return
emped = TRUE
var/atom/A = parent
A.cut_overlay("working")
A.add_overlay("emp")
addtimer(CALLBACK(src, PROC_REF(reboot)), 300, TIMER_UNIQUE|TIMER_OVERRIDE) //if a new EMP happens, remove the old timer so it doesn't reactivate early
SStgui.close_uis(src) //Close the UI control if it is open.
///Restarts the GPS after getting turned off by an EMP.
/datum/component/gps/item/proc/reboot()
emped = FALSE
var/atom/A = parent
A.cut_overlay("emp")
A.add_overlay("working")
///Calls toggletracking
/datum/component/gps/item/proc/on_AltClick(datum/source, mob/user)
SIGNAL_HANDLER
toggletracking(user)
///Toggles the tracking for the gps
/datum/component/gps/item/proc/toggletracking(mob/user)
if(!user.can_perform_action(parent))
return //user not valid to use gps
if(emped)
to_chat(user, span_warning("It's busted!"))
return
var/atom/A = parent
if(tracking)
A.cut_overlay("working")
to_chat(user, span_notice("[parent] is no longer tracking, or visible to other GPS devices."))
tracking = FALSE
else
A.add_overlay("working")
to_chat(user, span_notice("[parent] is now tracking, and visible to other GPS devices."))
tracking = TRUE
/datum/component/gps/item/ui_interact(mob/user, datum/tgui/ui)
if(emped)
to_chat(user, span_hear("[parent] fizzles weakly."))
return
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Gps")
ui.open()
ui.set_autoupdate(updating)
/datum/component/gps/item/ui_state(mob/user)
return state
/datum/component/gps/item/ui_data(mob/user)
var/list/data = list()
data["power"] = tracking
data["tag"] = gpstag
data["updating"] = updating
data["globalmode"] = global_mode
if(!tracking || emped) //Do not bother scanning if the GPS is off or EMPed
return data
var/turf/curr = get_turf(parent)
data["currentArea"] = "[get_area_name(curr, TRUE)]"
data["currentCoords"] = "[curr.x], [curr.y], [curr.z]"
var/list/signals = list()
data["signals"] = list()
for(var/gps in GLOB.GPS_list)
var/datum/component/gps/G = gps
if(G.emped || !G.tracking || G == src)
continue
var/turf/pos = get_turf(G.parent)
if(!pos || !global_mode && pos.z != curr.z)
continue
var/list/signal = list()
signal["entrytag"] = G.gpstag //Name or 'tag' of the GPS
signal["coords"] = "[pos.x], [pos.y], [pos.z]"
if(pos.z == curr.z) //Distance/Direction calculations for same z-level only
signal["dist"] = max(get_dist(curr, pos), 0) //Distance between the src and remote GPS turfs
signal["degrees"] = round(get_angle(curr, pos)) //0-360 degree directional bearing, for more precision.
signals += list(signal) //Add this signal to the list of signals
data["signals"] = signals
return data
/datum/component/gps/item/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("rename")
var/atom/parentasatom = parent
var/a = tgui_input_text(usr, "Enter the desired tag", "GPS Tag", gpstag, 20)
if (!a)
return
gpstag = a
. = TRUE
usr.log_message("renamed [parentasatom] to \"[initial(parentasatom.name)] ([gpstag])\".", LOG_GAME)
parentasatom.name = "[initial(parentasatom.name)] ([gpstag])"
if("power")
toggletracking(usr)
. = TRUE
if("updating")
updating = !updating
. = TRUE
if("globalmode")
global_mode = !global_mode
. = TRUE