LttP: Bartering, add price types for replacement items
This commit is contained in:
		
							parent
							
								
									d55a057a4d
								
							
						
					
					
						commit
						b7aa5a17b7
					
				| 
						 | 
				
			
			@ -1080,7 +1080,7 @@ class Spoiler():
 | 
			
		|||
 | 
			
		||||
                if item['replacement'] is None:
 | 
			
		||||
                    continue
 | 
			
		||||
                shopdata['item_{}'.format(index)] += ", {} - {}".format(item['replacement'], item['replacement_price']) if item['replacement_price'] else item['replacement']
 | 
			
		||||
                shopdata['item_{}'.format(index)] += f", {item['replacement']} - {item['replacement_price']} {price_type_display_name[item['replacement_price_type']]}"
 | 
			
		||||
            self.shops.append(shopdata)
 | 
			
		||||
 | 
			
		||||
        for player in self.world.get_game_players("A Link to the Past"):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -375,7 +375,6 @@ class ExcludeLocations(OptionSet):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
per_game_common_options = {
 | 
			
		||||
    # placeholder until they're actually implemented
 | 
			
		||||
    "local_items": LocalItems,
 | 
			
		||||
    "non_local_items": NonLocalItems,
 | 
			
		||||
    "start_inventory": StartInventory,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1678,6 +1678,16 @@ def patch_race_rom(rom, world, player):
 | 
			
		|||
    rom.encrypt(world, player)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_price_data(price: int, price_type: int) -> bytes:
 | 
			
		||||
    if price_type != ShopPriceType.Rupees:
 | 
			
		||||
        # Set special price flag 0x8000
 | 
			
		||||
        # Then set the type of price we're setting 0x7F00 (this starts from Hearts, not Rupees, subtract 1)
 | 
			
		||||
        # Then append the price/index into the second byte 0x00FF
 | 
			
		||||
        return int16_as_bytes(0x8000 | 0x100 * (price_type - 1) | price)
 | 
			
		||||
    else:
 | 
			
		||||
        return int16_as_bytes(price)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def write_custom_shops(rom, world, player):
 | 
			
		||||
    shops = sorted([shop for shop in world.shops if shop.custom and shop.region.player == player],
 | 
			
		||||
                   key=lambda shop: shop.sram_offset)
 | 
			
		||||
| 
						 | 
				
			
			@ -1711,13 +1721,8 @@ def write_custom_shops(rom, world, player):
 | 
			
		|||
        for index, item in enumerate(shop.inventory):
 | 
			
		||||
            if item is None:
 | 
			
		||||
                break
 | 
			
		||||
            if item['price_type'] != ShopPriceType.Rupees:
 | 
			
		||||
                # Set special price flag 0x8000
 | 
			
		||||
                # Then set the type of price we're setting 0x7F00 (this starts from Hearts, not Rupees, subtract 1)
 | 
			
		||||
                # Then append the price/index into the second byte 0x00FF
 | 
			
		||||
                price_data = int16_as_bytes(0x8000 | 0x100 * (item["price_type"] - 1) | item['price'])
 | 
			
		||||
            else:
 | 
			
		||||
                price_data = int16_as_bytes(item['price'])
 | 
			
		||||
            price_data = get_price_data(item['price'], item["price_type"])
 | 
			
		||||
            replacement_price_data = get_price_data(item['replacement_price'], item['replacement_price_type'])
 | 
			
		||||
            slot = 0 if shop.type == ShopType.TakeAny else index
 | 
			
		||||
            if not item['item'] in item_table:  # item not native to ALTTP
 | 
			
		||||
                item_code = get_nonnative_item_sprite(item['item'])
 | 
			
		||||
| 
						 | 
				
			
			@ -1728,7 +1733,7 @@ def write_custom_shops(rom, world, player):
 | 
			
		|||
 | 
			
		||||
            item_data = [shop_id, item_code] + price_data + \
 | 
			
		||||
                        [item['max'], ItemFactory(item['replacement'], player).code if item['replacement'] else 0xFF] + \
 | 
			
		||||
                        int16_as_bytes(item['replacement_price']) + [0 if item['player'] == player else item['player']]
 | 
			
		||||
                        replacement_price_data + [0 if item['player'] == player else item['player']]
 | 
			
		||||
            items_data.extend(item_data)
 | 
			
		||||
 | 
			
		||||
    rom.write_bytes(0x184800, shop_data)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,7 +102,8 @@ class Shop():
 | 
			
		|||
 | 
			
		||||
    def add_inventory(self, slot: int, item: str, price: int, max: int = 0,
 | 
			
		||||
                      replacement: Optional[str] = None, replacement_price: int = 0, create_location: bool = False,
 | 
			
		||||
                      player: int = 0, price_type: int = ShopPriceType.Rupees):
 | 
			
		||||
                      player: int = 0, price_type: int = ShopPriceType.Rupees,
 | 
			
		||||
                      replacement_price_type: int = ShopPriceType.Rupees):
 | 
			
		||||
        self.inventory[slot] = {
 | 
			
		||||
            'item': item,
 | 
			
		||||
            'price': price,
 | 
			
		||||
| 
						 | 
				
			
			@ -110,6 +111,7 @@ class Shop():
 | 
			
		|||
            'max': max,
 | 
			
		||||
            'replacement': replacement,
 | 
			
		||||
            'replacement_price': replacement_price,
 | 
			
		||||
            'replacement_price_type': replacement_price_type,
 | 
			
		||||
            'create_location': create_location,
 | 
			
		||||
            'player': player
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -129,6 +131,7 @@ class Shop():
 | 
			
		|||
            'max': max,
 | 
			
		||||
            'replacement': self.inventory[slot]["item"],
 | 
			
		||||
            'replacement_price': self.inventory[slot]["price"],
 | 
			
		||||
            'replacement_price_type': self.inventory[slot]["price_type"],
 | 
			
		||||
            'create_location': self.inventory[slot]["create_location"],
 | 
			
		||||
            'player': player
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -257,6 +260,8 @@ def ShopSlotFill(world):
 | 
			
		|||
 | 
			
		||||
                    shop.push_inventory(location.shop_slot, item_name, price * 5, 1,
 | 
			
		||||
                                        location.item.player if location.item.player != location.player else 0)
 | 
			
		||||
                    if 'P' in world.shop_shuffle[location.player]:
 | 
			
		||||
                        price_to_funny_price(shop.inventory[location.shop_slot], world, location.player)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def create_shops(world, player: int):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue