-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathmob_helpers.dm
581 lines (528 loc) · 17.8 KB
/
mob_helpers.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
// see _DEFINES/is_helpers.dm for mob type checks
///Find the mob at the bottom of a buckle chain
/mob/proc/lowest_buckled_mob()
. = src
if(buckled && ismob(buckled))
var/mob/Buckled = buckled
. = Buckled.lowest_buckled_mob()
///Convert a PRECISE ZONE into the BODY_ZONE
/proc/check_zone(zone)
if(!zone)
return BODY_ZONE_CHEST
switch(zone)
if(BODY_ZONE_PRECISE_EYES)
zone = BODY_ZONE_HEAD
if(BODY_ZONE_PRECISE_MOUTH)
zone = BODY_ZONE_HEAD
if(BODY_ZONE_PRECISE_L_HAND)
zone = BODY_ZONE_L_ARM
if(BODY_ZONE_PRECISE_R_HAND)
zone = BODY_ZONE_R_ARM
if(BODY_ZONE_PRECISE_L_FOOT)
zone = BODY_ZONE_L_LEG
if(BODY_ZONE_PRECISE_R_FOOT)
zone = BODY_ZONE_R_LEG
if(BODY_ZONE_PRECISE_GROIN)
zone = BODY_ZONE_CHEST
return zone
/**
* Return the zone or randomly, another valid zone
*
* probability controls the chance it chooses the passed in zone, or another random zone
* defaults to 80
*/
/proc/ran_zone(zone, probability = 80)
if(prob(probability))
zone = check_zone(zone)
else
zone = pickweight(list(BODY_ZONE_HEAD = 1, BODY_ZONE_CHEST = 1, BODY_ZONE_L_ARM = 4, BODY_ZONE_R_ARM = 4, BODY_ZONE_L_LEG = 4, BODY_ZONE_R_LEG = 4))
return zone
///Would this zone be above the neck
/proc/above_neck(zone)
var/list/zones = list(BODY_ZONE_HEAD, BODY_ZONE_PRECISE_MOUTH, BODY_ZONE_PRECISE_EYES)
if(zones.Find(zone))
return 1
else
return 0
/**
* Convert random parts of a passed in message to stars
*
* * n - the string to convert
* * pr - probability any character gets changed
*
* This proc is dangerously laggy, avoid it or die
*/
/proc/stars(n, pr)
n = html_encode(n)
if (pr == null)
pr = 25
if (pr <= 0)
return null
else
if (pr >= 100)
return n
var/te = n
var/t = ""
n = length(n)
for(var/p = 1 to min(n,MAX_BROADCAST_LEN))
if ((copytext(te, p, p + 1) == " " || prob(pr)))
t = text("[][]", t, copytext(te, p, p + 1))
else
t = text("[]*", t)
if(n > MAX_BROADCAST_LEN)
t += "..." //signals missing text
return sanitize(t)
/**
* Makes you speak like you're drunk
*/
/proc/slur(phrase)
phrase = html_decode(phrase)
var/leng = length(phrase)
. = ""
var/newletter = ""
var/rawchar = ""
for(var/i = 1, i <= leng, i += length(rawchar))
rawchar = newletter = phrase[i]
if(rand(1, 3) == 3)
var/lowerletter = lowertext(newletter)
if(lowerletter == "o")
newletter = "u"
else if(lowerletter == "s")
newletter = "ch"
else if(lowerletter == "a")
newletter = "ah"
else if(lowerletter == "u")
newletter = "oo"
else if(lowerletter == "c")
newletter = "k"
if(rand(1, 20) == 20)
if(newletter == " ")
newletter = "...huuuhhh..."
else if(newletter == ".")
newletter = " *BURP*."
switch(rand(1, 20))
if(1)
newletter += "'"
if(10)
newletter += "[newletter]"
if(20)
newletter += "[newletter][newletter]"
else
newletter += ""
. += "[newletter]"
return sanitize(.)
/// Makes you talk like you got cult stunned, which is slurring but with some dark messages
/proc/cultslur(phrase) // Inflicted on victims of a stun talisman
phrase = html_decode(phrase)
var/leng = length(phrase)
. = ""
var/newletter = ""
var/rawchar = ""
for(var/i = 1, i <= leng, i += length(rawchar))
rawchar = newletter = phrase[i]
if(rand(1, 2) == 2)
var/lowerletter = lowertext(newletter)
if(lowerletter == "o")
newletter = "u"
else if(lowerletter == "t")
newletter = "ch"
else if(lowerletter == "a")
newletter = "ah"
else if(lowerletter == "u")
newletter = "oo"
else if(lowerletter == "c")
newletter = " NAR "
else if(lowerletter == "s")
newletter = " SIE "
if(rand(1, 4) == 4)
if(newletter == " ")
newletter = " no hope... "
else if(newletter == "H")
newletter = " IT COMES... "
switch(rand(1, 15))
if(1)
newletter = "'"
if(2)
newletter += "agn"
if(3)
newletter = "fth"
if(4)
newletter = "nglu"
if(5)
newletter = "glor"
else
newletter += ""
. += newletter
return sanitize(.)
///Adds stuttering to the message passed in
/proc/stutter(phrase)
phrase = html_decode(phrase)
var/leng = length(phrase)
. = ""
var/newletter = ""
var/rawchar
for(var/i = 1, i <= leng, i += length(rawchar))
rawchar = newletter = phrase[i]
if(prob(80) && !(lowertext(newletter) in list("a", "e", "i", "o", "u", " ")))
if(prob(10))
newletter = "[newletter]-[newletter]-[newletter]-[newletter]"
else if(prob(20))
newletter = "[newletter]-[newletter]-[newletter]"
else if (prob(5))
newletter = ""
else
newletter = "[newletter]-[newletter]"
. += newletter
return sanitize(.)
///Convert a message to derpy speak
/proc/derpspeech(message, stuttering)
message = replacetext(message, " am ", " ")
message = replacetext(message, " is ", " ")
message = replacetext(message, " are ", " ")
message = replacetext(message, "you", "u")
message = replacetext(message, "help", "halp")
message = replacetext(message, "grief", "grife")
message = replacetext(message, "space", "spess")
message = replacetext(message, "carp", "crap")
message = replacetext(message, "reason", "raisin")
if(prob(50))
message = uppertext(message)
message += "[stutter(pick("!", "!!", "!!!"))]"
if(!stuttering && prob(15))
message = stutter(message)
return message
/proc/lizardspeech(message)
var/static/regex/lizard_hiss = new("s+", "g")
var/static/regex/lizard_hiSS = new("S+", "g")
if(message[1] != "*")
message = lizard_hiss.Replace(message, "sss")
message = lizard_hiSS.Replace(message, "SSS")
return message
/**
* Turn text into complete gibberish!
*
* text is the inputted message, and any value higher than 70 for chance will cause letters to be replaced instead of added
*/
/proc/Gibberish(text, replace_characters = FALSE, chance = 50)
text = html_decode(text)
. = ""
var/rawchar = ""
var/letter = ""
var/lentext = length(text)
for(var/i = 1, i <= lentext, i += length(rawchar))
rawchar = letter = text[i]
if(prob(chance))
if(replace_characters)
letter = ""
for(var/j in 1 to rand(0, 2))
letter += pick("#", "@", "*", "&", "%", "$", "/", "<", ">", ";", "*", "*", "*", "*", "*", "*", "*")
. += letter
return sanitize(.)
///Shake the camera of the person viewing the mob SO REAL!
/proc/shake_camera(mob/M, duration, strength=1)
if(!M || !M.client || duration < 1)
return
var/client/C = M.client
var/oldx = C.pixel_x
var/oldy = C.pixel_y
var/max = strength*world.icon_size
var/min = -(strength*world.icon_size)
for(var/i in 0 to duration-1)
if (i == 0)
animate(C, pixel_x=rand(min,max), pixel_y=rand(min,max), time=0.1 SECONDS)
else
animate(pixel_x=rand(min,max), pixel_y=rand(min,max), time=0.1 SECONDS)
animate(pixel_x=oldx, pixel_y=oldy, time=0.1 SECONDS)
///Find if the message has the real name of any user mob in the mob_list
/proc/findname(msg)
if(!istext(msg))
msg = "[msg]"
for(var/i in GLOB.mob_list)
var/mob/M = i
if(M.real_name == msg)
return M
return 0
///Find the first name of a mob from the real name with regex
/mob/proc/first_name()
var/static/regex/firstname = new("^\[^\\s-\]+") //First word before whitespace or "-"
firstname.Find(real_name)
return firstname.match
///Checks if passed through item is blind
/proc/is_blind(A)
SHOULD_BE_PURE(TRUE)
if(ismob(A))
var/mob/B = A
return B.eye_blind ? TRUE : HAS_TRAIT(B, TRAIT_BLIND)
return FALSE
// moved out of admins.dm because things other than admin procs were calling this.
/**
* Is this mob special to the gamemode?
*
* returns 1 for special characters and 2 for heroes of gamemode
*
*/
/proc/is_special_character(mob/M)
if(!SSticker.HasRoundStarted())
return FALSE
if(!istype(M))
return FALSE
if(issilicon(M))
if(iscyborg(M)) //For cyborgs, returns 1 if the cyborg has a law 0 and special_role. Returns 0 if the borg is merely slaved to an AI traitor.
return FALSE
else if(isAI(M))
var/mob/living/silicon/ai/A = M
if(A.laws && A.laws.zeroth && A.mind && A.mind.special_role)
return TRUE
return FALSE
if(M.mind?.special_role)//If they have a mind and special role, they are some type of traitor or antagonist.
if(IS_REVOLUTIONARY(M))
return 2
if(M.mind in SSgamemode.cult)
return 2
if(M.mind.has_antag_datum(/datum/antagonist/nukeop,TRUE))
return 2
if(M.mind.has_antag_datum(/datum/antagonist/changeling,TRUE))
return 2
if(IS_WIZARD(M))
return 2
if(M.mind in SSgamemode.apprentices)
return 2
return TRUE
if(M.mind && LAZYLEN(M.mind.antag_datums)) //they have an antag datum!
return TRUE
return FALSE
/mob/proc/reagent_check(datum/reagent/R) // utilized in the species code
return 1
/**
* Fancy notifications for ghosts
*
* The kitchen sink of notification procs
*
* Arguments:
* * message
* * ghost_sound sound to play
* * enter_link Href link to enter the ghost role being notified for
* * source The source of the notification
* * alert_overlay The alert overlay to show in the alert message
* * action What action to take upon the ghost interacting with the notification, defaults to NOTIFY_JUMP
* * flashwindow Flash the byond client window
* * ignore_key Ignore keys if they're in the GLOB.poll_ignore list
* * header The header of the notifiaction
* * notify_suiciders If it should notify suiciders (who do not qualify for many ghost roles)
* * notify_volume How loud the sound should be to spook the user
*/
/proc/notify_ghosts(message, ghost_sound = null, enter_link = null, atom/source = null, mutable_appearance/alert_overlay = null, action = NOTIFY_JUMP, flashwindow = TRUE, ignore_mapload = TRUE, ignore_key, header = null, notify_suiciders = TRUE, notify_volume = 100) //Easy notification of ghosts.
if(ignore_mapload && SSatoms.initialized != INITIALIZATION_INNEW_REGULAR) //don't notify for objects created during a map load
return
for(var/mob/dead/observer/O in GLOB.player_list)
if(O.client)
if(!notify_suiciders && (O in GLOB.suicided_mob_list))
continue
if (ignore_key && (O.ckey in GLOB.poll_ignore[ignore_key]))
continue
var/orbit_link
if (source && (action == NOTIFY_ORBIT || action == NOTIFY_ATTACKORBIT))
orbit_link = " <a href='?src=[REF(O)];follow=[REF(source)]'>(Orbit)</a>"
to_chat(O, span_ghostalert("[message][(enter_link) ? " [enter_link]" : ""][orbit_link]"))
if(ghost_sound)
SEND_SOUND(O, sound(ghost_sound, volume = notify_volume))
if(flashwindow)
window_flash(O.client)
if(source)
var/atom/movable/screen/alert/notify_action/A = O.throw_alert("[REF(source)]_notify_action", /atom/movable/screen/alert/notify_action)
if(A)
var/ui_style = O.client?.prefs?.read_preference(/datum/preference/choiced/ui_style)
if(ui_style)
A.icon = ui_style2icon(ui_style)
if (header)
A.name = header
A.desc = message
A.action = action
A.target = source
if(!alert_overlay)
alert_overlay = new(source)
alert_overlay.layer = FLOAT_LAYER
alert_overlay.plane = FLOAT_PLANE
A.add_overlay(alert_overlay)
/**
* Heal a robotic body part on a mob
*/
/proc/item_heal_robotic(mob/living/carbon/human/H, mob/user, brute_heal, burn_heal)
var/obj/item/bodypart/affecting = H.get_bodypart(check_zone(user.zone_selected))
var/list/damaged_parts = H.get_damaged_bodyparts(brute_heal, burn_heal, status = BODYPART_ROBOTIC) // list of damaged parts we can heal
if(damaged_parts.len && !(affecting in damaged_parts))
affecting = pick(damaged_parts) // pick a random damaged part if the selected one is fine
if(affecting && affecting.status == BODYPART_ROBOTIC)
var/dam //changes repair text based on how much brute/burn was supplied
if(brute_heal > burn_heal)
dam = 1
else
dam = 0
if((brute_heal > 0 && affecting.brute_dam > 0) || (burn_heal > 0 && affecting.burn_dam > 0))
if(affecting.heal_damage(brute_heal, burn_heal, 0, BODYPART_ROBOTIC))
H.update_damage_overlays()
user.visible_message("[user] has fixed some of the [dam ? "dents on" : "burnt wires in"] [H]'s [affecting.name].", \
span_notice("You fix some of the [dam ? "dents on" : "burnt wires in"] [H == user ? "your" : "[H]'s"] [affecting.name]."))
return TRUE //successful heal
else
return FALSE
///Is the passed in mob an admin ghost
/proc/IsAdminGhost(mob/user)
if(!user) //Are they a mob? Auto interface updates call this with a null src
return
if(!user.client) // Do they have a client?
return
if(!isobserver(user)) // Are they a ghost?
return
if(!check_rights_for(user.client, R_ADMIN)) // Are they allowed?
return
if(!user.client.AI_Interact) // Do they have it enabled?
return
return TRUE
/**
* Offer control of the passed in mob to dead player
*
* Automatic logging and uses pollCandidatesForMob, how convenient
*/
/proc/offer_control(mob/M)
to_chat(M, "Control of your mob has been offered to dead players.")
if(usr)
log_admin("[key_name(usr)] has offered control of ([key_name(M)]) to ghosts.")
message_admins("[key_name_admin(usr)] has offered control of ([ADMIN_LOOKUPFLW(M)]) to ghosts")
var/poll_message = "Do you want to play as [M.real_name]?"
if(M?.mind?.assigned_role)
poll_message = "[poll_message] Job:[M.mind.assigned_role]."
if(M?.mind?.special_role)
poll_message = "[poll_message] Status:[M.mind.special_role]."
else if(M.mind)
var/datum/antagonist/A = M.mind.has_antag_datum(/datum/antagonist/)
if(A)
poll_message = "[poll_message] Status:[A.name]."
var/list/mob/dead/observer/candidates = pollCandidatesForMob(poll_message, ROLE_PAI, null, FALSE, 150, M)
if(LAZYLEN(candidates))
var/mob/dead/observer/C = pick(candidates)
to_chat(M, "Your mob has been taken over by a ghost!")
message_admins("[key_name_admin(C)] has taken control of ([ADMIN_LOOKUPFLW(M)])")
var/mob/dead/observer/G = M.ghostize(FALSE)
if(istype(G))
G.mind = null
M.key = C.key
return TRUE
else
to_chat(M, "There were no ghosts willing to take control.")
message_admins("No ghosts were willing to take control of [ADMIN_LOOKUPFLW(M)])")
return FALSE
///Is the mob a flying mob
/mob/proc/is_flying(mob/M = src)
if(M.movement_type & FLYING)
return 1
else
return 0
/mob/proc/is_overdosed(mob/M = src)
for(var/datum/reagent/R as anything in M.reagents.reagent_list)
if(R.overdosed)
return TRUE
return FALSE
///Clicks a random nearby mob with the source from this mob
/mob/proc/click_random_mob()
var/list/nearby_mobs = list()
for(var/mob/living/L in range(1, src))
if(L!=src)
nearby_mobs |= L
if(nearby_mobs.len)
var/mob/living/T = pick(nearby_mobs)
ClickOn(T)
/// Logs a message in a mob's individual log, and in the global logs as well if log_globally is true
/mob/log_message(message, message_type, color=null, log_globally = TRUE)
if(!LAZYLEN(message))
stack_trace("Empty message")
return
// Cannot use the list as a map if the key is a number, so we stringify it (thank you BYOND)
var/smessage_type = num2text(message_type)
if(client)
if(!islist(client.player_details.logging[smessage_type]))
client.player_details.logging[smessage_type] = list()
if(!islist(logging[smessage_type]))
logging[smessage_type] = list()
var/colored_message = message
if(color)
if(color[1] == "#")
colored_message = "<font color=[color]>[message]</font>"
else
colored_message = "<font color='[color]'>[message]</font>"
//This makes readability a bit better for admins.
switch(message_type)
if(LOG_WHISPER)
colored_message = "(WHISPER) [colored_message]"
if(LOG_OOC)
colored_message = "(OOC) [colored_message]"
if(LOG_ASAY)
colored_message = "(ASAY) [colored_message]"
if(LOG_EMOTE)
colored_message = "(EMOTE) [colored_message]"
var/list/timestamped_message = list("\[[worldtime2text()]\] [key_name(src)] [loc_name(src)] (Event #[LAZYLEN(logging[smessage_type])])" = colored_message)
logging[smessage_type] += timestamped_message
if(client)
client.player_details.logging[smessage_type] += timestamped_message
..()
///Can the mob hear
/mob/proc/can_hear()
. = TRUE
/mob/proc/has_mouth()
return FALSE
/**
* Examine text for traits shared by multiple types.
*
* I wish examine was less copypasted. (oranges say, be the change you want to see buddy)
*/
/mob/proc/common_trait_examine()
if(HAS_TRAIT(src, TRAIT_DISSECTED))
. += "[span_notice("This body has been dissected and analyzed. It is no longer worth experimenting on.")]<br>"
/**
* Get the list of keywords for policy config
*
* This gets the type, mind assigned roles and antag datums as a list, these are later used
* to send the user relevant headadmin policy config
*/
/mob/proc/get_policy_keywords()
. = list()
. += "[type]"
if(mind)
. += mind.assigned_role
. += mind.special_role //In case there's something special leftover, try to avoid
for(var/datum/antagonist/A in mind.antag_datums)
. += "[A.type]"
///Can the mob see reagents inside of containers?
/mob/proc/can_see_reagents()
return stat == DEAD || has_unlimited_silicon_privilege //Dead guys and silicons can always see reagents
/mob/living/proc/getBruteLoss_nonProsthetic()
return getBruteLoss()
/mob/living/proc/getFireLoss_nonProsthetic()
return getFireLoss()
/mob/living/carbon/getBruteLoss_nonProsthetic()
var/amount = 0
for(var/obj/item/bodypart/chosen_bodypart in bodyparts)
if(chosen_bodypart.status < BODYPART_ROBOTIC)
amount += chosen_bodypart.brute_dam
return amount
/mob/living/carbon/getFireLoss_nonProsthetic()
var/amount = 0
for(var/obj/item/bodypart/chosen_bodypart in bodyparts)
if(chosen_bodypart.status < BODYPART_ROBOTIC)
amount += chosen_bodypart.burn_dam
return amount
/mob/proc/default_lighting_cutoff()
if(client?.combo_hud_enabled && client?.prefs?.toggles & COMBOHUD_LIGHTING)
return LIGHTING_CUTOFF_FULLBRIGHT
return initial(lighting_cutoff)
/// Returns a client from a mob, mind or client
/proc/get_player_client(player)
if(ismob(player))
var/mob/player_mob = player
player = player_mob.client
else if(istype(player, /datum/mind))
var/datum/mind/player_mind = player
player = player_mind.current.client
if(!istype(player, /client))
return
return player