forked from pythonwars/PythonWars-1996
-
Notifications
You must be signed in to change notification settings - Fork 0
/
living.py
4068 lines (3444 loc) · 182 KB
/
living.py
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
# PythonWars copyright © 2020 by Paul Penner. All rights reserved. In order to
# use this codebase you must comply with all licenses.
#
# Original Diku Mud copyright © 1990, 1991 by Sebastian Hammer,
# Michael Seifert, Hans Henrik Stærfeldt, Tom Madsen, and Katja Nyboe.
#
# Merc Diku Mud improvements copyright © 1992, 1993 by Michael
# Chastain, Michael Quan, and Mitchell Tse.
#
# ROM 2.4 is copyright 1993-1998 Russ Taylor. ROM has been brought to
# you by the ROM consortium: Russ Taylor (rtaylor@hypercube.org),
# Gabrielle Taylor (gtaylor@hypercube.org), and Brian Moore (zump@rom.org).
#
# Ported to Python by Davion of MudBytes.net using Miniboa
# (https://code.google.com/p/miniboa/).
#
# In order to use any part of this Merc Diku Mud, you must comply with
# both the original Diku license in 'license.doc' as well the Merc
# license in 'license.txt'. In particular, you may not remove either of
# these copyright notices.
#
# Much time and thought has gone into this software, and you are
# benefiting. We hope that you share your changes too. What goes
# around, comes around.
import json
import time
import affects
import bit
import comm
import const
import environment
import equipment
import fight
import game_utils
import handler_ch
import handler_game
import immortal
import instance
import inventory
import merc
import object_creator
import physical
import state_checks
import type_bypass
class Grouping:
def __init__(self):
super().__init__()
self.master = None
self.leader = None
self.followers = 0
self.clan = ""
self.lord = ""
# It is very important that this be an equivalence relation:
# (1) A ~ A
# (2) if A ~ B then B ~ A
# (3) if A ~ B and B ~ C, then A ~ C
def is_same_group(self, bch):
ach = self
if not ach or not bch:
return False
if ach.leader:
ach = ach.leader
if bch.leader:
bch = bch.leader
return ach == bch
def stop_follower(self):
if not self.master:
comm.notify("stop_follower: null master", merc.CONSOLE_ERROR)
return
# noinspection PyUnresolvedReferences
if self.is_affected(merc.AFF_CHARM):
# noinspection PyUnresolvedReferences
self.affected_by.rem_bit(merc.AFF_CHARM)
# noinspection PyUnresolvedReferences
self.affect_strip("charm person")
# noinspection PyUnresolvedReferences
if instance.characters[self.master].can_see(self) and self.in_room:
handler_game.act("$n stops following you.", self, None, instance.characters[self.master], merc.TO_VICT)
handler_game.act("You stop following $N.", self, None, instance.characters[self.master], merc.TO_CHAR)
self.master = None
self.leader = None
class BodyParts:
def __init__(self):
super().__init__()
self.head = bit.Bit(flagset_name="blochead_flags")
self.body = bit.Bit(flagset_name="blocbody_flags")
self.arm_left = bit.Bit(flagset_name="blocarm_flags")
self.arm_right = bit.Bit(flagset_name="blocarm_flags")
self.leg_left = bit.Bit(flagset_name="blocleg_flags")
self.leg_right = bit.Bit(flagset_name="blocleg_flags")
self.bleeding = bit.Bit(flagset_name="blocbleed_flags")
# Serialization
def to_json(self, outer_encoder=None):
if outer_encoder is None:
outer_encoder = json.JSONEncoder.default
tmp_dict = {}
for k, v in self.__dict__.items():
if str(type(v)) in ("<class 'function'>", "<class 'method'>"):
continue
elif str(k) in ("desc", "send"):
continue
elif str(k) in ("_last_saved", "_md5"):
continue
else:
tmp_dict[k] = v
cls_name = "__class__/" + __name__ + "." + self.__class__.__name__
return {cls_name: outer_encoder(tmp_dict)}
@classmethod
def from_json(cls, data, outer_decoder=None):
if outer_decoder is None:
outer_decoder = json.JSONDecoder.decode
cls_name = "__class__/" + __name__ + "." + cls.__name__
if cls_name in data:
tmp_data = outer_decoder(data[cls_name])
return cls(**tmp_data)
return data
# JINPOINT - 11/30/2020 @ 1:03 PM - Must be a more pythonic way to handle this function. Have seen fixes to large elif functions,
# but nothing that quite mathes this setup (multiple class variables).
def reg_mend(self):
ribs = 0
body_table = [(merc.BROKEN_RIBS_1, 1), (merc.BROKEN_RIBS_2, 2), (merc.BROKEN_RIBS_4, 4), (merc.BROKEN_RIBS_8, 8),
(merc.BROKEN_RIBS_16, 16)]
for (aa, bb) in body_table:
if self.body.is_set(aa):
ribs += bb
teeth = 0
body_table = [(merc.LOST_TOOTH_1, 1), (merc.LOST_TOOTH_2, 2), (merc.LOST_TOOTH_4, 4), (merc.LOST_TOOTH_8, 8),
(merc.LOST_TOOTH_16, 16)]
for (aa, bb) in body_table:
if self.head.is_set(aa):
teeth += bb
if ribs > 0:
self.mend_broken_ribs(ribs)
elif self.head.is_set(merc.LOST_EYE_L):
self.mend_lost_eye(False)
elif self.head.is_set(merc.LOST_EYE_R):
self.mend_lost_eye(True)
elif self.head.is_set(merc.LOST_EAR_L):
self.mend_lost_ear(False)
elif self.head.is_set(merc.LOST_EAR_R):
self.mend_lost_ear(True)
elif self.head.is_set(merc.LOST_NOSE):
self.mend_lost_nose()
elif teeth > 0:
self.mend_missing_teeth(teeth)
elif self.head.is_set(merc.BROKEN_NOSE):
self.mend_broken_nose()
elif self.head.is_set(merc.BROKEN_JAW):
self.mend_broken_jaw()
elif self.head.is_set(merc.BROKEN_SKULL):
self.mend_broken_skull()
elif self.body.is_set(merc.BROKEN_SPINE):
self.mend_broken_spine()
elif self.body.is_set(merc.BROKEN_NECK):
self.mend_broken_neck()
elif self.arm_left.is_set(merc.LOST_ARM):
self.mend_lost_arm(right=False)
elif self.arm_right.is_set(merc.LOST_ARM):
self.mend_lost_arm(right=True)
elif self.leg_left.is_set(merc.LOST_LEG):
self.mend_lost_leg(False)
elif self.leg_right.is_set(merc.LOST_LEG):
self.mend_lost_leg(True)
elif self.arm_left.is_set(merc.BROKEN_ARM):
self.mend_broken_arm(right=False)
elif self.arm_right.is_set(merc.BROKEN_ARM):
self.mend_broken_arm(right=True)
elif self.leg_left.is_set(merc.BROKEN_LEG):
self.mend_broken_leg(False)
elif self.leg_right.is_set(merc.BROKEN_LEG):
self.mend_broken_leg(True)
elif self.arm_left.is_set(merc.LOST_HAND):
self.mend_lost_hand(right=False)
elif self.arm_right.is_set(merc.LOST_HAND):
self.mend_lost_hand(right=True)
elif self.leg_left.is_set(merc.LOST_FOOT):
self.mend_lost_foot(False)
elif self.leg_right.is_set(merc.LOST_FOOT):
self.mend_lost_foot(True)
elif self.arm_left.is_set(merc.LOST_THUMB):
self.mend_lost_finger_t(right=False)
elif self.arm_left.is_set(merc.BROKEN_THUMB):
self.mend_broken_finger_t(right=False)
elif self.arm_left.is_set(merc.LOST_FINGER_I):
self.mend_lost_finger_i(right=False)
elif self.arm_left.is_set(merc.BROKEN_FINGER_I):
self.mend_broken_finger_i(right=False)
elif self.arm_left.is_set(merc.LOST_FINGER_M):
self.mend_lost_finger_m(right=False)
elif self.arm_left.is_set(merc.BROKEN_FINGER_M):
self.mend_broken_finger_m(right=False)
elif self.arm_left.is_set(merc.LOST_FINGER_R):
self.mend_lost_finger_r(right=False)
elif self.arm_left.is_set(merc.BROKEN_FINGER_R):
self.mend_broken_finger_r(right=False)
elif self.arm_left.is_set(merc.LOST_FINGER_L):
self.mend_lost_finger_l(right=False)
elif self.arm_left.is_set(merc.BROKEN_FINGER_L):
self.mend_broken_finger_l(right=False)
elif self.arm_right.is_set(merc.LOST_THUMB):
self.mend_lost_finger_t(right=True)
elif self.arm_right.is_set(merc.BROKEN_THUMB):
self.mend_broken_finger_t(right=True)
elif self.arm_right.is_set(merc.LOST_FINGER_I):
self.mend_lost_finger_i(right=True)
elif self.arm_right.is_set(merc.BROKEN_FINGER_I):
self.mend_broken_finger_i(right=True)
elif self.arm_right.is_set(merc.LOST_FINGER_M):
self.mend_lost_finger_m(right=True)
elif self.arm_right.is_set(merc.BROKEN_FINGER_M):
self.mend_broken_finger_m(right=True)
elif self.arm_right.is_set(merc.LOST_FINGER_R):
self.mend_lost_finger_r(right=True)
elif self.arm_right.is_set(merc.BROKEN_FINGER_R):
self.mend_broken_finger_r(right=True)
elif self.arm_right.is_set(merc.LOST_FINGER_L):
self.mend_lost_finger_l(right=True)
elif self.arm_right.is_set(merc.BROKEN_FINGER_L):
self.mend_broken_finger_l(right=True)
elif self.body.is_set(merc.CUT_THROAT):
self.mend_cut_throat()
else:
comm.notify("reg_mend: bad body location found.", merc.CONSOLE_ERROR)
def mend_broken_ribs(self, ribs):
self.body.rem_bit(merc.BROKEN_RIBS_1)
self.body.rem_bit(merc.BROKEN_RIBS_2)
self.body.rem_bit(merc.BROKEN_RIBS_4)
self.body.rem_bit(merc.BROKEN_RIBS_8)
self.body.rem_bit(merc.BROKEN_RIBS_16)
ribs -= 1
if ribs >= 16:
ribs -= 16
self.body.set_bit(merc.BROKEN_RIBS_16)
if ribs >= 8:
ribs -= 8
self.body.set_bit(merc.BROKEN_RIBS_8)
if ribs >= 4:
ribs -= 4
self.body.set_bit(merc.BROKEN_RIBS_4)
if ribs >= 2:
ribs -= 2
self.body.set_bit(merc.BROKEN_RIBS_2)
if ribs >= 1:
ribs -= 1
self.body.set_bit(merc.BROKEN_RIBS_1)
handler_game.act("One of your ribs snap back into place.", self, None, None, merc.TO_CHAR)
handler_game.act("One of $n's ribs snap back into place.", self, None, None, merc.TO_ROOM)
def mend_lost_eye(self, right):
if right:
handler_game.act("An eyeball appears in $n's right eye socket.", self, None, None, merc.TO_ROOM)
handler_game.act("An eyeball appears in your right eye socket.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.LOST_EYE_R)
else:
handler_game.act("An eyeball appears in $n's left eye socket.", self, None, None, merc.TO_ROOM)
handler_game.act("An eyeball appears in your left eye socket.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.LOST_EYE_L)
def mend_lost_ear(self, right):
if right:
handler_game.act("An ear grows on the right side of $n's head.", self, None, None, merc.TO_ROOM)
handler_game.act("An ear grows on the right side of your head.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.LOST_EAR_R)
else:
handler_game.act("An ear grows on the left side of $n's head.", self, None, None, merc.TO_ROOM)
handler_game.act("An ear grows on the left side of your head.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.LOST_EAR_L)
def mend_lost_nose(self):
handler_game.act("A nose grows on the front of $n's face.", self, None, None, merc.TO_ROOM)
handler_game.act("A nose grows on the front of your face.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.LOST_NOSE)
self.head.rem_bit(merc.BROKEN_NOSE)
def mend_missing_teeth(self, teeth):
self.head.rem_bit(merc.LOST_TOOTH_1)
self.head.rem_bit(merc.LOST_TOOTH_2)
self.head.rem_bit(merc.LOST_TOOTH_4)
self.head.rem_bit(merc.LOST_TOOTH_8)
self.head.rem_bit(merc.LOST_TOOTH_16)
teeth -= 1
if teeth >= 16:
teeth -= 16
self.head.set_bit(merc.LOST_TOOTH_16)
if teeth >= 8:
teeth -= 8
self.head.set_bit(merc.LOST_TOOTH_8)
if teeth >= 4:
teeth -= 4
self.head.set_bit(merc.LOST_TOOTH_4)
if teeth >= 2:
teeth -= 2
self.head.set_bit(merc.LOST_TOOTH_2)
if teeth >= 1:
teeth -= 1
self.head.set_bit(merc.LOST_TOOTH_1)
handler_game.act("A missing tooth grows in your mouth.", self, None, None, merc.TO_CHAR)
handler_game.act("A missing tooth grows in $n's mouth.", self, None, None, merc.TO_ROOM)
def mend_broken_nose(self):
handler_game.act("$n's nose snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your nose snaps back into place.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.BROKEN_NOSE)
def mend_broken_jaw(self):
handler_game.act("$n's jaw snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your jaw snaps back into place.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.BROKEN_JAW)
def mend_broken_skull(self):
handler_game.act("$n's skull knits itself back together.", self, None, None, merc.TO_ROOM)
handler_game.act("Your skull knits itself back together.", self, None, None, merc.TO_CHAR)
self.head.rem_bit(merc.BROKEN_SKULL)
def mend_broken_spine(self):
handler_game.act("$n's spine knits itself back together.", self, None, None, merc.TO_ROOM)
handler_game.act("Your spine knits itself back together.", self, None, None, merc.TO_CHAR)
self.body.rem_bit(merc.BROKEN_SPINE)
def mend_broken_neck(self):
handler_game.act("$n's neck snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your neck snaps back into place.", self, None, None, merc.TO_CHAR)
self.body.rem_bit(merc.BROKEN_NECK)
def mend_lost_arm(self, right):
if right:
handler_game.act("An arm grows from the stump of $n's right shoulder.", self, None, None, merc.TO_ROOM)
handler_game.act("An arm grows from the stump of your right shoulder.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_ARM)
self.arm_right.rem_bit(merc.BROKEN_ARM)
self.arm_right.set_bit(merc.LOST_HAND)
else:
handler_game.act("An arm grows from the stump of $n's left shoulder.", self, None, None, merc.TO_ROOM)
handler_game.act("An arm grows from the stump of your left shoulder.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_ARM)
self.arm_left.rem_bit(merc.BROKEN_ARM)
self.arm_left.set_bit(merc.LOST_HAND)
def mend_lost_leg(self, right):
if right:
handler_game.act("A leg grows from the stump of $n's right hip.", self, None, None, merc.TO_ROOM)
handler_game.act("A leg grows from the stump of your right hip.", self, None, None, merc.TO_CHAR)
self.leg_right.rem_bit(merc.LOST_LEG)
self.leg_right.rem_bit(merc.BROKEN_LEG)
self.leg_right.set_bit(merc.LOST_FOOT)
else:
handler_game.act("A leg grows from the stump of $n's left hip.", self, None, None, merc.TO_ROOM)
handler_game.act("A leg grows from the stump of your left hip.", self, None, None, merc.TO_CHAR)
self.leg_left.rem_bit(merc.LOST_LEG)
self.leg_left.rem_bit(merc.BROKEN_LEG)
self.leg_left.set_bit(merc.LOST_FOOT)
def mend_broken_arm(self, right):
if right:
handler_game.act("$n's right arm snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right arm snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_ARM)
else:
handler_game.act("$n's left arm snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left arm snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_ARM)
def mend_broken_leg(self, right):
if right:
handler_game.act("$n's right leg snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right leg snaps back into place.", self, None, None, merc.TO_CHAR)
self.leg_right.rem_bit(merc.BROKEN_LEG)
else:
handler_game.act("$n's left leg snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left leg snaps back into place.", self, None, None, merc.TO_CHAR)
self.leg_left.rem_bit(merc.BROKEN_LEG)
def mend_lost_hand(self, right):
if right:
handler_game.act("A hand grows from the stump of $n's right wrist.", self, None, None, merc.TO_ROOM)
handler_game.act("A hand grows from the stump of your right wrist.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_HAND)
self.arm_right.set_bit(merc.LOST_THUMB)
self.arm_right.set_bit(merc.LOST_FINGER_I)
self.arm_right.set_bit(merc.LOST_FINGER_M)
self.arm_right.set_bit(merc.LOST_FINGER_R)
self.arm_right.set_bit(merc.LOST_FINGER_L)
else:
handler_game.act("A hand grows from the stump of $n's left wrist.", self, None, None, merc.TO_ROOM)
handler_game.act("A hand grows from the stump of your left wrist.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_HAND)
self.arm_left.set_bit(merc.LOST_THUMB)
self.arm_left.set_bit(merc.LOST_FINGER_I)
self.arm_left.set_bit(merc.LOST_FINGER_M)
self.arm_left.set_bit(merc.LOST_FINGER_R)
self.arm_left.set_bit(merc.LOST_FINGER_L)
def mend_lost_foot(self, right):
if right:
handler_game.act("A foot grows from the stump of $n's right ankle.", self, None, None, merc.TO_ROOM)
handler_game.act("A foot grows from the stump of your right ankle.", self, None, None, merc.TO_CHAR)
self.leg_right.rem_bit(merc.LOST_FOOT)
else:
handler_game.act("A foot grows from the stump of $n's left ankle.", self, None, None, merc.TO_ROOM)
handler_game.act("A foot grows from the stump of your left ankle.", self, None, None, merc.TO_CHAR)
self.leg_left.rem_bit(merc.LOST_FOOT)
def mend_lost_finger_t(self, right):
if right:
handler_game.act("A thumb slides out of $n's right hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A thumb slides out of your right hand.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_THUMB)
self.arm_right.rem_bit(merc.BROKEN_THUMB)
else:
handler_game.act("A thumb slides out of $n's left hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A thumb slides out of your left hand.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_THUMB)
self.arm_left.rem_bit(merc.BROKEN_THUMB)
def mend_broken_finger_t(self, right):
if right:
handler_game.act("$n's right thumb snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right thumb snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_THUMB)
else:
handler_game.act("$n's left thumb snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left thumb snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_THUMB)
def mend_lost_finger_i(self, right):
if right:
handler_game.act("An index finger slides out of $n's right hand.", self, None, None, merc.TO_ROOM)
handler_game.act("An index finger slides out of your right hand.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_FINGER_I)
self.arm_right.rem_bit(merc.BROKEN_FINGER_I)
else:
handler_game.act("An index finger slides out of $n's left hand.", self, None, None, merc.TO_ROOM)
handler_game.act("An index finger slides out of your left hand.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_FINGER_I)
self.arm_left.rem_bit(merc.BROKEN_FINGER_I)
def mend_broken_finger_i(self, right):
if right:
handler_game.act("$n's right index finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right index finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_FINGER_I)
else:
handler_game.act("$n's left index finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left index finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_FINGER_I)
def mend_lost_finger_m(self, right):
if right:
handler_game.act("A middle finger slides out of $n's right hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A middle finger slides out of your right hand.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_FINGER_M)
self.arm_right.rem_bit(merc.BROKEN_FINGER_M)
else:
handler_game.act("A middle finger slides out of $n's left hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A middle finger slides out of your left hand.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_FINGER_M)
self.arm_left.rem_bit(merc.BROKEN_FINGER_M)
def mend_broken_finger_m(self, right):
if right:
handler_game.act("$n's right middle finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right middle finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_FINGER_M)
else:
handler_game.act("$n's left middle finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left middle finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_FINGER_M)
def mend_lost_finger_r(self, right):
if right:
handler_game.act("A ring finger slides out of $n's right hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A ring finger slides out of your right hand.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_FINGER_R)
self.arm_right.rem_bit(merc.BROKEN_FINGER_R)
else:
handler_game.act("A ring finger slides out of $n's left hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A ring finger slides out of your left hand.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_FINGER_R)
self.arm_left.rem_bit(merc.BROKEN_FINGER_R)
def mend_broken_finger_r(self, right):
if right:
handler_game.act("$n's right ring finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right ring finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_FINGER_R)
else:
handler_game.act("$n's left ring finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left ring finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_FINGER_R)
def mend_lost_finger_l(self, right):
if right:
handler_game.act("A little finger slides out of $n's right hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A little finger slides out of your right hand.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.LOST_FINGER_L)
self.arm_right.rem_bit(merc.BROKEN_FINGER_L)
else:
handler_game.act("A little finger slides out of $n's left hand.", self, None, None, merc.TO_ROOM)
handler_game.act("A little finger slides out of your left hand.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.LOST_FINGER_L)
self.arm_left.rem_bit(merc.BROKEN_FINGER_L)
def mend_broken_finger_l(self, right):
if right:
handler_game.act("$n's right little finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your right little finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_right.rem_bit(merc.BROKEN_FINGER_L)
else:
handler_game.act("$n's left little finger snaps back into place.", self, None, None, merc.TO_ROOM)
handler_game.act("Your left little finger snaps back into place.", self, None, None, merc.TO_CHAR)
self.arm_left.rem_bit(merc.BROKEN_FINGER_L)
def mend_cut_throat(self):
if self.bleeding.is_set(merc.BLEEDING_THROAT):
return
handler_game.act("The wound in $n's throat closes up.", self, None, None, merc.TO_ROOM)
handler_game.act("The wound in your throat closes up.", self, None, None, merc.TO_CHAR)
self.body.rem_bit(merc.CUT_THROAT)
def is_ok_to_wear(self, slot, wolf_ok, success):
if slot == "head":
if self.head.is_set(merc.LOST_HEAD):
return False
elif slot == "face":
if self.head.is_set(merc.LOST_HEAD):
return False
elif slot == "left_hand":
# noinspection PyUnresolvedReferences
if not self.is_npc() and self.special.is_set(merc.SPC_WOLFMAN) and not wolf_ok:
return False
part_list = [merc.LOST_ARM, merc.BROKEN_ARM, merc.LOST_HAND, merc.BROKEN_THUMB, merc.LOST_THUMB]
for item in part_list:
if self.arm_left.is_set(item):
return False
count = 0
part_list = [merc.LOST_FINGER_I, merc.LOST_FINGER_M, merc.LOST_FINGER_R, merc.LOST_FINGER_L, merc.BROKEN_FINGER_I,
merc.BROKEN_FINGER_M, merc.BROKEN_FINGER_R, merc.BROKEN_FINGER_L]
for item in part_list:
if self.arm_left.is_set(item):
count += 1
if count > 2:
return False
elif slot == "right_hand":
# noinspection PyUnresolvedReferences
if not self.is_npc() and self.special.is_set(merc.SPC_WOLFMAN) and not wolf_ok:
return False
part_list = [merc.LOST_ARM, merc.BROKEN_ARM, merc.LOST_HAND, merc.BROKEN_THUMB, merc.LOST_THUMB]
for item in part_list:
if self.arm_right.is_set(item):
return False
count = 0
part_list = [merc.LOST_FINGER_I, merc.LOST_FINGER_M, merc.LOST_FINGER_R, merc.LOST_FINGER_L, merc.BROKEN_FINGER_I,
merc.BROKEN_FINGER_M, merc.BROKEN_FINGER_R, merc.BROKEN_FINGER_L]
for item in part_list:
if self.arm_right.is_set(item):
count += 1
if count > 2:
return False
elif slot == "left_wrist":
if self.arm_left.is_set(merc.LOST_ARM) or self.arm_left.is_set(merc.LOST_HAND):
return False
elif slot == "right_wrist":
if self.arm_right.is_set(merc.LOST_ARM) or self.arm_right.is_set(merc.LOST_HAND):
return False
elif slot == "left_finger":
part_list = [merc.LOST_ARM, merc.LOST_HAND, merc.LOST_FINGER_R]
for item in part_list:
if self.arm_left.is_set(item):
return False
elif slot == "right_finger":
part_list = [merc.LOST_ARM, merc.LOST_HAND, merc.LOST_FINGER_R]
for item in part_list:
if self.arm_right.is_set(item):
return False
elif slot == "arms":
if self.arm_left.is_set(merc.LOST_ARM) and self.arm_right.is_set(merc.LOST_ARM):
return False
elif slot == "hands":
if self.arm_left.is_set(merc.LOST_ARM) and self.arm_right.is_set(merc.LOST_ARM):
return False
if self.arm_left.is_set(merc.LOST_HAND) or self.arm_right.is_set(merc.LOST_HAND):
return False
elif slot == "legs":
if self.leg_left.is_set(merc.LOST_LEG) and self.leg_right.is_set(merc.LOST_LEG):
return False
elif slot == "feet":
if self.leg_left.is_set(merc.LOST_LEG) and self.leg_right.is_set(merc.LOST_LEG):
return False
if self.leg_left.is_set(merc.LOST_FOOT) or self.leg_right.is_set(merc.LOST_FOOT):
return False
return success
class Fight:
def __init__(self):
super().__init__()
self._fighting = None
self.hunting = ""
self._hitroll = 0
self._damroll = 0
self._armor = 100
self.wimpy = 0
self.saving_throw = 0
self.timer = 0
self.wait = 0
self.mkill = 0
self.mdeath = 0
self.pkill = 0
self.pdeath = 0
self.race = 0
self.damcap = [1000, 0]
self.wpn = [0] * merc.MAX_WPN
self.spl = [0] * merc.MAX_MAGIC
self.stance = [0] * merc.MAX_STANCE
self.cmbt = [0] * 8
def send(self, pstr):
pass
@property
def hitroll(self):
from const import str_app
# noinspection PyUnresolvedReferences
value = self._hitroll + str_app[self.stat(merc.STAT_STR)].tohit
# noinspection PyUnresolvedReferences
if not self.is_npc():
# noinspection PyUnresolvedReferences
if self.is_vampire() and self.powers[merc.UNI_RAGE] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.UNI_RAGE]
# noinspection PyUnresolvedReferences
elif self.special.is_set(merc.SPC_WOLFMAN) and self.powers[merc.UNI_RAGE] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.UNI_RAGE]
elif self.is_demon() and self.powers[merc.DEMON_POWER] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.DEMON_POWER] * self.powers[merc.DEMON_POWER]
elif self.special.is_set(merc.SPC_CHAMPION) and self.powers[merc.DEMON_POWER] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.DEMON_POWER] * self.powers[merc.DEMON_POWER]
elif self.is_highlander() and self.itemaff.is_set(merc.ITEMA_HIGHLANDER):
# noinspection PyUnresolvedReferences
wpn = self.powers[merc.HPOWER_WPNSKILL]
if wpn in [1, 3]:
if self.wpn[wpn] >= 500:
value += 500
else:
value += self.wpn[wpn]
return value
@hitroll.setter
def hitroll(self, value):
self._hitroll = value
@property
def damroll(self):
from const import str_app
# noinspection PyUnresolvedReferences
value = self._damroll + str_app[self.stat(merc.STAT_STR)].todam
# noinspection PyUnresolvedReferences
if not self.is_npc():
# noinspection PyUnresolvedReferences
if self.is_vampire() and self.powers[merc.UNI_RAGE] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.UNI_RAGE]
# noinspection PyUnresolvedReferences
elif self.special.is_set(merc.SPC_WOLFMAN) and self.powers[merc.UNI_RAGE] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.UNI_RAGE]
# noinspection PyUnresolvedReferences
elif self.is_demon() and self.powers[merc.DEMON_POWER] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.DEMON_POWER] * self.powers[merc.DEMON_POWER]
# noinspection PyUnresolvedReferences
elif self.special.is_set(merc.SPC_CHAMPION) and self.powers[merc.DEMON_POWER] > 0:
# noinspection PyUnresolvedReferences
value += self.powers[merc.DEMON_POWER] * self.powers[merc.DEMON_POWER]
# noinspection PyUnresolvedReferences
elif self.is_highlander() and self.itemaff.is_set(merc.ITEMA_HIGHLANDER):
# noinspection PyUnresolvedReferences
wpn = self.powers[merc.HPOWER_WPNSKILL]
if self.wpn[wpn] >= 500:
value += 500
else:
value += self.wpn[wpn]
return value
@damroll.setter
def damroll(self, value):
self._damroll = value
@property
def armor(self):
from const import dex_app
# noinspection PyUnresolvedReferences
value = self._armor + (dex_app[self.stat(merc.STAT_DEX)].defensive if self.is_awake() else 0)
# noinspection PyUnresolvedReferences
if not self.is_npc():
# noinspection PyUnresolvedReferences
if self.is_highlander() and self.itemaff.is_set(merc.ITEMA_HIGHLANDER):
# noinspection PyUnresolvedReferences
wpn = self.powers[merc.HPOWER_WPNSKILL]
if wpn in [1, 3]:
value += self.wpn[wpn]
return value
@armor.setter
def armor(self, value):
self._armor = value
@property
def fighting(self):
return instance.characters.get(self._fighting, None)
@fighting.setter
def fighting(self, value):
if type(value) is int:
value = instance.characters.get(value, None) # Ensure fighting exists.
if value and not isinstance(value, Fight):
# noinspection PyUnresolvedReferences
comm.notify("Instance fighting non combat. {} fighting {}".format(self.name, value.name), merc.CONSOLE_ERROR)
return
if value:
# noinspection PyUnresolvedReferences
value = value.instance_id
if type(value) is None:
value = None
self._fighting = value # None or instance_id
def wait_state(self, npulse):
self.wait = max(self.wait, npulse)
def can_pk(self):
return self.trust in merc.irange(merc.LEVEL_AVATAR, merc.LEVEL_MAGE)
def fightaction(self, victim, actype, dtype, wpntype):
# noinspection PyUnresolvedReferences
if self.is_npc() or actype not in merc.irange(1, 20) or not victim:
return
if actype == 1: # Trip
if game_utils.number_percent() <= self.wpn[merc.WPN_UNARMED]:
fight.trip(self, victim)
elif actype == 2 and game_utils.number_percent() < 75:
# noinspection PyUnresolvedReferences
self.cmd_kick("")
elif actype == 7:
if game_utils.number_percent() < 25:
fight.disarm(self, victim)
elif actype == 9:
handler_game.act("You kick a spray of dirt into $N's face.", self, None, victim, merc.TO_CHAR)
handler_game.act("$n kicks a spray of dirt into your face.", self, None, victim, merc.TO_VICT)
handler_game.act("$n kicks a spray of dirt into $N's face.", self, None, victim, merc.TO_NOTVICT)
if victim.is_affected(merc.AFF_BLIND) or game_utils.number_percent() < 25:
return
aff = handler_game.AffectData(type="blindness", location=merc.APPLY_HITROLL, modifier=-4, duration=1, bitvector=merc.AFF_BLIND)
victim.affect_add(aff)
handler_game.act("$n is blinded!", victim, None, None, merc.TO_ROOM)
victim.send("You are blinded!\n")
elif actype == 12:
handler_game.act("You gouge your fingers into $N's eyes.", self, None, victim, merc.TO_CHAR)
handler_game.act("$n gouges $s fingers into your eyes.", self, None, victim, merc.TO_VICT)
handler_game.act("$n gouges $s fingers into $N's eyes.", self, None, victim, merc.TO_NOTVICT)
if victim.is_affected(merc.AFF_BLIND) or game_utils.number_percent() < 75:
fight.one_hit(self, victim, dtype, wpntype)
else:
aff = handler_game.AffectData(type="blindness", location=merc.APPLY_HITROLL, modifier=-4, duration=1, bitvector=merc.AFF_BLIND)
victim.affect_add(aff)
handler_game.act("$n is blinded!", victim, None, None, merc.TO_ROOM)
victim.send("You are blinded!\n")
elif actype == 14:
if victim.move > 0:
handler_game.act("You leap in the air and stamp on $N's feet.", self, None, victim, merc.TO_CHAR)
handler_game.act("$n leaps in the air and stamps on your feet.", self, None, victim, merc.TO_VICT)
handler_game.act("$n leaps in the air and stamps on $N's feet.", self, None, victim, merc.TO_NOTVICT)
victim.move -= game_utils.number_range(25, 50)
if victim.move < 0:
victim.move = 0
def critical_hit(self, victim, dt, dam):
critical = 0
dtype = dt - 1000
if dtype not in merc.irange(0, 12):
return
# noinspection PyUnresolvedReferences
if self.is_npc():
# noinspection PyUnresolvedReferences
critical += (self.level + 1) // 5
else:
critical += (self.wpn[dtype] + 1) // 10
if victim.is_npc():
critical -= (victim.level + 1) // 5
else:
dtype = merc.TYPE_HIT
item = victim.get_eq("right_hand")
if item and item.item_type == merc.ITEM_WEAPON:
dtype += item.value[3]
wpn1 = dtype - 1000
if wpn1 not in merc.irange(0, 12):
wpn1 = 0
dtype = merc.TYPE_HIT
item = victim.get_eq("left_hand")
if item and item.item_type == merc.ITEM_WEAPON:
dtype += item.value[3]
wpn2 = dtype - 1000
if wpn2 not in merc.irange(0, 12):
wpn2 = 0
if victim.wpn[wpn1] > victim.wpn[wpn2]:
critical -= (victim.wpn[wpn1] + 1) // 10
else:
critical -= (victim.wpn[wpn2] + 1) // 10
critical = state_checks.urange(1, critical, 5)
if game_utils.number_percent() > critical:
return
critical = game_utils.number_range(1, 23)
if critical == 1:
if victim.head.is_set(merc.LOST_EYE_L) and victim.head.is_set(merc.LOST_EYE_R):
return
damaged = victim.get_eq("face")
# noinspection PyUnresolvedReferences
if damaged and damaged.toughness > 0 and not self.itemaff.is_set(merc.ITEMA_VORPAL):
handler_game.act("$p prevents you from loosing an eye.", victim, damaged, None, merc.TO_CHAR)
handler_game.act("$p prevents $n from loosing an eye.", victim, damaged, None, merc.TO_ROOM)
if dam - damaged.toughness < 0:
return
if dam - damaged.toughness > damaged.resistance:
damaged.condition -= damaged.resistance
else:
damaged.condition -= (dam - damaged.toughness)
if damaged.condition < 1:
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_CHAR)
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_ROOM)
victim.get(damaged)
damaged.extract()
return
if not victim.head.is_set(merc.LOST_EYE_L) and game_utils.number_percent() < 50:
victim.head.set_bit(merc.LOST_EYE_L)
elif not victim.head.is_set(merc.LOST_EYE_R):
victim.head.set_bit(merc.LOST_EYE_R)
elif not victim.head.is_set(merc.LOST_EYE_L):
victim.head.set_bit(merc.LOST_EYE_L)
else:
return
handler_game.act("Your skillful blow takes out $N's eye!", self, None, victim, merc.TO_CHAR)
handler_game.act("$n's skillful blow takes out $N's eye!", self, None, victim, merc.TO_NOTVICT)
handler_game.act("$n's skillful blow takes out your eye!", self, None, victim, merc.TO_VICT)
object_creator.make_part(victim, "eyeball")
elif critical == 2:
if victim.head.is_set(merc.LOST_EAR_L) and victim.head.is_set(merc.LOST_EAR_R):
return
damaged = victim.get_eq("head")
# noinspection PyUnresolvedReferences
if damaged and damaged.toughness > 0 and not self.itemaff.is_set(merc.ITEMA_VORPAL):
handler_game.act("$p prevents you from loosing an ear.", victim, damaged, None, merc.TO_CHAR)
handler_game.act("$p prevents $n from loosing an ear.", victim, damaged, None, merc.TO_ROOM)
if dam - damaged.toughness < 0:
return
if dam - damaged.toughness > damaged.resistance:
damaged.condition -= damaged.resistance
else:
damaged.condition -= dam - damaged.toughness
if damaged.condition < 1:
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_CHAR)
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_ROOM)
victim.get(damaged)
damaged.extract()
return
if not victim.head.is_set(merc.LOST_EAR_L) and game_utils.number_percent() < 50:
victim.head.set_bit(merc.LOST_EAR_L)
elif not victim.head.is_set(merc.LOST_EAR_R):
victim.head.set_bit(merc.LOST_EAR_R)
elif not victim.head.is_set(merc.LOST_EAR_L):
victim.head.set_bit(merc.LOST_EAR_L)
else:
return
handler_game.act("Your skillful blow cuts off $N's ear!", self, None, victim, merc.TO_CHAR)
handler_game.act("$n's skillful blow cuts off $N's ear!", self, None, victim, merc.TO_NOTVICT)
handler_game.act("$n's skillful blow cuts off your ear!", self, None, victim, merc.TO_VICT)
object_creator.make_part(victim, "ear")
elif critical == 3:
if victim.head.is_set(merc.LOST_NOSE):
return
damaged = victim.get_eq("face")
# noinspection PyUnresolvedReferences
if damaged and damaged.toughness > 0 and not self.itemaff.is_set(merc.ITEMA_VORPAL):
handler_game.act("$p prevents you from loosing your nose.", victim, damaged, None, merc.TO_CHAR)
handler_game.act("$p prevents $n from loosing $s nose.", victim, damaged, None, merc.TO_ROOM)
if dam - damaged.toughness < 0:
return
if dam - damaged.toughness > damaged.resistance:
damaged.condition -= damaged.resistance
else:
damaged.condition -= dam - damaged.toughness
if damaged.condition < 1:
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_CHAR)
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_ROOM)
victim.get(damaged)
damaged.extract()
return
victim.head.set_bit(merc.LOST_NOSE)
handler_game.act("Your skillful blow cuts off $N's nose!", self, None, victim, merc.TO_CHAR)
handler_game.act("$n's skillful blow cuts off $N's nose!", self, None, victim, merc.TO_NOTVICT)
handler_game.act("$n's skillful blow cuts off your nose!", self, None, victim, merc.TO_VICT)
object_creator.make_part(victim, "nose")
elif critical == 4:
if victim.head.is_set(merc.LOST_NOSE) or victim.head.is_set(merc.BROKEN_NOSE):
return
damaged = victim.get_eq("face")
# noinspection PyUnresolvedReferences
if damaged and damaged.toughness > 0 and not self.itemaff.is_set(merc.ITEMA_VORPAL):
handler_game.act("$p prevents you from breaking your nose.", victim, damaged, None, merc.TO_CHAR)
handler_game.act("$p prevents $n from breaking $s nose.", victim, damaged, None, merc.TO_ROOM)
if dam - damaged.toughness < 0:
return
if dam - damaged.toughness > damaged.resistance:
damaged.condition -= damaged.resistance
else:
damaged.condition -= dam - damaged.toughness
if damaged.condition < 1:
handler_game.act("$p falls broken to the ground.", self, damaged, None, merc.TO_CHAR)