#!/usr/bin/env python2 from random import randint from collections import namedtuple import pokedex.db import pokedex.db.tables as t Pickup = namedtuple('Pickup', 'version_group rates common_items rare_items') # The item lists below are taken directly from the games, and differ from # the popularly reported values, e.g., on Serebii and Bulbapedia, in the # following ways: # # - Hyper Potion at level 1-10, 1%, instead of various other items # - There are no Lucky Eggs. Anywhere. Ever. # These rates have been verified in SoulSilver rates = [30, 10, 10, 10, 10, 10, 10, 5, 3] # The following function is a sketch how the pickup items are chosen, taken # from SoulSilver (U). For full details set a breakpoint at 0x02244106. # # Note that the 1% items are backwards: # n=98 gives index 1, and n=99 gives index 0 def get_reward(pickup, level, n=None): if n is None: n = randint(0, 99) level = (level - 1) // 10 assert 0 <= level < 10 threshold = 0 for index, rate in enumerate(pickup.rates): threshold += rate if n < threshold: return pickup.common_items[level + index] else: assert 98 <= n <= 99 index = 99 - n assert 0 <= index <= 1 return pickup.rare_items[level + index] # Emerald (U) # The rewards lists are located at 0x31c440 in the ROM. # The second immediately follows the first, at 0x31C464. # 0x0031C440: 0D000E00 16000300 56005500 4B001700 ........V.U.K... # 0x0031C450: 02001500 44004000 18003F00 13001900 ....D.@...?..... # 0x0031C460: 45002500 15006E00 BB001300 2200B400 E.%...n....."... # 0x0031C470: 4C012400 2101C800 3A011E28 323C4650 L.$.!...:..(2