@@ -167,13 +167,22 @@ def getCheckStatus(self, check_type, flag_index=None, shop_index=None, level_ind
167167 # shop_index: 0 = cranky, 1 = funky, 2 = candy, 3 = bfi
168168 # flag_index: as expected
169169 if check_type == "shop" :
170- if shop_index == 3 :
171- header = 0x807FF6E8
170+ cache_key = (shop_index , kong_index , level_index )
171+ if cache_key in self ._purchase_cache :
172+ # Retrieve cached values
173+ purchase_type , purchase_value , purchase_kong = self ._purchase_cache [cache_key ]
172174 else :
173- header = 0x807FF400 + (shop_index * 0xF0 ) + (kong_index * 0x30 ) + (level_index * 6 )
174- purchase_type = self .n64_client .read_u16 (header + 0 )
175- purchase_value = self .n64_client .read_u16 (header + 2 )
176- purchase_kong = self .n64_client .read_u8 (header + 4 )
175+ # Calculate header and read values
176+ if shop_index == 3 :
177+ header = 0x807FF6E8
178+ else :
179+ header = 0x807FF400 + (shop_index * 0xF0 ) + (kong_index * 0x30 ) + (level_index * 6 )
180+ purchase_type = self .n64_client .read_u16 (header + 0 )
181+ purchase_value = self .n64_client .read_u16 (header + 2 )
182+ purchase_kong = self .n64_client .read_u8 (header + 4 )
183+ # Cache the values
184+ self ._purchase_cache [cache_key ] = (purchase_type , purchase_value , purchase_kong )
185+
177186 return self ._getShopStatus (purchase_type , purchase_value , purchase_kong )
178187 else :
179188 if self .flag_lookup is None :
@@ -232,7 +241,7 @@ async def readChecks(self, cb):
232241 shift = int (key ) & 7
233242 flag_status = (int (val [0 ]) >> shift ) & 1
234243 _bulk_read_dict [int (key )] = flag_status
235- for id in self .remaining_checks :
244+ for id in self .remaining_checks [:] :
236245 name = check_id_to_name .get (id )
237246 # Try to get the check via location_name_to_flag
238247 check = location_name_to_flag .get (name )
@@ -268,47 +277,21 @@ async def readChecks(self, cb):
268277 new_checks .append (id )
269278 continue
270279 elif len (content ) == 3 :
271- level_index = None
272- shop_index = None
273- kong_index = None
274- if content [0 ] == "Japes" :
275- level_index = 0
276- elif content [0 ] == "Aztec" :
277- level_index = 1
278- elif content [0 ] == "Factory" :
279- level_index = 2
280- elif content [0 ] == "Galleon" :
281- level_index = 3
282- elif content [0 ] == "Forest" :
283- level_index = 4
284- elif content [0 ] == "Caves" :
285- level_index = 5
286- elif content [0 ] == "Castle" :
287- level_index = 6
288- elif content [0 ] == "Isles" :
289- level_index = 7
290- if content [1 ] == "Cranky" :
291- shop_index = 0
292- elif content [1 ] == "Funky" :
293- shop_index = 1
294- elif content [1 ] == "Candy" :
295- shop_index = 2
296- if content [2 ] == "Donkey" :
297- kong_index = 0
298- elif content [2 ] == "Diddy" :
299- kong_index = 1
300- elif content [2 ] == "Lanky" :
301- kong_index = 2
302- elif content [2 ] == "Tiny" :
303- kong_index = 3
304- elif content [2 ] == "Chunky" :
305- kong_index = 4
280+ level_mapping = {"Japes" : 0 , "Aztec" : 1 , "Factory" : 2 , "Galleon" : 3 , "Forest" : 4 , "Caves" : 5 , "Castle" : 6 , "Isles" : 7 }
281+ shop_mapping = {"Cranky" : 0 , "Funky" : 1 , "Candy" : 2 }
282+ kong_mapping = {"Donkey" : 0 , "Diddy" : 1 , "Lanky" : 2 , "Tiny" : 3 , "Chunky" : 4 }
283+
284+ level_index = level_mapping .get (content [0 ])
285+ shop_index = shop_mapping .get (content [1 ])
286+ kong_index = kong_mapping .get (content [2 ])
287+
306288 # If any of these are not set, continue
307289 if level_index is None or shop_index is None or kong_index is None :
308290 continue
291+
309292 check_status = self .getCheckStatus ("shop" , None , shop_index , level_index , kong_index )
310293 if check_status :
311- # logger.info (f"Found {name} via shop")
294+ print (f"Found { name } via shop check " )
312295 self .remaining_checks .remove (id )
313296 new_checks .append (id )
314297 continue
0 commit comments