Skip to content

Commit abc3cee

Browse files
authored
adds a component to make it obvious what items came from a gift (#4625)
1 parent 8fa9eb9 commit abc3cee

File tree

8 files changed

+119
-6
lines changed

8 files changed

+119
-6
lines changed

code/__DEFINES/traits/monkestation/declarations.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
#define TRAIT_BYPASS_COMPRESS_CHECK "can_compress_anyways"
122122
/// This item is considered "trash" (and will be eaten by cleaner slimes)
123123
#define TRAIT_TRASH_ITEM "trash_item"
124+
/// This item came from a gift.
125+
#define TRAIT_GIFT_ITEM "gift_item"
124126

125127
// /atom/movable
126128
/// Things with this trait can pass through wooden barricades.

code/__DEFINES/~monkestation/vv.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define VV_HK_EXAMINE_GIFT "examine_gift"

code/__HELPERS/~monkestation-helpers/atoms.dm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@
2626
default_typecache ||= typecacheof(list(/obj/effect, /atom/movable/screen))
2727
typecache = default_typecache
2828
return typecache_filter_list_reverse(src.contents, typecache)
29+
30+
/// Returns a list of all items in our contents that were obtained from gifts.
31+
/atom/proc/get_all_gift_contents() as /list
32+
RETURN_TYPE(/list/obj/item)
33+
. = list()
34+
for(var/obj/item/thing as anything in get_all_contents_type(/obj/item))
35+
if(!QDELETED(thing) && HAS_TRAIT(thing, TRAIT_GIFT_ITEM))
36+
. += thing

code/_globalvars/traits/_traits.dm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,24 +611,31 @@ GLOBAL_LIST_INIT(traits_by_type, list(
611611
),
612612
/obj/item = list(
613613
"TRAIT_APC_SHOCKING" = TRAIT_APC_SHOCKING,
614+
"TRAIT_ASSISTED_BREATHING" = TRAIT_ASSISTED_BREATHING,
614615
"TRAIT_BASIC_QUALITY_BAIT" = TRAIT_BASIC_QUALITY_BAIT,
615616
"TRAIT_BELT_SATCHEL" = TRAIT_BELT_SATCHEL,
616617
"TRAIT_BLIND_TOOL" = TRAIT_BLIND_TOOL,
617618
"TRAIT_BYPASS_COMPRESS_CHECK" = TRAIT_BYPASS_COMPRESS_CHECK,
618619
"TRAIT_CUSTOM_TAP_SOUND" = TRAIT_CUSTOM_TAP_SOUND,
619620
"TRAIT_DANGEROUS_OBJECT" = TRAIT_DANGEROUS_OBJECT,
621+
"TRAIT_FEATHERED" = TRAIT_FEATHERED,
620622
"TRAIT_FISHING_BAIT" = TRAIT_FISHING_BAIT,
621623
"TRAIT_FOOD_GRILLED" = TRAIT_FOOD_GRILLED,
624+
"TRAIT_GIFT_ITEM" = TRAIT_GIFT_ITEM,
622625
"TRAIT_GOOD_QUALITY_BAIT" = TRAIT_GOOD_QUALITY_BAIT,
623626
"TRAIT_GREAT_QUALITY_BAIT" = TRAIT_GREAT_QUALITY_BAIT,
624627
"TRAIT_HAUNTED" = TRAIT_HAUNTED,
625628
"TRAIT_HONKSPAMMING" = TRAIT_HONKSPAMMING,
626629
"TRAIT_INNATELY_FANTASTICAL_ITEM" = TRAIT_INNATELY_FANTASTICAL_ITEM,
630+
"TRAIT_INSTANTLY_PROCESSES_BOULDERS" = TRAIT_INSTANTLY_PROCESSES_BOULDERS,
631+
"TRAIT_LABOURED_BREATHING" = TRAIT_LABOURED_BREATHING,
627632
"TRAIT_MAT_TRANSMUTED" = TRAIT_MAT_TRANSMUTED,
628633
"TRAIT_MAY_CONTAIN_BLENDED_DUST" = TRAIT_MAY_CONTAIN_BLENDED_DUST,
629634
"TRAIT_NEEDS_TWO_HANDS" = TRAIT_NEEDS_TWO_HANDS,
630635
"TRAIT_NODROP" = TRAIT_NODROP,
636+
"TRAIT_NON_IMPORTANT_SHOE_BLOCK" = TRAIT_NON_IMPORTANT_SHOE_BLOCK,
631637
"TRAIT_NO_BARCODES" = TRAIT_NO_BARCODES,
638+
"TRAIT_NO_ORGAN_DECAY" = TRAIT_NO_ORGAN_DECAY,
632639
"TRAIT_NO_STORAGE_INSERT" = TRAIT_NO_STORAGE_INSERT,
633640
"TRAIT_NO_TELEPORT" = TRAIT_NO_TELEPORT,
634641
"TRAIT_OMNI_BAIT" = TRAIT_OMNI_BAIT,
@@ -639,17 +646,11 @@ GLOBAL_LIST_INIT(traits_by_type, list(
639646
"TRAIT_T_RAY_VISIBLE" = TRAIT_T_RAY_VISIBLE,
640647
"TRAIT_UNCATCHABLE" = TRAIT_UNCATCHABLE,
641648
"TRAIT_WIELDED" = TRAIT_WIELDED,
642-
"TRAIT_FEATHERED" = TRAIT_FEATHERED,
643-
"TRAIT_NON_IMPORTANT_SHOE_BLOCK" = TRAIT_NON_IMPORTANT_SHOE_BLOCK,
644-
"TRAIT_LABOURED_BREATHING" = TRAIT_LABOURED_BREATHING,
645-
"TRAIT_ASSISTED_BREATHING" = TRAIT_ASSISTED_BREATHING,
646-
"TRAIT_NO_ORGAN_DECAY" = TRAIT_NO_ORGAN_DECAY,
647649
/* "TRAIT_BAIT_UNCONSUMABLE" = TRAIT_BAIT_UNCONSUMABLE, */
648650
/* "TRAIT_BAKEABLE" = TRAIT_BAKEABLE, */
649651
/* "TRAIT_BYPASS_RANGED_ARMOR" = TRAIT_BYPASS_RANGED_ARMOR, */
650652
/* "TRAIT_CONTRABAND_BLOCKER" = TRAIT_CONTRABAND_BLOCKER, */
651653
/* "TRAIT_GERM_SENSITIVE" = TRAIT_GERM_SENSITIVE, */
652-
"TRAIT_INSTANTLY_PROCESSES_BOULDERS" = TRAIT_INSTANTLY_PROCESSES_BOULDERS,
653654
/* "TRAIT_ITEM_OBJECTIVE_BLOCKED" = TRAIT_ITEM_OBJECTIVE_BLOCKED, */
654655
/* "TRAIT_NO_SIDE_KICK" = TRAIT_NO_SIDE_KICK, */
655656
),

code/game/objects/items/gift.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ GLOBAL_LIST_EMPTY(possible_gifts)
5050
M.investigate_log("has unwrapped a present containing [I.type].", INVESTIGATE_PRESENTS)
5151
M.put_in_hands(I)
5252
I.add_fingerprint(M)
53+
I.AddComponent(/datum/component/gift_item, M) // monkestation edit: gift item info component
5354
else
5455
M.visible_message(span_danger("Oh no! The present that [M] opened had nothing inside it!"))
5556

code/modules/admin/verbs/admingame.dm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
4646
body += "<br>\[<b>Byond version:</b> [full_version]\]<br>"
4747

48+
// monkestation start: gift info
49+
var/list/gifts = M.get_all_gift_contents()
50+
var/gift_amt = length(gifts)
51+
if(gift_amt)
52+
body += "<br><br><b>Gift items in contents:</b><br>"
53+
for(var/idx in 1 to gift_amt)
54+
var/obj/item/gift = gifts[idx]
55+
body += VV_HREF_TARGET(gift, VV_HK_EXAMINE_GIFT, "<b>[gift.name]</b> (<i>[gift.type]</i>)")
56+
if(idx < gift_amt)
57+
body += "<br>"
58+
// monkestation end
59+
4860

4961
body += "<br><br>\[ "
5062
body += "<a href='?_src_=vars;[HrefToken()];Vars=[REF(M)]'>VV</a> - "
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/// Simple thing that marks an items as having come from a gift.
2+
/datum/component/gift_item
3+
/// The ckey of the player who opened the gift.
4+
var/ckey
5+
/// Weakref to the mob who opened the gift.
6+
var/datum/weakref/giftee
7+
/// Weakref to the mob who opened the gift.
8+
var/datum/weakref/mind
9+
/// The (real) name of mob who opened the gift.
10+
var/name
11+
/// The `world.time` when the gift was opened.
12+
var/open_world_time
13+
/// The `world.timeofday` when the gift was opened.
14+
var/open_timeofday
15+
16+
/datum/component/gift_item/Initialize(mob/living/giftee)
17+
if(!isitem(parent))
18+
stack_trace("Tried to assign [type] to a non-item")
19+
return COMPONENT_INCOMPATIBLE
20+
if(!isliving(giftee))
21+
stack_trace("Tried to assign [type] to something that wasn't a living mob!")
22+
return COMPONENT_INCOMPATIBLE
23+
if(!giftee.ckey)
24+
stack_trace("Tried to assign [type] to a non-player mob!")
25+
return COMPONENT_INCOMPATIBLE
26+
src.ckey = giftee.ckey
27+
src.giftee = WEAKREF(giftee)
28+
src.mind = WEAKREF(giftee.mind)
29+
src.name = "[giftee.mind?.name || giftee.real_name || giftee.name || "N/A"]"
30+
src.open_world_time = world.time
31+
src.open_timeofday = world.timeofday
32+
33+
/datum/component/gift_item/Destroy(force)
34+
giftee = null
35+
mind = null
36+
return ..()
37+
38+
/datum/component/gift_item/RegisterWithParent()
39+
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
40+
RegisterSignal(parent, COMSIG_ATOM_EXAMINE_MORE, PROC_REF(on_examine_more))
41+
RegisterSignal(parent, COMSIG_VV_TOPIC, PROC_REF(handle_vv_topic))
42+
ADD_TRAIT(parent, TRAIT_GIFT_ITEM, type)
43+
44+
/datum/component/gift_item/UnregisterFromParent()
45+
UnregisterSignal(parent, list(COMSIG_ATOM_EXAMINE, COMSIG_ATOM_EXAMINE_MORE, COMSIG_VV_TOPIC))
46+
REMOVE_TRAIT(parent, TRAIT_GIFT_ITEM, type)
47+
48+
/datum/component/gift_item/proc/on_examine(obj/item/source, mob/examiner, list/examine_text)
49+
SIGNAL_HANDLER
50+
if(check_rights_for(examiner.client, R_ADMIN))
51+
// ensure we always target the right mob for the admin buttons
52+
var/mob/target_mob = resolve_opener_mob()
53+
examine_text += ""
54+
examine_text += span_bold("\[") + span_info(" This item came from a gift opened by [span_name(name)] ([ckey]) [ADMIN_FULLMONTY_NONAME(target_mob)] ") + span_bold("\]")
55+
examine_text += span_bold("\[") + span_info(" It was unwrapped from a gift [span_bold(DisplayTimeText(world.time - open_world_time) + " ago")], at server time [span_bold(time2text(open_timeofday, "YYYY-MM-DD hh:mm:ss"))] ") + span_bold("\]")
56+
examine_text += ""
57+
else if(isobserver(examiner) || HAS_TRAIT(examiner, TRAIT_PRESENT_VISION) || SSticker.current_state >= GAME_STATE_FINISHED)
58+
examine_text += ""
59+
examine_text += span_bold("\[") + span_info(" This item came from a gift opened by [span_name(name)] [DisplayTimeText(world.time - open_world_time)] ago ") + span_bold("\]")
60+
examine_text += ""
61+
62+
/datum/component/gift_item/proc/on_examine_more(obj/item/source, mob/examiner, list/examine_text)
63+
SIGNAL_HANDLER
64+
examine_text += span_info("This item seems to have been a gift!")
65+
66+
/datum/component/gift_item/proc/resolve_opener_mob() as /mob
67+
RETURN_TYPE(/mob)
68+
var/mob/opener = giftee.resolve()
69+
var/datum/mind/opener_mind = mind.resolve()
70+
if(opener?.ckey == ckey)
71+
return opener
72+
else if(opener_mind?.current?.ckey == ckey)
73+
return opener_mind.current
74+
else if(GLOB.directory[ckey])
75+
var/client/current_client = GLOB.directory[ckey]
76+
return current_client.mob
77+
else
78+
for(var/mob/mob in GLOB.mob_list)
79+
if(mob.ckey == ckey)
80+
return mob
81+
82+
/datum/component/gift_item/proc/handle_vv_topic(datum/source, mob/user, list/href_list)
83+
SIGNAL_HANDLER
84+
if(href_list[VV_HK_EXAMINE_GIFT] && check_rights(R_ADMIN))
85+
user.examinate(parent)
86+
return COMPONENT_VV_HANDLED

tgstation.dme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
#include "code\__DEFINES\~monkestation\twitch.dm"
470470
#include "code\__DEFINES\~monkestation\uplink.dm"
471471
#include "code\__DEFINES\~monkestation\virology.dm"
472+
#include "code\__DEFINES\~monkestation\vv.dm"
472473
#include "code\__DEFINES\~monkestation\dcs\signals\signals_atom.dm"
473474
#include "code\__DEFINES\~monkestation\dcs\signals\signals_blueshift.dm"
474475
#include "code\__DEFINES\~monkestation\dcs\signals\signals_carbon.dm"
@@ -5955,6 +5956,7 @@
59555956
#include "monkestation\code\datums\components\carbon_sprint.dm"
59565957
#include "monkestation\code\datums\components\charge_adjuster.dm"
59575958
#include "monkestation\code\datums\components\crafting.dm"
5959+
#include "monkestation\code\datums\components\gift_item.dm"
59585960
#include "monkestation\code\datums\components\gps.dm"
59595961
#include "monkestation\code\datums\components\irradiated.dm"
59605962
#include "monkestation\code\datums\components\lock_on_cursor.dm"

0 commit comments

Comments
 (0)