From b7aa5a17b78ebccd6d692777c8848cd87f476ec2 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 2 Oct 2021 10:15:00 +0200 Subject: [PATCH] LttP: Bartering, add price types for replacement items --- BaseClasses.py | 2 +- Options.py | 1 - worlds/alttp/Rom.py | 21 +++++++++++++-------- worlds/alttp/Shops.py | 7 ++++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index f3bf1b39..6f9775b5 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -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"): diff --git a/Options.py b/Options.py index fdb1b8a6..3b73aba3 100644 --- a/Options.py +++ b/Options.py @@ -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, diff --git a/worlds/alttp/Rom.py b/worlds/alttp/Rom.py index 10354b5a..efedecb0 100644 --- a/worlds/alttp/Rom.py +++ b/worlds/alttp/Rom.py @@ -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) diff --git a/worlds/alttp/Shops.py b/worlds/alttp/Shops.py index a1c5ad5f..09ee8f9d 100644 --- a/worlds/alttp/Shops.py +++ b/worlds/alttp/Shops.py @@ -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):