-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathmail.dm
382 lines (326 loc) · 13.8 KB
/
mail.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/// Mail is tamper-evident and unresealable, postmarked by CentCom for an individual recepient.
/obj/item/mail
name = "mail"
gender = NEUTER
desc = "An officially postmarked, tamper-evident parcel regulated by CentCom and made of high-quality materials."
icon = 'icons/obj/bureaucracy.dmi'
icon_state = "mail_small"
item_flags = NOBLUDGEON
w_class = WEIGHT_CLASS_SMALL
//drop_sound = 'sound/items/handling/paper_drop.ogg'
//pickup_sound = 'sound/items/handling/paper_pickup.ogg'
mouse_drag_pointer = MOUSE_ACTIVE_POINTER
/// Destination tagging for the mail sorter.
var/sort_tag = NONE
/// Weak reference to who this mail is for and who can open it.
var/datum/weakref/recipient_ref
/// How many goodies this mail contains.
var/goodie_count = 1
/// Goodies which can be given to anyone. The base weight for cash is 37. For there to be a 50/50 chance of getting a department item, they need 37 weight as well.
var/list/generic_goodies = list( //yogs, add coins, sorted least valuable to most valuable
/obj/item/stack/spacecash/c50 = 4,
/obj/item/stack/spacecash/c100 = 10,
/obj/item/stack/spacecash/c200 = 6,
/obj/item/stack/spacecash/c500 = 2,
/obj/item/stack/spacecash/c1000 = 1,
/obj/effect/spawner/lootdrop/coin = 8,
/obj/effect/spawner/lootdrop/donkpockets = 6
)
// Overlays (pure fluff)
/// Does the letter have the postmark overlay?
var/postmarked = TRUE
/// Does the letter have a stamp overlay?
var/stamped = TRUE
/// List of all stamp overlays on the letter.
var/list/stamps = list()
/// Maximum number of stamps on the letter.
var/stamp_max = 1
/// Physical offset of stamps on the object. X direction.
var/stamp_offset_x = 0
/// Physical offset of stamps on the object. Y direction.
var/stamp_offset_y = 2
///mail will have the color of the department the recipient is in.
var/static/list/department_colors
/obj/item/mail/envelope
name = "envelope"
icon_state = "mail_large"
goodie_count = 2
stamp_max = 2
stamp_offset_y = 5
/obj/item/mail/Initialize(mapload)
. = ..()
RegisterSignal(src, COMSIG_MOVABLE_DISPOSING, PROC_REF(disposal_handling))
//AddElement(/datum/element/item_scaling, 0.75, 1)
if(isnull(department_colors))
department_colors = list(
ACCOUNT_CIV = COLOR_WHITE,
ACCOUNT_ENG = COLOR_PALE_ORANGE,
ACCOUNT_SCI = COLOR_PALE_PURPLE_GRAY,
ACCOUNT_MED = COLOR_PALE_BLUE_GRAY,
ACCOUNT_SRV = COLOR_PALE_GREEN_GRAY,
ACCOUNT_CAR = COLOR_BEIGE,
ACCOUNT_SEC = COLOR_PALE_RED_GRAY,
)
// Icons
// Add some random stamps.
if(stamped == TRUE)
var/stamp_count = rand(1, stamp_max)
for(var/i in 1 to stamp_count)
stamps += list("stamp_[rand(2, 6)]")
update_appearance(UPDATE_ICON)
/obj/item/mail/update_overlays()
. = ..()
var/bonus_stamp_offset = 0
for(var/stamp in stamps)
var/image/stamp_image = image(
icon = icon,
icon_state = stamp,
pixel_x = stamp_offset_x,
pixel_y = stamp_offset_y + bonus_stamp_offset
)
stamp_image.appearance_flags |= RESET_COLOR
. += stamp_image
bonus_stamp_offset -= 5
if(postmarked == TRUE)
var/image/postmark_image = image(
icon = icon,
icon_state = "postmark",
pixel_x = stamp_offset_x + rand(-3, 1),
pixel_y = stamp_offset_y + rand(bonus_stamp_offset + 3, 1)
)
postmark_image.appearance_flags |= RESET_COLOR
. += postmark_image
/obj/item/mail/attackby(obj/item/W, mob/user, params)
// Destination tagging
if(istype(W, /obj/item/destTagger))
var/obj/item/destTagger/destination_tag = W
if(sort_tag != destination_tag.currTag)
var/tag = uppertext(GLOB.TAGGERLOCATIONS[destination_tag.currTag])
to_chat(user, span_notice("*[tag]*"))
sort_tag = destination_tag.currTag
playsound(loc, 'sound/machines/twobeep_high.ogg', 100, TRUE)
/obj/item/mail/attack_self(mob/user)
var/recipient_real = FALSE // Whether there is a recipient
if(recipient_ref)
var/datum/mind/recipient = recipient_ref.resolve()
// If the recipient's mind has gone, then anyone can open their mail
// whether a mind can actually be qdel'd is an exercise for the reader
if(recipient && recipient != user?.mind)
to_chat(user, span_notice("You can't open somebody else's mail! That's <em>illegal</em>!"))
return
recipient_real = recipient // This will be truthy if recipient resolved successfully
to_chat(user, span_notice("You start to unwrap the package..."))
if(!do_after(user, 1.5 SECONDS, user, IGNORE_USER_LOC_CHANGE))
return
user.temporarilyRemoveItemFromInventory(src, TRUE)
for (var/content in contents)
user.put_in_hands(content)
playsound(loc, 'sound/items/poster_ripped.ogg', 50, TRUE)
if(recipient_real) // If this is official NT mail for someone, give cargo money for delivering it successfully
var/datum/bank_account/D = SSeconomy.get_dep_account(ACCOUNT_CAR)
D?.adjust_money(150)
qdel(src)
/obj/item/mail/examine_more(mob/user)
. = ..()
var/list/msg = list(span_notice("<i>You notice the postmarking on the front of the mail...</i>"))
var/datum/mind/recipient = recipient_ref.resolve()
if(recipient)
msg += "\t[span_info("Certified NT mail for [recipient].")]"
else
msg += "\t[span_info("Certified mail for [GLOB.station_name].")]"
msg += "\t[span_info("Distribute by hand or via destination tagger using the certified NT disposal system.")]"
return msg
/// Accepts a mind to initialize goodies for a piece of mail.
/obj/item/mail/proc/initialize_for_recipient(datum/mind/recipient)
name = "[initial(name)] for [recipient.name] ([recipient.assigned_role])"
recipient_ref = WEAKREF(recipient)
var/mob/living/body = recipient.current
var/list/goodies = generic_goodies.Copy()
var/datum/job/this_job = SSjob.GetJob(recipient.assigned_role)
if(this_job)
if(this_job.paycheck_department && department_colors[this_job.paycheck_department])
color = department_colors[this_job.paycheck_department]
var/list/job_goodies = this_job.get_mail_goodies()
job_goodies = job_goodies.Copy()
if(LAZYLEN(job_goodies))
// certain roles and jobs (prisoner) do not receive generic gifts.
if(this_job.exclusive_mail_goodies)
goodies = job_goodies
else
goodies += job_goodies
if(recipient.current && HAS_TRAIT(recipient.current, TRAIT_BADMAIL)) //reduce the weight of every item by 10
for(var/item in goodies)
goodies[item] -= 10
if(goodies[item] <= 0) //remove everything with a weight below 0
goodies -= item
if(!length(goodies)) //if everything was removed for some reason
return FALSE
for(var/iterator in 1 to goodie_count)
var/target_good = pickweight(goodies)
var/atom/movable/target_atom = new target_good(src)
body.log_message("[key_name(body)] received [target_atom.name] in the mail ([target_good])", LOG_GAME)
return TRUE
/// Alternate setup, just complete garbage inside and anyone can open
/obj/item/mail/proc/junk_mail()
sort_tag = 1 // Default sort for junk mail is the trash
var/obj/junk = /obj/item/paper/fluff/junkmail_generic
var/special_name = FALSE
if(prob(25))
special_name = TRUE
junk = pick(list(/obj/item/paper/pamphlet/gateway, /obj/item/paper/pamphlet/centcom/visitor_info, /obj/item/paper/fluff/junkmail_redpill, /obj/effect/decal/cleanable/ash))
var/list/junk_names = list(
/obj/item/paper/pamphlet/gateway = "[initial(name)] for [pick(GLOB.adjectives)] adventurers",
/obj/item/paper/pamphlet/centcom/visitor_info = "[initial(name)] for info about visiting nanotrasen space stations",
/obj/item/paper/fluff/junkmail_redpill = "[initial(name)] for those feeling [pick(GLOB.adjectives)] working at Nanotrasen",
/obj/effect/decal/cleanable/ash = "[initial(name)] with INCREDIBLY IMPORTANT ARTIFACT- DELIVER TO SCIENCE DIVISION. HANDLE WITH CARE.",
)
color = pick(department_colors) //eh, who gives a shit.
name = special_name ? junk_names[junk] : "important [initial(name)]"
junk = new junk(src)
return TRUE
/obj/item/mail/proc/disposal_handling(disposal_source, obj/structure/disposalholder/disposal_holder, obj/machinery/disposal/disposal_machine, hasmob)
if(!hasmob)
disposal_holder.destinationTag = sort_tag
/// Subtype that's always junkmail
/obj/item/mail/junkmail/Initialize(mapload)
. = ..()
junk_mail()
/// Crate for mail from CentCom.
/obj/structure/closet/crate/mail
name = "mail crate"
desc = "A certified post crate from CentCom."
icon_state = "mail"
/obj/structure/closet/crate/mail/update_icon_state()
. = ..()
if(opened)
icon_state = "[initial(icon_state)]open"
if(locate(/obj/item/mail) in src)
icon_state = initial(icon_state)
else
icon_state = "[initial(icon_state)]sealed"
/// Fills this mail crate with N pieces of mail, where N is the lower of the amount var passed, and the maximum capacity of this crate. If N is larger than the number of alive human players, it will be padded by a proportional amount of junkmail.
/obj/structure/closet/crate/mail/proc/populate(amount)
var/mail_count = min(amount, storage_capacity)
// Fills the
var/list/mail_recipients = list()
for(var/mob/living/carbon/human in GLOB.player_list)
if(human.stat == DEAD || !human.mind)
continue
// Skip wizards, nuke ops, cyborgs; Centcom does not send them mail
var/datum/job/this_job = SSjob.GetJob(human.mind.assigned_role)
if(!this_job || this_job.faction != "Station")
continue
if(is_synth(human))
continue
mail_recipients += human.mind
for(var/i in 1 to mail_count)
var/obj/item/mail/new_mail
if(prob(FULL_CRATE_LETTER_ODDS))
new_mail = new /obj/item/mail(src)
else
new_mail = new /obj/item/mail/envelope(src)
var/datum/mind/recipient = pick_n_take(mail_recipients)
if(recipient)
new_mail.initialize_for_recipient(recipient)
else if(prob(MAIL_JUNK_CHANCE))
new_mail.junk_mail()
update_appearance(UPDATE_ICON)
return mail_count
/// Crate for mail that automatically depletes the economy subsystem's pending mail counter.
/obj/structure/closet/crate/mail/economy/Initialize(mapload)
. = ..()
var/mail_handled = populate(SSeconomy.mail_waiting)
SSeconomy.mail_waiting -= mail_handled
/// Crate for mail that automatically generates a lot of mail. Usually only normal mail, but on lowpop it may end up just being junk.
/obj/structure/closet/crate/mail/full
name = "brimming mail crate"
desc = "A certified post crate from CentCom. Looks stuffed to the gills."
/obj/structure/closet/crate/mail/full/Initialize(mapload)
. = ..()
populate(INFINITY)
/// Mailbag.
/obj/item/storage/bag/mail
name = "mail bag"
desc = "A bag for letters, envelopes, and other postage."
icon = 'icons/obj/library.dmi'
icon_state = "bookbag"
worn_icon_state = "bookbag"
resistance_flags = FLAMMABLE
/obj/item/storage/bag/mail/Initialize(mapload)
. = ..()
var/datum/component/storage/storage = GetComponent(/datum/component/storage)
storage.max_w_class = WEIGHT_CLASS_NORMAL
storage.max_combined_w_class = 42
storage.max_items = 21
storage.display_numerical_stacking = FALSE
storage.set_holdable(list(
/obj/item/mail,
/obj/item/smallDelivery,
/obj/item/paper
))
/obj/item/paper/fluff/junkmail_redpill
name = "smudged paper"
icon_state = "scrap"
var/nuclear_option_odds = 0.1
/obj/item/paper/fluff/junkmail_redpill/Initialize(mapload)
. = ..()
if(!prob(nuclear_option_odds)) // 1 in 1000 chance of getting 2 random nuke code characters.
info = "<i>You need to escape the simulation. Don't forget the numbers, they help you remember:</i> '[rand(0,9)][rand(0,9)]...'"
return
var/obj/machinery/nuclearbomb/selfdestruct/nuke = locate() in GLOB.nuke_list
var/code = random_nukecode()
if(nuke)
if(nuke.r_code == "ADMIN")
nuke.r_code = code
message_admins("Through junkmail, the self-destruct code was set to \"[code]\".")
log_game("Through junkmail, the self-destruct code was set to \"[code]\".")
else
code = nuke.r_code
info = "<i>You need to escape the simulation. Don't forget the numbers, they help you remember:</i> '[code[rand(1,5)]][code[rand(1,5)]]...'"
/obj/item/paper/fluff/junkmail_redpill/true //admin letter enabling players to brute force their way through the nuke code if they're so inclined.
nuclear_option_odds = 100
/obj/item/paper/fluff/junkmail_generic
name = "important document"
icon_state = "paper_words"
/obj/item/paper/fluff/junkmail_generic/Initialize(mapload)
. = ..()
info = pick(GLOB.junkmail_messages)
/client/proc/debug_mail_loot()
set name = "Debug Mail Loot"
set category = "Misc.Server Debug"
var/obj/item/mail/mail = new
var/list/generic_goodies = mail.generic_goodies
qdel(mail)
var/generic_goodie_weight = 0
var/goodietype
to_chat(src, generic_goodies.len)
for(goodietype in generic_goodies)
generic_goodie_weight += generic_goodies[goodietype]
to_chat(src, generic_goodie_weight)
var/debug_info = "Generic Goodies (Weight: [generic_goodie_weight]):\n"
if(generic_goodie_weight)
for(goodietype in generic_goodies)
var/atom/goodie = goodietype
var/goodie_weight = generic_goodies[goodietype]
debug_info += " - [initial(goodie.name)]: [goodie_weight] ([(goodie_weight / generic_goodie_weight) * 100]%)\n"
for(var/datum/job/job in SSjob.occupations)
if(job.faction != "Station")
debug_info += "\n[job.title] is not a station job, skipping"
continue
var/list/job_goodies = job.mail_goodies
if(job_goodies.len == 0)
debug_info += "\n[span_red("No specific goodies for [job.title]")]\n"
continue
var/exclusive = job.exclusive_mail_goodies
var/effective_generic_goodie_weight = exclusive ? 0 : generic_goodie_weight
var/job_goodies_weight = effective_generic_goodie_weight
for(goodietype in job_goodies)
job_goodies_weight += job_goodies[goodietype]
debug_info += "\n[job.title] Goodies (Weight: [job_goodies_weight]): \n"
if(job_goodies_weight)
debug_info += "Generic Goodies: [effective_generic_goodie_weight] ([(effective_generic_goodie_weight / job_goodies_weight) * 100]%)\n"
for(goodietype in job_goodies)
var/goodie_weight = job_goodies[goodietype]
var/atom/goodie = goodietype
debug_info += " - [initial(goodie.name)]: [goodie_weight] ([(goodie_weight / job_goodies_weight) * 100]%)\n"
to_chat(src, examine_block(debug_info))