You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orna_tools.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from flask import Flask, render_template, jsonify, request
  2. app = Flask(__name__)
  3. @app.route('/')
  4. def index():
  5. return render_template('index.html')
  6. @app.route('/results', methods=['POST'])
  7. def results():
  8. combinations = calculate_combinations(request.get_json())
  9. return jsonify(combinations)
  10. # Data Methods
  11. def calculate_combinations(equipment, do_print=False):
  12. # name, defense, resistance
  13. eq_headware = equipment["head"]
  14. eq_chestware = equipment["chest"]
  15. eq_legwear = equipment["legs"]
  16. # Create a list of all possible eq combinations
  17. results = []
  18. for hw in eq_headware:
  19. for cw in eq_chestware:
  20. for lw in eq_legwear:
  21. result = {}
  22. result["eq"] = [hw[0], cw[0], lw[0]]
  23. result["def"] = hw[1] + cw[1] + lw[1]
  24. result["res"] = hw[2] + cw[2] + lw[2]
  25. results.append(result)
  26. # Sort the combinations by combined total of def anf res
  27. results.sort(key=lambda i: i["def"] + i["res"])
  28. if do_print:
  29. for result in results:
  30. print("{} ({} def {} res) -".format(result["def"] + result["res"], result["def"], result["res"]))
  31. for eq in result["eq"]:
  32. print("\t{}".format(eq))
  33. return results
  34. """
  35. eq_headware = [
  36. ["Ljosalfar Hood", 98, 510],
  37. ["Kobold Hood", 0, 614],
  38. ["Northern Cowl", 584, 130],
  39. ["High Fomorian Hood", 487, 112]
  40. ]
  41. eq_chestware = [
  42. ["Ljosalfar Robe", 121, 528],
  43. ["High Fomorian Garb", 544, 0],
  44. ["Darkest Garb", 514, 169],
  45. ["Northern Garb", 535, 119],
  46. ["Northern Robe", 486, 108]
  47. ]
  48. eq_legwear = [
  49. ["Northern Boots", 636, 142],
  50. ["Terra Boots", 129, 369],
  51. ["High Fomorian Boots", 516, 0],
  52. ["Ljosalfar Boots", 280, 280]
  53. ]
  54. """