mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-14 09:35:30 +01:00
344d3b6266
## About The Pull Request This PR reimplements https://github.com/tgstation/tgstation/pull/71538 atop `master`. Quoting the original PR: > Every `icon_exists()` call will cache the entire file. Past me didn't realise _why_ file opts were so expensive, but I do now. This is immeasurably slower on a single call, and _significantly_ faster on subsequent calls to the same file. I attempted to handle some of the review comments that were posted there, by splitting screaming functionality into its own proc. * `if(icon_state in icon_states(file))` and `if(!(icon_state in icon_states(file)))` were refactored to use `icon_exists(file, icon_state)`. * Where screaming was seemingly wanted (and where there wasn't a more descriptive error inside the `if` block), I refactored them to use `icon_exists_or_scream(file, icon_state)` * The exception to the above was under `/datum/unit_test/turf_icons/Run()` and `/datum/unit_test/worn_icons/Run()`, where `icon_states()` was being passed a mode flag. Given that this is only used in unit tests (where performance isn't a priority), I opted to leave these be. Additionally, I revised the documentation comment for `/proc/icon_exists()`, as I felt it was a bit vague currently. ## Why It's Good For The Game https://youtu.be/Z9G1Mf6TZRs ## Changelog No player-facing changes (hopefully). --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
186 lines
5.3 KiB
Plaintext
186 lines
5.3 KiB
Plaintext
/obj/item/chameleon
|
|
name = "chameleon projector"
|
|
icon = 'icons/obj/devices/syndie_gadget.dmi'
|
|
icon_state = "shield0"
|
|
obj_flags = CONDUCTS_ELECTRICITY
|
|
item_flags = NOBLUDGEON
|
|
slot_flags = ITEM_SLOT_BELT
|
|
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'
|
|
throwforce = 5
|
|
throw_speed = 3
|
|
throw_range = 5
|
|
w_class = WEIGHT_CLASS_SMALL
|
|
var/can_use = 1
|
|
var/obj/effect/dummy/chameleon/active_dummy = null
|
|
var/saved_appearance = null
|
|
|
|
/obj/item/chameleon/Initialize(mapload)
|
|
. = ..()
|
|
var/obj/item/cigbutt/butt = /obj/item/cigbutt
|
|
saved_appearance = initial(butt.appearance)
|
|
|
|
/obj/item/chameleon/dropped()
|
|
..()
|
|
disrupt()
|
|
|
|
/obj/item/chameleon/equipped()
|
|
..()
|
|
disrupt()
|
|
|
|
/obj/item/chameleon/attack_self(mob/user)
|
|
if (isturf(user.loc) || istype(user.loc, /obj/structure) || active_dummy)
|
|
toggle(user)
|
|
else
|
|
to_chat(user, span_warning("You can't use [src] while inside something!"))
|
|
|
|
/obj/item/chameleon/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
|
|
if(!can_copy(interacting_with) || SHOULD_SKIP_INTERACTION(interacting_with, src, user))
|
|
return NONE
|
|
make_copy(interacting_with, user)
|
|
return ITEM_INTERACT_SUCCESS
|
|
|
|
/obj/item/chameleon/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
|
|
if(!can_copy(interacting_with)) // RMB scan works on storage items, LMB scan does not
|
|
return NONE
|
|
make_copy(interacting_with, user)
|
|
return ITEM_INTERACT_SUCCESS
|
|
|
|
/obj/item/chameleon/proc/can_copy(atom/target)
|
|
if(!check_sprite(target))
|
|
return FALSE
|
|
if(active_dummy)//I now present you the blackli(f)st
|
|
return FALSE
|
|
if(isturf(target))
|
|
return FALSE
|
|
if(ismob(target))
|
|
return FALSE
|
|
if(istype(target, /obj/structure/falsewall))
|
|
return FALSE
|
|
if(target.alpha != 255)
|
|
return FALSE
|
|
if(target.invisibility != 0)
|
|
return FALSE
|
|
if(iseffect(target) && !istype(target, /obj/effect/decal)) //be a footprint
|
|
return FALSE
|
|
return TRUE
|
|
|
|
/obj/item/chameleon/proc/make_copy(atom/target, mob/user)
|
|
playsound(get_turf(src), 'sound/items/weapons/flash.ogg', 100, TRUE, -6)
|
|
to_chat(user, span_notice("Scanned [target]."))
|
|
var/obj/temp = new /obj()
|
|
temp.appearance = target.appearance
|
|
temp.layer = initial(target.layer) // scanning things in your inventory
|
|
SET_PLANE_EXPLICIT(temp, initial(plane), src)
|
|
saved_appearance = temp.appearance
|
|
|
|
/obj/item/chameleon/proc/check_sprite(atom/target)
|
|
return icon_exists(target.icon, target.icon_state)
|
|
|
|
/obj/item/chameleon/proc/toggle(mob/user)
|
|
if(!can_use || !saved_appearance)
|
|
return
|
|
if(active_dummy)
|
|
eject_all()
|
|
playsound(get_turf(src), 'sound/effects/pop.ogg', 100, TRUE, -6)
|
|
qdel(active_dummy)
|
|
active_dummy = null
|
|
to_chat(user, span_notice("You deactivate \the [src]."))
|
|
new /obj/effect/temp_visual/emp/pulse(get_turf(src))
|
|
else
|
|
playsound(get_turf(src), 'sound/effects/pop.ogg', 100, TRUE, -6)
|
|
var/obj/effect/dummy/chameleon/C = new/obj/effect/dummy/chameleon(user.drop_location())
|
|
C.activate(user, saved_appearance, src)
|
|
to_chat(user, span_notice("You activate \the [src]."))
|
|
new /obj/effect/temp_visual/emp/pulse(get_turf(src))
|
|
user.cancel_camera()
|
|
|
|
/obj/item/chameleon/proc/disrupt(delete_dummy = 1)
|
|
if(active_dummy)
|
|
for(var/mob/M in active_dummy)
|
|
to_chat(M, span_danger("Your chameleon projector deactivates."))
|
|
var/datum/effect_system/spark_spread/spark_system = new /datum/effect_system/spark_spread
|
|
spark_system.set_up(5, 0, src)
|
|
spark_system.attach(src)
|
|
spark_system.start()
|
|
eject_all()
|
|
if(delete_dummy)
|
|
qdel(active_dummy)
|
|
active_dummy = null
|
|
can_use = FALSE
|
|
addtimer(VARSET_CALLBACK(src, can_use, TRUE), 5 SECONDS)
|
|
|
|
/obj/item/chameleon/proc/eject_all()
|
|
for(var/atom/movable/A in active_dummy)
|
|
A.forceMove(active_dummy.loc)
|
|
if(ismob(A))
|
|
var/mob/M = A
|
|
M.reset_perspective(null)
|
|
|
|
/obj/effect/dummy/chameleon
|
|
name = ""
|
|
desc = ""
|
|
density = FALSE
|
|
var/can_move = 0
|
|
var/obj/item/chameleon/master = null
|
|
|
|
/obj/effect/dummy/chameleon/proc/activate(mob/M, saved_appearance, obj/item/chameleon/C)
|
|
appearance = saved_appearance
|
|
if(istype(M.buckled, /obj/vehicle))
|
|
var/obj/vehicle/V = M.buckled
|
|
V.unbuckle_mob(M, force = TRUE)
|
|
M.forceMove(src)
|
|
master = C
|
|
master.active_dummy = src
|
|
|
|
/obj/effect/dummy/chameleon/attackby()
|
|
master.disrupt()
|
|
|
|
//ATTACK HAND IGNORING PARENT RETURN VALUE
|
|
/obj/effect/dummy/chameleon/attack_hand(mob/user, list/modifiers)
|
|
master.disrupt()
|
|
|
|
/obj/effect/dummy/chameleon/attack_animal(mob/user, list/modifiers)
|
|
master.disrupt()
|
|
|
|
/obj/effect/dummy/chameleon/attack_alien(mob/user, list/modifiers)
|
|
master.disrupt()
|
|
|
|
/obj/effect/dummy/chameleon/ex_act(S, T)
|
|
master.disrupt()
|
|
return TRUE
|
|
|
|
/obj/effect/dummy/chameleon/bullet_act()
|
|
. = ..()
|
|
master.disrupt()
|
|
|
|
/obj/effect/dummy/chameleon/relaymove(mob/living/user, direction)
|
|
if(!isturf(loc) || isspaceturf(loc) || !direction)
|
|
return //No magical movement! Trust me, this bad boy can do things like leap out of pipes if you're not careful
|
|
|
|
if(can_move < world.time)
|
|
var/amount
|
|
switch(user.bodytemperature)
|
|
if(300 to INFINITY)
|
|
amount = 10
|
|
if(295 to 300)
|
|
amount = 13
|
|
if(280 to 295)
|
|
amount = 16
|
|
if(260 to 280)
|
|
amount = 20
|
|
else
|
|
amount = 25
|
|
|
|
can_move = world.time + amount
|
|
try_step_multiz(direction)
|
|
return
|
|
|
|
/obj/effect/dummy/chameleon/Destroy()
|
|
if(master)
|
|
master.disrupt(0)
|
|
master = null
|
|
return ..()
|