Filling traits.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import sys
  2. import os
  3. import argparse
  4. import math
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument('-dir', '--directory', '--game-directory', dest='game_dir',
  7. help='set path of GAME_DIR', required=True)
  8. print("Type arguments and tap enter. If there are not any arguments tap enter with empty string")
  9. print("Use -h or --help to get list of arguments")
  10. args = parser.parse_args(input().split())
  11. path_to_game = args.game_dir
  12. def get_lvl(path):
  13. lvl = 0
  14. for file in os.listdir(path=path):
  15. if file == 'unitname.txt':
  16. cur_file = open(path + '\\' + file, 'r')
  17. # print(cur_file)
  18. name = cur_file.read()
  19. if 'IV' in name:
  20. lvl = 4
  21. elif 'III' in name:
  22. lvl = 3
  23. elif 'II' in name:
  24. lvl = 2
  25. elif 'I' in name:
  26. lvl = 1
  27. cur_file.close()
  28. return lvl
  29. def get_baseclass(path):
  30. for file in os.listdir(path=path):
  31. if file == 'baseclass.txt':
  32. cur_file = open(path + '\\' + file, 'r')
  33. name = cur_file.read()
  34. cur_file.close()
  35. return name
  36. def print_traits(file, lvl, baseclass):
  37. file.write('lvl=')
  38. file.write(str(lvl) + '\n')
  39. file.write('cost=')
  40. file.write(str(125 + 150 * (lvl - 1)) + '\n')
  41. file.write('starting_ap=')
  42. file.write(str(max(2, lvl ** 2 - 2 * lvl - 2 * lvl // 4)) + '\n')
  43. if baseclass == 'Warrior\n' or baseclass == 'Rider\n':
  44. file.write('strength=')
  45. file.write(str(lvl + 1) + '\n')
  46. file.write('agility=')
  47. stat = max(lvl - 1, 0)
  48. file.write(str(stat) + '\n')
  49. file.write('intelligence=')
  50. stat = max(lvl - 2, 0)
  51. file.write(str(stat) + '\n')
  52. elif baseclass == 'Archer\n' or baseclass == 'Rogue\n':
  53. stat = max(lvl - 2, 0)
  54. file.write('strength=')
  55. file.write(str(stat) + '\n')
  56. file.write('agility=')
  57. stat = max(lvl, 0)
  58. file.write(str(lvl + 1) + '\n')
  59. file.write('intelligence=')
  60. stat = max(lvl - 2, 0)
  61. file.write(str(stat) + '\n')
  62. else:
  63. stat = max(lvl - 2, 0)
  64. file.write('strength=')
  65. file.write(str(stat) + '\n')
  66. file.write('agility=')
  67. stat = max(lvl - 2, 0)
  68. file.write(str(stat) + '\n')
  69. file.write('intelligence=')
  70. file.write(str(lvl + 1) + '\n')
  71. file.write('initiative=')
  72. if baseclass == 'Rider\n' or 'Rogue\n':
  73. file.write(str(math.ceil(lvl * 2.5)) + '\n')
  74. elif baseclass == 'Archer\n' or 'Warrior\n':
  75. file.write(str(math.ceil(lvl * 2)) + '\n')
  76. elif baseclass == 'Mage\n':
  77. file.write(str(math.ceil(lvl * 1.5)) + '\n')
  78. if baseclass == 'Rogue\n':
  79. file.write('magic_def=' + str(math.ceil(lvl * 1.5)) + '\n')
  80. file.write('physic_def=' + str(math.ceil(lvl)) + '\n')
  81. elif baseclass == 'Rider\n':
  82. file.write('magic_def=' + str(max(1, int(math.ceil(lvl * 0.75)))) + '\n')
  83. file.write('physic_def=' + str(math.ceil(lvl * 1.5)) + '\n')
  84. elif baseclass == 'Warrior\n':
  85. file.write('magic_def=' + str(max(1, int(math.ceil(lvl * 0.75)))) + '\n')
  86. file.write('physic_def=' + str(math.ceil(lvl * 2)) + '\n')
  87. elif baseclass == 'Mage\n':
  88. file.write('magic_def=' + str(math.ceil(lvl * 2)) + '\n')
  89. file.write('physic_def=' + str(max(1, int(math.ceil(lvl * 0.75)))) + '\n')
  90. elif baseclass == 'Archer\n':
  91. file.write('magic_def=' + str(math.ceil(lvl)) + '\n')
  92. file.write('physic_def=' + str(max(1, int(math.ceil(lvl * 0.75)))) + '\n')
  93. def race_traits_fill(racename):
  94. path_to_race = path_to_game + '\\assets\\units\\' + racename
  95. for class_dir in os.listdir(path=path_to_race):
  96. if '.' not in class_dir:
  97. for file in os.listdir(path=path_to_race + '\\' + class_dir):
  98. if file.startswith('traits'):
  99. path = path_to_race + '\\' + class_dir + '\\' + file
  100. try:
  101. lvl = get_lvl(path_to_race + '\\' + class_dir)
  102. baseclass = get_baseclass(path_to_race + '\\' + class_dir)
  103. os.rename(path, path_to_race + '\\' + class_dir + '\\' + 'traits.ini')
  104. path = path_to_race + '\\' + class_dir + '\\' + 'traits.ini';
  105. cur_file = open(path, 'w')
  106. print_traits(cur_file, lvl, baseclass)
  107. cur_file.close()
  108. print(path + ' - OK!')
  109. except OSError:
  110. print(path + ' - FAILED!')
  111. # -d D:\Honourihed\repo
  112. def create_folders(racename, folder_name):
  113. path_to_race = path_to_game + '\\assets\\units\\' + racename
  114. for class_dir in os.listdir(path=path_to_race):
  115. if '.' not in class_dir:
  116. new_path = path_to_race + '\\' + class_dir + '\\' + folder_name
  117. if not os.path.exists(new_path):
  118. os.mkdir(new_path)
  119. def main():
  120. # race_traits_fill('undead')
  121. # race_traits_fill('human')
  122. create_folders('undead', 'sprites')
  123. create_folders('human', 'sprites')
  124. if __name__ == '__main__':
  125. main()