-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_area_reader.py
More file actions
1335 lines (1118 loc) · 40 KB
/
Copy pathtest_area_reader.py
File metadata and controls
1335 lines (1118 loc) · 40 KB
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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import tempfile
from pathlib import Path
import pytest
from hypothesis import given, settings
from hypothesis import strategies as st
import area_reader.dialects.circle
import area_reader.dialects.coffeemud
import area_reader.dialects.merc
import area_reader.dialects.rom
import area_reader.dialects.smaug
import area_reader.dialects.swr
import area_reader.model
import area_reader.parser
from area_reader import constants
def write_area(directory, text):
path = Path(directory) / "area.are"
path.write_text(text, encoding="ascii")
return path
def assert_jsonifies(area_file):
as_dict = area_file.as_dict()
assert json.loads(area_file.as_json()) == json.loads(json.dumps(as_dict))
def test_dice_roll_includes_the_maximum_face(monkeypatch):
monkeypatch.setattr(
area_reader.model.random,
"randrange",
lambda start, stop: stop - 1,
)
assert area_reader.model.Dice(number=2, sides=6, bonus=3).roll() == 15
assert area_reader.model.Dice(number=2, sides=1, bonus=3).roll() == 5
def test_dice_roll_zero_sides_contributes_zero():
assert area_reader.model.Dice(number=2, sides=0, bonus=0).roll() == 0
assert area_reader.model.Dice(number=5, sides=0, bonus=7).roll() == 7
assert area_reader.model.Dice().roll() == 0
def test_dice_roll_negative_sides_rolls_one_per_die():
assert area_reader.model.Dice(number=3, sides=-4, bonus=2).roll() == 5
def test_forms_instant_decay_is_bit_d():
from area_reader.constants import FORMS
assert FORMS.INSTANT_DECAY.value == 8
assert FORMS(8) is FORMS.INSTANT_DECAY
assert FORMS(12) == FORMS.MAGICAL | FORMS.INSTANT_DECAY
assert FORMS.OTHER.value == 16
def test_wear_location_wrist_l_named_with_alias():
from area_reader.constants import WEAR_LOCATIONS
assert WEAR_LOCATIONS(14) is WEAR_LOCATIONS.WRIST_L
assert WEAR_LOCATIONS.RIST_L is WEAR_LOCATIONS.WRIST_L
reset_command = st.sampled_from(["M", "O", "P", "G", "E", "D", "R"])
small_int = st.integers(min_value=0, max_value=9999)
rom_source_dir = Path(r"C:\Users\Q\src\Rom24b6\area")
merc_source_dir = Path(r"C:\Users\Q\src\merc-mud\area")
smaug_source_dir = Path(r"C:\Users\Q\src\_smaug_\db\area")
swr_source_dir = Path(r"C:\Users\Q\src\swrfuss")
circle_source_dir = Path(r"C:\Users\Q\src\circlemud")
coffeemud_source_dir = Path(r"C:\Users\Q\src\coffeemud")
def write_coffeemud_file(directory, text):
path = Path(directory) / "area.cmare"
path.write_text(text, encoding="utf-8")
return path
def write_circle_world(directory, *, zon=None, wld=None, mob=None, obj=None, shp=None):
root = Path(directory)
world = root / "lib" / "world"
for family, text in {
"zon": zon,
"wld": wld,
"mob": mob,
"obj": obj,
"shp": shp,
}.items():
family_dir = world / family
family_dir.mkdir(parents=True, exist_ok=True)
index = family_dir / "index"
if text is None:
index.write_text("$\n", encoding="ascii")
continue
filename = f"1.{family}"
(family_dir / filename).write_text(text, encoding="ascii")
index.write_text(f"{filename}\n$\n", encoding="ascii")
return root
def swr_are_paths():
if not swr_source_dir.exists():
return []
return sorted(swr_source_dir.rglob("*.are"))
def circle_indexed_paths(family):
index = circle_source_dir / "lib" / "world" / family / "index"
if not index.exists():
return []
base = index.parent
paths = []
for line in index.read_text(encoding="ascii").splitlines():
name = line.strip()
if not name or name == "$":
continue
paths.append(base / name)
return paths
def test_loading_rom_area(rom_path):
af = area_reader.dialects.rom.RomAreaFile(rom_path)
af.load_sections()
assert af.area
assert af.as_dict()
assert_jsonifies(af)
def test_loading_merc_area(merc_path):
af = area_reader.dialects.merc.MercAreaFile(merc_path)
af.load_sections()
assert af.area
assert_jsonifies(af)
def test_help_with_empty_keyword_loads():
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
"""#HELPS
0 ~
Empty keyword help text.~
0 $~
#$
""",
)
af = area_reader.dialects.rom.RomAreaFile(path)
af.load_sections()
assert len(af.area.helps) == 1
assert af.area.helps[0].keyword == ""
assert af.area.helps[0].text == "Empty keyword help text."
def test_coffeemud_top_level_mobs_parse_as_dict_and_json():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<MOBS><MOB><MCLAS>GenMob</MCLAS><MLEVL>8</MLEVL><MABLE>11</MABLE><MREJV>90</MREJV><MTEXT><NAME>the death dog</NAME></MTEXT></MOB></MOBS>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
assert af.area.top_level == "MOBS"
assert len(af.area.mobs) == 1
assert af.area.mobs[0].class_id == "GenMob"
assert af.as_dict()["mobs"][0]["class_id"] == "GenMob"
assert "GenMob" in af.as_json()
assert_jsonifies(af)
def test_coffeemud_top_level_items_parse():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<ITEMS><ITEM><ICLAS>GenItem</ICLAS><IUSES>2147483647</IUSES><ILEVL>68</ILEVL><IABLE>0</IABLE><IREJV>0</IREJV><ITEXT><NAME>an iron sifter</NAME></ITEXT></ITEM></ITEMS>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
assert af.area.top_level == "ITEMS"
assert len(af.area.items) == 1
assert af.area.items[0].class_id == "GenItem"
def test_coffeemud_top_level_area_parses_metadata():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<AREA><ACLAS>StdArea</ACLAS><ANAME>Test Area</ANAME><ADESC>A test area.</ADESC><ACLIM>1</ACLIM><ASUBS /><ATECH>2</ATECH><ADATA /><AROOMS /></AREA>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
assert af.area.top_level == "AREA"
assert af.area.class_id == "StdArea"
assert af.area.name == "Test Area"
assert af.area.description == "A test area."
def test_coffeemud_direct_room_parses_as_room_record():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<AROOM><ROOMID>Test Area#1</ROOMID><RAREA>Test Area</RAREA><RCLAS>StoneRoom</RCLAS><RDISP>A quiet room</RDISP><RDESC>A plain room.</RDESC><RTEXT /><ROOMEXITS /><ROOMCONTENT><ROOMMOBS /><ROOMITEMS /></ROOMCONTENT></AROOM>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
assert af.area.top_level == "AROOM"
assert "Test Area#1" in af.area.rooms
assert af.area.rooms["Test Area#1"].class_id == "StoneRoom"
def test_coffeemud_mob_reads_nested_common_fields_and_collections():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<MOBS><MOB><MCLAS>GenMob</MCLAS><MLEVL>8</MLEVL><MABLE>11</MABLE><MREJV>90</MREJV><MTEXT><NAME>the death dog</NAME><DESC>A large two-headed hound barks at you viciously.</DESC><DISP>The death dog stands here.</DISP><PROP>11|76|8|8|0|8|90|1.0|19|23|0|</PROP><BEHAVES><BHAVE><BCLASS>CombatAbilities</BCLASS><BPARMS /></BHAVE><BHAVE><BCLASS>MobileAggressive</BCLASS><BPARMS>WANDER</BPARMS></BHAVE></BEHAVES><AFFECS><AFF><ACLASS>Skill_Dodge</ACLASS><ATEXT /></AFF></AFFECS><FLAG>0</FLAG><MONEY>14</MONEY><VARMONEY>0.0</VARMONEY><GENDER>N</GENDER><MRACE>Dog</MRACE><FACTIONS><FCTN ID="ALIGNMENT.INI">1</FCTN><FCTN ID="INCLINATION.INI">0</FCTN></FACTIONS><ABLTYS><ABLTY><ACLASS>Skill_Disarm</ACLASS><APROF>100</APROF><ADATA><AWRAP /></ADATA></ABLTY></ABLTYS></MTEXT></MOB></MOBS>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
mob = af.area.mobs[0]
assert mob.class_id == "GenMob"
assert mob.level == 8
assert mob.ability == 11
assert mob.rejuv == 90
assert mob.name == "the death dog"
assert mob.description == "A large two-headed hound barks at you viciously."
assert mob.display == "The death dog stands here."
assert mob.race == "Dog"
assert mob.gender == "N"
assert mob.money == 14
assert [behavior.class_id for behavior in mob.behaviors] == ["CombatAbilities", "MobileAggressive"]
assert mob.behaviors[1].parameters == "WANDER"
assert mob.affects[0].class_id == "Skill_Dodge"
assert mob.factions["ALIGNMENT.INI"] == 1
assert mob.factions["INCLINATION.INI"] == 0
assert mob.abilities[0].class_id == "Skill_Disarm"
assert mob.abilities[0].proficiency == 100
assert mob.raw_data["PROP"] == "11|76|8|8|0|8|90|1.0|19|23|0|"
def test_coffeemud_item_reads_nested_common_fields_container_fields_and_affects():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<ITEMS><ITEM><ICLAS>GenContainer</ICLAS><IUSES>2147483647</IUSES><ILEVL>42</ILEVL><IABLE>0</IABLE><IREJV>0</IREJV><ITEXT><NAME>an iron potion rack</NAME><DESC>an iron potion rack. </DESC><DISP>an iron potion rack lies here</DISP><PROP>0|0|0|0|0|42|0|1.0|21|0|0|</PROP><IMG /><BEHAVES /><AFFECS><AFF><ACLASS>Prop_NoPurge</ACLASS><ATEXT /></AFF></AFFECS><FLAG>27</FLAG><IDENT /><VALUE>105</VALUE><MTRAL>801</MTRAL><READ /><WORNL>false</WORNL><WORNB>512</WORNB><CAPA>120</CAPA><CONT>2048</CONT><OPENTK>30</OPENTK></ITEXT></ITEM></ITEMS>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
item = af.area.items[0]
assert item.class_id == "GenContainer"
assert item.uses == 2147483647
assert item.level == 42
assert item.name == "an iron potion rack"
assert item.description == "an iron potion rack. "
assert item.display == "an iron potion rack lies here"
assert item.prop == "0|0|0|0|0|42|0|1.0|21|0|0|"
assert item.flag == 27
assert item.value == 105
assert item.material == 801
assert item.read_text == ""
assert item.worn_location == "false"
assert item.worn_bitmap == 512
assert item.capacity == 120
assert item.container_flags == 2048
assert item.open_ticks == 30
assert item.affects[0].class_id == "Prop_NoPurge"
def test_coffeemud_area_reads_rooms_exits_and_room_content():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<AREA><ACLAS>StdArea</ACLAS><ANAME>Test Area</ANAME><ADESC>A test area.</ADESC><ACLIM>1</ACLIM><ASUBS>builder</ASUBS><ATECH>2</ATECH><ADATA><AUTHOR>Builder</AUTHOR></ADATA><AROOMS><AROOM><ROOMID>Test Area#1</ROOMID><RAREA>Test Area</RAREA><RCLAS>StoneRoom</RCLAS><RDISP>A quiet room</RDISP><RDESC>A plain room.</RDESC><RTEXT><RCLIM>3</RCLIM><RATMO>4</RATMO></RTEXT><ROOMEXITS><REXIT><XDIRE>0</XDIRE><XDOOR>Test Area#2</XDOOR><XEXIT><EXID>StdOpenDoorway</EXID><EXDAT><NAME>a doorway</NAME></EXDAT></XEXIT></REXIT></ROOMEXITS><ROOMCONTENT><ROOMMOBS><RMOB><MCLAS>GenMob</MCLAS><MLEVL>5</MLEVL><MABLE>1</MABLE><MREJV>10</MREJV><MTEXT><NAME>a room mob</NAME><MONEY>7</MONEY></MTEXT></RMOB></ROOMMOBS><ROOMITEMS><RITEM COUNT=2><ICLAS>GenItem</ICLAS><IIDEN>item1</IIDEN><ILOCA>container1</ILOCA><IUSES>1</IUSES><ILEVL>2</ILEVL><IABLE>3</IABLE><IREJV>4</IREJV><ITEXT><NAME>a room item</NAME><VALUE>9</VALUE></ITEXT></RITEM></ROOMITEMS></ROOMCONTENT></AROOM></AROOMS></AREA>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
assert af.area.class_id == "StdArea"
assert af.area.name == "Test Area"
assert af.area.raw_data["AUTHOR"] == "Builder"
room = af.area.rooms["Test Area#1"]
assert room.class_id == "StoneRoom"
assert room.display == "A quiet room"
assert room.climate == 3
assert room.atmosphere == 4
assert room.exits[0].direction == 0
assert room.exits[0].target_room_id == "Test Area#2"
assert room.exits[0].class_id == "StdOpenDoorway"
assert room.exits[0].raw_data["NAME"] == "a doorway"
assert room.mobs[0].name == "a room mob"
assert room.mobs[0].money == 7
assert room.items[0].class_id == "GenItem"
assert room.items[0].count == 2
assert room.items[0].ident == "item1"
assert room.items[0].location == "container1"
assert room.items[0].name == "a room item"
assert room.items[0].value == 9
def test_coffeemud_item_parses_nested_ssarea():
with tempfile.TemporaryDirectory() as directory:
path = write_coffeemud_file(
directory,
"""<ITEMS><ITEM><ICLAS>GenBoardable</ICLAS><IUSES>100</IUSES><ILEVL>1</ILEVL><IABLE>0</IABLE><IREJV>0</IREJV><ITEXT><NAME>a skiff</NAME><DESC>a small skiff</DESC><DISP>a skiff is here</DISP><SSAREA><AREA><ACLAS>StdBoardableShip</ACLAS><ANAME>Skiff</ANAME><ADESC /><ACLIM>0</ACLIM><ASUBS /><ATECH>0</ATECH><ADATA /><AROOMS><AROOM><ROOMID>Skiff#0</ROOMID><RAREA>Skiff</RAREA><RCLAS>ShipDeck</RCLAS><RDISP>The Deck</RDISP><RDESC /><RTEXT /><ROOMEXITS /><ROOMCONTENT><ROOMMOBS /><ROOMITEMS /></ROOMCONTENT></AROOM></AROOMS></AREA></SSAREA></ITEXT></ITEM></ITEMS>""",
)
af = area_reader.dialects.coffeemud.CoffeeMudAreaFile(path)
af.load_sections()
item = af.area.items[0]
assert "SSAREA" in item.raw_data
assert item.nested_area.name == "Skiff"
assert item.nested_area.class_id == "StdBoardableShip"
assert "Skiff#0" in item.nested_area.rooms
@given(arg1=small_int, arg2=small_int, arg3=small_int, arg4=small_int)
@settings(max_examples=30, deadline=None)
def test_rom_reset_reads_arg4_for_mobile_resets(arg1, arg2, arg3, arg4):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
file.are~
Test~
{{ All }} Test~
1 99
#RESETS
M 0 {arg1} {arg2} {arg3} {arg4}
S
#$
""",
)
af = area_reader.dialects.rom.RomAreaFile(path)
af.load_sections()
reset = af.area.resets[0]
assert reset.command == "M"
assert reset.arg1 == arg1
assert reset.arg2 == arg2
assert reset.arg3 == arg3
assert reset.arg4 == arg4
@given(command=reset_command, arg1=small_int, arg2=small_int, arg3=small_int)
@settings(max_examples=30, deadline=None)
def test_merc_resets_follow_three_argument_loader(command, arg1, arg2, arg3):
line_arg3 = "" if command in ("G", "R") else f" {arg3}"
expected_arg3 = 0 if command in ("G", "R") else arg3
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
Test~
#RESETS
{command} 0 {arg1} {arg2}{line_arg3}
S
#$
""",
)
af = area_reader.dialects.merc.MercAreaFile(path)
af.load_sections()
reset = af.area.resets[0]
assert reset.command == command
assert reset.arg1 == arg1
assert reset.arg2 == arg2
assert reset.arg3 == expected_arg3
assert reset.arg4 is None
assert reset.arg5 is None
@given(wealth=st.integers(min_value=0, max_value=2_000_000))
@settings(max_examples=30, deadline=None)
def test_rom_mobile_wealth_is_read_raw(wealth):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
file.are~
Test~
{{ All }} Test~
1 99
#MOBILES
#1
mob~
a mob~
A mob stands here.
~
A plain mobile.
~
human~
0 0 0 0
1 2 1d1+1 1d1+1 1d1+1 bite
0 0 0 0
0 0 0 0
standing standing neutral {wealth}
0 0 medium none
#0
#$
""",
)
af = area_reader.dialects.rom.RomAreaFile(path)
af.load_sections()
assert af.area.mobs[1].wealth == wealth
@given(room_flags=st.integers(min_value=0, max_value=255), sector_type=st.integers(min_value=0, max_value=9))
@settings(max_examples=30, deadline=None)
def test_merc_rooms_use_merc_room_flag_type(room_flags, sector_type):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
Test~
#ROOMS
#1
Room~
Description.
~
0 {room_flags} {sector_type}
S
#0
#$
""",
)
af = area_reader.dialects.merc.MercAreaFile(path)
af.load_sections()
room = af.area.rooms[1]
assert isinstance(room, area_reader.dialects.merc.MercRoom)
assert isinstance(room.room_flags, constants.MERC_ROOM_FLAGS)
@given(
version=st.integers(min_value=0, max_value=9),
low_soft=st.integers(min_value=0, max_value=60),
high_soft=st.integers(min_value=0, max_value=60),
low_hard=st.integers(min_value=0, max_value=60),
high_hard=st.integers(min_value=0, max_value=60),
)
@settings(max_examples=20, deadline=None)
def test_smaug_reads_real_top_level_metadata(version, low_soft, high_soft, low_hard, high_hard):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
SMAUG Test~
#VERSION {version}
#AUTHOR Builder~
#RANGES
{low_soft} {high_soft} {low_hard} {high_hard}
$
#FLAGS 7
#ECONOMY 123 456
#MOBILES
#0
#ROOMS
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
assert af.area.name == "SMAUG Test"
assert af.area.version == version
assert af.area.author == "Builder"
assert af.area.low_soft_range == low_soft
assert af.area.high_soft_range == high_soft
assert af.area.low_hard_range == low_hard
assert af.area.high_hard_range == high_hard
assert af.area.flags == 7
assert af.area.high_economy == 123
assert af.area.low_economy == 456
@given(
act=st.integers(min_value=0, max_value=2_000_000),
affected=st.integers(min_value=0, max_value=2_000_000),
alignment=st.integers(min_value=-1000, max_value=1000),
level=st.integers(min_value=1, max_value=100),
gold=st.integers(min_value=0, max_value=1_000_000),
exp=st.integers(min_value=0, max_value=1_000_000),
)
@settings(max_examples=20, deadline=None)
def test_smaug_basic_mobile_uses_smaug_mobile_layout(act, affected, alignment, level, gold, exp):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
SMAUG Test~
#MOBILES
#1
mob~
a mob~
A mob stands here.
~
A plain mobile.
~
{act} {affected} {alignment} S
{level} 2 3 1d4+5 2d6+7
{gold} {exp}
8 5 1
#0
#ROOMS
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
mob = af.area.mobs[1]
assert mob.act == act | constants.ROM_ACT_TYPES.IS_NPC
assert mob.affected_by == affected
assert mob.alignment == alignment
assert mob.level == level
assert mob.hitroll == 2
assert mob.ac == 3
assert mob.hit.number == 1
assert mob.hit.sides == 4
assert mob.hit.bonus == 5
assert mob.damage.number == 2
assert mob.damage.sides == 6
assert mob.damage.bonus == 7
assert mob.wealth == gold
def test_smaug_extended_bitvectors_preserve_word_boundaries():
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
"""#AREA
SMAUG Test~
#MOBILES
#1
mob~
a mob~
A mob stands here.
~
A plain mobile.
~
1073741827&2048 0&4 0 S
1 0 0 1d1+0 1d1+0
0 0
8 8 0
#0
#ROOMS
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
mob = af.area.mobs[1]
assert int(mob.act) == (1073741827 | (2048 << 32))
assert int(mob.affected_by) == 4 << 32
def test_smaug_mobile_flags_use_smaug_engine_bit_positions():
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
"""#AREA
SMAUG Test~
#MOBILES
#1
mob~
a mob~
A mob stands here.
~
A plain mobile.
~
2048 4194344 0 S
1 0 0 1d1+0 1d1+0
0 0
8 8 0
#0
#ROOMS
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
mob = af.area.mobs[1]
assert mob.act == (constants.SMAUG_ACT_TYPES.IS_NPC | constants.SMAUG_ACT_TYPES.IMMORTAL)
assert mob.affected_by == (
constants.SMAUG_AFFECTED_BY.DETECT_INVIS
| constants.SMAUG_AFFECTED_BY.DETECT_HIDDEN
| constants.SMAUG_AFFECTED_BY.TRUESIGHT
)
result = af.as_dict()["mobs"][1]
assert result["act"] == "SMAUG_ACT_TYPES.IS_NPC|IMMORTAL"
assert result["affected_by"] == ("SMAUG_AFFECTED_BY.DETECT_INVIS|DETECT_HIDDEN|TRUESIGHT")
@given(
fix_types=st.sampled_from(
([0, 0, 0], [5, 9, 15], [98, 99, 100]),
),
)
@settings(max_examples=3, deadline=None)
def test_smaug_repairs_consume_exactly_three_fix_types(fix_types):
keeper = 21_002
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
Repair Test~
#REPAIRS
{keeper} {" ".join(map(str, fix_types))} 100 1 0 23 ; repair shop
0
#SPECIALS
M {keeper} spec_repair
S
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
assert len(af.area.specials) == 1
assert af.area.specials[0].arg1 == keeper
assert af.area.specials[0].arg2 == "spec_repair"
@given(
sector_type=st.integers(min_value=0, max_value=10),
tele_delay=st.integers(min_value=0, max_value=100),
tele_vnum=st.integers(min_value=0, max_value=50000),
tunnel=st.integers(min_value=0, max_value=100),
max_weight=st.integers(min_value=0, max_value=10000),
)
@settings(max_examples=20, deadline=None)
def test_smaug_rooms_read_tail_fields(sector_type, tele_delay, tele_vnum, tunnel, max_weight):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
SMAUG Test~
#MOBILES
#0
#ROOMS
#1
Room~
Description.
~
0 0 {sector_type} {tele_delay} {tele_vnum} {tunnel} {max_weight}
S
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
room = af.area.rooms[1]
assert isinstance(room, area_reader.dialects.smaug.SmaugRoom)
assert room.sector_type == sector_type
assert room.tele_delay == tele_delay
assert room.tele_vnum == tele_vnum
assert room.tunnel == tunnel
assert room.max_weight == max_weight
@given(
left_flag=st.sampled_from([1, 2, 4, 8, 16, 32]),
right_flag=st.sampled_from([64, 128, 256, 512]),
weight=st.integers(min_value=1, max_value=1000),
cost=st.integers(min_value=0, max_value=100000),
)
@settings(max_examples=20, deadline=None)
def test_smaug_objects_read_pipe_composed_wear_flags(left_flag, right_flag, weight, cost):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#AREA
SMAUG Test~
#MOBILES
#0
#OBJECTS
#1
object~
an object~
An object is here.~
~
9 0 {left_flag}|{right_flag}
0 0 0 0
{weight} {cost} 0
#0
#ROOMS
#0
#$
""",
)
af = area_reader.dialects.smaug.SmaugAreaFile(path)
af.load_sections()
item = af.area.objects[1]
assert isinstance(item, area_reader.dialects.smaug.SmaugItem)
assert item.wear_flags == left_flag | right_flag
assert item.weight == weight
assert item.cost == cost
@given(
version=st.integers(min_value=1, max_value=99),
low_soft=st.integers(min_value=0, max_value=60),
high_soft=st.integers(min_value=60, max_value=103),
low_hard=st.integers(min_value=0, max_value=60),
high_hard=st.integers(min_value=60, max_value=103),
mob_vnum=st.integers(min_value=1, max_value=50000),
object_vnum=st.integers(min_value=1, max_value=50000),
room_vnum=st.integers(min_value=1, max_value=50000),
gold=st.integers(min_value=0, max_value=1_000_000),
)
@settings(max_examples=20, deadline=None)
def test_swr_fuss_area_reads_keyed_records(
version, low_soft, high_soft, low_hard, high_hard, mob_vnum, object_vnum, room_vnum, gold
):
with tempfile.TemporaryDirectory() as directory:
path = write_area(
directory,
f"""#FUSSAREA
#AREADATA
Version {version}
Name SWR Test~
Author Builder~
Ranges {low_soft} {high_soft} {low_hard} {high_hard}
Economy 123 456
ResetFreq 15
#ENDAREADATA
#MOBILE
Vnum {mob_vnum}
Keywords test mob~
Short a test mob~
Long A test mob waits here.
~
Desc A plain SWR mobile.
~
Race Human~
Position standing~
DefPos standing~
Gender neuter~
Actflags npc sentinel~
Stats1 0 50 0 0 {gold} 0
Stats2 5 10 25
Stats3 1 4 2
Stats4 0 0 0 3 3
Attribs 10 10 10 10 10 10 10 0
Saves 0 0 0 0 0
Speaks common~
Speaking common~
#ENDMOBILE
#OBJECT
Vnum {object_vnum}
Keywords test object~
Type trash~
Short a test object~
Long A test object lies here.~
WFlags take~
Values 1 2 3 4 5 6
Stats 7 8 9 10 11
#ENDOBJECT
#ROOM
Vnum {room_vnum}
Name Test Room~
Sector city~
Flags nomob indoors~
Stats 1 2 3
Desc A plain SWR room.
~
Reset M 0 {mob_vnum} 1 {room_vnum}
#ENDROOM
#ENDAREA
""",
)
af = area_reader.dialects.swr.SwrAreaFile(path)
af.load_sections()
assert_jsonifies(af)
assert af.area.name == "SWR Test"
assert af.area.version == version
assert af.area.author == "Builder"
assert af.area.low_soft_range == low_soft
assert af.area.high_soft_range == high_soft
assert af.area.low_hard_range == low_hard
assert af.area.high_hard_range == high_hard
assert af.area.high_economy == 123
assert af.area.low_economy == 456
assert af.area.mobs[mob_vnum].wealth == gold
assert af.area.objects[object_vnum].weight == 7
assert af.area.objects[object_vnum].cost == 8
assert af.area.rooms[room_vnum].name == "Test Room"
assert af.area.rooms[room_vnum].resets[0].command == "M"
def test_circle_rooms_read_flags_exits_and_extra_descriptions():
with tempfile.TemporaryDirectory() as directory:
root = write_circle_world(
directory,
wld="""#3001
Temple~
The temple is quiet.
~
30 dJ 0
D0
A northern road.
~
gate~
2 3010 3002
E
altar~
The altar is worn smooth.
~
S
$
""",
)
af = area_reader.dialects.circle.CircleAreaFile(root)
af.load_sections()
assert_jsonifies(af)
room = af.area.rooms[3001]
assert room.name == "Temple"
assert room.room_flags == area_reader.dialects.circle.circle_asciiflag_conv("dJ")
assert room.sector_type == 0
assert room.exits[0].description == "A northern road.\n"
assert room.exits[0].keyword == "gate"
assert room.exits[0].exit_info == constants.EXIT_FLAGS.ISDOOR | constants.EXIT_FLAGS.PICKPROOF
assert room.exits[0].key == 3010
assert room.exits[0].destination == 3002
assert room.extra_descriptions[0].keyword == "altar"
def test_circle_simple_mobile_uses_circle_transforms():
with tempfile.TemporaryDirectory() as directory:
root = write_circle_world(
directory,
mob="""#10
clone~
the clone~
A boring old clone is standing here.
~
This clone is nothing to look at.
~
b 0 -25 S
7 3 4 2d8+11 1d4+2
50 125
8 6 1
$
""",
)
af = area_reader.dialects.circle.CircleAreaFile(root)
af.load_sections()
mob = af.area.mobs[10]
assert mob.name == "clone"
assert (
mob.act
== area_reader.dialects.circle.circle_asciiflag_conv("b") | area_reader.dialects.circle.CircleMobFlags.ISNPC
)
assert mob.affected_by == 0
assert mob.alignment == -25
assert mob.level == 7
assert mob.hitroll == 17
assert mob.ac == 40
assert mob.hit == area_reader.model.Dice(number=2, sides=8, bonus=11)
assert mob.damage == area_reader.model.Dice(number=1, sides=4, bonus=2)
assert mob.wealth == 50
assert mob.exp == 125
assert mob.start_pos == 8
assert mob.default_pos == 6
assert mob.sex == 1
def test_circle_enhanced_mobile_reads_espec_section():
with tempfile.TemporaryDirectory() as directory:
root = write_circle_world(
directory,
mob="""#1
Puff dragon fractal~
Puff~
Puff the Fractal Dragon is here.
~
Puff considers a higher reality.
~
anopqr dkp 1000 E
26 1 -1 5d10+550 4d6+3
10000 155000
8 8 2
BareHandAttack: 12
Str: 18
E
$
""",
)
af = area_reader.dialects.circle.CircleAreaFile(root)
af.load_sections()
mob = af.area.mobs[1]
assert mob.level == 26
assert mob.especs["BareHandAttack"] == "12"
assert mob.especs["Str"] == "18"
def test_circle_objects_end_at_next_record():
with tempfile.TemporaryDirectory() as directory:
root = write_circle_world(
directory,
obj="""#10
waybread bread~
a waybread~
Some waybread has been put here.~
~
19 g 1
24 0 0 0
1 50 50
E
waybread bread~
The waybread is traditional travelling food.
~
#11
coin~
a coin~
A coin lies here.~
~
20 0 1
1 2 3 4
1 2 3
$
""",
)
af = area_reader.dialects.circle.CircleAreaFile(root)
af.load_sections()
assert sorted(af.area.objects) == [10, 11]
item = af.area.objects[10]
assert item.item_type == 19
assert item.extra_flags == area_reader.dialects.circle.circle_asciiflag_conv("g")
assert item.wear_flags == 1
assert item.value == [24, 0, 0, 0]
assert item.weight == 1
assert item.cost == 50
assert item.rent == 50
assert item.extra_descriptions[0].keyword == "waybread bread"
def test_circle_zones_follow_circle_reset_command_arity():
with tempfile.TemporaryDirectory() as directory:
root = write_circle_world(
directory,
zon="""#30
Midgaard~
3000 3099 30 2
M 0 3000 1 3001
G 1 3010 2