-
Notifications
You must be signed in to change notification settings - Fork 1
/
proficiencies.py
230 lines (180 loc) · 6.69 KB
/
proficiencies.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
__filename__ = "proficiencies.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.0.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "DnD Mechanics"
from random import randint
def _proficiency_name(prof: str) -> str:
if '(' not in prof:
return prof
return prof.split('(')[0].strip()
def _proficiency_param(prof: str) -> int:
if '(' not in prof:
return 0
return int(prof.split('(')[1].replace(')', '').strip())
def _prof_fighting_style_damage(id: int, players: {},
weapon_type: str, value: int) -> int:
if not players[id].get('fightingStyle'):
return 0
fight_style = players[id]['fightingStyle'].lower()
if fight_style == 'archery':
if 'bow' in weapon_type:
return 2
if fight_style.startswith('duel'):
if 'ranged' not in weapon_type:
if 'fist' not in weapon_type:
if players[id]['clo_lhand'] == 0 or \
players[id]['clo_rhand'] == 0:
return 2
return 0
def _damage_proficiency_item(prof: str, id: int, players: int,
weapon_type: str) -> int:
if isinstance(prof, list):
return 0
prof_name = _proficiency_name(prof)
prof_value = _proficiency_param(prof)
switcher = {
"Second Wind": _prof_second_wind,
# "Action Surge": _profActionSurge,
# "Martial Archetype": _profMartialArchetype,
# "Ability Score Improvement": _profAbilityScore,
# "Extra Attack": _profExtraAttack,
# "Martial Archetype feature": _profMartialArchetypeFeature,
"Indomitable": _prof_indomitable,
# "Spellcasting": _profSpellcasting,
# "Arcane Recovery": _profArcaneRecovery,
# "Arcane Tradition": _profArcaneTradition,
# "Arcane Tradition feature": _profArcaneTraditionFeature,
# "Spell Mastery": _profSpellMastery,
# "Signature Spell": _profSignatureSpell,
# "Cantrips": _profCantrips,
"Fighting Style": _prof_fighting_style_damage
}
if not switcher.get(prof_name):
return 0
try:
return switcher[prof_name](id, players, weapon_type, prof_value)
except Exception as ex:
print("_damage_proficiency_item error " + prof + ' ' + str(ex))
return 0
def damage_proficiency(id: int, players: {}, weapon_type: str,
character_class_db: {}) -> int:
if not players[id].get('race'):
return 0
player_race = players[id]['race']
if not character_class_db.get(player_race):
return 0
damage = 0
for lvl in range(1, players[id]['lvl']):
if not character_class_db[player_race].get(str(lvl)):
continue
prof_list = character_class_db[player_race][str(lvl)]
for plyr in prof_list:
damage = damage + \
_damage_proficiency_item(plyr, id, players, weapon_type)
return damage
def _prof_second_wind(id: int, players: {}, prof_value: int) -> int:
if players[id]['restRequired'] != 0:
return 0
players[id]['restRequired'] = 1
return randint(1, 10)
def _prof_indomitable(id: int, players: {}, prof_value: int) -> int:
if players[id]['restRequired'] != 0:
return 0
players[id]['restRequired'] = 1
return randint(1, 10)
def _defense_proficiency_item(prof: str, id: int, players: {}) -> int:
"""TODO: currently unused
"""
if isinstance(prof, list):
return 0
prof_name = _proficiency_name(prof)
prof_value = _proficiency_param(prof)
switcher = {
"Second Wind": _prof_second_wind,
# "Arcane Recovery": _profArcaneRecovery,
"Indomitable": _prof_indomitable
}
if not switcher.get(prof_name):
return 0
try:
return switcher[prof_name](id, players, prof_value)
except BaseException as ex:
print("_defense_proficiency_item error " + prof + ' ' + str(ex))
return 0
def _weapon_proficiency_item(prof: str, id: int, players: {},
weapon_type: str) -> int:
if isinstance(prof, list):
return 0
prof_name = _proficiency_name(prof)
prof_value = _proficiency_param(prof)
switcher = {
# "Second Wind": _prof_second_wind
}
if not switcher.get(prof_name):
return 0
try:
return switcher[prof_name](id, players, prof_value)
except BaseException as ex:
print("_weapon_proficiency_item error " + prof + ' ' + str(ex))
return 0
def weapon_proficiency(id: int, players: {}, weapon_type: str,
character_class_db: {}) -> int:
"""TODO: currently unused
"""
if not players[id].get('race'):
return 0
player_race = players[id]['race']
if not character_class_db.get(player_race):
return 0
competence = int(players[id]['lvl']) - 1
for lvl in range(1, players[id]['lvl']):
if character_class_db[player_race].get(str(lvl)):
prof_list = character_class_db[player_race][str(lvl)]
for prf in prof_list:
competence = competence + \
_weapon_proficiency_item(prf, id, players, weapon_type)
if competence > 4:
competence = 4
return competence
def _thieves_cant_count_chars(txt: str) -> int:
result = 0
for char in txt.lower():
if char in ('a', 'e', 'i', 'o', 'u'):
result += 1
return result
def thieves_cant(spoken_text: str) -> str:
cant_code = (
"Hey, girl, hey!",
"Look what the cat dragged in",
"Yo ho",
"Is that you?",
"What do we have here?",
"Ain’t you a sight for sore eyes",
"My, my, don’t that beat all",
"Well aren’t you a piece of work",
"Howdy Pardner",
"At your service",
"Cheerio, old chap",
"You got some fried potatoes to go with that Lamb Chop?",
"You got some fried potatoes to go with that Beefcake?",
"Hey, beautiful",
"Hey, handsome",
"‘Ello Guv’nor",
"I haven’t seen you in 6 months",
"Wow, it’s been a few years",
"Can you believe it’s been over 10 years?",
"Seems like you left the village a lifetime ago",
"Gosh, it feels like forever since I’ve seen you",
"Will I see you at the harvest festival " +
"(or any other hometown gathering) this year?",
"Yes, I’ll be there",
"No, I am otherwise engaged",
"Give my regards to your Granny",
"…and have your pets spayed")
index = (_thieves_cant_count_chars(spoken_text) +
len(spoken_text.split(' '))) % len(cant_code)
return cant_code[index]