#!/usr/bin/env python3 """Restore production rune buffs to f2p NPCs, excluding THUG, KBD, ZOMBIE_INVOKED, MAN_ARDOUGNE. For each NPC + rune item, copy production's amounts to the new file's matching weight slots. Weights stay the same; only amounts change. Restored items: LESSER_DEMON FIRE_RUNE x20→x45, x40→x45 (wait — match by weight) LESSER_DEMON DEATH_RUNE x2→x10 DARKWIZARD_LVL13 FIRE_RUNE x3→x7, x8→x12 DARKWIZARD_LVL25 FIRE_RUNE x7→x10, x12→x15 GIANT DEATH_RUNE x1→x5 LESSER_DEMON_WMAZEKEY FIRE_RUNE x20→x25, x40→x45 GREATER_DEMON FIRE_RUNE x25→x60, x50→x100 GREATER_DEMON DEATH_RUNE x3→x30 PIRATE_LVL30 CHAOS_RUNE x1→x2 PIRATE_LVL30 LAW_RUNE x1→x2 """ import sys, os, re, shutil sys.path.insert(0, '/Users/tomassimkus/VS/openrsc-develop') os.chdir('/Users/tomassimkus/VS/openrsc-develop') from update_drops import parse_update_sql, write_update_sql from compare_drops import load_enums from collections import defaultdict _, npc_id_to_name, _, item_id_to_name = load_enums() # Sync working file with pk_npcdrops.sql shutil.copy("pk_npcdrops.sql", "pk_npcdrops_update.sql") # Parse production def parse_prod(): with open("pk_npcdrops_production.sql") as f: c = f.read() out = defaultdict(list) for m in re.finditer(r"\((\d+),\s*'(-?\d+)',\s*(-?\d+),\s*(\d+),\s*\d+\)", c): out[int(m.group(1))].append((int(m.group(3)), int(m.group(2)), int(m.group(4)))) return out prod = parse_prod() # Rune item IDs FIRE_RUNE = 31 DEATH_RUNE = 38 CHAOS_RUNE = 41 LAW_RUNE = 42 # Target (npc_id, rune_iid) pairs to restore TARGETS = [ (22, FIRE_RUNE), # LESSER_DEMON (22, DEATH_RUNE), # LESSER_DEMON (57, FIRE_RUNE), # DARKWIZARD_LVL13 (60, FIRE_RUNE), # DARKWIZARD_LVL25 (61, DEATH_RUNE), # GIANT (181, FIRE_RUNE), # LESSER_DEMON_WMAZEKEY (184, FIRE_RUNE), # GREATER_DEMON (184, DEATH_RUNE), # GREATER_DEMON (264, CHAOS_RUNE), # PIRATE_LVL30 (264, LAW_RUNE), # PIRATE_LVL30 ] header, rows, footer = parse_update_sql() changes = [] for nid, iid in TARGETS: # Production entries for this (npc, item), sorted by weight desc prod_entries = sorted( [(amt, w) for i, amt, w in prod[nid] if i == iid and w > 0], key=lambda x: -x[1] ) # New file row indices for matching (npc, item), sorted by weight desc new_indices = [(i, rows[i]) for i in range(len(rows)) if rows[i][0] == nid and rows[i][2] == iid and rows[i][3] > 0] new_indices.sort(key=lambda x: -x[1][3]) if len(prod_entries) != len(new_indices): print(f" ⚠ MISMATCH for NPC {nid} item {iid}: prod has {len(prod_entries)}, new has {len(new_indices)}") continue for (prod_amt, prod_w), (idx, row) in zip(prod_entries, new_indices): old_amt = row[1] if int(old_amt) != prod_amt: new_row = (row[0], str(prod_amt), row[2], row[3], row[4]) rows[idx] = new_row iname = item_id_to_name.get(iid, "?") nname = npc_id_to_name.get(nid, "?") changes.append((nid, nname, iname, old_amt, prod_amt, row[3])) rows.sort(key=lambda r: (r[0], 0 if r[3] == 0 else 1, r[3], r[2])) write_update_sql(header, rows, footer) shutil.copy("pk_npcdrops_update.sql", "pk_npcdrops.sql") shutil.copy("pk_npcdrops_update.sql", "pk_npcdrops_p2p_update.sql") print(f"Restored {len(changes)} rune buffs:") print(f" {'NPC':<22} {'Item':<14} {'Was':>6} → {'Now':>6} Weight") print(" " + "-" * 70) for nid, nname, iname, old, new, w in changes: print(f" {nname:<22} {iname:<14} x{old:<5} → x{new:<5} (weight={w:,})")