#!/usr/bin/env python3 """Fix the bone ID bug. The previous update_drops.py BONE_TYPE_TO_ITEM mapping had wrong item IDs, causing several NPCs to drop the wrong "bone" item: big_bones → 466 (UNICORN_HORN) should be 413 (BIG_BONES) dragon_bones → 274 (ORANGE_GOBLIN_ARMOUR) should be 814 (DRAGON_BONES) ashes → 23 (FLOUR) should be 181 (ASHES) Affected NPCs (synced via use-java in this session, weight=0 entries with wrong IDs): Big Bones bug: FIRE_GIANT (344), JOGRE (523) Dragon Bones bug: KBD (477), BLACK_DRAGON (291), RED_DRAGON (201), BLUE_DRAGON (202) Ashes bug: BLACK_DEMON (290) This script: 1. Fixes the update_drops.py BONE_TYPE_TO_ITEM mapping for future syncs. 2. Patches the 7 NPCs' guaranteed-drop rows in pk_npcdrops_update.sql. """ import sys, os, re 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 _, npc_id_to_name, _, item_id_to_name = load_enums() # Per-NPC bone fix: (npc_id, old_wrong_iid, new_correct_iid) PATCHES = [ # Big Bones bug (344, 466, 413), # FIRE_GIANT: Unicorn Horn → Big Bones (523, 466, 413), # JOGRE # Dragon Bones bug (477, 274, 814), # KBD: Orange Goblin Armour → Dragon Bones (291, 274, 814), # BLACK_DRAGON (201, 274, 814), # RED_DRAGON (202, 274, 814), # BLUE_DRAGON # Ashes bug (290, 23, 181), # BLACK_DEMON: Flour → Ashes ] # Step 1: Fix update_drops.py mapping print("Step 1: Fixing BONE_TYPE_TO_ITEM in update_drops.py...") with open('update_drops.py') as f: src = f.read() NEW_MAP = '''BONE_TYPE_TO_ITEM = { "normal_bones": 20, # Bones "big_bones": 413, # Big Bones "bat_bones": 604, # Bat Bones "dragon_bones": 814, # Dragon Bones "ashes": 181, # Ashes }''' src_fixed = re.sub( r'BONE_TYPE_TO_ITEM = \{[^}]+\}', NEW_MAP, src, count=1, flags=re.DOTALL, ) if src == src_fixed: print(" WARNING: BONE_TYPE_TO_ITEM block not replaced. Skipping update_drops.py edit.") else: with open('update_drops.py', 'w') as f: f.write(src_fixed) print(" Updated BONE_TYPE_TO_ITEM with correct IDs.") # Step 2: Patch SQL rows print() print("Step 2: Patching pk_npcdrops_update.sql rows...") header, rows, footer = parse_update_sql() patches_by_npc = {nid: (old, new) for nid, old, new in PATCHES} new_rows = [] patched = 0 for nid, amt, iid, w, idx in rows: if nid in patches_by_npc and w == 0: old, new = patches_by_npc[nid] if iid == old: new_rows.append((nid, amt, new, w, idx)) patched += 1 continue new_rows.append((nid, amt, iid, w, idx)) new_rows.sort(key=lambda r: (r[0], 0 if r[3] == 0 else 1, r[3], r[2])) write_update_sql(header, new_rows, footer) print(f" Patched {patched} bone rows.") # Verify print() print("Verification:") print(f"{'NPC':<24} {'Bone item now':<30}") print("-" * 60) _, rows_after, _ = parse_update_sql() for nid, _, _ in PATCHES: for n, amt, iid, w, _ in rows_after: if n == nid and w == 0: iname = item_id_to_name.get(iid, "?") print(f" {npc_id_to_name.get(nid):<22} {iname} (id {iid})") break