-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.sprak
778 lines (691 loc) · 20.4 KB
/
server.sprak
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
#################
### functions ###
#################
# returns the name of thing that provides function
string thing_with_function(string function)
string server_1 = "PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1"
string server_2 = "Heart"
string server_bank = "FinanceComputer"
string server_data_storage = "Hotel_Lobby_ComputerCashier"
string server_door_lock = "Hotel_Lobby_ComputerCashier"
string server_large_recorder = "PoliceOfficeInterior_LargeRecorder_LargeRecorder_1"
string server_meteorology = "MeteorologyServer"
string server_wellspring = "Wellspringer"
string thing_with_change_balance = server_bank
# Name() not used as connection gets blocked
string thing_with_char_to_int = server_1
string thing_with_copy_to_clipboard = "Hotel_ServerBasement_Extractor_1"
string thing_with_get_all_rooms = server_1
string thing_with_get_balance_for_person = server_bank
string thing_with_get_numeric_data = server_2
string thing_with_get_position = server_1
string thing_with_get_rain = server_meteorology
string thing_with_get_room = server_1
string thing_with_get_things_of_type = server_1
string thing_with_get_things_in_room = server_1
string thing_with_get_type_of_thing = server_1
string thing_with_interact_with = server_1
# Name() not used as connection gets blocked
string thing_with_int_to_char = server_1
string thing_with_load_memory = server_data_storage
string thing_with_lock = server_door_lock
string thing_with_move_person = server_large_recorder
string thing_with_register_seller = server_wellspring
# Name() not used as connection gets blocked
string thing_with_remove = server_1
string thing_with_save_memory = server_data_storage
string thing_with_set_numeric_data = server_2
string thing_with_set_position = server_1
string thing_with_set_weather = server_meteorology
string thing_with_sleep = server_large_recorder
string thing_with_string_contains = server_large_recorder
string thing_with_unlock = server_door_lock
string thing_with_zap_person = server_large_recorder
string thing_with_zap_person_gently = server_2
if function == "ChangeBalance"
return thing_with_change_balance
end
if function == "CharToInt"
return thing_with_char_to_int
end
if function == "CopyToClipboard"
return thing_with_copy_to_clipboard
end
if function == "GetAllRooms"
return thing_with_get_all_rooms
end
if function == "GetBalanceForPerson"
return thing_with_get_balance_for_person
end
if function == "GetNumericData"
return thing_with_get_numeric_data
end
if function == "GetPosition"
return thing_with_get_position
end
if function == "GetRain"
return thing_with_get_rain
end
if function == "GetRoom"
return thing_with_get_room
end
if function == "GetThingsInRoom"
return thing_with_get_things_in_room
end
if function == "GetThingsOfType"
return thing_with_get_things_of_type
end
if function == "GetTypeOfThing"
return thing_with_get_type_of_thing
end
if function == "InteractWith"
return thing_with_interact_with
end
if function == "IntToChar"
return thing_with_int_to_char
end
if function == "LoadMemory"
return thing_with_load_memory
end
if function == "Lock"
return thing_with_lock
end
if function == "MovePerson"
return thing_with_move_person
end
if function == "RegisterSeller"
return thing_with_register_seller
end
if function == "Remove"
return thing_with_remove
end
if function == "SaveMemory"
return thing_with_save_memory
end
if function == "SetNumericData"
return thing_with_set_numeric_data
end
if function == "SetPosition"
return thing_with_set_position
end
if function == "SetRain"
return thing_with_set_weather
end
if function == "Sleep"
return thing_with_sleep
end
if function == "StringContains"
return thing_with_string_contains
end
if function == "Unlock"
return thing_with_unlock
end
if function == "ZapPerson"
return thing_with_zap_person
end
if function == "ZapPersonGently"
return thing_with_zap_person_gently
end
end
# returns the proper prefix that supplies function
string supply(string function)
return Connect(thing_with_function(function))
end
# returns true if "thing" has function
bool has_function(string thing, string function)
return Connect(thing).HasFunction(function)
end
# delays script execution by delay_duration
void delay_by(number delay_duration)
supply("Sleep").Sleep(delay_duration)
end
# copies content of value to clipboard
void copy(value)
supply("CopyToClipboard").CopyToClipboard(value)
end
### mathematics ###
# returns the answer of base raised to the power of exponent
number power(number base, number exponent)
number answer = 1
loop from 0 to exponent - 1
answer *= base
end
return answer
end
### data manipulation ###
# returns true if a character is uppercase
bool is_uppercase(var character)
string connect = supply("CharToInt")
return connect.CharToInt(character) >= -32 && connect.CharToInt(character) <= -7
end
# coverts uppercase characters to lowercase characters
string uppercase_to_lowercase(var text)
string lowered = ""
loop character in text
if is_uppercase(character)
lowered += supply("IntToChar").IntToChar(supply("CharToInt").CharToInt(character) + 32)
else
lowered += character
end
end
return lowered
end
# converts the first character of a string to a number
number character_to_number(string character)
return supply("CharToInt").CharToInt(character)
end
# slices a string
string slice(string input_string, number index, string last_character)
string output_slice = ""
loop
if input_string[index] == last_character
break
else
output_slice += input_string[index]
end
index++
end
return output_slice
end
# converts a string to a number
number string_to_number(string input_string)
number output_number = 0
number current_number = 0
bool is_negative = false
number string_length = Count(input_string) - 1
loop character in input_string
if character == "-"
is_negative = true
else
current_number = character_to_number(character) + 49
if string_length != 0
current_number *= power(10, string_length)
end
output_number += current_number
end
string_length--
end
if is_negative
output_number *= -1
end
return output_number
end
# converts an array to a string
string array_to_string(array list)
string stringified = ""
loop element in list
stringified += element
end
return stringified
end
# accepts an array and returns an array with the same elements in addition to an element inserted at a chosen index
array array_element_insert(array_old, index_insertion, value)
number array_old_amount = Count(array_old) - 1
array array_new = []
number index_a = 0
loop array_old
if index_a < index_insertion
Append(array_new, @)
end
index_a ++
end
Append(array_new, value)
if index_insertion < array_old_amount
loop x from index_insertion to array_old_amount
Append(array_new, array_old[x])
end
end
return array_new
end
# removes the element in the chosen index of an array
void array_element_delete(array_old, index_deletion)
supply("Remove").Remove(array_old, index_deletion)
end
# returns true if a string is present in a string
bool string_has(string whole, string section)
return supply("StringContains").StringContains(whole, section)
end
# saves a piece of data to server_data_storage variable set in thing_with_function() using key
void save(var key, var data)
return supply("SaveMemory").SaveMemory(key, data)
end
# loads a piece of data to server_data_storage variable set in thing_with_function() using key
void load(var key)
return supply("LoadMemory").LoadMemory(key)
end
### things ###
# returns the category of a string
string category_of(string thing)
return supply("GetTypeOfThing").GetTypeOfThing(thing)
end
# returns true if a string is a person
bool string_is_a_person(string person)
return category_of(person) == "character"
end
# returns an array of things of certain category
array array_of_things_in_category(string category)
return supply("GetThingsOfType").GetThingsOfType(category)
end
# returns a string of things of certain category, delimited by delimiter
string string_of_things_in_category(string category, string delimiter)
string list_of_things = ""
loop array_of_things_in_category(category)
list_of_things += @ + delimiter
end
return list_of_things
end
# returns a string of a position of a thing in standard format
string standard_position_of(string thing)
return supply("GetPosition").GetPosition(thing)
end
# returns an array of a position of a thing
array array_of_position_of(string input_string)
string position = standard_position_of(input_string)
string room = room_of(input_string)
number room_name_length = Count(room)
string x = slice(position, 21 + room_name_length, ",")
string y = slice(position, 22 + room_name_length + Count(x), ")")
return [room, string_to_number(x), string_to_number(y)]
end
# returns a string of a position of thing, delimited by delimiter
string string_of_position_of(string input_string, string delimiter)
string position = standard_position_of(input_string)
string room = room_of(input_string)
number room_name_length = Count(room)
string x = slice(position, 21 + room_name_length, ",")
string y = slice(position, 22 + room_name_length + Count(x), ")")
return room + delimiter + string_to_number(x) + delimiter + string_to_number(y)
end
# returns the x coordinate of a thing
number x_of(string input_string)
return string_to_number(slice(standard_position_of(input_string), 21 + Count(room_of(input_string)), ","))
end
# returns the y coordinate of a thing
number y_of(string input_string)
string position = standard_position_of(input_string)
number room_name_length = Count(room_of(input_string))
return string_to_number(slice(position, 22 + room_name_length + Count(slice(position, 21 + room_name_length, ",")), ")"))
end
# returns an array of everything in the world
array array_of_everything()
array list = []
loop room in array_of_all_rooms()
loop array_of_things_in(room)
Append(list, @)
end
end
return list
end
# returns a string of everything in the world, delimited by delimiter
string string_of_everything(string delimiter)
string list = ""
loop room in array_of_all_rooms()
loop array_of_things_in(room)
list += @ + delimiter
end
end
return list
end
# returns a string of everything in the world and their positions, delimited by delimiter
string string_of_everything_and_their_positions(string delimiter)
string list = ""
loop room in array_of_all_rooms()
loop array_of_things_in(room)
list += @ + delimiter + room_of(@) + delimiter + x_of(@) + delimiter + y_of(@) + ". "
end
end
return list
end
# returns an array of things with names containing the search string
array array_search_for_thing(string search_string)
array list = []
loop array_of_all_rooms()
loop thing in array_of_things_in(@)
if string_has(uppercase_to_lowercase(thing), uppercase_to_lowercase(search_string))
Append(list, thing)
end
end
end
return list
end
# returns a string of things with names containing the search string, delimited by delimiter
string string_search_for_thing(string search_string, string delimiter)
string list = ""
loop array_of_all_rooms()
loop thing in array_of_things_in(@)
if string_has(uppercase_to_lowercase(thing), uppercase_to_lowercase(search_string))
list += thing + delimiter
end
end
end
return list
end
# returns a string of things with names containing the search string and their positions, delimited by delimiter
string string_search_for_thing_with_position(string search_string, string delimiter_position, string delimiter_thing)
string list = ""
loop array_of_all_rooms()
loop thing in array_of_things_in(@)
if string_has(uppercase_to_lowercase(thing), uppercase_to_lowercase(search_string))
list += thing + delimiter_position + string_of_position_of(thing, delimiter_position) + delimiter_thing
end
end
end
return list
end
# locks doors
void lock(string door)
supply("Lock").Lock(door)
end
# unlocks doors
void unlock(string door)
supply("Unlock").Unlock(door)
end
# locks all doors in room
void lock_doors_in_room(string room)
loop array_of_things_in(room)
if (category_of(@) == "door")
lock(@)
end
end
end
# unlocks all doors in room
void unlock_doors_in_room(string room)
loop array_of_things_in(room)
if (category_of(@) == "door")
unlock(@)
end
end
end
# locks all doors in room containing a person
void lock_doors_in_room_of(string person)
lock_doors_in_room(room_of(person))
end
# unlocks all doors in room containing a person
void unlock_doors_in_room_of(string person)
unlock_doors_in_room(room_of(person))
end
# locks all doors in room containing the user
void lock_doors_near()
lock_doors_in_room_of(GetUser())
end
# unlocks all doors in room containing the user
void unlock_doors_near()
unlock_doors_in_room_of(GetUser())
end
# locks all doors
void lock_all_doors()
loop array_of_things_in_category("door")
lock(@)
end
end
# unlocks all doors
void unlock_all_doors()
loop array_of_things_in_category("door")
unlock(@)
end
end
# returns a data value of a thing
void the_data_of(string thing, string stat)
return supply("GetNumericData").GetNumericData(thing, stat)
end
# returns a person's sleepiness
number the_sleepiness_of(string person)
return the_data_of(person, "sleepiness")
end
# returns a person's walk_speed
number the_walk_speed_of(string person)
return the_data_of(person, "walkSpeed")
end
# returns a person's corruption
number the_corruption_of(string person)
return the_data_of(person, "corruption")
end
# returns a person's drunkenness
number the_drunkenness_of(string person)
return the_data_of(person, "drunkenness")
end
# returns a person's smelliness
number the_smelliness_of(string person)
return the_data_of(person, "smelliness")
end
# returns a person's charisma
number the_charisma_of(string person)
return the_data_of(person, "charisma")
end
# returns a person's happiness
number the_happiness_of(string person)
return the_data_of(person, "happiness")
end
# returns a person's supremacy
number the_supremacy_of(string person)
return the_data_of(person, "supremacy")
end
# set a person's stat
void set_the_data_of(string thing, string stat, var value)
supply("SetNumericData").SetNumericData(thing, stat, value)
end
# set a person's sleepiness
void set_the_sleepiness_of(string person, number value)
set_the_data_of(person, "sleepiness", value)
end
# set a person's sleepiness
void set_the_walk_speed_of(string person, number value)
set_the_data_of(person, "walkSpeed", value)
end
# set a person's corruption
void set_the_corruption_of(string person, number value)
set_the_data_of(person, "sleepiness", value)
end
# set a person's drunkenness
void set_the_drunkenness_of(string person, number value)
set_the_data_of(person, "drunkenness", value)
end
# set a person's smelliness
void set_the_smelliness_of(string person, number value)
set_the_data_of(person, "smelliness", value)
end
# set a person's charisma
void set_the_charisma_of(string person, number value)
set_the_data_of(person, "charisma", value)
end
# set a person's happiness
void set_the_happiness_of(string person, number value)
set_the_data_of(person, "happiness", value)
end
# set a person's supremacy
void set_the_supremacy_of(string person, number value)
set_the_data_of(person, "supremacy", value)
end
# zaps a person (makes person sleep)
void zap(string person)
move_item_to_thing(thing_with_function("ZapPerson"), person)
supply("ZapPerson").ZapPerson(person)
end
# gently zaps a person (stuns person)
void gently_zap(string person)
supply("ZapPersonGently").ZapPersonGently(person)
end
# zaps people in an array
void zap_all_in_array(array zap_targets, number zap_duration, number delay_duration)
if Count(zap_targets) != 0
loop from 0 to zap_duration
loop zap_targets
zap(@)
end
delay_by(delay_duration)
end
end
end
# gently zaps people in an array
void gently_zap_all_in_array(array gently_zap_targets, number zap_duration, number delay_duration)
if Count(gently_zap_targets) != 0
loop from 0 to zap_duration
loop gently_zap_targets
gently_zap(@)
end
delay_by(delay_duration)
end
end
end
# zaps other people in the room the user is in
void zap_others_near(number zap_duration, number delay_duration)
array list = array_of_people_near(GetUser())
if Count(list) != 0
loop from 0 to zap_duration
loop list
zap(@)
end
delay_by(delay_duration)
end
end
end
# gently zaps other people in the room the user is in
void gently_zap_others_near(number zap_duration, number delay_duration)
array list = array_of_people_near(GetUser())
if Count(list) != 0
loop from 0 to zap_duration
loop list
gently_zap(@)
end
delay_by(delay_duration)
end
end
end
# cause a person to interact with a thing
void interact_with(string person, string thing)
supply("InteractWith").InteractWith(person, thing)
end
### cash ###
# return a person's balance
number the_balance_of(string person)
return supply("GetBalanceForPerson").GetBalanceForPerson(person)
end
# changes person's balance by a value
void change_the_balance_of(string person, number cash)
supply("ChangeBalance").ChangeBalance(person, cash)
end
# returns the difference between a number and a person's balance
number the_balance_difference_between(string person, number value)
return value - the_balance_of(person)
end
# sets how much cash a person has
void set_cash(string person, number cash)
change_the_balance_of(person, the_balance_difference_between(person, cash))
end
# registers cash to Wellspringer server under a person's name
void register(string person, number cash)
supply("RegisterSeller").RegisterSeller(person, cash)
end
### environment ###
# returns the weather value
number the_weather_value()
supply("GetRain").GetRain()
end
# sets the weather value
void set_the_weather_value(number value)
if the_weather_value() != value
supply("SetRain").SetRain(value)
end
end
# sets actual weather
void set_weather(number choice)
if choice == 1
if the_weather_value() >= 25
set_the_weather_value(0)
end
end
if choice == 2
if the_weather_value() >= 100 || the_weather_value() <=24
set_the_weather_value(25)
end
end
if choice == 3
if the_weather_value() >= 200 || the_weather_value() <= 99
set_the_weather_value(100)
end
end
if choice == 4
if the_weather_value() <= 199
set_the_weather_value(200)
end
end
end
### rooms ###
# return string containing current room of person
string room_of(string person)
return supply("GetRoom").GetRoom(person)
end
# returns an array of all rooms
array array_of_all_rooms()
return supply("GetAllRooms").GetAllRooms()
end
# returns true if a string is a room
bool is_room(string room)
if room_of(room) == ""
return true
end
end
# returns an array of rooms with names containing the search string
array array_search_for_room(string search_string)
array list = []
loop room in array_of_all_rooms()
if string_has(uppercase_to_lowercase(room), uppercase_to_lowercase(search_string))
Append(list, room)
end
end
return list
end
# returns a string of rooms with names containing the search string, delimited by delimiter
string string_search_for_room(string search_string, string delimiter)
string list = ""
loop room in array_of_all_rooms()
if string_has(uppercase_to_lowercase(room), uppercase_to_lowercase(search_string))
list += room + delimiter
end
end
return list
end
# returns an array of all items in a room
array array_of_things_in(string room)
return supply("GetThingsInRoom").GetThingsInRoom(room)
end
# returns an array of all people in a room
array array_of_people_in(string room)
array list = []
loop array_of_things_in(room)
if string_is_a_person(@)
Append(list, @)
end
end
return list
end
# returns an array of all the people in a room that a person is in, except for that person
array array_of_people_near(string person)
array list = []
loop array_of_people_in(room_of(person))
if string_is_a_person(@) && @ != person
Append(list, @)
end
end
return list
end
### teleport ###
# move item to thing
void move_item_to_thing(string item, string thing)
supply("SetPosition").SetPosition(item, thing)
end
# move person to thing
void move_person_to_thing(string person, string thing)
move_item_to_thing(thing_with_function("MovePerson"), person)
supply("MovePerson").MovePerson(person, thing)
end
# move item to room
void move_item_to_room(string item, string room, number index)
array things_in_room = array_of_things_in(room)
move_item_to_thing(item, things_in_room[index])
end
# move person to room
void move_person_to_room(string person, string room, number index)
array things_in_room = array_of_things_in(room)
move_person_to_thing(person, things_in_room[index])
end