This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
1135 lines (1058 loc) · 38.2 KB
/
main.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
#!/usr/bin/env python3.6.1
# coding=utf-8
# SKYRIM 2: THE SCROLL IS NOT YOUNG
# Copyright (c) 2017 Jake Ledoux All Rights Reserved.
import sys
if '-?' in sys.argv or '-help' in sys.argv:
print("\nSkyrim 2 Launch Arguments:\n\n\t"+
"-nointro (Disable intro)\n\t"
"-nosave (Disable autosave)\n\t"
"-noload (Bypass existing saved game)\n\t"
"-? or -help (Returns this screen)\n"
)
sys.exit()
import os, time, random, copy, json
from msvcrt import getch # Keypresses on Windows. Cross-platform later.
from colorama import init, Fore, Back, Style
from data import termsize, art
# Getting keypresses for menus
def getkey():
key = ord(getch())
if key in [9, 27]: #Tab, ESC
return 'esc'
elif key in [13, 101]: #E, Enter
return 'enter'
elif key == 32: # Spacebar
return 'space'
elif key == 102:
return 'f'
elif key == 113:
return 'q'
elif key == 115: # S
return 'down'
elif key == 119: # W
return 'up'
elif key == 224: #Special keys (arrows, f keys, ins, del, etc.)
key = ord(getch())
if key == 82: # Insert
clear()
print_message("Kaching!")
char.bag = {'armor_bone' : 1, 'sword_bone' : 1, 'bow_bone' : 1, 'health_elixir' : 9999}
char.arrows = 1
char.gold = 99999999
char.hp = [1000,1000]
elif key == 80: #Down arrow
return 'down'
elif key == 72: #Up arrow
return 'up'
# Drawing menus
# menu_list = List of options, pre_text = String displayed before menu, post_text = String displayed after menu
def menu(menu_list, pre_text = None, post_text = None, special_f=False, special_q=False, menu_item=0):
while True:
menu_list2 = []
clear()
#Print pre_text
if pre_text != None:
print(pre_text+"\n")
# Appending cursor to menu options
for x in range(0, len(menu_list)):
menu_list2 += " "
for x in range(0, len(menu_list)):
if menu_list[x] in ['Back','Quit','Run','Cancel']:
menu_list2[x] += "\n "
if x == menu_item:
menu_list2[x] += " > "+menu_list[x]
else:
menu_list2[x] += " "+menu_list[x]
print(menu_list2[x])
#Print post_text
if post_text != None:
print("\n"+post_text)
# Get and handle keypresses
key = getkey()
if key == "esc":
return "Back"
elif key == "up":
menu_item -= 1
elif key == "down":
menu_item += 1
elif special_f and key == "f" and menu_list[menu_item].strip() not in ['Back','Quit','Run','Cancel']:
return "special_f "+menu_list[menu_item].strip()
elif special_q and key == "q" and menu_list[menu_item].strip() not in ['Back','Quit','Run','Cancel']:
return "special_q "+menu_list[menu_item].strip()
# Wrap bottom and top of menus
if menu_item > len(menu_list)-1:
menu_item = 0
elif menu_item < 0:
menu_item = len(menu_list)-1
if key == "enter" :
return menu_list[menu_item].strip() # Returns the string option selected
def save():
with open("data/save.corn","w+") as f:
f.write(json.dumps(char.quest_active)+"\n")
f.write(json.dumps(char.hp)+"\n")
f.write(json.dumps(char.xp)+"\n")
f.write(json.dumps(char.lvl)+"\n")
f.write(json.dumps(char.gold)+"\n")
f.write(json.dumps(char.deathwish)+"\n")
f.write(json.dumps(char.hand)+"\n")
f.write(json.dumps(char.armor)+"\n")
f.write(json.dumps(char.bag)+"\n")
f.write(json.dumps(stats.time)+"\n")
f.write(json.dumps(char.arrows)+"\n")
def load():
with open("data/db.corn","r") as f:
state = None
temp = f.read()
for i in temp.split("\n"):
if i == '':
continue
if '[WEAPONS]' in i:
state = 'weapons'
elif '[AID]' in i:
state = 'aid'
elif '[ARMOR]' in i:
state = 'armor'
else:
if state == 'weapons':
stats.values[i.split("\t")[2]] = int(i.split("\t")[0])
stats.dmg[i.split("\t")[2]] = int(i.split("\t")[1])
stats.names[i.split("\t")[2]] = i.split("\t")[3]
elif state == 'aid':
stats.values[i.split("\t")[2]] = int(i.split("\t")[0])
stats.heal[i.split("\t")[2]] = int(i.split("\t")[1])
stats.names[i.split("\t")[2]] = i.split("\t")[3]
elif state == 'armor':
stats.values[i.split("\t")[2]] = int(i.split("\t")[0])
stats.dfc[i.split("\t")[2]] = int(i.split("\t")[1])
stats.names[i.split("\t")[2]] = i.split("\t")[3]
if os.path.isfile("data/save.corn") and "-noload" not in sys.argv:
with open("data/save.corn","r") as f:
char.quest_active = json.loads(f.readline().strip())
char.hp = json.loads(f.readline().strip())
char.xp = json.loads(f.readline().strip())
char.lvl = json.loads(f.readline().strip())
char.gold = json.loads(f.readline().strip())
char.deathwish = json.loads(f.readline().strip())
char.hand = json.loads(f.readline().strip())
char.armor = json.loads(f.readline().strip())
char.bag = json.loads(f.readline().strip())
stats.time = json.loads(f.readline().strip())
char.arrows = json.loads(f.readline().strip())
def dialogue(name, speech, menu_list = None):
menu_item = 0
while True:
menu_list2 = []
clear()
message = speech
# Character dialogue
print("\n\t "+name+":")
suffix = ""
for i in range(len(name)+1):
suffix += "═"
suffix += "═╧"
for i in range(30-len(suffix)):
suffix += "═"
print('\t╔═══╧═'+suffix+'╗\n\t║ ║')
wrapped_message = []
while len(message) > 30:
for i in range(30,-1,-1):
if message[i] == " ":
wrapped_message += [message[:i].strip()]
message = message[i:]
break
wrapped_message += [message.strip()]
for i in wrapped_message:
suffix = ""
for i2 in range(30-len(i)):
suffix += " "
suffix += " ║"
print("\t║ "+i+suffix)
print('\t║ ║\n\t╚═══════════════════════════════════╝\n')
if menu_list == None:
print('\n')
enter()
return
# Appending cursor to menu options
for x in range(0, len(menu_list)):
menu_list2 += " "
for x in range(0, len(menu_list)):
if menu_list[x] in ['Back','Quit','Run','Cancel']:
menu_list2[x] += "\n "
if x == menu_item:
menu_list2[x] += "\t"+Back.WHITE+Fore.BLACK+menu_list[x]
else:
menu_list2[x] += "\t"+menu_list[x]
print(menu_list2[x])
# Get and handle keypresses
key = getkey()
if key == "up":
menu_item -= 1
elif key == "down":
menu_item += 1
# Wrap bottom and top of menus
if menu_item > len(menu_list)-1:
menu_item = 0
elif menu_item < 0:
menu_item = len(menu_list)-1
if key == "enter" :
return menu_item
def clear():
os.system("cls" if os.name == "nt" else "clear")
def get_name(item):
return stats.names[item]
def get_item(name):
return list(stats.names.keys())[list(stats.names.values()).index(name)]
def switch_weapon():
menu_item = 0
while True:
weapons = []
for i in char.bag:
if i in stats.dmg:
if i == char.hand:
weapons += [get_name(i)+" [ACTIVE]"]
else:
weapons += [get_name(i)]
weapons += ['Back']
action = menu(weapons, Style.BRIGHT+"WEAPON SELECTION"+Style.RESET_ALL+"\n\nArrows: "+str(char.arrows),"E/Enter: Equip - F: Drop", special_f=True, menu_item=menu_item)
if action not in ['Cancel','Back']:
if "[ACTIVE]" in action:
action = " ".join(action.split(" ")[:-1])
if "special_f" in action:
action = " ".join(action.split(" ")[1:])
use_item(get_item(action))
if char.hand not in char.bag:
char.hand = "fists"
else:
char.hand = get_item(action)
try:
menu_item = weapons.index(action)
except:
menu_item = weapons.index(action+" [ACTIVE]")
else:
break
def switch_armor():
menu_item = 0
while True:
armor = []
for i in char.bag:
if i in stats.dfc:
if i in char.armor:
armor += [get_name(i)+" [ACTIVE]"]
else:
armor += [get_name(i)]
armor += ['Back']
action = menu(armor, "CLOTHING SELECTION","E/Enter: Equip - F: Drop", special_f=True, menu_item=menu_item)
if action not in ['Cancel','Back']:
if "[ACTIVE]" in action:
action = " ".join(action.split(" ")[:-1])
if "special_f" in action:
action = " ".join(action.split(" ")[1:])
use_item(get_item(action))
if char.armor not in char.bag:
char.armor = "nothing"
else:
char.armor = get_item(action)
try:
menu_item = armor.index(action)
except:
menu_item = armor.index(action+" [ACTIVE]")
else:
break
def use_aid():
menu_item = 0
while True:
items = []
for i in char.bag:
if i in stats.heal:
items += [get_name(i)+": "+str(char.bag[i])]
items += ['Back']
action = menu(items, "ITEM SELECTION","E/Enter: Use - F: Drop", special_f=True, menu_item=menu_item)
if action not in ['Back','Cancel']:
if "special_f" in action:
action = action[:action.index(":")]
action = " ".join(action.split(" ")[1:])
use_item(get_item(action))
elif char.hp[0] == char.hp[1]:
print("\n"+Style.BRIGHT+Back.RED+"You are already fully healed.")
enter()
else:
action = action[:action.index(":")]
char.hp[0] += stats.heal[get_item(action)]
if char.hp[0] > char.hp[1]:
char.hp[0] = char.hp[1]
use_item(get_item(action))
clear()
print("\nYou use 1 "+action+" for a total of "+str(stats.heal[get_item(action)])+" healing points.")
print("Current HP: "+get_hp())
if get_item(action) in char.bag:
print("You now have "+str(char.bag[get_item(action)])+" remaing "+action+"s.")
else:
print("You have no remaing "+action+"s.")
enter()
for i in items:
if " ".join(i.split(" ")[1:]) == action:
menu_item = items.index(action)
break
else:
break
def enter(silent=False):
if not silent:
print("Press enter.")
key = None
while key != 'enter':
key = getkey()
clear()
def use_item(item):
if item not in ['fists','nothing']:
char.bag[item] -= 1
if char.bag[item] < 1:
del char.bag[item]
def advance_time(minutes):
stats.time[1] += minutes
if stats.time[1] >= 60:
stats.time[0] += stats.time[1]//60
stats.time[1] = stats.time[1]%60
if stats.time[0] > 23:
stats.time[0] -= 24
def get_time():
ampm = "PM" if stats.time[0] > 11 else "AM"
hour = stats.time[0]
minute = str(stats.time[1])
if hour == 0:
hour = 12
elif hour > 12:
hour -= 12
if len(minute) < 2:
minute = "0"+minute
return str(hour)+":"+minute+" "+ampm
def print_message(intext):
clear()
prefix = ""
for i in range(int(round(termsize.getTerminalSize()[1]/2))-1):
prefix += "\n"
for i in range(int(round((termsize.getTerminalSize()[0]-len(intext))/2))):
prefix += " "
print(prefix+intext)
prefix2 = "\n"
for i in range(int(round(termsize.getTerminalSize()[0]/2))-5):
prefix2 += " "
print(prefix2,end="")
enter()
def sign(object, message, alive=True):
clear()
if alive:
print(object+":\n")
else:
print("The "+object+" reads:\n")
wrapped_message = []
while len(message) > 30:
for i in range(30,-1,-1):
if message[i] == " ":
wrapped_message += [message[:i].strip()]
message = message[i:]
break
wrapped_message += [message.strip()]
print("\t"+Fore.BLACK+Back.WHITE+"╔═══════════════════════════════════╗\n"+
"\t║ ║")
for i in wrapped_message:
suffix = ""
for i2 in range(30-len(i)):
suffix += " "
suffix += " ║"
print("\t"+Fore.BLACK+Back.WHITE+"║ "+i+suffix)
print('\t'+Fore.BLACK+Back.WHITE+'║ ║\n\t╚═══════════════════════════════════╝\n')
print()
enter()
def combat(enemy, run=True, safe=False, speak="Where do you think you're going?"):
scene_active = True
enemy['name'] = Style.BRIGHT+enemy['name']+Style.RESET_ALL
while scene_active:
action = menu(['Attack','Use Item','Switch Weapon','Run'],"Enemy: "+enemy['name']+"\nEnemy HP: "+get_hp(enemy), "HP: "+get_hp())
advance_time(random.randint(10,30))
critical_attack = False
if action == "Attack":
if "bow" in char.hand and char.arrows > 1:
critial_okay = True
elif "bow" not in char.hand:
crit_okay = True
else:
crit_okay = False
if random.randrange(10) and crit_okay:
print_message(Style.BRIGHT+Fore.CYAN+"Critical attack! x3 damage!")
critical_attack = True
if enemy['can_block'] and "bow" not in char.hand:
action = menu(hml,"Where do you aim?")
hit = hml.index(action) == random.randint(0,2)
if critical_attack:
hit = True
if hit:
print_message("Clean hit!")
else:
print_message("The enemy blocks your attack!")
hit = False
elif "bow" in char.hand:
if char.arrows > 0:
print_message("You fire your bow...")
bow_aim = random.randint(1,4)
if bow_aim <= enemy['size'] or critical_attack:
hit = True
print_message("...and hit the "+Style.BRIGHT+enemy['name']+"!")
else:
hit = False
print_message("...and miss.")
else:
hit = False
print_message("You're out of arrows!")
if hit:
attack = int(round((stats.dmg[char.hand] * 1-(enemy['dfc']/100))))
clear()
if critical_attack:
attack *= 3
enemy['hp'][0] -= attack
print_message("You deal "+Style.BRIGHT+Fore.RED+str(attack)+" damage.")
if enemy['hp'][0] < 1:
clear()
suffix = " is killed." if safe == False else " is defeated."
print("The attacking "+enemy['name']+suffix)
xp_earned = int(round(5*enemy['hp'][1]))
gold_earned = int(round(enemy['hp'][1]*((random.randrange(100)+50)/100)))
char.xp += xp_earned
char.gold += gold_earned
print("\n You gain:")
print("\t "+Style.BRIGHT+str(xp_earned)+Style.RESET_ALL+" XP.")
print("\t "+Fore.YELLOW+str(gold_earned)+Style.RESET_ALL+" gold.\n")
enter()
if char.xp >= 1000:
char.xp -= 1000
char.lvl += 1
char.hp[1] += 10
char.hp[0] = char.hp[1]
print("You've leveled up! You are now level "+str(char.lvl)+".")
enter()
scene_active = False
return True
elif action == 'Switch Weapon':
switch_weapon()
elif action == 'Use Item':
use_aid()
elif action == 'Run' or 'Back':
if run:
clear()
escape = random.randrange(2)
if escape == 0:
print_message("You manage to run away safely.")
else:
attack = int(round(((enemy['dmg']*(1-(random.randrange(10)/20)))*(1-(stats.dfc[char.armor]/100)))/2))
char.hp[0] -= attack
print_message("You run away, but not before suffering "+Style.BRIGHT+Fore.RED+str(attack)+" damage.")
if char.hp[0] <= 0:
die()
scene_active = False
return False
scene_active = False
return True
else:
dialogue(enemy['name'],speak)
attack = int(round((enemy['dmg']*(1-(random.randrange(10)/20)))*(1-(stats.dfc[char.armor]/100))))
char.hp[0] -= attack
clear()
print_message("The enemy attacks! You suffer "+Style.BRIGHT+Fore.RED+str(attack)+" damage.")
if char.hp[0] <= 0:
die()
scene_active = False
return False
def die():
clear()
print_message(Fore.RED+Style.BRIGHT+"YOU DIED.")
print_message("You have lost your items and 100 gold has been deducted from you stash.")
char.bag = copy.deepcopy(char.default_bag)
char.hp[0] = char.hp[1]
char.gold -= 100
char.deathwish = False
if char.gold < 0:
char.gold = 0
hand = "fists"
armor = "rags"
def get_hp(enemy=None):
if enemy:
hp = enemy['hp']
else:
hp = char.hp
if hp[0] <= hp[1]/5:
return Style.BRIGHT+Fore.RED+str(hp[0])+"/"+Style.NORMAL+str(hp[1])
elif hp[0] <= hp[1]/1.3333:
return Style.BRIGHT+Fore.YELLOW+str(hp[0])+"/"+Style.NORMAL+str(hp[1])
else:
return Style.BRIGHT+Fore.GREEN+str(hp[0])+"/"+Style.NORMAL+str(hp[1])
def reward(amount, name=None, silent=False):
if not silent:
clear()
border = ["╔══","║ "," ║","","╚══","═╝",""]
if name == None:
outtext = "You have been rewarded "+str(amount)+" gold!"
else:
outtext = name+" has rewarded you "+str(amount)+" gold!"
prefix = ""
for i in range(int(round((termsize.getTerminalSize()[1]/2)))-3):
print()
for i in range(int(round((termsize.getTerminalSize()[0]/2)-(len(outtext)/2)))-6):
prefix += " "
for i in range(len(outtext)):
border[0] += "═"
border[3] += " "
for i in range(int(round((len(outtext)-len("Press enter."))/2))):
border[6] += "═"
border[0] += "══╗"
for i in range(len(border[0]) - len(border[4]+border[6]+"Press enter."+border[6]+border[5])):
border[5] = "═"+border[5]
print(prefix+Back.YELLOW+Fore.BLACK+border[0])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+border[3]+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+Style.BRIGHT+Fore.WHITE+outtext+Style.NORMAL+Fore.BLACK+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+border[3]+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[4]+border[6]+"Press enter."+border[6]+border[5])
enter(True)
char.gold += amount
def reward_item(giftid,amount=1,name=None, silent=False):
if not silent:
clear()
border = ["╔══","║ "," ║","","╚══","╝",""]
if name == None:
outtext = "You have been given ["+get_name(giftid)+"] x"+str(amount)+"."
else:
outtext = name+" has given you ["+get_name(giftid)+"] x"+str(amount)+"."
prefix = ""
for i in range(int(round((termsize.getTerminalSize()[1]/2)))-3):
print()
for i in range(int(round((termsize.getTerminalSize()[0]/2)-(len(outtext)/2)))-6):
prefix += " "
for i in range(len(outtext)):
border[0] += "═"
border[3] += " "
for i in range(int(round((len(outtext)-len("Press enter."))/2))):
border[6] += "═"
border[0] += "══╗"
for i in range(len(border[0]) - len(border[4]+border[6]+"Press enter."+border[6]+border[5])):
border[5] = "═"+border[5]
print(prefix+Back.YELLOW+Fore.BLACK+border[0])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+border[3]+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+Style.BRIGHT+Fore.WHITE+outtext+Style.DIM+Fore.BLACK+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[1]+border[3]+border[2])
print(prefix+Back.YELLOW+Fore.BLACK+border[4]+border[6]+"Press enter."+border[6]+border[5])
enter(True)
if giftid in char.bag:
char.bag[giftid] += amount
else:
char.bag[giftid] = amount
hml =['High','Middle','Low']
# All the character's data
class char:
quest_active = 0
hp = [100, 100] # [CURRENT HP, MAX HP]
xp = 0
lvl = 0
gold = 0
arrows = 0
deathwish = False
hand = "fists"
armor = "rags"
bag = {'fists' : 1, "rags" : 1, "nothing" : 1} # The Player's inventory. {"potions" : 2, "sword_iron" : 1}
default_bag = {'fists' : 1, "rags" : 1, "nothing" : 1}
# Catch-all class where I put non-character related data
class stats:
dfc = {}
heal = {}
names = {}
dmg = {}
values = {}
enemies = [ # Database of enemies and their stats, Size is from 1 to 3
{'name' : 'Bear', 'hp' : [20,20], 'dmg' : 30, 'dfc' : 5, 'can_block': False, 'size': 3},
{'name' : 'Tree Monkey', 'hp' : [3,3], 'dmg' : 5, 'dfc' : 0, 'can_block': False, 'size': 1},
{'name' : 'Wanderer', 'hp' : [10,10], 'dmg' : 15, 'dfc' : 30, 'can_block': True, 'size': 2},
{'name' : 'Dragonling', 'hp' : [15,15], 'dmg' : 18, 'dfc' : 10, 'can_block': False, 'size': 2},
{'name' : 'Warlock', 'hp' : [50,50], 'dmg' : 35, 'dfc' : 30, 'can_block': True, 'size': 2},
]
time = [7,0] # Hours, Minutes
shopbag = {}
# Initiate Game
if os.name == "nt":
os.system("title SKYRIM 2")
load()
init(autoreset=True)
# INTRO
if '-nointro' not in sys.argv: # Check if the script was run with -nointro
prefix = ""
for i in range(int(round(termsize.getTerminalSize()[1]/2))-1):
prefix += "\n"
for i in range(int(round((termsize.getTerminalSize()[0]-30)/2))):
prefix += " "
clear()
time.sleep(1)
print(prefix+"........ ......... ........")
time.sleep(.2)
clear()
print(prefix+"bethesda softworks presents...")
time.sleep(.2)
clear()
print(prefix+"BETHESDA SOFTWORKS PRESENTS...")
time.sleep(2)
clear()
print(prefix+"bethesda softworks presents...")
time.sleep(.2)
clear()
print(prefix+"........ ......... ........")
time.sleep(.2)
clear()
time.sleep(2)
prefix = ""
prefix2 = ""
for i in range(int(round(termsize.getTerminalSize()[1]/2))-art.logo[3]):
prefix += "\n"
for i in range(int(round(termsize.getTerminalSize()[0]/2))-art.logo[2]):
prefix2 += " "
clear()
print(prefix)
for i in art.logo[0].split("\n"):
print(prefix2+Style.BRIGHT+Fore.BLACK+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[0].split("\n"):
print(prefix2+Style.DIM+Fore.WHITE+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[1].split("\n"):
print(prefix2+Style.NORMAL+Fore.WHITE+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[1].split("\n"):
print(prefix2+Style.BRIGHT+Fore.WHITE+i)
time.sleep(2)
prefix2 = ""
for i in range(int(round(termsize.getTerminalSize()[0]/2))-5):
prefix2 += " "
print(prefix2,end="")
enter()
prefix = ""
prefix2 = ""
for i in range(int(round(termsize.getTerminalSize()[1]/2))-art.logo[3]):
prefix += "\n"
for i in range(int(round(termsize.getTerminalSize()[0]/2))-art.logo[2]):
prefix2 += " "
print(prefix)
for i in art.logo[1].split("\n"): # 1
print(prefix2+Style.BRIGHT+Fore.WHITE+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[1].split("\n"): # 2
print(prefix2+Style.NORMAL+Fore.WHITE+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[0].split("\n"): # 3
print(prefix2+Style.DIM+Fore.WHITE+i)
time.sleep(.2)
clear()
print(prefix)
for i in art.logo[0].split("\n"): # 4
print(prefix2+Style.BRIGHT+Fore.BLACK+i)
time.sleep(.2)
clear()
time.sleep(2)
# GAME LOOP
menu_item = 0
while True:
# Double check item validities
if char.hand not in char.bag:
char.hand = "fists"
if char.armor not in char.bag:
char.armor = "nothing"
# Scene selection
scenes = ['Shop','Wilderness','The King\'s Castle','Inventory','Quit']
scene = menu(scenes, 'Gold: '+Fore.YELLOW+str(char.gold)+Style.RESET_ALL+
'\nHP: '+get_hp()+Style.RESET_ALL+
'\nXP: '+Fore.WHITE+Style.BRIGHT+str(char.xp)+Style.NORMAL+'/1000'+Style.RESET_ALL+'\nLevel: '+Fore.WHITE+Style.BRIGHT+str(char.lvl)+Style.RESET_ALL,
" "+Back.WHITE+Fore.BLACK+" "+get_time()+" ", menu_item=menu_item)
scene_active = True # When this is false, the loop returns to the main menu
# Buy and sell items
if scene == "Shop":
stats.shopbag = {}
for i in list(stats.names.keys()):
stats.shopbag[i] = 100
menu_item = 0
while scene_active:
if stats.time[0] < 8 or stats.time[0] > 20:
clear()
sign("sign on the door","SHOP IS CLOSED. OUR HOURS ARE 8 AM TO 9 PM EXCEPT ON HOLIDAYS. FREE WIFI INSIDE.", False)
advance_time(5)
scene_active = False
continue
action = menu(['Buy','Sell','Back'], Style.BRIGHT+'SHOP', menu_item=menu_item)
if action == "Back":
scene_active = False
elif action == "Buy":
menu_item = 0
while True:
action = menu(['Weapons','Clothing','Aid','Back'], Style.BRIGHT+'SHOP: BUY', menu_item=menu_item)
if action == 'Weapons':
menu_item = 0
while True:
advance_time(random.randint(8,15))
items = []
for i in stats.shopbag:
if i not in stats.dmg or i in ['fists','nothing','king_goose']:
continue
tabs = "\t\t" if len(get_name(i)) >= 12 else "\t\t\t"
items += [get_name(i)+tabs+"Value: "+str(stats.values[i])+"\tStock: "+str(stats.shopbag[i])]
items += ['Back']
action = menu(items, Style.BRIGHT+'SHOP: BUY: WEAPONS\n\nShopkeeper\'s Gold: '+Style.RESET_ALL+Fore.YELLOW+"INFINITE (WIP)"+Style.RESET_ALL+Style.BRIGHT+"\nYour Gold: "+Style.RESET_ALL+Fore.YELLOW+str(char.gold),"E/Enter: Buy", menu_item=menu_item)
if action not in ['Cancel','Back']:
action = action[:action.index("\t")].strip()
if char.gold >= stats.values[get_item(action)]:
stats.shopbag[get_item(action)] -= 1
if stats.shopbag[get_item(action)] < 1:
del stats.shopbag[get_item(action)]
try:
char.bag[get_item(action)] += 1
except:
char.bag[get_item(action)] = 1
char.gold -= stats.values[get_item(action)]
else:
print("\n"+Style.BRIGHT+Back.RED+"You don't have enough gold!")
enter()
for i in items:
try:
if i[:i.index("(")].strip() == action:
menu_item = items.index(i)
break
except:
if i == action:
menu_item = items.index(i)
break
else:
menu_item = 0
break
elif action == 'Clothing':
menu_item = 0
while True:
advance_time(random.randint(8,15))
items = []
for i in stats.shopbag:
if i not in stats.dfc or i in ['fists','nothing','king_goose']:
continue
tabs = "\t\t" if len(get_name(i)) >= 12 else "\t\t\t"
items += [get_name(i)+tabs+"Value: "+str(stats.values[i])+"\tStock: "+str(stats.shopbag[i])]
items += ['Back']
action = menu(items, Style.BRIGHT+'SHOP: BUY: CLOTHING\n\nShopkeeper\'s Gold: '+Style.RESET_ALL+Fore.YELLOW+"INFINITE (WIP)"+Style.RESET_ALL+Style.BRIGHT+"\nYour Gold: "+Style.RESET_ALL+Fore.YELLOW+str(char.gold),"E/Enter: Buy", menu_item=menu_item)
if action not in ['Cancel','Back']:
action = action[:action.index("\t")].strip()
if char.gold >= stats.values[get_item(action)]:
stats.shopbag[get_item(action)] -= 1
if stats.shopbag[get_item(action)] < 1:
del stats.shopbag[get_item(action)]
try:
char.bag[get_item(action)] += 1
except:
char.bag[get_item(action)] = 1
char.gold -= stats.values[get_item(action)]
else:
print("\n"+Style.BRIGHT+Back.RED+"You don't have enough gold!")
enter()
for i in items:
try:
if i[:i.index("(")].strip() == action:
menu_item = items.index(i)
break
except:
if i == action:
menu_item = items.index(i)
break
else:
menu_item = 1
break
elif action == 'Aid':
menu_item = 0
while True:
advance_time(random.randint(8,15))
items = []
for i in stats.shopbag:
if i not in stats.heal or i in ['fists','nothing','king_goose']:
continue
tabs = "\t\t" if len(get_name(i)) >= 12 else "\t\t\t"
items += [get_name(i)+tabs+"Value: "+str(stats.values[i])+"\tStock: "+str(stats.shopbag[i])]
items += ['Back']
action = menu(items, Style.BRIGHT+'SHOP: BUY: AID\n\nShopkeeper\'s Gold: '+Style.RESET_ALL+Fore.YELLOW+"INFINITE (WIP)"+Style.RESET_ALL+Style.BRIGHT+"\nYour Gold: "+Style.RESET_ALL+Fore.YELLOW+str(char.gold),"E/Enter: Buy", menu_item=menu_item)
if action not in ['Cancel','Back']:
action = action[:action.index("\t")].strip()
if char.gold >= stats.values[get_item(action)]:
stats.shopbag[get_item(action)] -= 1
if stats.shopbag[get_item(action)] < 1:
del stats.shopbag[get_item(action)]
try:
char.bag[get_item(action)] += 1
except:
char.bag[get_item(action)] = 1
char.gold -= stats.values[get_item(action)]
else:
print("\n"+Style.BRIGHT+Back.RED+"You don't have enough gold!")
enter()
for i in items:
try:
if i[:i.index("(")].strip() == action:
menu_item = items.index(i)
break
except:
if i == action:
menu_item = items.index(i)
break
else:
menu_item = 2
break
elif action == "Back":
menu_item = 0
break
elif action == "Sell":
while True:
advance_time(random.randint(8,15))
items = []
for i in char.bag:
if i not in ['nothing','fists']:
if i in [char.hand,char.armor]:
items += [get_name(i)+" [ACTIVE]"+" (Amount: "+str(char.bag[i])+" / Value: "+str(int(round(stats.values[i]*.7)))+")"]
else:
items += [get_name(i)+" (Amount: "+str(char.bag[i])+" / Value: "+str(int(round(stats.values[i]*.7)))+")"]
items += ['Back']
action = menu(items, Style.BRIGHT+"SHOP: SELL"+Style.RESET_ALL+"\n\nShopkeeper's Gold: INFINITE\nYour Gold: "+str(char.gold),"E/Enter: Sell - F: Drop", special_f=True, menu_item=menu_item)
if action not in ['Cancel','Back']:
try:
action = action[:action.index("[")].strip()
print(action)
except:
action = action[:action.index("(")].strip()
if "special_f" in action:
action = " ".join(action.split(" ")[1:])
use_item(get_item(action))
if char.hand not in char.bag:
char.hand = "fists"
if char.armor not in char.bag:
char.armor = "nothing"
else:
use_item(get_item(action))
if char.hand not in char.bag:
char.hand = "fists"
if char.armor not in char.bag:
char.armor = "nothing"
char.gold += int(round(stats.values[get_item(action)]*.7))
try:
stats.shopbag[get_item(action)] += 1
except:
stats.shopbag[get_item(action)] = 1
for i in items:
try:
if i[:i.index("(")].strip() == action:
menu_item = items.index(i)
break
except:
if i == action:
menu_item = items.index(i)
break
else:
menu_item = 1
break
elif action == 'Back':
scene_active = False
menu_item = 0
# Fight random enemies
elif scene == "Wilderness":
if char.quest_active == 2.5:
print_message("You enter the wilderness looking for the King's lost goose...")
print_message("As you continue forward, you spot a sign down the path.")
sign("sign on the tree","WE HAVE YOUR DUMB GOOSE. CATCH US IF YOU CAN.",False)
print_message("You sprint down the path...")
dialogue("?","Hey, you!")
print_message("You turn around and see a young punk emerge from the bushes.")
dialogue("Punk","That's right, I'm talking to you. You want your goose? You're going to have to get through me!")
if not combat({'name' : 'Punk', 'hp' : [10,10], 'dmg' : 1, 'dfc' : 0, 'can_block': True, 'size': 2},False,True):
continue
dialogue("Punk","No fair!")
print_message("A tall Nord walks out of the bushes.")
dialogue("Tall Nord","I see you've defeated my young apprentice, but you're not gonna get through me!")
dialogue("Tall Nord","POWER OF THE SUN, FLOW THROUGH ME!!!")
if not combat({'name' : 'Tall Nord', 'hp' : [30,30], 'dmg' : 8, 'dfc' : 20, 'can_block': True, 'size': 2},False,True):
continue
dialogue("Tall Nord","I- I\'ve been defeated in combat. How can this be?",
["You did alright.","You suck and so does your apprentice.","Can I have the goose now?","Give me the goose or taste my blade."])
print_message("The tall Nord puts two fingers in his mouth and whistles loudly.")
print_message("A large, fat bear with makeshift armor comes stumbling out of the bushes.")
dialogue("Tall Nord","Roller, attack!")
if not combat({'name' : 'Roller the Bear', 'hp' : [50,50], 'dmg' : 30, 'dfc' : 30, 'can_block': False, 'size': 3},False,speak="Get back here! [in bear]"):
continue
dialogue("Tall Nord","Roller, NOOOO!")
dialogue("Roller the Bear","*roars in defeat*")
print_message("The bear rolls over dead.")
action = dialogue("Tall Nord","Fine... take the goose. It's just ahead, straight down the path. Just... please don't kill us.",
['Fine. Just this once.','Run.','Request denied.','*mimic the lightsaber ignition sound with your mouth*'])
if action in [0,1]:
dialogue("Tall Nord","Thank you! Thank you!")
print_message('The Nord and punk scurry off into the bushes.')
else:
print_message("You swiftly behead both the Nord and the punk.")
print_message("After a few minutes of walking down the path, you come across the King's goose.")
dialogue("Goose","HONK")
print_message("You grab the goose. It honks and struggles, but you manage to stuff it in your bag.")
reward_item("king_goose",silent=True)
enter()
char.quest_active = 3
else:
combat(copy.deepcopy(stats.enemies[random.randrange(len(stats.enemies))]))
elif scene == 'The King\'s Castle':
advance_time(30)
if char.quest_active == -1:
clear()
print_message("There are no more quests. Nice job...")
enter()
if char.quest_active == 0:
action = dialogue("The King","Hm. Go get me a sweetroll, my boy! Here's 1 gold, it should suffice.",
['Yes sir.','With haste, my liege.','Why? Haven\'t you had enough sweets already?','Buzz off, old man.'])
if action in [0,1]:
dialogue("The King","God speed!")
reward(1, silent=True)
char.quest_active = 1
continue
elif action in [2]:
dialogue("The King","Get out of my sight.")
elif action == 3:
dialogue("The King","Not yet learned learned your place, have you? I can fix that.")
char.deathwish = True
if char.quest_active == 1:
action = dialogue("The King","Oh, I see you've returned! Have you brought my long-awaited snack?",
['Yes, here it is.','No, not yet.','What did you want again?','I don\'t want to get it for you anymore.'])