-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEntity_class.py
2187 lines (1948 loc) · 96.3 KB
/
Entity_class.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
from Ifstatement_class import ifstatements
from Dmg_class import dmg
from AI_class import AI
from Token_class import *
from Spell_class import *
from random import random, shuffle
import numpy as np
import json
import os
import sys
class entity: #A Character
def __init__(self, name, team, DM, archive = False, external_json = False): #Atk - Attack [+x to Hit, mean dmg]
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
if archive == False:
path = application_path + '/Entities/' + str(name) + '.json'
else:
path = application_path + '/Archive/' + str(name) + '.json'
if external_json == False:
file = open(path)
data = json.load(file)
file.close()
else:
data = external_json
self.data = data
self.DM = DM
self.TM = TokenManager(self) #Token Manager
#Base Properties
self.name = str(name)
self.orignial_name = str(name) #restore name after zB WildShape
self.team = team #which Team they fight for
self.type = str(data['Type'])
self.base_type = self.type
self.AC = int(data['AC']) #Current AC that will be called, and reset at start of turn
self.shape_AC =int(data['AC']) #AC of the current form, changed by wild shape
self.base_AC = int(data['AC']) #AC of initial form, will be set to this after reshape
self.HP = int(data['HP'])
self.proficiency = int(data['Proficiency'])
self.tohit = int(data['To_Hit'])
self.base_tohit = int(data['To_Hit'])
self.base_attacks = int(data['Attacks']) #attacks of original form #number auf Attacks
self.attacks = self.base_attacks #at end_of_turn attack_counter reset to self.attack
self.dmg = float(data['DMG']) #dmg per attack
self.base_dmg = float(data['DMG'])
self.offhand_dmg = float(data['OffHand']) #If 0, no Offhand dmg
self.level = float(data['Level']) #It is not fully implementet yet, but level is used in some functions already, Level is used as CR for wildshape and co
try: self.strategy_level = int(data['StrategyLevel']) #Value 1-10, how strategig a player is, 10 means min. randomness
except: self.strategy_level = 5 #Medium startegy
if self.strategy_level < 1: self.strategy_level = 1
if self.strategy_level > 10: self.strategy_level = 10
#Calculate Random Weight, for target_attack_score function
#random factor between 1 and the RandomWeight
#Random Weight of 0 is no random, should not be
#Random Weight around 2 is average
self.random_weight = 38.4/(self.strategy_level+2.47)-2.95
#Position management
self.speed = int(data['Speed'])
#positions: 0 - front line, 1 - mid, 2 - back line
self.position_txt = data['Position'] #front is default
self.base_position = 0
if 'middle' in self.position_txt:
self.base_position = 1
elif 'back' in self.position_txt:
self.base_position = 2
self.position = self.base_position #This position will be called
# airborn = 3 for player who can fly
#Can the Character use range attacks
self.range_attack = int(data['Range_Attack'])
if self.range_attack == 1:
self.has_range_attack = True
else:
self.has_range_attack = False
#Abilities and Stats
self.Str = int(data['Str'])
self.Dex = int(data['Dex'])
self.Con = int(data['Con'])
self.Int = int(data['Int'])
self.Wis = int(data['Wis'])
self.Cha = int(data['Cha'])
self.stats_list = [self.Str, self.Dex, self.Con, self.Int, self.Wis, self.Cha] #used for temp changes and request
self.base_stats_list = self.stats_list
self.modifier = [round((self.stats_list[i] -10)/2 -0.1, 0) for i in range(0,6)] #calculate the mod
self.base_modifier = self.modifier
#actually only the modifier are currently ever used
self.saves_prof = data['Saves_Proficiency'] #Already in Entity, not implementet in fight functions tho
#list for saves of all kind. if = 0, no advantage
#if > 0 has advantage
#if < 0 has disadvantage
self.HeroVillain = int(data['Hero_or_Villain'])
#Damage Types
self.damage_type = data['Damage_Type']
self.base_damage_type = self.damage_type
self.damage_resistances = data['Damage_Resistance']
self.base_damage_resistamces = self.damage_resistances
self.damage_immunity = data['Damage_Immunity']
self.base_damage_immunity = self.damage_immunity
self.damage_vulnerability = data['Damage_Vulnerabilities']
self.base_damage_vulnerability = self.damage_vulnerability
self.additional_resistances = '' #for rage and stuff
self.last_used_DMG_Type = data['Damage_Type']
#Spellcasting
self.spell_mod = int(data['Spell_Mod']) #spell modifier
self.spell_dc = int(data['Spell_DC']) #spell save DC
self.spell_slots = [int(data['Spell_Slot_' + str(i)]) for i in range(1,10)] #fixed spell slots available ( 0 - Level1, 1 - Level2, ...)
self.spell_slot_counter = [int(data['Spell_Slot_' + str(i)]) for i in range(1,10)] #current counter for used spell slots
#Spells known
self.spell_list = data['Spell_List']
#If this updates, the All_Spells in the GUI will load this
#Keep this in Order of the Spell Level, so that it also fits for the GUI
self.SpellNames = ['FireBolt', 'ChillTouch', 'EldritchBlast',
'BurningHands', 'MagicMissile', 'GuidingBolt', 'Entangle', 'CureWounds', 'HealingWord', 'Hex', 'ArmorOfAgathys', 'FalseLife', 'Shield', 'InflictWounds', 'HuntersMark',
'AganazzarsSorcher', 'ScorchingRay', 'Shatter', 'SpiritualWeapon',
'Fireball', 'LightningBolt', 'Haste', 'ConjureAnimals', 'CallLightning',
'Blight', 'SickeningRadiance', 'WallOfFire', 'Polymorph',
'Cloudkill']
#Add here all Spell classes that are impemented
self.Spell_classes = [firebolt, chill_touch, eldritch_blast,
burning_hands, magic_missile, guiding_bolt, entangle, cure_wounds, healing_word, hex, armor_of_agathys, false_life, shield, inflict_wounds, hunters_mark,
aganazzars_sorcher, scorching_ray, shatter, spiritual_weapon,
fireball, lightningBolt, haste, conjure_animals, call_lightning,
blight, sickeningRadiance, wallOfFire, polymorph,
cloudkill]
#A Spell Class will only be added to the spellbook, if the Spell name is in self.spell_list
self.SpellBook = dict()
for x in self.Spell_classes:
spell_to_lern = x(self) #Initiate Spell
if spell_to_lern.is_known: #If Spell is known, append to SpellBook
self.SpellBook[spell_to_lern.spell_name] = spell_to_lern
#Haste
self.is_hasted = False
self.haste_round_counter = 0 #when this counter hits 10, haste will wear off
#Hex
self.is_hexed = False
self.is_hexing = False
self.can_choose_new_hex = False
self.CurrentHexToken = False #This is the Hex Concentration Token
#Hunters Mark
self.is_hunters_marked = False
self.is_hunters_marking = False
self.can_choose_new_hunters_mark = False
self.CurrentHuntersMarkToken = False #This is the Hunters Mark Concentration Token
#Armor of Agathys
self.has_armor_of_agathys = False
self.agathys_dmg = 0
#Spiritual Weapon
self.has_spiritual_weapon = False
self.SpiritualWeaponDmg = 0
self.SpiritualWeaponCounter = 0
#Conjure Animals
self.is_summoned = False #if True it will be removed from fight after dead
self.summoner = False #general for all summoned entities
self.has_summons = False
#Guiding Bolt
self.is_guiding_bolted = False
#Chill Touch
self.chill_touched = False
#Cloudkill
self.is_cloud_killing = False
#sickening radiance
self.is_using_sickening_radiance = False
#Special Abilities
self.other_abilities = data['Other_Abilities']
#Action Surge
if 'ActionSurge' in self.other_abilities:
self.knows_action_surge = True
else: self.knows_action_surge = False
self.action_surges = int(data['ActionSurges']) #The base how many action surge the player has
self.action_surge_counter = self.action_surges
self.action_surge_used = False
#Improved Critical
if 'ImprovedCritical' in self.other_abilities:
self.knows_improved_critical = True
else:self.knows_improved_critical = False
#Second Wind
if 'SecondWind' in self.other_abilities:
self.knows_second_wind = True
else:
self.knows_second_wind = False
self.has_used_second_wind = False
#Archery
if 'Archery' in self.other_abilities:
self.knows_archery = True
else: self.knows_archery = False
#Great Weapon Fighting
if 'GreatWeaponFighting' in self.other_abilities:
self.knows_great_weapon_fighting = True
else: self.knows_great_weapon_fighting = False
#Interception
if 'Interception' in self.other_abilities:
self.knows_interception = True
else: self.knows_interception = False
self.interception_amount = 0 #is true if a interceptor is close, see end_of_turn
#UncannyDodge
if 'UncannyDodge' in self.other_abilities:
self.knows_uncanny_dodge = True
else:
self.knows_uncanny_dodge = False
#Cunning Action
self.knows_cunning_action = False
if 'CunningAction' in self.other_abilities:
self.knows_cunning_action = True
#Wails from the Grave
self.wailsfromthegrave = 0
self.wailsfromthegrave_counter = self.proficiency
if 'WailsFromTheGrave' in self.other_abilities:
self.wailsfromthegrave = 1 #is checked in Attack Function, wails from the grave adds just ot sneak attack at the moment, improvement maybe?
#Sneak Attack
self.sneak_attack_dmg = float(data['Sneak_Attack_Dmg']) #If Sneak_Attack is larger then 0, the Entity has sneak Attack
self.sneak_attack_counter = 1 #set 0 after sneak attack
#Assassinate
self.knows_assassinate = False
if 'Assassinate' in self.other_abilities:
self.knows_assassinate = True
#RecklessAttack
self.knows_reckless_attack = False
if 'RecklessAttack' in self.other_abilities:
self.knows_reckless_attack = True
self.reckless = 0 #while reckless, u have ad but attacks against u have too, must be called in Player AI
#Rage
self.knows_rage = False
self.rage_dmg = 0
if 'Rage' in self.other_abilities:
self.knows_rage = True
self.rage_dmg = float(data['RageDmg'])
self.raged = 0 # 1 if currently raging
self.rage_round_counter = 0
#Frenzy
self.knows_frenzy = False
if 'Frenzy' in self.other_abilities:
self.knows_frenzy = True
self.is_in_frenzy = False
if 'BearTotem' in self.other_abilities:
self.knows_bear_totem = True
else:
self.knows_bear_totem = False
if 'EagleTotem' in self.other_abilities:
self.knows_eagle_totem = True
else:
self.knows_eagle_totem = False
if 'WolfTotem' in self.other_abilities:
self.knows_wolf_totem = True
else:
self.knows_wolf_totem = False
self.has_wolf_mark = False #Is true if you were attacked last by a Totel of the Wolf barbarian
#Lay On Hands
self.lay_on_hands = int(data['Lay_on_Hands_Pool']) #pool of lay on hands pool
self.lay_on_hands_counter = self.lay_on_hands #lay on hands pool left
#Smite
self.knows_smite = False
if 'Smite' in self.other_abilities:
self.knows_smite = True
#Aura of Protection
self.knows_aura_of_protection = False
if 'AuraOfProtection' in self.other_abilities:
self.knows_aura_of_protection = True
#Is implemented in the do_your_turn function via area of effect chooser
#Inspiration
if 'Inspiration' in self.other_abilities:
self.knows_inspiration = True
self.inspiration_die = int(data['Inspiration'])
if self.inspiration_die not in [0,2,3,4,5,6]:
self.inspiration_die = 0
else:
self.knows_inspiration = False
self.inspiration_die = 0
self.inspired = 0 #here the amount a target is inspired
if self.modifier[5] > 0: self.base_inspirations = self.modifier[5]
else: self.base_inspirations = 1
self.inspiration_counter = self.base_inspirations #for baric inspiration char mod
#Combat Inspiration
if 'CombatInspiration' in self.other_abilities:
self.knows_combat_inspiration = True
else: self.knows_combat_inspiration = False
self.is_combat_inspired = False
if 'CuttingWords' in self.other_abilities:
self.knows_cutting_words = True
else: self.knows_cutting_words = False
#ChannelDevinity
self.channel_divinity_counter = int(data['ChannelDivinity'])
if self.channel_divinity_counter > 0:
self.knows_channel_divinity = True
else:
self.knows_channel_divinity = False
#Turn Undead
if 'TurnUndead' in self.other_abilities:
self.knows_turn_undead = True
else:
self.knows_turn_undead = False
self.is_a_turned_undead = False
self.turned_undead_round_counter = 0
#DestroyUndead
self.destroy_undead_CR = float(data['DestroyUndeadCR'])
#Agonizing Blast
self.knows_agonizing_blast = False
if 'AgonizingBlast' in self.other_abilities:
self.knows_agonizing_blast = True
#Primal Companion
try: self.favored_foe_dmg = float(data['FavoredFoeDmg'])
except: self.favored_foe_dmg = 0
self.knows_favored_foe = False
self.favored_foe_counter = self.proficiency
self.has_favored_foe = False
if self.favored_foe_dmg > 0: self.knows_favored_foe = True
self.knows_primal_companion = False
self.used_primal_companion = False #only use once per fight
if 'PrimalCompanion' in self.other_abilities:
self.knows_primal_companion = True
self.primal_companion = False
self.knows_beastial_fury = False
if 'BestialFury' in self.other_abilities:
self.knows_beastial_fury = True
#Feats
#Great Weapon Master
self.knows_great_weapon_master = False
if 'GreatWeaponMaster' in self.other_abilities:
self.knows_great_weapon_master = True
self.has_additional_great_weapon_attack = False
self.knows_polearm_master = False
if 'PolearmMaster' in self.other_abilities:
self.knows_polearm_master = True
poleArmDMG = 2.5 + max(self.base_modifier[0], self.base_modifier[1]) #Dex or Str
if self.offhand_dmg < poleArmDMG:
self.offhand_dmg = poleArmDMG #1d4 + attack mod
#Meta Magic
self.sorcery_points_base = int(data['Sorcery_Points'])
self.sorcery_points = self.sorcery_points_base
self.knows_quickened_spell = False
if 'QuickenedSpell' in self.other_abilities:
self.knows_quickened_spell = True
self.quickened_spell = 0 #if 1 a Action Spell will be casted as BA, can be called as via quickened Spell function from spell class
self.knows_empowered_spell = False
if 'EmpoweredSpell' in self.other_abilities:
self.knows_empowered_spell = True
self.empowered_spell = False #if True, the next Spell will ne empowered (20% mehr dmg)
self.knows_twinned_spell = False
if 'TwinnedSpell' in self.other_abilities:
self.knows_twinned_spell = True
# Ki Points
try: self.ki_points_base = int(data['Ki_Points'])
except: self.ki_points_base = 0
self.ki_points = self.ki_points_base
self.ki_save_dc = 8 + self.proficiency + self.modifier[4]
self.knows_deflect_missiles = False
if 'DeflectMissiles' in self.other_abilities:
self.knows_deflect_missiles = True
self.knows_flurry_of_blows = False
if 'FlurryOfBlows' in self.other_abilities:
self.knows_flurry_of_blows = True
self.knows_patient_defense = False
if 'PatientDefense' in self.other_abilities:
self.knows_patient_defense = True
self.knows_step_of_the_wind = False
if 'StepOfTheWind' in self.other_abilities:
self.knows_step_of_the_wind = True
self.knows_stunning_strike = False
if 'StunningStrike' in self.other_abilities:
self.knows_stunning_strike = True
self.knows_open_hand_technique = False
if 'OpenHandTechnique' in self.other_abilities:
self.knows_open_hand_technique = True
#Monster Abilites
self.knows_dragons_breath = False
if 'DragonsBreath' in self.other_abilities:
self.knows_dragons_breath = True
self.knows_spider_web = False
if 'SpiderWeb' in self.other_abilities:
self.knows_spider_web = True
self.knows_poison_bite = False
self.poison_bites = 1 #Only once per turn
self.poison_bite_dmg = 0 #dmg of poison bite
self.poison_bite_dc = 0
if 'PoisonBite' in self.other_abilities:
self.knows_poison_bite = True
#Dmg roughly scales with Level
self.poison_bite_dmg = 8 + self.level*3
self.poison_bite_dc = int(11.1 + self.level/3)
self.knows_recharge_aoe = False
if 'RechargeAOE' in self.other_abilities:
self.knows_recharge_aoe = True
try: self.aoe_recharge_dmg = data['AOERechargeDmg']
except: self.aoe_recharge_dmg = 0
try: self.aoe_recharge_dc = int(data['AOERechargeDC'])
except: self.aoe_recharge_dc = 0
try: self.aoe_save_type = int(data['AOESaveType']) #0 - Str, 1 - Dex, ...
except: self.aoe_save_type = 0
try: self.aoe_recharge_area = int(data['AOERechargeArea'])
except: self.aoe_recharge_area = 0
try:
self.aoe_recharge_propability = float(data['AOERechargePropability'])
if self.aoe_recharge_propability > 1: self.aoe_recharge_propability = 1
if self.aoe_recharge_propability < 0: self.aoe_recharge_propability = 0
except: self.aoe_recharge_propability = 0
try: self.aoe_recharge_type = data['AOERechargeType']
except: self.aoe_recharge_type = 'fire'
try: self.start_of_turn_heal = int(data['StartOfTurnHeal'])
except: self.start_of_turn_heal = 0 #heals this amount at start of turn
try: self.legendary_resistances = int(data['LegendaryResistances'])
except: self.legendary_resistances = 0
self.legendary_resistances_counter = self.legendary_resistances
#Wild Shape / New Shapes
self.shape_name = ''
self.shape_remark = ''
self.is_shape_changed = False
self.is_in_wild_shape = False
self.BeastForms = {
0:{'Name': 'Wolf', 'Level': 0.25},
1:{'Name': 'Brown Bear', 'Level': 1},
2:{'Name': 'Crocodile', 'Level': 0.5},
3:{'Name': 'Ape', 'Level': 0.5},
4:{'Name': 'Giant Eagle', 'Level': 1},
5:{'Name': 'Giant Boar', 'Level': 2},
6:{'Name': 'Polar Bear', 'Level': 2},
7:{'Name': 'Boar', 'Level': 0.25}
}
self.DruidCR = 0
self.knows_wild_shape = False
if 'WildShape' in self.other_abilities:
self.knows_wild_shape = True
self.DruidCR = float(data['DruidCR']) #This is the max CR in which the druid can wild shape
if self.DruidCR < 0.25: self.DruidCR = 0.25 #min CR
self.knows_combat_wild_shape = False
if 'CombatWildShape' in self.other_abilities:
self.knows_combat_wild_shape = True
self.shape_HP = 0 #temp HP of the current (different) shape
self.wild_shape_uses = 2
#Fight Counter
self.state = 1 # 1 - alive, 0 - uncouncious, -1 dead
self.death_counter = 0
self.heal_counter = 0
self.CHP = self.HP #CHP - current HP
self.THP = 0 #Temporary HitPoints (dont stack)
self.initiative = 0
self.attack_counter = self.attacks #will be reset to attack at start of turn
self.is_attacking = False #Is set true if player has used acktion to attack
self.unconscious_counter = 0 #This counts how often the player was unconscious in the fight for the statistics
self.action = 1
self.bonus_action = 1
self.reaction = 1
self.has_cast_left = True #if a spell is cast, hast_cast_left = False
self.is_concentrating = False
#Conditions
self.restrained = False #will be ckeckt wenn attack/ed, !!!!!!!!! only handle via Tokens
self.prone = 0
self.is_blinded = False #tokensubtype bl
self.is_dodged = False #is handled by the DodgedToken
self.is_stunned = False #tokensubtype st
self.is_incapacitated = False #tokensubtype ic
self.is_paralyzed = False #tokensubtype pl
self.is_poisoned = False #tokensubtype ps
self.is_invisible = False #tokensubtype iv
self.last_attacker = 0
self.dmg_dealed = 0
self.heal_given = 0
self.dash_target = False
self.has_dashed_this_round = False
self.no_attack_of_opportunity_yet = True
self.dragons_breath_is_charged = False
self.spider_web_is_charged = False
self.recharge_aoe_is_charged = False
#AI
self.AI = AI(self)
def rollD20(self, advantage_disadvantage=0): #-1 is disadvantage +1 is advantage
d20_1 = int(random()*20 + 1)
d20_2 = int(random()*20 + 1)
if advantage_disadvantage > 0:
d20 = max([d20_1, d20_2])
elif advantage_disadvantage < 0:
d20 = min([d20_1, d20_2])
else:
d20 = d20_1
#Inspiration hits here, at the top most layer of this simulation, creazy isnt it
if self.inspired != 0:
#Only use it if roll is low, but not that low
if d20 < 13 and d20 > 6:
d20 += self.inspired
self.inspired = 0
self.is_combat_inspired = False
self.DM.say('(with inspiration), ')
return d20
#---------------------Character State Handling----------------
def unconscious(self):
self.DM.say(self.name + ' is unconscious ', True)
self.CHP = 0
self.state = 0 # now unconscious
self.unconscious_counter += 1 #for statistics
#if u get uncounscious:
self.end_rage()
self.break_concentration()
self.TM.unconscious()
if self.team == 1: #this is for Monsters
self.state = -1
def get_conscious(self):
self.DM.say(self.name + ' regains consciousness', True)
self.state = 1
self.heal_counter = 0
self.death_counter = 0
def death(self):
self.CHP = 0
self.state = -1
#if u die:
self.end_rage()
self.break_concentration()
self.TM.death()
def check_uncanny_dodge(self, dmg):
#-----------Uncanny Dodge
if self.knows_uncanny_dodge:
if dmg.abs_amount() > 0 and self.reaction == 1 and self.state == 1: #uncanny dodge condition
dmg.multiply(1/2) #Uncanny Dodge halfs all dmg
self.reaction = 0
self.DM.say(' Uncanny Dodge')
def check_new_state(self, was_ranged):
#State Handling after Changing CHP
#----------State Handling Unconscious
if self.state == 0: #if the player is dying
if self.CHP > 0: #was healed over 0
self.get_conscious()
if self.CHP <0:
if self.CHP < -1*self.HP:
self.death()
self.DM.say(str(self.name) + ' died due to the damage ', True)
else:
self.CHP = 0
if was_ranged:
self.death_counter += 1
else: #melee is auto crit
self.death_counter += 2
if self.death_counter >= 3:
self.death()
self.DM.say(str(self.name) + ' was attacked and died', True)
else:
self.DM.say(str(self.name) + ' death saves at ' + self.StringDeathCounter(), True)
#----------State handling alive
if self.state == 1: #the following is if the player was alive before
if self.CHP < 0-self.HP: #if more then -HP dmg, character dies
self.death()
self.DM.say(str(self.name) + ' died due to the damage ', True)
if self.CHP <= 0 and self.state != -1: #if below 0 and not dead, state dying
self.unconscious()
def changeCHP(self, Dmg, attacker, was_ranged):
self.check_uncanny_dodge(Dmg)
damage = Dmg.calculate_for(self) #call dmg class, does the Resistances
#This calculates the total dmg with respect to resistances
#-----------Statistics
if damage > 0:
attacker.dmg_dealed += damage
if attacker.is_summoned: #Append the dmg of summons to summoner
attacker.summoner.dmg_dealed += damage
attacker.last_used_DMG_Type = Dmg.damage_type()
elif damage < 0:
attacker.heal_given -= damage
#---------Damage Deal
AgathysDmg = dmg() #0 dmg
if damage > 0: #if damage, it will be checkt if wild shape HP are still there
if self.is_a_turned_undead:
self.end_turned_undead()
self.make_concentration_check(damage) #Make Concentration Check for the dmg
#Concentration Checks are done in and outside of wild shape/other shapes
if self.is_shape_changed:
self.change_shape_HP(damage, attacker, was_ranged)
#Not checking resistances anymore, already done
else:
if self.THP > 0: #Temporary Hitpoints
AgathysDmg = self.check_for_armor_of_agathys() #returns the agathys dmg
if damage < self.THP: #Still THP
self.THP -= damage
self.DM.say(self.name + ' takes DMG: ' + Dmg.text() + 'now: ' + str(round(self.CHP,2)) + ' + ' + str(round(self.THP,2)) + ' temporary HP', True)
damage = 0
else: #THP gone
damage = damage - self.THP #substract THP
self.THP = 0
self.DM.say('temporaray HP empty, ')
#Change CHP
if damage > 0: #If still damage left
self.CHP -= damage
self.DM.say(self.name + ' takes DMG: ' + Dmg.text() + 'now at: ' + str(round(self.CHP,2)), True)
#---------Armor of Agathys
if AgathysDmg.abs_amount() > 0 and was_ranged == False:
self.DM.say(attacker.name + ' is harmed by the Armor of Agathys', True)
attacker.changeCHP(AgathysDmg, self, was_ranged=False)
#---------Heal
if damage < 0: #neg. damage is heal Currently Heal is always applied to CHP never to shape HP
if self.state == -1:
print('This is stupid, dead cant be healed', True)
quit()
if self.chill_touched:
self.DM.say(self.name + ' is chill touched and cant be healed.')
elif abs(self.HP - self.CHP) >= abs(damage):
self.CHP -= damage
self.DM.say(str(self.name) + ' is healed for: ' + str(-damage) + ' now at: ' + str(round(self.CHP,2)), True)
else: #if more heal then HP, only fill HP up
damage = -1*(self.HP - self.CHP)
self.CHP -= damage
self.DM.say(str(self.name) + ' is healed for: ' + str(-damage) + ' now at: ' + str(round(self.CHP,2)), True)
self.check_new_state(was_ranged)
def change_shape_HP(self, damage, attacker, was_ranged):
if damage < self.shape_HP: #damage hits the wild shape
self.shape_HP -= damage
self.DM.say(str(self.name) + ' takes damage in ' + self.shape_remark + ' shape: ' + str(round(damage,2)) + ' now: ' + str(round(self.shape_HP,2)), True)
else: #wild shape breakes, overhang goes to changeCHP
overhang_damage = abs(self.shape_HP - damage)
#reshape after critical damage
self.DM.say(str(self.name) + ' ' + self.shape_remark + ' shape breaks ', True)
self.drop_shape() #function that resets the players stats
#Remember, this function is called in ChangeCHP, so resistances and stuff has already been handled
#For this reason a 'true' dmg type is passed here
Dmg = dmg(overhang_damage, 'true')
self.changeCHP(Dmg, attacker, was_ranged)
def addTHP(self, newTHP):
if self.THP == 0: #currently no THP
self.THP = newTHP
elif self.has_armor_of_agathys:
self.THP = newTHP
self.break_armor_of_agathys()
#New THP will break the Armor
else:
self.THP = newTHP
self.DM.say(self.name + ' gains ' + str(newTHP) + ' temporary HP', True)
def stand_up(self):
rules = [self.prone == 1, self.restrained == 0]
errors = [self.name + ' tried to stand up but is not prone',
self.name + ' tried to stand up, but is restrained']
ifstatements(rules, errors, self.DM).check()
self.prone = 0
self.DM.say(self.name + ' stood up to end prone', True)
def dps(self):
#DPS is a reference used to determine the performance of the player so far in the fight
#It is used by some AI functions to determine the value of the target in a fight
#This Function returns a value for the dps
#Heal is values 2 times dmg
return (self.dmg_dealed + self.heal_given*2)/self.DM.rounds_number
def value(self):
#This function is designed to help decision making in AI
#It returns a current, roughly dmg equal score of the entity to compare how important it is for the team
#Score that should be roughly a dmg per round equal value
Score = self.dps() #see .dps() func, is dmg and heal*2 per turn
if self.is_invisible:
Score = Score*1.2
if self.is_hasted:
Score = Score*1.1
if self.prone == 1:
Score = Score*0.95
if self.restrained == 1:
Score = Score*0.9
if self.is_blinded:
Score = Score*0.9
if self.is_poisoned:
Score = Score*0.95
if self.is_incapacitated:
Score = Score*0.2
if self.is_stunned:
Score = Score*0.15
if self.is_paralyzed:
Score = Score*0.1
return Score
def update_additional_resistances(self):
#If this function is called it checks all possible things that could add a resisantace
self.additional_resistances = ''
if self.raged == 1:
self.additional_resistances += 'piercing, bludgeoning, slashing, '
if self.knows_bear_totem:
self.additional_resistances += 'acid, cold, fire, force, lightning, thunder, necrotic, poison, radiant'
#---------------------Checks and Saves
def make_check(self, which_check): #0-Str, 1-Dex, ...
d20_roll = self.rollD20()
result = d20_roll + self.modifier[which_check] #calc modifier
return result
def check_advantage(self, which_save, extraAdvantage = 0, notSilent = True):
saves_adv_dis = [0,0,0,0,0,0] #calculate all factors to saves:
text = '' #collect text to say
if self.restrained == 1: #disadvantage in dex if restrained
saves_adv_dis[1] -= 1
text += 'restrained, '
if self.is_dodged:
saves_adv_dis[1] += 1 #dodge adv on dex save
text += 'dodged, '
if self.raged == 1: #str ad if raged
saves_adv_dis[0] += 1
text += 'raging, '
if self.is_hasted:
saves_adv_dis[1] += 1
text += 'hasted, '
if self.is_hexed:
HexType = int(random()*2 + 1) #random hex disad at Str, Dex or Con
HexText = ['Str ', 'Dex ', 'Con ']
text += 'hexed ' + HexText[HexType] + ', '
saves_adv_dis[HexType] -= 1 #one rand disad
if extraAdvantage != 0: #an extra, external source of advantage
if extraAdvantage > 0:
text += 'adv, '
else:
text += 'disad, '
if notSilent: self.DM.say(text) #only if not silent
return saves_adv_dis[which_save] + extraAdvantage
def make_save(self, which_save, extraAdvantage = 0, DC = False): #0-Str, 1-Dex, 2-Con, 3-Int, 4-Wis, 5-Cha
#how to disadvantage and advantage here !!!
save_text = ['Str', 'Dex', 'Con', 'Int', 'Wis', 'Cha']
self.DM.say(str(self.name) + ' is ', True)
Advantage = self.check_advantage(which_save, extraAdvantage = extraAdvantage)
AuraBonus = self.protection_aura()
if AuraBonus > 0:
self.DM.say('in protection aura, ')
if Advantage < 0:
d20_roll = self.rollD20(advantage_disadvantage=-1)
self.DM.say('in disadvantage doing a ' + save_text[which_save] + ' save: ')
elif Advantage > 0:
d20_roll = self.rollD20(advantage_disadvantage=1)
self.DM.say('in advantage doing a ' + save_text[which_save] + ' save: ')
else:
d20_roll = self.rollD20(advantage_disadvantage=0)
self.DM.say('doing a ' + save_text[which_save] + ' save: ')
modifier = self.modifier[which_save]
if save_text[which_save] in self.saves_prof: #Save Proficiency
modifier += self.proficiency
result = d20_roll + modifier + AuraBonus #calc modifier
#Legendary Resistances
if result < DC and self.legendary_resistances_counter > 0:
self.legendary_resistances_counter -= 1
self.DM.say(self.name + ' uses a legendary resistance: ' + str(self.legendary_resistances_counter) + '/' + str(self.legendary_resistances))
return 10000 #make sure to pass save
else:
#Just display text
roll_text = str(int(d20_roll)) + ' + ' + str(int(modifier))
if AuraBonus != 0: roll_text += ' + ' + str(int(AuraBonus))
if DC != False: roll_text += ' / ' + str(DC) + ' '
self.DM.say(roll_text)
return result
def make_death_save(self):
d20_roll = int(random()*20 + 1)
AuraBonus = self.protection_aura()
if AuraBonus > 0:
d20_roll += AuraBonus
self.DM.say(''.join(['Aura of protection +',str(int(AuraBonus)),' : ']), True)
self.DM.say(self.StringDeathCheck(d20_roll), True)
if self.death_counter >= 3:
self.death()
self.DM.say(str(self.name) + ' failed death save and died', True)
if self.heal_counter >= 3:
self.CHP = 1
self.get_conscious()
def StringDeathCheck(self, d20_roll):
if d20_roll < 11:
self.death_counter += 1
TextResult = str(self.name) + ' did not made the death save '
elif d20_roll > 10 and d20_roll != 20:
self.heal_counter += 1
TextResult = str(self.name) + ' made the death save'
if d20_roll == 20:
self.heal_counter += 2
TextResult = str(self.name) + ' made the death save critical'
TextResult += self.StringDeathCounter()
return TextResult
def StringDeathCounter(self):
text = '(' + str(self.death_counter) + '-/' + str(self.heal_counter) + '+)'
return text
#---------------Concentration and Conjuration Spells-----------
def make_concentration_check(self, damage):
if self.is_concentrating:
saveDC = 10
if damage/2 > 10: saveDC = int(damage/2)
save_res = self.make_save(2, DC=saveDC)
if save_res >= saveDC: #concentration is con save
return
else:
self.break_concentration()
return
else:
return
def break_concentration(self):
self.TM.break_concentration()
#Will test for concentration tokens
#If Concentration breaks, it will say so
def break_armor_of_agathys(self):
if self.has_armor_of_agathys and self.THP > 0:
self.has_armor_of_agathys = False
self.THP = 0
self.agathys_dmg = 0
self.DM.say(self.name + ' Armor of Agathys breaks, ')
else:
print(self.name + ' Armor of Agathys broke without having one')
quit()
def break_spiritual_weapon(self):
if self.has_spiritual_weapon:
self.has_spiritual_weapon = False
self.SpiritualWeaponCounter = 0 #reset counter
self.SpiritualWeaponDmg = 0
self.DM.say('Spiritual Weapon of ' + self.name + ' vanishes, ')
def end_turned_undead(self):
self.is_a_turned_undead == False #no longer turned
self.turned_undead_round_counter = 0
self.DM.say(self.name + ' is no longer turned', True)
#--------------------Position Management----------------------
def need_dash(self, target, fight, AttackIsRanged = False):
#0 - need no dash
#1 - need dash
#2 - not reachable
#ABack-25ft-AMid-25ft-AFront-BFront-25ft-BMid-25ft-BBack
#no Dash for ranged attacks
if AttackIsRanged: return 0
if self.has_range_attack: return 0
if target.position == 3: return 0 #Airborn is in range
#The Distance between lines scales with how dense the Battlefield is
# 0 Wide Space
# 1 normal
# 2 crowded
distance = 25
if self.DM.density == 0:
distance = 50
elif self.DM.density == 2:
distance = 12.5
EnemiesLeft = [x for x in fight if x.team != self.team and x.state == 1]
EnemiesInFront = [Enemy for Enemy in EnemiesLeft if Enemy.position == 0]
EnemiesInMid = [Enemy for Enemy in EnemiesLeft if Enemy.position == 1]
if self.position < 3: #0,1,2 Front, Mid, Back
if len(EnemiesInFront) == 0 and len(EnemiesInMid) == 0: OpenLines=2 #open Front and Mid
elif len(EnemiesInFront) == 0: OpenLines = 1 #open front
else: OpenLines = 0 #no open line
if self.position == 3: #airborn
if target.position < 3: OpenLines=3 #basically 3 open lines
else: return 0
#Test if Dash is ness
#example: Mid Attacks Mid, no open front: 1 + 1 = 2*25ft = 50ft
if self.speed >= (target.position + self.position - OpenLines)*distance: return 0
elif self.dash_target == target: return 0 #The player has used dash last round to get to this target
#Only works if you can still dash with action or cunning action or eagle totem
elif self.action == 1 or (self.knows_cunning_action and self.bonus_action ==1) or (self.knows_eagle_totem and self.bonus_action ==1):
if 2*self.speed >= (target.position + self.position - OpenLines)*distance: return 1
else: return 2
else: return 2
def will_provoke_Attack(self, target, fight, AttackIsRanged = False):
#this function tells if an attack of opportunity will be provoked
if AttackIsRanged: return False
if self.has_range_attack: return False
if self.dash_target == target: return False
EnemiesLeft = [x for x in fight if x.team != self.team and x.state == 1]
EnemiesInFront = [Enemy for Enemy in EnemiesLeft if Enemy.position == 0]
EnemiesInMid = [Enemy for Enemy in EnemiesLeft if Enemy.position == 1]
#Open Lines
if self.position < 3: #0,1,2 Front, Mid, Back
if len(EnemiesInFront) == 0 and len(EnemiesInMid) == 0: return False #open Front and Mid
elif len(EnemiesInFront) == 0: OpenLines = 1 #open front
else: OpenLines = 0 #no open line
if self.position == 3: return False #no opp. attacks from the air
#Compare Lines
#if you cross more then 2 lines (like, front - back or mid - mid) you provoke opp. attack
if self.position == 2:
OpenLines += 1 #back Player can attack Front with no Opp Attack
if self.position + target.position - OpenLines >= 2:
return True
else: return False
def use_disengage(self):
if self.bonus_action == 1 and self.knows_cunning_action:
self.DM.say(self.name + ' used cunning action to disengage', True)
self.bonus_action = 0
elif self.action == 1:
self.DM.say(self.name + ' used an action to disengage', True)
self.action = 0
else:
print(self.name + ' tried to disengage, but has no action left', True)
quit()
def enemies_reachable_sort(self,fight, AttackIsRanged = False):
#This function is used to determine which Enemies are theoretically in reach to attack for a Player
#This also includes Players, that are only reachable by dashing or by provoking attacks of Opportunity
#The following Rules Apply
#----------0---------
#Front can always melee attack the other front
#Front can attack the other mid, if the player speed suffice
#Front can attack the other back, if player speed suffice and by provoking an opportunity attack
#If there is no Player in the other Front, the Front can melee attack mid and back
#If there is no front, the distance to mid and back reduces
#----------1---------
#mid can meelee attack front
#mid can attack mid, if speed suffices, and by provoking an opportunity attack
#If there is no Player in the other Front, the mid can melee attack mid and back
#If there is no Player in the other Front and Mid, mid can attack all
#----------2---------
#back can attack Front
#----------3---------
#airborn can melee attack all, but must land for that
#if airborn lands, it is then in front
#Airborn can not be attacked by melee at this point
#----------R---------
#If player has reanged attacks, player can attack all regardless
#Idea: Line Airborn, only hittable by ranged
#At the start of turn, a creature desides to go airborn or land
#This includes Character Players that are unconscious
EnemiesNotDead = [x for x in fight if x.team != self.team and (x.state == 1 or (x.team != 1 and x.state == 0))]
if AttackIsRanged: return EnemiesNotDead #Everyone in Range
if self.has_range_attack: return EnemiesNotDead #Everyone in Range