-
Notifications
You must be signed in to change notification settings - Fork 1
/
zone_handling.py
1659 lines (1587 loc) · 85 KB
/
zone_handling.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
# zone_handling.py
# Copyright (c) 2024 by @Cromha
#
# Bane Of Wargs is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
#
# Bane Of Wargs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.
# source imports
import logger_sys
import text_handling
import uuid_handling
import weapon_upgrade_handling
import train
import dungeon
import terminal_handling
import time_handling
import dialog_handling
import yaml_handling
from colors import *
from terminal_handling import cout, cinput, cinput_int
# external imports
import random
import time
import appdirs
program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs'))
ZONE_COLORS_DICT = {
0: COLOR_GREENS_4 + '╬',
1: COLOR_GREENS_5 + '╬',
2: COLOR_GREEN + '╬',
3: COLOR_GREENS_12 + '╬',
4: COLOR_GREENS_2 + '↟',
5: COLOR_GREENS_1 + '⇞',
6: COLOR_GRAY_4 + '▲',
7: COLOR_GRAY_5 + '▲',
8: COLOR_GRAY_3 + '▲',
9: COLOR_GRAY_1 + '▲',
10: COLOR_YELLOW_6 + '≡',
11: COLOR_YELLOW_7 + '≡',
12: COLOR_YELLOW_7 + '≡',
13: COLOR_ORANGE_5 + '≡',
14: COLOR_ORANGE_3 + '≡',
15: COLOR_ORANGE_4 + '≡',
16: COLOR_ORANGE_4 + '≡',
17: COLOR_ORANGE_6 + '≡',
18: COLOR_ORANGE_6 + '≡',
19: COLOR_ORANGE_7 + '≡',
20: COLOR_MAGENTA_7 + '#',
21: COLOR_YELLOW_8 + '≡',
22: COLOR_GREENS_20 + '«',
23: COLOR_YELLOW_3 + '«',
24: COLOR_RED_1 + '«',
25: COLOR_RED_0 + '«',
26: COLOR_BLUE_5 + '⌂',
27: COLOR_BLUE_13 + '⌂',
28: COLOR_BLUE_13 + '⟰',
29: COLOR_BLUE_13 + '⟰',
30: COLOR_BLUE_13 + '⥣',
31: COLOR_BLUE_13 + '⤊',
32: COLOR_BLUE_13 + '±',
33: COLOR_CYAN_3 + '≈',
34: COLOR_CYAN_1 + '≈',
35: COLOR_GREENS_0 + '#',
36: COLOR_BLUE_13 + '⟰',
37: COLOR_BLUE_14 + '⇭',
38: COLOR_BLUE_14 + '±'
}
SELLING_ZONES = [
"hostel",
"forge",
"stable",
"blacksmith",
"grocery",
"harbor"
]
# Handling functions
def get_cost(cost, dropoff, round_cost=True):
cost = cost - cost * dropoff
if round_cost:
return round(cost, 2)
else:
return cost
# Information printing functions
def print_zone_news(zone, map_zone, player):
logger_sys.log_message(f"INFO: Printing map zone '{map_zone}' news")
cout("NEWS:")
village_news = zone[map_zone]["news"]
village_news_len = len(village_news)
choose_rand_news = random.randint(0, (village_news_len - 1))
choose_rand_news = village_news[int(choose_rand_news)]
text_handling.print_long_string(choose_rand_news)
if (
zone[map_zone]["type"] in SELLING_ZONES and
player["discounts"][map_zone]["dropoff"] is not None
):
cout(COLOR_RED + COLOR_STYLE_BRIGHT + "!!!SALES DISCOUNT!!!" + COLOR_RESET_ALL)
text = (
f"A @{COLOR_GREEN}@-{int(player['discounts'][map_zone]['dropoff'] * 100)}%@{COLOR_RESET_ALL}@ " +
f"dropoff on every item's happening at @\033[38;2;255;128;0m@{zone[map_zone]['name']}@{COLOR_RESET_ALL}@" +
f"! Only @{COLOR_BACK_BLUE}@{round(player['discounts'][map_zone]['remaining time'] * 24)} " +
f"hours@{COLOR_RESET_ALL}@ remain!"
)
text_handling.print_long_string(text)
cout(COLOR_RED + COLOR_STYLE_BRIGHT + "!!!SALES DISCOUNT!!!" + COLOR_RESET_ALL)
text = '='
text_handling.print_separator(text)
def print_forge_information(map_zone, zone, item, player):
current_forge = zone[map_zone]
current_forge_name = current_forge["name"]
logger_sys.log_message(f"INFO: Printing current forge '{current_forge_name}' information to GUI")
cout(COLOR_STYLE_BRIGHT + str(current_forge["name"]) + ":" + COLOR_RESET_ALL)
text = current_forge["description"]
text_handling.print_long_string(text)
cout(" ")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
if "None" not in current_forge["forge"]["buys"]:
cout("METAL RESALES:")
count = 0
metal_buys = current_forge["forge"]["buys"]
metal_buys_len = len(metal_buys)
while count < metal_buys_len:
current_metal = str(metal_buys[count])
cout(
" -" + current_metal + " " + COLOR_YELLOW + COLOR_STYLE_BRIGHT +
str(get_cost(round(item[current_metal]["gold"] * current_forge["cost value"], 2), dropoff)) + COLOR_RESET_ALL
)
count += 1
if "None" not in current_forge["forge"]["sells"]:
cout("METAL SALES:")
count = 0
metal_sells = current_forge["forge"]["sells"]
metal_sells_len = len(metal_sells)
while count < metal_sells_len:
current_metal = str(metal_sells[count])
cout(
" -" + current_metal + " " + COLOR_YELLOW + COLOR_STYLE_BRIGHT +
str(get_cost(round(item[current_metal]["gold"] * current_forge["cost value"], 2), dropoff)) + COLOR_RESET_ALL
)
count += 1
text = '='
text_handling.print_separator(text)
def print_blacksmith_information(map_zone, zone, item, player):
current_black_smith = zone[map_zone]
current_black_smith_name = current_black_smith["name"]
logger_sys.log_message(f"INFO: Printing current blacksmith '{current_black_smith_name}' information to GUI")
cout(COLOR_STYLE_BRIGHT + str(current_black_smith["name"]) + ":" + COLOR_RESET_ALL)
text = current_black_smith["description"]
text_handling.print_long_string(text)
cout("")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
if "None" not in current_black_smith["blacksmith"]["buys"]:
cout("EQUIPMENT RESALES:")
count = 0
weapon_buys = current_black_smith["blacksmith"]["buys"]
weapon_buys_len = len(weapon_buys)
while count < weapon_buys_len:
current_weapon = str(weapon_buys[int(count)])
cout(
" -" + current_weapon + " " + COLOR_YELLOW + COLOR_STYLE_BRIGHT +
str(
get_cost(round(item[current_weapon]["gold"] * current_black_smith["cost value"], 2), dropoff)
) + COLOR_RESET_ALL
)
count += 1
if "None" not in current_black_smith["blacksmith"]["orders"]:
cout("EQUIPMENT ORDERS:")
count = 0
weapon_orders = current_black_smith["blacksmith"]["orders"]
weapon_orders_len = len(weapon_orders)
while count < weapon_orders_len:
current_weapon = str(list(weapon_orders)[int(count)])
current_weapon_materials = current_black_smith["blacksmith"]["orders"][current_weapon]["needed materials"]
count2 = 0
global_current_weapon_materials = []
current_weapon_materials_num = len(current_weapon_materials)
while count2 < current_weapon_materials_num:
current_material = current_weapon_materials[count2]
global_current_weapon_materials += [current_material]
count2 += 1
count2 = 0
global_current_weapon_materials = text_handling.multiple_items_in_list_formatting(
global_current_weapon_materials
)
global_current_weapon_materials = str(global_current_weapon_materials)
global_current_weapon_materials = global_current_weapon_materials.replace("'", '')
global_current_weapon_materials = global_current_weapon_materials.replace("[", '')
global_current_weapon_materials = global_current_weapon_materials.replace("]", '')
cout(
" -" + current_weapon + " " + COLOR_YELLOW + COLOR_STYLE_BRIGHT +
str(get_cost(round(zone[map_zone]["blacksmith"]["orders"][current_weapon]["gold"]), dropoff)) +
COLOR_RESET_ALL + COLOR_GREEN + COLOR_STYLE_BRIGHT +
" (" + COLOR_RESET_ALL + global_current_weapon_materials +
COLOR_GREEN + COLOR_STYLE_BRIGHT + ")" + COLOR_RESET_ALL
)
count += 1
text = '='
text_handling.print_separator(text)
def print_stable_information(map_zone, zone, mounts, item, player, map_location):
current_stable = zone[map_zone]
current_stable_name = current_stable["name"]
cout(COLOR_STYLE_BRIGHT + str(current_stable["name"]) + ":" + COLOR_RESET_ALL)
logger_sys.log_message(f"INFO: Printing current stable '{current_stable_name}' information to GUI")
text = current_stable["description"]
text_handling.print_long_string(text)
cout(" ")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
cout(
"DEPOSIT COST/DAY: " + COLOR_YELLOW + COLOR_STYLE_BRIGHT + str(get_cost(current_stable["deposit gold"], dropoff)) +
COLOR_RESET_ALL
)
cout(
"TRAINING COST/DAY: " + COLOR_YELLOW + COLOR_STYLE_BRIGHT + str(get_cost(current_stable["training gold"], dropoff)) +
COLOR_RESET_ALL
)
options = ['Train Mount', '']
if "None" not in current_stable["stable"]["sells"]["mounts"]:
cout("MOUNTS SALES:")
count = 0
stable_mounts = current_stable["stable"]["sells"]["mounts"]
stable_mounts_len = len(stable_mounts)
while count < stable_mounts_len:
current_mount = str(stable_mounts[int(count)])
cout(
" -" + current_stable["stable"]["sells"]["mounts"][int(count)] + " " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(
get_cost(round(mounts[current_mount]["gold"] * current_stable["cost value"], 2), dropoff)
) +
COLOR_RESET_ALL
)
count += 1
if "None" not in current_stable["stable"]["sells"]["items"]:
options += ['Buy Item']
cout("ITEMS SALES:")
count = 0
stable_items = current_stable["stable"]["sells"]["items"]
stable_items_len = len(stable_items)
while count < stable_items_len:
current_mount = str(stable_items[int(count)])
cout(
" -" + current_stable["stable"]["sells"]["items"][int(count)] + " " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(
get_cost(round(item[current_mount]["gold"] * current_stable["cost value"], 2), dropoff)
) +
COLOR_RESET_ALL
)
count += 1
cout(" ")
deposited_mounts_num = 0
count = 0
mounts_list_len = len(player["mounts"])
deposited_mounts_names = []
if "None" not in list(player["mounts"]):
while count < mounts_list_len:
selected_mount = list(player["mounts"])[count]
selected_mount = str(selected_mount)
if (
player["mounts"][selected_mount]["location"] == "point" +
str(map_location)
and player["mounts"][selected_mount]["is deposited"]
):
deposited_mounts_num += 1
deposited_mounts_names += [str(player["mounts"][selected_mount]["name"])]
count += 1
else:
deposited_mounts_names = 0
deposited_mounts_num = 0
deposited_mounts_names = str(deposited_mounts_names)
deposited_mounts_names = deposited_mounts_names.replace('[', '(')
deposited_mounts_names = deposited_mounts_names.replace(']', COLOR_RESET_ALL + ')')
deposited_mounts_names = deposited_mounts_names.replace("'", COLOR_GREEN + COLOR_STYLE_BRIGHT)
deposited_mounts_names = deposited_mounts_names.replace(',', COLOR_RESET_ALL + ',')
if deposited_mounts_num == 0:
cout("MOUNTS DEPOSITED HERE: " + COLOR_BLUE + COLOR_STYLE_BRIGHT + str(deposited_mounts_num) + COLOR_RESET_ALL)
else:
cout(
"MOUNTS DEPOSITED HERE: " + COLOR_BLUE + COLOR_STYLE_BRIGHT +
str(deposited_mounts_num) + COLOR_RESET_ALL + " " + deposited_mounts_names
)
text = '='
text_handling.print_separator(text)
def print_hostel_information(map_zone, zone, item, drinks, player):
current_hostel = zone[map_zone]
current_hostel_name = current_hostel["name"]
logger_sys.log_message(f"INFO: Printing current hostel '{current_hostel_name}' information to GUI")
cout(COLOR_STYLE_BRIGHT + str(current_hostel["name"]) + ":" + COLOR_RESET_ALL)
text = current_hostel["description"]
text_handling.print_long_string(text)
cout(" ")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
cout(
"SLEEP COST: " + COLOR_YELLOW + COLOR_STYLE_BRIGHT + str(get_cost(current_hostel["sleep gold"], dropoff)) +
COLOR_RESET_ALL
)
if "None" not in current_hostel["sells"]["drinks"]:
cout("DRINKS SALES:")
count = 0
hostel_drinks = current_hostel["sells"]["drinks"]
hostel_drinks_len = len(hostel_drinks)
while count < hostel_drinks_len:
current_drink = str(current_hostel["sells"]["drinks"][int(count)])
cout(
" -" + current_hostel["sells"]["drinks"][int(count)] + " " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(
get_cost(round(drinks[current_drink]["gold"] * current_hostel["cost value"], 2), dropoff)
) +
COLOR_RESET_ALL
)
count += 1
if "None" not in current_hostel["sells"]["items"]:
cout("ITEMS SALES")
count = 0
hostel_items = current_hostel["sells"]["items"]
hostel_items_len = len(hostel_items)
while count < hostel_items_len:
current_item = str(current_hostel["sells"]["items"][int(count)])
cout(
" -" + current_hostel["sells"]["items"][int(count)] + " " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(get_cost(round(item[current_item]["gold"] * current_hostel["cost value"], 2), dropoff)) +
COLOR_RESET_ALL
)
count += 1
if "None" not in current_hostel["buys"]["items"]:
cout("ITEMS RESALES:")
count = 0
hostel_items = current_hostel["buys"]["items"]
hostel_items_len = len(hostel_items)
while count < hostel_items_len:
current_item = str(current_hostel["buys"]["items"][int(count)])
cout(
" -" + current_hostel["buys"]["items"][int(count)] + " " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(get_cost(round(item[current_item]["gold"] * current_hostel["cost value"], 2), dropoff)) +
COLOR_RESET_ALL
)
count += 1
text = '='
text_handling.print_separator(text)
def print_grocery_information(map_zone, zone, item, player):
current_grocery = zone[map_zone]
current_grocery_name = current_grocery["name"]
logger_sys.log_message(f"INFO: Printing current grocery '{current_grocery_name}' information to GUI")
cout(COLOR_STYLE_BRIGHT + str(current_grocery["name"]) + ":" + COLOR_RESET_ALL)
text = current_grocery["description"]
text_handling.print_long_string(text)
cout()
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
cout("ITEMS SALES:")
sold_items_list = player["groceries data"][map_zone]["items sales"]
sold_items = []
for i in sold_items_list:
sold_items += [
f" -{i} {COLOR_YELLOW}{get_cost(round(zone[map_zone]['cost value'] * item[i]['gold'], 2), dropoff)}" +
COLOR_RESET_ALL
]
for i in sold_items:
cout(i)
text = '='
text_handling.print_separator(text)
def print_harbor_information(map_zone, zone, map, player):
current_harbor = zone[map_zone]
current_harbor_name = current_harbor["name"]
logger_sys.log_message(f"INFO: Printing current harbor '{current_harbor_name}' information to GUI")
cout(COLOR_STYLE_BRIGHT + str(current_harbor["name"]) + ":" + COLOR_RESET_ALL)
text = current_harbor["description"]
text_handling.print_long_string(text)
cout()
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
cout("TRAVELS:")
travels = []
count = 0
for travel in current_harbor["travels"]:
destination = map[f"point{current_harbor['travels'][travel]['destination']}"]
destination = f"({COLOR_GREEN}{destination['x']} {COLOR_RESET_ALL},{COLOR_GREEN}{destination['y']}{COLOR_RESET_ALL})"
travels += [
f" -{list(current_harbor['travels'])[count]} {destination}" +
f" {COLOR_YELLOW}{get_cost(round(current_harbor['travels'][travel]['cost'], 2), dropoff)}{COLOR_RESET_ALL}"
]
count += 1
for travel in travels:
cout(travel)
text = '='
text_handling.print_separator(text)
# Interactions functions
def interaction_hostel(map_zone, zone, player, drinks, item, save_file, preferences, previous_player):
logger_sys.log_message(f"INFO: Current map zone '{map_zone}' is an hostel --> can interact")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
text = '='
text_handling.print_separator(text)
logger_sys.log_message(f"INFO: Adding correct interactions options depending on the hostel '{map_zone}' capabilities")
options = ['Sleep']
if "None" not in zone[map_zone]["sells"]["drinks"]:
options += ['Buy Drink']
if "None" not in zone[map_zone]["sells"]["items"]:
options += ['Buy Item']
if "None" not in zone[map_zone]["buys"]["items"]:
options += ['Sell Item']
options += ['Exit']
continue_hostel_actions = True
logger_sys.log_message("INFO: Starting loop of hostel actions")
while continue_hostel_actions:
choice = terminal_handling.show_menu(options)
logger_sys.log_message(f"INFO: Player has chosen option '{choice}'")
if choice == 'Sleep':
cout("Are you sure you want to spend the night here? It will ")
ask = cinput("cost you " + str(zone[map_zone]["sleep gold"]) + " gold (y/n) ")
text = '='
text_handling.print_separator(text)
if ask.lower().startswith('y'):
if player["difficulty mode"] >= 1:
logger_sys.log_message("INFO: Dumping player RAM save into its save file")
dumped = yaml_handling.dump(player)
previous_player = player
logger_sys.log_message(f"INFO: Dumping player save data: '{dumped}'")
save_file_quit = save_file
with open(save_file_quit, "w") as f:
f.write(dumped)
logger_sys.log_message(f"INFO: Dumping player save data to save '{save_file_quit}'")
save_name_backup = save_file.replace('save_', '~0 save_')
with open(save_name_backup, "w") as f:
f.write(dumped)
logger_sys.log_message(f"INFO: Dumping player save data to backup save '{save_name_backup}'")
dumped = yaml_handling.dump(preferences)
logger_sys.log_message(f"INFO: Dumping player preferences data: '{dumped}'")
with open(program_dir + '/preferences.yaml', 'w') as f:
f.write(dumped)
logger_sys.log_message(f"INFO: Dumping player preferences to file '" + program_dir + "/preferences.yaml'")
logger_sys.log_message("INFO: Starting player sleeping process")
if int(player["gold"]) > int(get_cost(zone[map_zone]["sleep gold"], dropoff)):
sleep_gold = get_cost(zone[map_zone]["sleep gold"], dropoff, False)
logger_sys.log_message(f"INFO: Removed {sleep_gold} from player --> sleep costs")
player["gold"] -= sleep_gold
loading = 7
cout(" ")
while loading > 0:
cout("Sleeping... Zzz", end='\r')
time.sleep(.25)
cout("Sleeping... zZz", end='\r')
time.sleep(.25)
cout("Sleeping... zzZ", end='\r')
time.sleep(.25)
cout("Sleeping... zzz", end='\r')
time.sleep(.25)
cout("Sleeping... Zzz", end='\r')
time.sleep(.25)
cout("Sleeping... zZz", end='\r')
time.sleep(.25)
cout("Sleeping... zzZ", end='\r')
time.sleep(.25)
cout("Sleeping... zzz", end='\r')
time.sleep(.25)
player["health"] += random.randint(1, 7)
loading -= 1
logger_sys.log_message("INFO: Finished sleeping process")
logger_sys.log_message("INFO: Updating correct day time to morning")
player["elapsed time game days"] = float(float(round(player["elapsed time game days"] + 1, 0)) + .25)
continue_hostel_actions = False
if player["health"] > player["max health"]:
player["health"] = player["max health"]
else:
logger_sys.log_message("INFO: Canceling sleeping process --> player doesn't own enough gold")
cout(COLOR_YELLOW + "You don't own enough gold to sleep here." + COLOR_RESET_ALL)
elif choice == 'Buy Drink':
which_drink = cinput("Which drink do you want to buy? ")
logger_sys.log_message(f"INFO: Player has chosen drink '{which_drink}' to drink")
if (
which_drink in zone[map_zone]["sells"]["drinks"]
and get_cost(drinks[which_drink]["gold"] * zone[map_zone]["cost value"], dropoff) < player["gold"]
):
drink_cost = get_cost(
drinks[which_drink]["gold"] * zone[map_zone]["cost value"], dropoff, False
)
logger_sys.log_message(f"INFO: Buying drink '{which_drink}' --> removed {drink_cost} gold from player")
player["gold"] -= drink_cost
if drinks[which_drink]["healing level"] == 999:
logger_sys.log_message("INFO: Healed player to max health")
player["health"] = player["max health"]
else:
healing_level = drinks[which_drink]["healing level"]
logger_sys.log_message(f"INFO: Healed player {healing_level} hp")
player["health"] += drinks[which_drink]["healing level"]
else:
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your gold to be negative." + COLOR_RESET_ALL
)
logger_sys.log_message(f"INFO: Canceling buying process of drink '{which_drink}' --> doesn't have enough gold")
text_handling.print_long_string(text)
elif choice == 'Buy Item':
which_item = cinput("Which item do you want to buy? ")
logger_sys.log_message(f"INFO: Player has chosen item '{which_item}' to buy")
if (
which_item in zone[map_zone]["sells"]["items"]
and get_cost(item[which_item]["gold"] * zone[map_zone]["cost value"], dropoff) < player["gold"]
):
if player["inventory slots remaining"] > 0:
player["inventory slots remaining"] -= 1
logger_sys.log_message(f"INFO: Adding item '{which_item}' to player inventory")
player["inventory"].append(which_item)
item_cost = get_cost(item[which_item]["gold"] * zone[map_zone]["cost value"], dropoff, False)
logger_sys.log_message(f"INFO: Removing {item_cost} gold from player")
player["gold"] -= item_cost
else:
logger_sys.log_message("INFO: Canceling buying process --> doesn't have enough inventory slots")
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your inventory slots to be negative." +
COLOR_RESET_ALL
)
text_handling.print_long_string(text)
else:
logger_sys.log_message("INFO: Canceling buying process --> doesn't have enough gold")
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your gold to be negative." +
COLOR_RESET_ALL
)
text_handling.print_long_string(text)
elif choice == 'Sell Item':
which_item = cinput("Which item do you want to sell? ")
logger_sys.log_message(f"INFO: Player has chosen item '{which_item}' to sell")
if (
which_item in zone[map_zone]["buys"]["items"]
and which_item in player["inventory"]
):
logger_sys.log_message(f"INFO: Removing item '{which_item}' from player inventory")
player["inventory slots remaining"] += 1
gold = get_cost(item[which_item]["gold"] * zone[map_zone]["cost value"], dropoff, False)
logger_sys.log_message(f"INFO: Adding to player {gold} gold")
player["gold"] += gold
player["inventory"].remove(which_item)
which_item_number_inventory = 0
count = 0
p = True
while p:
if count >= len(player["inventory"]) + 1:
p = False
else:
selected_item = player["inventory"][count - 1]
if str(selected_item) == str(which_item):
which_item_number_inventory += 1
count += 1
if which_item_number_inventory <= 1:
if which_item == player["held item"]:
player["held item"] = " "
if which_item == player["held chestplate"]:
player["held chestplate"] = " "
if which_item == player["held boots"]:
player["held boots"] = " "
if which_item == player["held leggings"]:
player["held leggings"] = " "
if which_item == player["held shield"]:
player["held shield"] = " "
else:
logger_sys.log_message(f"INFO: Canceling selling process --> doesn't own item '{which_item}'")
text = COLOR_YELLOW + "You cannot sell that items because you don't own any of this item." + COLOR_RESET_ALL
text_handling.print_long_string(text)
else:
continue_hostel_actions = False
def interaction_stable(map_zone, zone, player, item, drinks, mounts, map_location, preferences, time_elapsing_coefficient):
logger_sys.log_message(f"INFO: Current map zone '{map_zone}' is a stable --> can interact")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
options = ["Train Mount", "Deposit Mount", "Ride Mount"]
if "None" not in zone[map_zone]["stable"]["sells"]["mounts"]:
options += ["Buy Mount"]
if "None" not in zone[map_zone]["stable"]["sells"]["drinks"]:
options += ["Buy Drink"]
if "None" not in zone[map_zone]["stable"]["sells"]["items"]:
options += ["Buy Item"]
options += ["Exit"]
active_stable_menu = True
text = '='
text_handling.print_separator(text)
logger_sys.log_message("INFO: Starting stable interaction loop")
while active_stable_menu:
action = terminal_handling.show_menu(options)
logger_sys.log_message(f"INFO: Player has chosen option '{action}'")
if action == 'Buy Item':
which_item = cinput("Which item do you want to buy? ")
logger_sys.log_message(f"INFO: Player has chosen item '{which_item}' to buy")
if (
which_item in zone[map_zone]["stable"]["sells"]["items"]
and get_cost(item[which_item]["gold"] * zone[map_zone]["cost value"], dropoff) < player["gold"]
):
if player["inventory slots remaining"] > 0:
logger_sys.log_message(f"INFO: Adding item '{which_item}' from player inventory")
player["inventory slots remaining"] -= 1
player["inventory"].append(which_item)
gold = get_cost(item[which_item]["gold"] * zone[map_zone]["cost value"], dropoff, False)
logger_sys.log_message(f"INFO: Removing {gold} gold from player")
player["gold"] -= gold
else:
logger_sys.log_message("INFO: Canceling buying process -> doesn't gas enough inventory slots")
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your inventory slots to be negative." +
COLOR_RESET_ALL
)
text_handling.print_long_string(text)
else:
logger_sys.log_message("INFO: Canceling buying process --> doesn't has enough gold")
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your gold to be negative." + COLOR_RESET_ALL
)
text_handling.print_long_string(text)
elif action == 'Buy Drink':
which_drink = cinput("Which drink do you want to buy? ")
logger_sys.log_message(f"INFO: Player has chosen drink '{which_drink}' to buy")
if (
which_drink in zone[map_zone]["stable"]["sells"]["drinks"]
and get_cost(drinks[which_drink]["gold"] * zone[map_zone]["cost value"], dropoff) < player["gold"]
):
gold = get_cost(drinks[which_drink]["gold"] * zone[map_zone]["cost value"], dropoff, False)
logger_sys.log_message(f"INFO: Removing {gold} gold from player")
player["gold"] -= gold
if drinks[which_drink]["healing level"] == 999:
logger_sys.log_message(f"INFO: Consuming drink '{which_drink}' --> healing player to max health")
player["health"] = player["max health"]
else:
healing_level = drinks[which_drink]["healing level"]
logger_sys.log_message(f"INFO: Consuming drink '{which_drink}' --> healing player {healing_level} hp")
player["health"] += drinks[which_drink]["healing level"]
else:
logger_sys.log_message("INFO: Canceling buying process --> doesn't have enough gold")
text = (
COLOR_YELLOW + "You cannot buy that items because it would cause your gold to be negative." + COLOR_RESET_ALL
)
text_handling.print_long_string(text)
elif action == 'Buy Mount':
which_mount = cinput("Which mount do you want to buy? ")
logger_sys.log_message(f"INFO: Player has chosen mount '{which_mount}' to buy")
if which_mount in zone[map_zone]["stable"]["sells"]["mounts"]:
mount_cost = get_cost(mounts[which_mount]["gold"] * zone[map_zone]["cost value"], dropoff, False)
if mount_cost < player["gold"]:
logger_sys.log_message(f"INFO: Removing player {mount_cost} gold")
player["gold"] -= mount_cost
generated_mount_uuid = uuid_handling.generate_random_uuid()
cout("How you mount should be named ?")
new_mount_name = cinput(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL)
logger_sys.log_message(f"INFO: Player has chosen name '{new_mount_name}' for its new mount")
mounts_names_list = []
count = 0
if "None" not in list(player["mounts"]):
mounts_list_len = len(player["mounts"])
while count < mounts_list_len:
selected_mount = list(player["mounts"])[count]
selected_mount = str(selected_mount)
mounts_names_list.append(str(player["mounts"][selected_mount]["name"]))
count += 1
if new_mount_name in mounts_names_list:
logger_sys.log_message(f"INFO: Canceling buying process --> already has a mount name '{new_mount_name}'")
cout(COLOR_YELLOW + "You already have a mount named like that." + COLOR_RESET_ALL)
text = '='
text_handling.print_separator(text)
else:
logger_sys.log_message("INFO: Creating new mount stats")
mount_stats = {
"agility addition": mounts[which_mount]["stats"]["agility addition"],
"resistance addition": mounts[which_mount]["stats"]["resistance addition"]
}
mount_dict = {
"deposited day": round(player["elapsed time game days"], 2),
"is deposited": True,
"level": 0,
"location": "point" + str(map_location),
"mount": str(which_mount),
"name": str(new_mount_name),
"stats": mount_stats,
"mph": mounts[which_mount]["mph"]
}
logger_sys.log_message(f"INFO: Created new mount stats: '{mount_dict}'")
player["mounts"][generated_mount_uuid] = mount_dict
logger_sys.log_message(f"INFO: Deposited new mount at map zone '{map_zone}'")
text = (
"Your mount is currently deposited at the " + zone[map_zone]["name"] +
"\nYou can ride it whenever you want."
)
text_handling.print_speech_text_effect(text, preferences)
text = '='
text_handling.print_separator(text)
else:
logger_sys.log_message("INFO: Canceling buying process --> doesn't has enough gold")
cout(COLOR_YELLOW + "You don't own enough gold to buy that mount" + COLOR_RESET_ALL)
else:
logger_sys.log_message(
f"INFO: Canceling buying process --> current stable '{map_zone}'" +
f" doesn't sell mount '{which_mount}'"
)
cout(COLOR_YELLOW + "The current stable do not sell this mount" + COLOR_RESET_ALL)
elif action == 'Deposit Mount':
if player["current mount"] != " ":
current_mount_uuid = str(player["current mount"])
mount_data = player["mounts"][current_mount_uuid]
current_mount = mount_data["name"]
current_mount_type = mount_data["mount"]
# check if required stables are in the stable attributes
required_mount_stable = str(mounts[str(mount_data["mount"])]["stable"]["required stable"])
if required_mount_stable in zone[map_zone]["stable"]["stables"]:
ask = cinput("Do you want to deposit your current mount " + mount_data["name"] + " ? (y/n) ")
if ask.lower().startswith('y'):
logger_sys.log_message(
f"INFO: Depositing currently player ridden mount '{current_mount}'" +
f" to map zone '{map_zone}"
)
player["current mount"] = " "
player["mounts"][current_mount_uuid]["is deposited"] = True
player["mounts"][current_mount_uuid]["deposited day"] = round(player["elapsed time game days"], 1)
player["mounts"][current_mount_uuid]["location"] = str("point" + str(map_location))
text = "="
text_handling.print_separator(text)
else:
logger_sys.log_message(
f"INFO: Canceling depositing process --> current stable '{map_zone}' " +
f"doesn't accept mounts of type '{current_mount_type}'"
)
cout(COLOR_YELLOW + "This stable doesn't accept this type of mount." + COLOR_RESET_ALL)
else:
logger_sys.log_message("INFO: Canceling depositing process --> doesn't ride any mounts by now")
cout(COLOR_YELLOW + "You don't have any mounts to deposit here." + COLOR_RESET_ALL)
elif action == 'Train Mount':
if player["current mount"] != ' ':
current_mount_uuid = str(player["current mount"])
current_mount_type = str(player["mounts"][current_mount_uuid]["mount"])
current_mount_data = mounts[current_mount_type]
if current_mount_data["stable"]["required stable"] in zone[map_zone]["stable"]["stables"]:
logger_sys.log_message("INFO: Starting mount training of mount '{current_mount_uuid}'")
train.training_loop(
current_mount_uuid, player, item, mounts, zone[map_zone], time_elapsing_coefficient, dropoff
)
else:
logger_sys.log_message(
f"INFO: Aborting mount training of mount '{current_mount_uuid}' " +
"--> the current stable isn't the right stable type"
)
cout(
COLOR_YELLOW + "The current stable doesn't have the right facilities for this mount" + COLOR_RESET_ALL
)
else:
logger_sys.log_message("INFO: Canceling mount train process --> doesn't ride any mounts by now")
text = (
COLOR_YELLOW + "You're not riding any mounts currently. You need to ride one to train it." + COLOR_RESET_ALL
)
text_handling.print_long_string(text)
elif action == 'Ride Mount':
if player["current mount"] == ' ':
logger_sys.log_message(f"INFO: Getting player deposited mounts at stable '{map_zone}'")
# get player total mounts at this place
deposited_mounts_num = 0
count = 0
mounts_list_len = len(player["mounts"])
deposited_mounts_names = []
if "None" not in list(player["mounts"]):
while count < mounts_list_len:
selected_mount = list(player["mounts"])[count]
selected_mount = str(selected_mount)
if (
player["mounts"][selected_mount]["location"] == "point" +
str(map_location) and player["mounts"][selected_mount]["is deposited"]
):
deposited_mounts_num += 1
deposited_mounts_names += [str(player["mounts"][selected_mount]["name"])]
count += 1
else:
deposited_mounts_names = None
deposited_mounts_num = 0
deposited_mounts_names_list = deposited_mounts_names
deposited_mounts_names = str(deposited_mounts_names)
deposited_mounts_names = deposited_mounts_names.replace("'", '')
deposited_mounts_names = deposited_mounts_names.replace("[", ' -')
deposited_mounts_names = deposited_mounts_names.replace("]", '')
deposited_mounts_names = deposited_mounts_names.replace(", ", '\n -')
cout("MOUNTS AT THIS STABLE:")
cout(deposited_mounts_names)
text = '='
text_handling.print_separator(text)
which_mount = cinput(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL)
logger_sys.log_message(f"INFO: Player has chosen mount '{which_mount}' to ride")
if which_mount in deposited_mounts_names_list:
# get what is the uuid of the mount of this name
count = 0
continue_searching = True
which_mount_uuid = ""
while count < len(list(player["mounts"])) and continue_searching:
selected_mount_uuid = list(player["mounts"])[count]
selected_mount_data = player["mounts"][selected_mount_uuid]
if selected_mount_data["name"] == which_mount:
continue_searching = False
which_mount_uuid = str(selected_mount_uuid)
count += 1
mount_take_back_cost = get_cost(round(
(
player["elapsed time game days"] - player["mounts"][which_mount_uuid]["deposited day"]
) * zone[map_zone]["deposit gold"], 2
), dropoff, False)
cout(
"If you take back this mount it will cost you " + COLOR_YELLOW +
COLOR_STYLE_BRIGHT + str(round(mount_take_back_cost, 2)) + COLOR_RESET_ALL + " gold. "
)
ask = cinput("(y/n) ")
if player["gold"] > mount_take_back_cost:
if ask.lower().startswith('y'):
logger_sys.log_message(f"INFO: Removing {mount_take_back_cost} gold from player")
player["gold"] -= mount_take_back_cost
player["current mount"] = str(which_mount_uuid)
player["mounts"][which_mount_uuid]["is deposited"] = False
player["mounts"][which_mount_uuid]["deposited day"] = 0
player["mounts"][which_mount_uuid]["location"] = "point" + str(map_location)
else:
logger_sys.log_message("INFO: Canceling taking back process --> doesn't has enough gold")
cout(COLOR_YELLOW + "You don't own enough gold to take back your mount." + COLOR_RESET_ALL)
else:
logger_sys.log_message(
"INFO: Canceling taking back process --> doesn't own that mount " +
"or the mount isn't deposited at this current location"
)
text = (
COLOR_YELLOW + "You don't own that mount or the mount isn't deposited at this current location" +
COLOR_RESET_ALL
)
text_handling.print_long_string(text)
else:
logger_sys.log_message(f"INFO: Canceling taking back process --> already riding a mount")
text = (
COLOR_YELLOW + "You are currently already riding a mount. You need " +
"to deposit your current mount before riding an other one." + COLOR_RESET_ALL
)
text_handling.print_long_string(text)
else:
active_stable_menu = False
def interaction_blacksmith(map_zone, zone, item, player):
logger_sys.log_message(f"INFO: Current map zone '{map_zone}' is a blacksmith --> can interact")
# Check if there's a discount active at this
# map zone
if player["discounts"][map_zone]["dropoff"] is not None:
dropoff = player["discounts"][map_zone]["dropoff"]
else:
dropoff = 0
text = '='
text_handling.print_separator(text)
options = ['Sell Equipment', 'Order Equipment', 'Upgrade Equipment', 'Check Order', 'Exit']
continue_blacksmith_actions = True
logger_sys.log_message("INFO: Starting blacksmith interact loop")
while continue_blacksmith_actions:
action = terminal_handling.show_menu(options)
logger_sys.log_message(f"INFO: Player has chosen option '{action}'")
if action == 'Sell Equipment':
which_weapon = cinput("Which equipment do you want to sell? ")
logger_sys.log_message(f"INFO: Player has chosen item '{which_weapon}' to sell")
if which_weapon in zone[map_zone]["blacksmith"]["buys"] and which_weapon in player["inventory"]:
player["inventory slots remaining"] += 1
gold = get_cost(item[which_weapon]["gold"] * zone[map_zone]["cost value"], dropoff, False)
player["gold"] += gold
logger_sys.log_message(f"INFO: Adding to player {gold} gold")
player["inventory"].remove(which_weapon)
logger_sys.log_message(f"INFO: Removing item '{which_weapon}' from player inventory")
else:
text = (
COLOR_YELLOW + "You cannot sell that equipment because you " +
"dont own any of that weapon or because the current blacksmith doesn't buy this weapon." +
COLOR_RESET_ALL
)
logger_sys.log_message(
f"INFO: Canceling selling process --> current blacksmith '{map_zone}' " +
f"doesn't sell item '{which_weapon}' or player doesn't own item '{which_weapon}'"
)
text_handling.print_long_string(text)
elif action == 'Order Equipment':
which_weapon = cinput("Which equipment do you want to order? ")
logger_sys.log_message(f"INFO: Player has chosen item '{which_weapon}' to order")
if (
which_weapon in zone[map_zone]["blacksmith"]["orders"]
and player["gold"] > get_cost(zone[map_zone]["blacksmith"]["orders"][which_weapon]["gold"], dropoff)
):
required_items = False
count = 0
required_items_number = 0
fake_player_inventory = player["inventory"]
while count < len(fake_player_inventory):
selected_item = fake_player_inventory[count]
if selected_item in zone[map_zone]["blacksmith"]["orders"][which_weapon]["needed materials"]:
required_items_number += 1
count += 1
if required_items_number == len(zone[map_zone]["blacksmith"]["orders"][which_weapon]["needed materials"]):
required_items = True
logger_sys.log_message("INFO: Player has required items --> continuing")
if required_items:
gold = get_cost(zone[map_zone]["blacksmith"]["orders"][which_weapon]["gold"], dropoff, False)
logger_sys.log_message(f"INFO: Removing from player {gold} gold")
player["gold"] -= gold
count = 0
remaining_items_to_remove = len(zone[map_zone]["blacksmith"]["orders"][which_weapon]["needed materials"])
while count < len(player["inventory"]) and remaining_items_to_remove != 0:
selected_item = zone[map_zone]["blacksmith"]["orders"][which_weapon]["needed materials"][count]
logger_sys.log_message(f"INFO: Removing from player inventory item '{selected_item}'")
player["inventory"].remove(selected_item)
player["inventory slots remaining"] += 1
remaining_items_to_remove -= 1
count += 1
order_uuid = uuid_handling.generate_random_uuid()
logger_sys.log_message(f"INFO: Creating order '{order_uuid}' dictionary")
order_dict = {
"paid gold": gold,
"ordered weapon": which_weapon,
"ordered day": player["elapsed time game days"],
"ordered blacksmith": zone[map_zone]["name"],
"time needed": zone[map_zone]["blacksmith"]["orders"][which_weapon]["time needed"],
"has taken back order": "false"
}
logger_sys.log_message(f"Created order '{order_uuid}' dictionary: '{order_dict}'")
player["orders"][order_uuid] = order_dict
text = (
"You'll be able to get your finished order in " + COLOR_MAGENTA +
COLOR_STYLE_BRIGHT + str(zone[map_zone]["blacksmith"]["orders"][which_weapon]["time needed"]) +
COLOR_RESET_ALL + " days."
)
text_handling.print_long_string(text)
else:
logger_sys.log_message("INFO: Canceling ordering process --> doesn't have necessary items")
text = (
COLOR_YELLOW + "You cannot order that equipment because you dont have the necessary items." +
COLOR_RESET_ALL
)