"""Generate RynthAi's ammo recipe table from the ACE world database. Every fletching combine that makes arrows, quarrels or atlatl darts, as the server knows it: head applied to shaft, result, and the recipe's difficulty. Replaces a hand-written list that had heads that don't exist ("Quarrelheads", "Atlatl Dart Heads": quarrels and darts use the same Arrowheads, the shaft decides), knew only the "Wrapped Bundle of" names (plain "Bundle of" is real too) and missed the elemental, Greater/Deadly, Infinite and unique heads. 1. Export the fletching recipes (skill 37) to a TSV, e.g. with the MariaDB CLI against a stock ace_world: mariadb -u root ace_world -e " SELECT r.id AS recipe, r.difficulty, r.success_Amount AS amt, cb.source_W_C_I_D AS src, ns.value AS source_name, cb.target_W_C_I_D AS tgt, nt.value AS target_name, r.success_W_C_I_D AS out_wcid, nr.value AS result_name FROM recipe r JOIN cook_book cb ON cb.recipe_Id = r.id LEFT JOIN weenie_properties_string ns ON ns.object_Id = cb.source_W_C_I_D AND ns.type = 1 LEFT JOIN weenie_properties_string nt ON nt.object_Id = cb.target_W_C_I_D AND nt.type = 1 LEFT JOIN weenie_properties_string nr ON nr.object_Id = r.success_W_C_I_D AND nr.type = 1 WHERE r.skill = 37 ORDER BY nr.value, ns.value;" > fletching.tsv 2. python gen-ammo-recipes.py fletching.tsv [out.cs] out.cs defaults to Plugins/RynthCore.Plugin.RynthAi/Combat/AmmoRecipes.Data.cs. """ import csv import os import re import sys AMMO = re.compile(r"(Arrow|Quarrel|Atlatl Dart)$") def category(shaft): if "Arrowshaft" in shaft: return "Bow" if "Quarrelshaft" in shaft: return "Crossbow" if "Dart" in shaft: return "Atlatl" raise SystemExit(f"unknown shaft: {shaft!r}") def cs(s): return '"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"' def main(): tsv = sys.argv[1] here = os.path.dirname(os.path.abspath(__file__)) out = sys.argv[2] if len(sys.argv) > 2 else os.path.join( here, "..", "Plugins", "RynthCore.Plugin.RynthAi", "Combat", "AmmoRecipes.Data.cs") rows = {} for r in csv.DictReader(open(tsv, encoding="utf-8-sig"), delimiter="\t"): result = r["result_name"] if not result or result == "NULL" or not AMMO.search(result): continue key = (r["source_name"], r["target_name"]) row = (r["source_name"], r["target_name"], result, category(r["target_name"]), int(r["difficulty"])) if key in rows: if rows[key][2] != result: raise SystemExit(f"one head+shaft, two results: {rows[key]} vs {row}") # Same names, two weenies (e.g. Greater Deadly Blunt at 300 and 320): the # client only sees names, so keep the harder one for the skill check. row = max(rows[key], row, key=lambda x: x[4]) rows[key] = row ordered = sorted(rows.values(), key=lambda x: (-x[4], x[3], x[2], x[0], x[1])) w = max(len(cs(x[0])) for x in ordered) + 1 v = max(len(cs(x[1])) for x in ordered) + 1 o = max(len(cs(x[2])) for x in ordered) + 1 lines = [ "// ", "// Generated by Tools/gen-ammo-recipes.py from the ACE world database", "// (recipe + cook_book, skill 37 = Fletching). Do not edit by hand: re-export and", "// re-run the script. Sorted by difficulty, highest first.", "// ", "", "namespace RynthCore.Plugin.RynthAi;", "", "public static partial class AmmoRecipes", "{", f" /// All {len(ordered)} fletching combines that make ammo, hardest (best) first.", " public static readonly AmmoRecipe[] All =", " {", ] for head, shaft, result, cat, diff in ordered: lines.append(f" new({(cs(head) + ',').ljust(w)} {(cs(shaft) + ',').ljust(v)} " f"{(cs(result) + ',').ljust(o)} WeaponCategory.{cat + ',':<9} {diff:3}),") lines += [" };", "}", ""] with open(out, "w", encoding="utf-8", newline="\r\n") as f: f.write("\n".join(lines)) print(f"{len(ordered)} recipes -> {os.path.normpath(out)}") if __name__ == "__main__": main()