-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypher.py
718 lines (612 loc) · 26 KB
/
cypher.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
import pandas as pd
import random
import ast
import csv
cypher_df = pd.read_csv('Cypher/Cyphers.csv')
abilities_df = pd.read_excel('Cypher/All_Abilities.xlsx')
character_sheet_path = 'Cypher/Character_Sheets.xlsx'
init_sheet = 'Cypher/initiative_tracking_sheet.csv'
# For rolling a d20 with Cypher formatting
def print_roll(difficulty, training, assets, effort):
valid_difficulty = {0:'Routine', 1:'Simple', 2:'Standard', 3:'Demanding', 4:'Difficult', 5:'Challenging', 6:'Intimidating', 7:'Formidable', 8:'Heroic', 9:'Immortal', 10:'Impossible'}
valid_training = {-1:'Inability', 0:'Untrained', 1:'Trained', 2:'Specialized'}
valid_assets = [0, 1, 2]
valid_effort = [0, 1, 2, 3, 4, 5, 6]
## Sanity Checks
if difficulty not in valid_difficulty.keys():
output = "That is not a valid difficulty!"
return output
if training not in valid_training.keys():
output = "That is not a valid skill level!"
return output
if assets not in valid_assets:
output = "That is not a valid number of assets!"
return output
if effort not in valid_effort:
output = "That is not a valid level of effort!"
return output
special_message = ""
success = 0
roll = random.randint(1,20)
meet_or_beat = (difficulty - training - assets - effort) * 3
if roll >= meet_or_beat:
success = 1
if roll == 1:
special_message = "***GM INTRUSION...***"
if roll == 17:
special_message = "If this roll was an attack, deal +1 damage."
if roll == 18:
special_message = "If this roll was an attack, deal +2 damage."
if roll == 19:
special_message = "If this roll was an attack, deal +3 damage. Otherwise, you get a minor effect!"
if roll == 20:
special_message = "If this roll was an attack, deal +4 damage. Otherwise, you get a major effect!"
if effort == 0:
cost = 0
if effort > 0:
cost = (effort*2) + 1
if special_message == "" and success == 1 and effort > 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}... Success!
Pool Cost: {} - Edge""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, cost)
return output
if special_message == "" and success == 1 and effort == 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}... Success!""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat)
return output
if special_message == "" and success == 0 and effort > 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}...
Pool Cost: {} - Edge""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, cost)
return output
if special_message == "" and success == 0 and effort == 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}...""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat)
return output
if special_message != "" and success == 1 and effort > 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}... Success!
Pool Cost: {} - Edge
{}""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, cost, special_message)
return output
if special_message != "" and success == 1 and effort == 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}... Success!
{}""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, special_message)
return output
if special_message != "" and success == 0 and effort > 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}...
Pool Cost: {} - Edge
{}""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, cost, special_message)
return output
if special_message != "" and success == 0 and effort == 0:
output = """>>> __**Roll Results:**__
Roll: {}
{}, {}, {} assets, {} effort
Number to Beat: {}...
{}""".format(roll, valid_difficulty[difficulty], valid_training[training], assets, effort, meet_or_beat, special_message)
return output
# For rolling xdx (nothing fancy here but crit failing)
def roll(num, sides):
n = int(num)
s = int(sides)
rolls = []
for i in range(n):
rolls.append(random.randint(1, s))
val = sum(rolls)
if n == 1 and sum(rolls) == 1:
return("Ouch, crit fail. You rolled a **1**. Better luck next time!")
else:
return("Rolling " + str(num) + "d" + str(sides) + ": **" + str(val) + "**")
# For rolling a random cypher from cypher_df
def cypher_level_roller(str):
n,s = str.split('d')
n = int(n)
s = int(s)
rolls = []
for i in range(n):
rolls.append(random.randint(1, s))
val = sum(rolls)
return val
def print_cypher():
cypher_num = random.randint(0, 54)
cypher_row = cypher_df.iloc[[cypher_num]]
cypher = cypher_row.values.tolist()[0]
output = """>>> __**{}**__
*{}*
{}
Level: {}""".format(cypher[0], cypher[1], cypher[2], cypher_level_roller(cypher[3]))
return output
# For looking up a specific Cypher ability
def print_ability(ability):
if ability not in abilities_df['Ability'].tolist():
output = "Sorry, {} was not found. Check your spelling and capitalization, or tell Shrani to fix it.".format(ability)
return output
cost = abilities_df.loc[abilities_df['Ability'] == ability, 'Cost'].item()
pool = abilities_df.loc[abilities_df['Ability'] == ability, 'Pool'].item()
desc = abilities_df.loc[abilities_df['Ability'] == ability, 'Description'].item()
if cost == 0:
output = """>>> __**{}**__
{}""".format(ability, desc)
else:
output = """>>> __**{}**__
Cost: {} {}
{}""".format(ability, cost, pool, desc)
return output
def list_ability():
abilities_df = pd.read_excel(character_sheet_path)
ability_list = abilities_df['Ability'].tolist()
return ability_list
# For Cypher character sheet lookups
def profile(name):
character_df = pd.read_excel(character_sheet_path)
# Pretty-prints character profile
full = character_df.loc[character_df['name'] == name, 'Full_Name'].item()
desc = character_df.loc[character_df['name'] == name, 'Descriptor'].item()
ctype = character_df.loc[character_df['name'] == name, 'Type'].item()
focus = character_df.loc[character_df['name'] == name, 'Focus'].item()
flav = character_df.loc[character_df['name'] == name, 'Flavor'].item()
tier = character_df.loc[character_df['name'] == name, 'Tier'].item()
effort = character_df.loc[character_df['name'] == name, 'Effort'].item()
xp = character_df.loc[character_df['name'] == name, 'XP'].item()
m_c = character_df.loc[character_df['name'] == name, 'Might_C'].item()
m_p = character_df.loc[character_df['name'] == name, 'Might_P'].item()
m_e = character_df.loc[character_df['name'] == name, 'Might_E'].item()
s_c = character_df.loc[character_df['name'] == name, 'Speed_C'].item()
s_p = character_df.loc[character_df['name'] == name, 'Speed_P'].item()
s_e = character_df.loc[character_df['name'] == name, 'Speed_E'].item()
i_c = character_df.loc[character_df['name'] == name, 'Int_C'].item()
i_p = character_df.loc[character_df['name'] == name, 'Int_P'].item()
i_e = character_df.loc[character_df['name'] == name, 'Int_E'].item()
cond = condition_lookup(name)
output = """>>> __**{}**__
*{} {} who {}*
*{}*
__Tier: {} Effort: {} XP: {}__
Might | {} Pool: {} Edge: {}
Speed | {} Pool: {} Edge: {}
Intellect | {} Pool: {} Edge: {}
Condition: {}""".format(full, desc, ctype, focus, flav, tier, effort, xp, m_c, m_p, m_e, s_c, s_p, s_e, i_c, i_p, i_e, cond)
return output
def condition_lookup(name):
character_df = pd.read_excel(character_sheet_path)
m_c = character_df.loc[character_df['name'] == name, 'Might_C'].item()
s_c = character_df.loc[character_df['name'] == name, 'Speed_C'].item()
i_c = character_df.loc[character_df['name'] == name, 'Int_C'].item()
counter = 0
if m_c == 0:
counter += 1
if s_c == 0:
counter += 1
if i_c == 0:
counter += 1
if counter == 0:
condition = 'Hale'
if counter == 1:
condition = 'Impaired: Effort costs 1 extra point per level applied. Minor and major effects do not apply on your rolls.'
if counter == 2:
condition = 'Debilitated: You can only move, and only an immediate distance. If your Speed Pool is 0, you cannot move at all.'
if counter == 3:
condition = 'Dead.'
if counter not in [0, 1, 2, 3]:
condition = 'Lookup Failed'
return condition
def skills(name):
character_skills = pd.read_excel(character_sheet_path)
# Pretty-prints skills
full = character_skills.loc[character_skills['name'] == name, 'Full_Name'].item()
train = character_skills.loc[character_skills['name'] == name, 'Trained'].item()
spec = character_skills.loc[character_skills['name'] == name, 'Specialized'].item()
inab = character_skills.loc[character_skills['name'] == name, 'Inability'].item()
output = """>>> __**{}**__
Trained | {}
Specialized | {}
Inability | {}""".format(full, train, spec, inab)
return output
def abilities(name):
character_ab = pd.read_excel(character_sheet_path)
# Pretty-prints abilities
full = character_ab.loc[character_ab['name'] == name, 'Full_Name'].item()
abilities = character_ab.loc[character_ab['name'] == name, 'Abilities'].item()
output = """>>> __**{}**__
{}""".format(full, abilities)
return output
def equipment(name):
character_eq = pd.read_excel(character_sheet_path)
# Pretty-prints equpiment
full = character_eq.loc[character_eq['name'] == name, 'Full_Name'].item()
cypher = character_eq.loc[character_eq['name'] == name, 'Cypher'].item()
equip = character_eq.loc[character_eq['name'] == name, 'Equipment'].item()
output = """>>> __**{}**__
Cypher | {}
Equipment | {}""".format(full, cypher, equip)
return output
def notes(name):
character_df = pd.read_excel(character_sheet_path)
# Pretty-prints equpiment
full = character_df.loc[character_df['name'] == name, 'Full_Name'].item()
notes = character_df.loc[character_df['name'] == name, 'Notes'].item()
output = """>>> __**{}**__
{}""".format(full, notes)
return output
# For spending points
def spend(name, might=0, speed=0, intel=0, xp=0):
character_df = pd.read_excel(character_sheet_path)
m_c = character_df.loc[character_df['name'] == name, 'Might_C'].item()
s_c = character_df.loc[character_df['name'] == name, 'Speed_C'].item()
i_c = character_df.loc[character_df['name'] == name, 'Int_C'].item()
xp_c = character_df.loc[character_df['name'] == name, 'XP'].item()
new_mc = m_c - might
new_sc = s_c - speed
new_ic = i_c - intel
new_xp = xp_c - xp
if new_mc < 0 or new_sc < 0 or new_ic < 0 or new_xp < 0:
output = "Spending failed: not enough funds!"
return output
else:
character_df.loc[character_df['name'] == name, 'Might_C'] = new_mc
character_df.loc[character_df['name'] == name, 'Speed_C'] = new_sc
character_df.loc[character_df['name'] == name, 'Int_C'] = new_ic
character_df.loc[character_df['name'] == name, 'XP'] = new_xp
character_df.to_excel(character_sheet_path, index=False)
output = "Character updated accordingly."
return output
# For recovering points
def recover(name, might=0, speed=0, intel=0):
character_df = pd.read_excel(character_sheet_path)
m_c = character_df.loc[character_df['name'] == name, 'Might_C'].item()
s_c = character_df.loc[character_df['name'] == name, 'Speed_C'].item()
i_c = character_df.loc[character_df['name'] == name, 'Int_C'].item()
new_mc = m_c + might
new_sc = s_c + speed
new_ic = i_c + intel
m_p = character_df.loc[character_df['name'] == name, 'Might_P'].item()
s_p = character_df.loc[character_df['name'] == name, 'Speed_P'].item()
i_p = character_df.loc[character_df['name'] == name, 'Int_P'].item()
if new_mc > m_p or new_sc > s_p or new_ic > i_p:
output = "Recovery failed: Your pools won't hold those values!"
return output
else:
character_df.loc[character_df['name'] == name, 'Might_C'] = new_mc
character_df.loc[character_df['name'] == name, 'Speed_C'] = new_sc
character_df.loc[character_df['name'] == name, 'Int_C'] = new_ic
character_df.to_excel(character_sheet_path, index=False)
output = "Character updated accordingly."
return output
# For gaining XP
def add_xp(name, amount):
character_df = pd.read_excel(character_sheet_path)
xp_c = character_df.loc[character_df['name'] == name, 'XP'].item()
new_xp = xp_c + amount
character_df.loc[character_df['name'] == name, 'XP'] = new_xp
character_df.to_excel(character_sheet_path, index=False)
output = "XP awarded!"
return output
# For using XP to advance
def advance(name, pools=None, effort=None, edge=None, skill=None, other=None):
character_df = pd.read_excel(character_sheet_path)
tier = character_df.loc[character_df['name'] == name, 'Tier'].item()
effort_c = character_df.loc[character_df['name'] == name, 'Effort'].item()
xp = character_df.loc[character_df['name'] == name, 'XP'].item()
m_c = character_df.loc[character_df['name'] == name, 'Might_C'].item()
m_p = character_df.loc[character_df['name'] == name, 'Might_P'].item()
m_e = character_df.loc[character_df['name'] == name, 'Might_E'].item()
s_c = character_df.loc[character_df['name'] == name, 'Speed_C'].item()
s_p = character_df.loc[character_df['name'] == name, 'Speed_P'].item()
s_e = character_df.loc[character_df['name'] == name, 'Speed_E'].item()
i_c = character_df.loc[character_df['name'] == name, 'Int_C'].item()
i_p = character_df.loc[character_df['name'] == name, 'Int_P'].item()
i_e = character_df.loc[character_df['name'] == name, 'Int_E'].item()
advance = character_df.loc[character_df['name'] == name, 'Advancement'].item()
adv = ast.literal_eval(advance)
requested_advs = []
if pools is not None:
requested_advs.append('pool')
if effort is not None:
requested_advs.append('effort')
if edge is not None:
requested_advs.append('edge')
if skill is not None:
requested_advs.append('skill')
if other is not None:
requested_advs.append('other')
if len(requested_advs) > 3:
output="Please only request 3 or fewer advancements at once."
return output
else:
val=True
### Check adv against requested_advs
for req in requested_advs:
if req in adv:
output="You've already chosen one of these advancements for this tier. Stopping."
return output
xp_needed = len(requested_advs) * 4
if xp < xp_needed:
output="You don't have enough XP to advance in this way!"
return output
else:
val=True
if 'pool' in requested_advs:
if len(pools) == 4:
m_a, s_a, i_a = pool_parser(pools)
if m_a + s_a + i_a != 4:
output="Pool input invalid, stopping."
return output
else:
character_df.loc[character_df['name'] == name, 'Might_C'] = m_c + m_a
character_df.loc[character_df['name'] == name, 'Speed_C'] = s_c + s_a
character_df.loc[character_df['name'] == name, 'Int_C'] = i_c + i_a
character_df.loc[character_df['name'] == name, 'Might_P'] = m_p + m_a
character_df.loc[character_df['name'] == name, 'Speed_P'] = s_p + s_a
character_df.loc[character_df['name'] == name, 'Int_P'] = i_p + i_a
adv.append('pool')
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
xp = xp - 4
character_df.loc[character_df['name'] == name, 'XP'] = xp
else:
output = "Pool input invalid, stopping."
return output
else:
val=True
if 'effort' in requested_advs:
character_df.loc[character_df['name'] == name, 'Effort'] = effort_c + 1
adv.append('effort')
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
xp = xp - 4
character_df.loc[character_df['name'] == name, 'XP'] = xp
else:
val=True
if 'edge' in requested_advs:
if edge.lower() == 'm':
character_df.loc[character_df['name'] == name, 'Might_E'] = m_e + 1
if edge.lower() == 's':
character_df.loc[character_df['name'] == name, 'Speed_E'] = s_e + 1
if edge.lower() == 'i':
character_df.loc[character_df['name'] == name, 'Int_E'] = i_e + 1
adv.append('edge')
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
xp = xp - 4
character_df.loc[character_df['name'] == name, 'XP'] = xp
else:
val=True
if 'skill' in requested_advs:
adv.append('skill')
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
xp = xp - 4
character_df.loc[character_df['name'] == name, 'XP'] = xp
else:
val=True
if 'other' in requested_advs:
adv.append('other')
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
xp = xp - 4
character_df.loc[character_df['name'] == name, 'XP'] = xp
else:
val=True
if len(adv) >= 4:
character_df.loc[character_df['name'] == name, 'Tier'] = tier + 1
adv = adv[4:]
character_df.loc[character_df['name'] == name, 'Advancement'] = str(adv)
else:
val=True
character_df.to_excel(character_sheet_path, index=False)
output = "Advancement complete!"
return output
def pool_parser(adv_string):
m = 0
s = 0
i = 0
for n in adv_string.lower():
if n == 'm':
m += 1
if n == 's':
s += 1
if n == 'i':
i += 1
return m,s,i
# For resting
def rest(name):
character_df = pd.read_excel(character_sheet_path)
tier = character_df.loc[character_df['name'] == name, 'Tier'].item()
roll = random.randint(1,6)
rest_amt = roll + tier
rest_type = character_df.loc[character_df['name'] == name, 'Rest'].item()
rest_msg = ""
output = """>>> __**Rest Result:**__
Rest Duration Used: {}
Points Refreshed: {}
Please use `/recover` next to divide these points among your stat pools.
{}""".format(rest_type, rest_amt, rest_msg)
character_df.loc[character_df['name'] == name, 'Rest'] = rest_cycle(rest_type)
character_df.to_excel(character_sheet_path, index=False)
return output
def rest_cycle(current):
rest_type_list = ['1 Action', '10 Minutes', '1 Hour', '10 Hours']
if current in rest_type_list:
place = rest_type_list.index(current)
if place < 3:
next_rest = rest_type_list[place + 1]
else:
next_rest = rest_type_list[0]
else:
next_rest = rest_type_list[0]
return next_rest
# For Cypher character sheet setup
def setup_character(name, full_name, desc, ctype, focus, flavor = " ", m = 8, s = 8, i = 8, m_e = 0, s_e = 0, i_e = 0):
character_df = pd.read_excel(character_sheet_path)
d = {'name':[name],
'Full_Name':[full_name],
'Descriptor':[desc],
'Type':[ctype],
'Focus':[focus],
'Flavor':[flavor],
'Tier':[1],
'Effort':[1],
'XP':[0],
'Might_C':[m],
'Might_P':[m],
'Might_E':[m_e],
'Speed_C':[s],
'Speed_P':[s],
'Speed_E':[s_e],
'Int_C':[i],
'Int_P':[i],
'Int_E':[i_e],
'Advancement':[[]],
'Rest': ['1 Action'],
'Trained': ['Add skills with edit_skills'],
'Specialized': ['None'],
'Inability': ['None'],
'Abilities': ['Add abilities with edit_abilities'],
'Cypher': ['Add inventory with edit_inventory'],
'Equipment': ['Add inventory with edit_inventory'],
'Notes': ['None yet!']}
char_df = pd.DataFrame.from_dict(data=d)
new_character_df = character_df.append(char_df, ignore_index=True)
new_character_df.to_excel(character_sheet_path, index=False)
return("New character added! Please edit skills, abilities, and inventory from their respective slash commands.")
# Edit character sheet
# Maintain skills
def trained_lookup(name):
character_df = pd.read_excel(character_sheet_path)
trained = character_df.loc[character_df['name'] == name, 'Trained'].item()
return(trained)
def spec_lookup(name):
character_df = pd.read_excel(character_sheet_path)
specialized = character_df.loc[character_df['name'] == name, 'Specialized'].item()
return(specialized)
def inability_lookup(name):
character_df = pd.read_excel(character_sheet_path)
inability = character_df.loc[character_df['name'] == name, 'Inability'].item()
return(inability)
def skills_update(name, trained, specialized, inability):
character_df = pd.read_excel(character_sheet_path)
character_df.loc[character_df['name'] == name, 'Trained'] = trained
character_df.loc[character_df['name'] == name, 'Specialized'] = specialized
character_df.loc[character_df['name'] == name, 'Inability'] = inability
character_df.to_excel(character_sheet_path, index=False)
return("Skills updated!")
# Maintain ability_list
def ability_lookup(name):
character_df = pd.read_excel(character_sheet_path)
abilities = character_df.loc[character_df['name'] == name, 'Abilities'].item()
return(abilities)
def ability_update(name, abilities):
character_df = pd.read_excel(character_sheet_path)
character_df.loc[character_df['name'] == name, 'Abilities'] = abilities
character_df.to_excel(character_sheet_path, index=False)
return("Abilities updated!")
# Maintain inventory
def cypher_lookup(name):
character_df = pd.read_excel(character_sheet_path)
cypher = character_df.loc[character_df['name'] == name, 'Cypher'].item()
return(cypher)
def equip_lookup(name):
character_df = pd.read_excel(character_sheet_path)
equip = character_df.loc[character_df['name'] == name, 'Equipment'].item()
return(equip)
def inventory_update(name, cypher, equip):
character_df = pd.read_excel(character_sheet_path)
character_df.loc[character_df['name'] == name, 'Cypher'] = cypher
character_df.loc[character_df['name'] == name, 'Equipment'] = equip
character_df.to_excel(character_sheet_path, index=False)
return("Inventory updated!")
# Maintain notes
def notes_lookup(name):
character_df = pd.read_excel(character_sheet_path)
notes = character_df.loc[character_df['name'] == name, 'Notes'].item()
return(notes)
def notes_update(name, notes):
character_df = pd.read_excel(character_sheet_path)
character_df.loc[character_df['name'] == name, 'Notes'] = notes
character_df.to_excel(character_sheet_path, index=False)
return("Notes updated!")
# Initiative Tracker functions
def track_initiative():
with open(init_sheet, 'w') as f:
f.write("init_listen,True\n")
output = "I am now listening for `/initiative` rolls!"
return output
def add_initiative(name, value):
with open(init_sheet, 'r') as f:
reader = csv.reader(f)
rows = [row for row in reader]
init_listen = rows[0][1]
if init_listen == 'True':
with open(init_sheet, 'a') as f:
f.write("{},{}\n".format(name,value))
output = "Added!"
else:
output = "I am not currently tracking initiative."
return output
def rm_initiative(name):
with open(init_sheet, "r+") as f:
reader = csv.reader(f)
rows = [row for row in reader if name not in row]
clean_rows = [ele for ele in rows if ele != []]
f.seek(0)
f.truncate()
writer = csv.writer(f)
writer.writerows(clean_rows)
output = "If {} was in there, they aren't now!".format(name)
return output
def sort_initiative():
with open(init_sheet, "r+") as f:
reader = csv.reader(f)
rows = [row for row in reader]
sorted_rows = sorted(rows[1:], key=lambda x: int(x[1]), reverse=True)
sorted_names = []
for name,value in sorted_rows:
sorted_names.append(name)
return sorted_rows, sorted_names
def untrack_initiative():
with open(init_sheet, 'w') as f:
f.write("init_listen,False")
output = "No longer tracking initiative."
return output
def print_initiative():
sorted_rows, sorted_names = sort_initiative()
output = "Initiative Tracker\n"
for row in sorted_rows:
row = "".join(element.ljust(10) for element in row)
output += row + "\n"
return output
def next_player(current_player):
sorted_rows, sorted_names = sort_initiative()
player_index = sorted_names.index(current_player)
if player_index != len(sorted_names)-1:
next_player = sorted_names[player_index+1]
else:
next_player = sorted_names[0]
return next_player
def roll_initiative(name):
character_df = pd.read_excel(character_sheet_path)
if name in character_df['name']:
if "initiative" in trained_lookup(name):
mod = 3
elif "initiative" in spec_lookup(name):
mod = 6
elif "initiative" in inability_lookup(name):
mod = -3
else:
mod = 0
else:
mod = 0
roll = random.randint(1,20)
initiative_value = roll + mod
return initiative_value