diff --git a/doc/main-tables.rst b/doc/main-tables.rst index ce76481..bc4484a 100644 --- a/doc/main-tables.rst +++ b/doc/main-tables.rst @@ -176,6 +176,8 @@ Mics tables .. dex-table:: Experience .. dex-table:: PalPark +.. dex-table:: PickupItem +.. dex-table:: PickupSlot .. dex-table:: StatHint Conquest tables diff --git a/pokedex/data/csv/pickup_items.csv b/pokedex/data/csv/pickup_items.csv new file mode 100644 index 0000000..b1311de --- /dev/null +++ b/pokedex/data/csv/pickup_items.csv @@ -0,0 +1,661 @@ +slot_id,min_level,max_level,item_id +1,1,10,17 +1,11,20,18 +1,21,30,26 +1,31,40,3 +1,41,50,79 +1,51,60,78 +1,61,70,57 +1,71,80,27 +1,81,90,2 +1,91,100,25 +2,1,10,18 +2,11,20,26 +2,21,30,3 +2,31,40,79 +2,41,50,78 +2,51,60,57 +2,61,70,27 +2,71,80,2 +2,81,90,25 +2,91,100,50 +3,1,10,26 +3,11,20,3 +3,21,30,79 +3,31,40,78 +3,41,50,57 +3,51,60,27 +3,61,70,2 +3,71,80,25 +3,81,90,50 +3,91,100,46 +4,1,10,3 +4,11,20,79 +4,21,30,78 +4,31,40,57 +4,41,50,27 +4,51,60,2 +4,61,70,25 +4,71,80,50 +4,81,90,46 +4,91,100,28 +5,1,10,79 +5,11,20,78 +5,21,30,57 +5,31,40,27 +5,41,50,2 +5,51,60,25 +5,61,70,50 +5,71,80,46 +5,81,90,28 +5,91,100,45 +6,1,10,78 +6,11,20,57 +6,21,30,27 +6,31,40,2 +6,41,50,25 +6,51,60,50 +6,61,70,46 +6,71,80,28 +6,81,90,45 +6,91,100,23 +7,1,10,57 +7,11,20,27 +7,21,30,2 +7,31,40,25 +7,41,50,50 +7,51,60,46 +7,61,70,28 +7,71,80,45 +7,81,90,23 +7,91,100,29 +8,1,10,27 +8,11,20,2 +8,21,30,25 +8,31,40,50 +8,41,50,46 +8,51,60,28 +8,61,70,45 +8,71,80,23 +8,81,90,29 +8,91,100,51 +9,1,10,2 +9,11,20,25 +9,21,30,50 +9,31,40,46 +9,41,50,28 +9,51,60,45 +9,61,70,23 +9,71,80,29 +9,81,90,51 +9,91,100,41 +10,1,10,92 +10,11,20,198 +10,21,30,23 +10,31,40,38 +10,41,50,191 +10,51,60,348 +10,61,70,40 +10,71,80,305 +10,81,90,211 +10,91,100,330 +11,1,10,25 +11,11,20,92 +11,21,30,198 +11,31,40,23 +11,41,50,38 +11,51,60,191 +11,61,70,348 +11,71,80,40 +11,81,90,305 +11,91,100,211 +12,1,10,17 +12,11,20,18 +12,21,30,26 +12,31,40,3 +12,41,50,79 +12,51,60,78 +12,61,70,27 +12,71,80,25 +12,81,90,2 +12,91,100,28 +13,1,10,18 +13,11,20,26 +13,21,30,3 +13,31,40,79 +13,41,50,78 +13,51,60,27 +13,61,70,25 +13,71,80,2 +13,81,90,28 +13,91,100,50 +14,1,10,26 +14,11,20,3 +14,21,30,79 +14,31,40,78 +14,41,50,27 +14,51,60,25 +14,61,70,2 +14,71,80,28 +14,81,90,50 +14,91,100,108 +15,1,10,3 +15,11,20,79 +15,21,30,78 +15,31,40,27 +15,41,50,25 +15,51,60,2 +15,61,70,28 +15,71,80,50 +15,81,90,108 +15,91,100,107 +16,1,10,79 +16,11,20,78 +16,21,30,27 +16,31,40,25 +16,41,50,2 +16,51,60,28 +16,61,70,50 +16,71,80,108 +16,81,90,107 +16,91,100,109 +17,1,10,78 +17,11,20,27 +17,21,30,25 +17,31,40,2 +17,41,50,28 +17,51,60,50 +17,61,70,108 +17,71,80,107 +17,81,90,109 +17,91,100,23 +18,1,10,27 +18,11,20,25 +18,21,30,2 +18,31,40,28 +18,41,50,50 +18,51,60,108 +18,61,70,107 +18,71,80,109 +18,81,90,23 +18,91,100,29 +19,1,10,25 +19,11,20,2 +19,21,30,28 +19,31,40,50 +19,41,50,108 +19,51,60,107 +19,61,70,109 +19,71,80,23 +19,81,90,29 +19,91,100,51 +20,1,10,2 +20,11,20,28 +20,21,30,50 +20,31,40,108 +20,41,50,107 +20,51,60,109 +20,61,70,23 +20,71,80,29 +20,81,90,51 +20,91,100,41 +21,1,10,92 +21,11,20,198 +21,21,30,23 +21,31,40,38 +21,41,50,191 +21,51,60,348 +21,61,70,40 +21,71,80,305 +21,81,90,211 +21,91,100,330 +22,1,10,25 +22,11,20,92 +22,21,30,198 +22,31,40,23 +22,41,50,38 +22,51,60,191 +22,61,70,348 +22,71,80,40 +22,81,90,305 +22,91,100,211 +23,1,10,17 +23,11,20,18 +23,21,30,26 +23,31,40,3 +23,41,50,79 +23,51,60,78 +23,61,70,27 +23,71,80,25 +23,81,90,2 +23,91,100,28 +24,1,10,18 +24,11,20,26 +24,21,30,3 +24,31,40,79 +24,41,50,78 +24,51,60,27 +24,61,70,25 +24,71,80,2 +24,81,90,28 +24,91,100,50 +25,1,10,26 +25,11,20,3 +25,21,30,79 +25,31,40,78 +25,41,50,27 +25,51,60,25 +25,61,70,2 +25,71,80,28 +25,81,90,50 +25,91,100,108 +26,1,10,3 +26,11,20,79 +26,21,30,78 +26,31,40,27 +26,41,50,25 +26,51,60,2 +26,61,70,28 +26,71,80,50 +26,81,90,108 +26,91,100,107 +27,1,10,79 +27,11,20,78 +27,21,30,27 +27,31,40,25 +27,41,50,2 +27,51,60,28 +27,61,70,50 +27,71,80,108 +27,81,90,107 +27,91,100,109 +28,1,10,78 +28,11,20,27 +28,21,30,25 +28,31,40,2 +28,41,50,28 +28,51,60,50 +28,61,70,108 +28,71,80,107 +28,81,90,109 +28,91,100,23 +29,1,10,27 +29,11,20,25 +29,21,30,2 +29,31,40,28 +29,41,50,50 +29,51,60,108 +29,61,70,107 +29,71,80,109 +29,81,90,23 +29,91,100,29 +30,1,10,25 +30,11,20,2 +30,21,30,28 +30,31,40,50 +30,41,50,108 +30,51,60,107 +30,61,70,109 +30,71,80,23 +30,81,90,29 +30,91,100,51 +31,1,10,2 +31,11,20,28 +31,21,30,50 +31,31,40,108 +31,41,50,107 +31,51,60,109 +31,61,70,23 +31,71,80,29 +31,81,90,51 +31,91,100,41 +32,1,10,92 +32,11,20,198 +32,21,30,23 +32,31,40,38 +32,41,50,191 +32,51,60,348 +32,61,70,40 +32,71,80,305 +32,81,90,211 +32,91,100,330 +33,1,10,25 +33,11,20,92 +33,21,30,198 +33,31,40,23 +33,41,50,38 +33,51,60,191 +33,61,70,348 +33,71,80,40 +33,81,90,305 +33,91,100,211 +34,1,10,17 +34,11,20,18 +34,21,30,26 +34,31,40,3 +34,41,50,79 +34,51,60,78 +34,61,70,27 +34,71,80,25 +34,81,90,2 +34,91,100,28 +35,1,10,18 +35,11,20,26 +35,21,30,3 +35,31,40,79 +35,41,50,78 +35,51,60,27 +35,61,70,25 +35,71,80,2 +35,81,90,28 +35,91,100,50 +36,1,10,26 +36,11,20,3 +36,21,30,79 +36,31,40,78 +36,41,50,27 +36,51,60,25 +36,61,70,2 +36,71,80,28 +36,81,90,50 +36,91,100,80 +37,1,10,3 +37,11,20,79 +37,21,30,78 +37,31,40,27 +37,41,50,25 +37,51,60,2 +37,61,70,28 +37,71,80,50 +37,81,90,80 +37,91,100,81 +38,1,10,79 +38,11,20,78 +38,21,30,27 +38,31,40,25 +38,41,50,2 +38,51,60,28 +38,61,70,50 +38,71,80,80 +38,81,90,81 +38,91,100,93 +39,1,10,78 +39,11,20,27 +39,21,30,25 +39,31,40,2 +39,41,50,28 +39,51,60,50 +39,61,70,80 +39,71,80,81 +39,81,90,93 +39,91,100,23 +40,1,10,27 +40,11,20,25 +40,21,30,2 +40,31,40,28 +40,41,50,50 +40,51,60,80 +40,61,70,81 +40,71,80,93 +40,81,90,23 +40,91,100,29 +41,1,10,25 +41,11,20,2 +41,21,30,28 +41,31,40,50 +41,41,50,80 +41,51,60,81 +41,61,70,93 +41,71,80,23 +41,81,90,29 +41,91,100,51 +42,1,10,2 +42,11,20,28 +42,21,30,50 +42,31,40,80 +42,41,50,81 +42,51,60,93 +42,61,70,23 +42,71,80,29 +42,81,90,51 +42,91,100,41 +43,1,10,92 +43,11,20,198 +43,21,30,23 +43,31,40,38 +43,41,50,255 +43,51,60,360 +43,61,70,40 +43,71,80,390 +43,81,90,211 +43,91,100,330 +44,1,10,25 +44,11,20,92 +44,21,30,198 +44,31,40,23 +44,41,50,38 +44,51,60,255 +44,61,70,360 +44,71,80,40 +44,81,90,390 +44,91,100,211 +45,1,10,17 +45,11,20,18 +45,21,30,26 +45,31,40,3 +45,41,50,79 +45,51,60,78 +45,61,70,27 +45,71,80,25 +45,81,90,2 +45,91,100,28 +46,1,10,18 +46,11,20,26 +46,21,30,3 +46,31,40,79 +46,41,50,78 +46,51,60,27 +46,61,70,25 +46,71,80,2 +46,81,90,28 +46,91,100,50 +47,1,10,26 +47,11,20,3 +47,21,30,79 +47,31,40,78 +47,41,50,27 +47,51,60,25 +47,61,70,2 +47,71,80,28 +47,81,90,50 +47,91,100,80 +48,1,10,3 +48,11,20,79 +48,21,30,78 +48,31,40,27 +48,41,50,25 +48,51,60,2 +48,61,70,28 +48,71,80,50 +48,81,90,80 +48,91,100,81 +49,1,10,79 +49,11,20,78 +49,21,30,27 +49,31,40,25 +49,41,50,2 +49,51,60,28 +49,61,70,50 +49,71,80,80 +49,81,90,81 +49,91,100,93 +50,1,10,78 +50,11,20,27 +50,21,30,25 +50,31,40,2 +50,41,50,28 +50,51,60,50 +50,61,70,80 +50,71,80,81 +50,81,90,93 +50,91,100,23 +51,1,10,27 +51,11,20,25 +51,21,30,2 +51,31,40,28 +51,41,50,50 +51,51,60,80 +51,61,70,81 +51,71,80,93 +51,81,90,23 +51,91,100,29 +52,1,10,25 +52,11,20,2 +52,21,30,28 +52,31,40,50 +52,41,50,80 +52,51,60,81 +52,61,70,93 +52,71,80,23 +52,81,90,29 +52,91,100,51 +53,1,10,2 +53,11,20,28 +53,21,30,50 +53,31,40,80 +53,41,50,81 +53,51,60,93 +53,61,70,23 +53,71,80,29 +53,81,90,51 +53,91,100,41 +54,1,10,92 +54,11,20,198 +54,21,30,23 +54,31,40,38 +54,41,50,255 +54,51,60,580 +54,61,70,40 +54,71,80,580 +54,81,90,211 +54,91,100,580 +55,1,10,25 +55,11,20,92 +55,21,30,198 +55,31,40,23 +55,41,50,38 +55,51,60,255 +55,61,70,580 +55,71,80,40 +55,81,90,580 +55,91,100,211 +56,1,10,17 +56,11,20,18 +56,21,30,26 +56,31,40,3 +56,41,50,79 +56,51,60,78 +56,61,70,27 +56,71,80,25 +56,81,90,2 +56,91,100,28 +57,1,10,18 +57,11,20,26 +57,21,30,3 +57,31,40,79 +57,41,50,78 +57,51,60,27 +57,61,70,25 +57,71,80,2 +57,81,90,28 +57,91,100,50 +58,1,10,26 +58,11,20,3 +58,21,30,79 +58,31,40,78 +58,41,50,27 +58,51,60,25 +58,61,70,2 +58,71,80,28 +58,81,90,50 +58,91,100,80 +59,1,10,3 +59,11,20,79 +59,21,30,78 +59,31,40,27 +59,41,50,25 +59,51,60,2 +59,61,70,28 +59,71,80,50 +59,81,90,80 +59,91,100,81 +60,1,10,79 +60,11,20,78 +60,21,30,27 +60,31,40,25 +60,41,50,2 +60,51,60,28 +60,61,70,50 +60,71,80,80 +60,81,90,81 +60,91,100,93 +61,1,10,78 +61,11,20,27 +61,21,30,25 +61,31,40,2 +61,41,50,28 +61,51,60,50 +61,61,70,80 +61,71,80,81 +61,81,90,93 +61,91,100,23 +62,1,10,27 +62,11,20,25 +62,21,30,2 +62,31,40,28 +62,41,50,50 +62,51,60,80 +62,61,70,81 +62,71,80,93 +62,81,90,23 +62,91,100,29 +63,1,10,25 +63,11,20,2 +63,21,30,28 +63,31,40,50 +63,41,50,80 +63,51,60,81 +63,61,70,93 +63,71,80,23 +63,81,90,29 +63,91,100,51 +64,1,10,2 +64,11,20,28 +64,21,30,50 +64,31,40,80 +64,41,50,81 +64,51,60,93 +64,61,70,23 +64,71,80,29 +64,81,90,51 +64,91,100,41 +65,1,10,92 +65,11,20,198 +65,21,30,23 +65,31,40,38 +65,41,50,255 +65,51,60,580 +65,61,70,40 +65,71,80,580 +65,81,90,211 +65,91,100,580 +66,1,10,25 +66,11,20,92 +66,21,30,198 +66,31,40,23 +66,41,50,38 +66,51,60,255 +66,61,70,580 +66,71,80,40 +66,81,90,580 +66,91,100,211 diff --git a/pokedex/data/csv/pickup_slots.csv b/pokedex/data/csv/pickup_slots.csv new file mode 100644 index 0000000..1911f60 --- /dev/null +++ b/pokedex/data/csv/pickup_slots.csv @@ -0,0 +1,67 @@ +id,version_group_id,slot,rarity +1,6,0,30 +2,6,1,10 +3,6,2,10 +4,6,3,10 +5,6,4,10 +6,6,5,10 +7,6,6,10 +8,6,7,5 +9,6,8,3 +10,6,9,1 +11,6,10,1 +12,8,0,30 +13,8,1,10 +14,8,2,10 +15,8,3,10 +16,8,4,10 +17,8,5,10 +18,8,6,10 +19,8,7,5 +20,8,8,3 +21,8,9,1 +22,8,10,1 +23,9,0,30 +24,9,1,10 +25,9,2,10 +26,9,3,10 +27,9,4,10 +28,9,5,10 +29,9,6,10 +30,9,7,5 +31,9,8,3 +32,9,9,1 +33,9,10,1 +34,10,0,30 +35,10,1,10 +36,10,2,10 +37,10,3,10 +38,10,4,10 +39,10,5,10 +40,10,6,10 +41,10,7,5 +42,10,8,3 +43,10,9,1 +44,10,10,1 +45,11,0,30 +46,11,1,10 +47,11,2,10 +48,11,3,10 +49,11,4,10 +50,11,5,10 +51,11,6,10 +52,11,7,4 +53,11,8,4 +54,11,9,1 +55,11,10,1 +56,14,0,30 +57,14,1,10 +58,14,2,10 +59,14,3,10 +60,14,4,10 +61,14,5,10 +62,14,6,10 +63,14,7,4 +64,14,8,4 +65,14,9,1 +66,14,10,1 diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index e02a342..a0caa78 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -1466,6 +1466,45 @@ create_translation_table('pal_park_area_names', PalParkArea, 'names', info=dict(description="The name", format='plaintext', official=False)), ) +class PickupItem(TableBase): + u"""Items which can be found with the Pickup ability. + + Level ranges are assumed not to overlap, and max_level is assumed to be + constant with respect to min_level. + """ + + __tablename__ = 'pickup_items' + __singlename__ = 'pickup_item' + + slot_id = Column(Integer, ForeignKey('pickup_slots.id'), primary_key=True, + info=dict(description="The slot")) + min_level = Column(Integer, nullable=False, primary_key=True, + info=dict(description="Minimum level at which this slot applies")) + max_level = Column(Integer, nullable=False, + info=dict(description="Maximum level at which this slot applies")) + item_id = Column(Integer, ForeignKey('items.id'), + info=dict(description="The item")) + +class PickupSlot(TableBase): + u"""The chance of finding a particular item with Pickup.""" + + __tablename__ = 'pickup_slots' + __singlename__ = 'pickup_slot' + + id = Column(Integer, primary_key=True, + info=dict(description="")) + version_group_id = Column(Integer, ForeignKey('version_groups.id'), + info=dict(description="The version group")) + slot = Column(Integer, nullable=False, + info=dict(description="Index of the slot + 1")) + rarity = Column(Integer, nullable=False, + info=dict(description="Percent chance of this slot being chosen")) + + __table_args__ = ( + UniqueConstraint(version_group_id, slot), + {}, + ) + class PokeathlonStat(TableBase): u"""A Pokéathlon stat, such as "Stamina" or "Jump". """ @@ -2471,6 +2510,12 @@ PalPark.area = relationship(PalParkArea, innerjoin=True, lazy='joined') +PickupItem.slot = relationship(PickupSlot) +PickupItem.item = relationship(Item) + +PickupSlot.version_group = relationship(VersionGroup) + + Pokedex.region = relationship(Region, innerjoin=True, backref='pokedexes') diff --git a/scripts/pickup.py b/scripts/pickup.py new file mode 100644 index 0000000..60c4db7 --- /dev/null +++ b/scripts/pickup.py @@ -0,0 +1,172 @@ +#!/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