Shopswap with higher spheres as well
This commit is contained in:
parent
ba07da6bba
commit
a67d657882
44
Shops.py
44
Shops.py
|
@ -10,6 +10,7 @@ from Utils import int16_as_bytes
|
||||||
|
|
||||||
logger = logging.getLogger("Shops")
|
logger = logging.getLogger("Shops")
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
class ShopType(Enum):
|
class ShopType(Enum):
|
||||||
Shop = 0
|
Shop = 0
|
||||||
|
@ -116,6 +117,7 @@ class UpgradeShop(Shop):
|
||||||
# Didn't check for more things breaking as not much else can be shuffled here currently
|
# Didn't check for more things breaking as not much else can be shuffled here currently
|
||||||
blacklist = item_name_groups["Potions"]
|
blacklist = item_name_groups["Potions"]
|
||||||
|
|
||||||
|
|
||||||
def ShopSlotFill(world):
|
def ShopSlotFill(world):
|
||||||
shop_slots: Set[Location] = {location for shop_locations in (shop.region.locations for shop in world.shops)
|
shop_slots: Set[Location] = {location for shop_locations in (shop.region.locations for shop in world.shops)
|
||||||
for location in shop_locations if location.shop_slot}
|
for location in shop_locations if location.shop_slot}
|
||||||
|
@ -140,7 +142,7 @@ def ShopSlotFill(world):
|
||||||
blacklist_words = {item_name for item_name in item_table if any(
|
blacklist_words = {item_name for item_name in item_table if any(
|
||||||
blacklist_word in item_name for blacklist_word in blacklist_words)}
|
blacklist_word in item_name for blacklist_word in blacklist_words)}
|
||||||
blacklist_words.add("Bee")
|
blacklist_words.add("Bee")
|
||||||
candidates_per_sphere = list(world.get_spheres())
|
candidates_per_sphere = list(list(sphere) for sphere in world.get_spheres())
|
||||||
|
|
||||||
candidate_condition = lambda location: not location.locked and \
|
candidate_condition = lambda location: not location.locked and \
|
||||||
not location.shop_slot and \
|
not location.shop_slot and \
|
||||||
|
@ -148,26 +150,27 @@ def ShopSlotFill(world):
|
||||||
|
|
||||||
# currently special care needs to be taken so that Shop.region.locations.item is identical to Shop.inventory
|
# currently special care needs to be taken so that Shop.region.locations.item is identical to Shop.inventory
|
||||||
# Potentially create Locations as needed and make inventory the only source, to prevent divergence
|
# Potentially create Locations as needed and make inventory the only source, to prevent divergence
|
||||||
|
cumu_weights = []
|
||||||
|
|
||||||
for sphere in candidates_per_sphere:
|
for sphere in candidates_per_sphere:
|
||||||
current_shop_slots = sphere.intersection(shop_slots)
|
if cumu_weights:
|
||||||
if current_shop_slots:
|
x = cumu_weights[-1]
|
||||||
# randomize order in a deterministic fashion
|
else:
|
||||||
sphere = sorted(sphere - current_shop_slots)
|
x = 0
|
||||||
|
cumu_weights.append(len(sphere) + x)
|
||||||
world.random.shuffle(sphere)
|
world.random.shuffle(sphere)
|
||||||
for location in sorted(current_shop_slots):
|
|
||||||
slot_num = int(location.name[-1]) - 1
|
for i, sphere in enumerate(candidates_per_sphere):
|
||||||
|
current_shop_slots = [location for location in sphere if location.shop_slot]
|
||||||
|
if current_shop_slots:
|
||||||
|
|
||||||
|
for location in current_shop_slots:
|
||||||
shop: Shop = location.parent_region.shop
|
shop: Shop = location.parent_region.shop
|
||||||
never = set() # candidates that will never work
|
swapping_sphere = world.random.choices(candidates_per_sphere[i:], cum_weights=cumu_weights[i:])[0]
|
||||||
for c in sphere: # chosen item locations
|
for c in swapping_sphere: # chosen item locations
|
||||||
if c in never:
|
if candidate_condition(c) and c.item_rule(location.item) and location.item_rule(c.item):
|
||||||
pass
|
|
||||||
elif not candidate_condition(c): # candidate will never work
|
|
||||||
never.add(c)
|
|
||||||
elif c.item_rule(location.item) and location.item_rule(c.item): # if rule is good...
|
|
||||||
swap_location_item(c, location, check_locked=False)
|
swap_location_item(c, location, check_locked=False)
|
||||||
never.add(c)
|
logger.debug(f'Swapping {c} into {location}:: {location.item}')
|
||||||
logger.info(f'Swapping {c} into {location}:: {location.item}')
|
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -186,9 +189,10 @@ def ShopSlotFill(world):
|
||||||
price = world.random.randrange(10, 60)
|
price = world.random.randrange(10, 60)
|
||||||
|
|
||||||
price *= 5
|
price *= 5
|
||||||
shop.push_inventory(slot_num, item_name, price, 1,
|
shop.push_inventory(int(location.name[-1]) - 1, item_name, price, 1,
|
||||||
location.item.player if location.item.player != location.player else 0)
|
location.item.player if location.item.player != location.player else 0)
|
||||||
|
|
||||||
|
|
||||||
def create_shops(world, player: int):
|
def create_shops(world, player: int):
|
||||||
cls_mapping = {ShopType.UpgradeShop: UpgradeShop,
|
cls_mapping = {ShopType.UpgradeShop: UpgradeShop,
|
||||||
ShopType.Shop: Shop,
|
ShopType.Shop: Shop,
|
||||||
|
@ -250,6 +254,7 @@ def create_shops(world, player: int):
|
||||||
|
|
||||||
world.clear_location_cache()
|
world.clear_location_cache()
|
||||||
|
|
||||||
|
|
||||||
# (type, room_id, shopkeeper, custom, locked, [items])
|
# (type, room_id, shopkeeper, custom, locked, [items])
|
||||||
# item = (item, price, max=0, replacement=None, replacement_price=0)
|
# item = (item, price, max=0, replacement=None, replacement_price=0)
|
||||||
_basic_shop_defaults = [('Red Potion', 150), ('Small Heart', 10), ('Bombs (10)', 50)]
|
_basic_shop_defaults = [('Red Potion', 150), ('Small Heart', 10), ('Bombs (10)', 50)]
|
||||||
|
@ -280,10 +285,11 @@ shop_table_by_location_id[(SHOP_ID_START + len(shop_table)*3 + 4)] = "Take-Any #
|
||||||
shop_table_by_location = {y: x for x, y in shop_table_by_location_id.items()}
|
shop_table_by_location = {y: x for x, y in shop_table_by_location_id.items()}
|
||||||
|
|
||||||
shop_generation_types = {
|
shop_generation_types = {
|
||||||
'default': _basic_shop_defaults + [('Bombs (3)', 20), ('Green Potion', 90), ('Blue Potion', 190), ('Bee', 10), ('Single Arrow', 5), ('Single Bomb', 10)] + [('Red Shield', 500), ('Blue Shield', 50)],
|
'default': _basic_shop_defaults + [('Bombs (3)', 20), ('Green Potion', 90), ('Blue Potion', 190), ('Bee', 10),
|
||||||
|
('Single Arrow', 5), ('Single Bomb', 10)] + [('Red Shield', 500),
|
||||||
|
('Blue Shield', 50)],
|
||||||
'potion': [('Red Potion', 150), ('Green Potion', 90), ('Blue Potion', 190)],
|
'potion': [('Red Potion', 150), ('Green Potion', 90), ('Blue Potion', 190)],
|
||||||
'discount_potion': [('Red Potion', 120), ('Green Potion', 60), ('Blue Potion', 160)],
|
'discount_potion': [('Red Potion', 120), ('Green Potion', 60), ('Blue Potion', 160)],
|
||||||
'bottle': [('Bee', 10)],
|
'bottle': [('Bee', 10)],
|
||||||
'time': [('Red Clock', 100), ('Blue Clock', 200), ('Green Clock', 300)],
|
'time': [('Red Clock', 100), ('Blue Clock', 200), ('Green Clock', 300)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue