#!/usr/bin/env python3 """Add RIGHT_HALF_DRAGON_SQUARE_SHIELD (1276) drops to every NPC that currently drops LEFT_HALF_DRAGON_SQUARE_SHIELD (1277), at exactly matching weight(s). If an NPC has multiple LEFT_HALF entries with different weights, mirror each one as a RIGHT_HALF entry. """ import shutil, sys, os 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, _, _ = load_enums() LEFT = 1277 RIGHT = 1276 shutil.copy("pk_npcdrops.sql", "pk_npcdrops_update.sql") header, rows, footer = parse_update_sql() # Collect LEFT_HALF entries per NPC (keep all weights) left_per_npc = defaultdict(list) for nid, amt, iid, w, _ in rows: if iid == LEFT and w > 0: left_per_npc[nid].append((amt, w)) # Remove any pre-existing RIGHT_HALF entries (we re-create them clean) new_rows = [r for r in rows if r[2] != RIGHT] removed = len(rows) - len(new_rows) # For each NPC with LEFT_HALF entries, add matching RIGHT_HALF entries added_count = 0 for nid, entries in left_per_npc.items(): for amt, w in entries: new_rows.append((nid, amt, RIGHT, w, 0)) added_count += 1 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) shutil.copy("pk_npcdrops_update.sql", "pk_npcdrops.sql") shutil.copy("pk_npcdrops_update.sql", "pk_npcdrops_p2p_update.sql") print(f"Removed {removed} old RIGHT_HALF entries (if any).") print(f"Added {added_count} new RIGHT_HALF entries across {len(left_per_npc)} NPCs.") print() print(f"Sample of new RIGHT_HALF rates per NPC (showing top 15 by rate):") # Re-parse to verify rates _, rows2, _ = parse_update_sql() totals = defaultdict(int) right_per_npc = defaultdict(int) left_per_npc_sum = defaultdict(int) for nid, amt, iid, w, _ in rows2: if w > 0: totals[nid] += w if iid == RIGHT and w > 0: right_per_npc[nid] += w if iid == LEFT and w > 0: left_per_npc_sum[nid] += w sample = sorted(right_per_npc.items(), key=lambda x: -(x[1] / totals[x[0]] if totals[x[0]] else 0)) for nid, rw in sample[:15]: tw = totals[nid] lw = left_per_npc_sum[nid] name = npc_id_to_name.get(nid, "?") pct = rw / tw * 100 print(f" {name:<32} RIGHT 1/{round(tw/rw):,} ({pct:.4f}%) ; LEFT 1/{round(tw/lw):,}")