diff --git a/worlds/grinch/__init__.py b/worlds/grinch/__init__.py index 76d811b9..2e956f45 100644 --- a/worlds/grinch/__init__.py +++ b/worlds/grinch/__init__.py @@ -84,33 +84,66 @@ class GrinchWorld(World): # Total available weight sum total_fillerweights = sum(self.options.filler_weight[filler] for filler in MISC_ITEMS_TABLE) + filler_total_count = 0 + highest_filler = None + highest_filler_ratio = 0 + # Fill remaining locations according to weight ratio for filler in MISC_ITEMS_TABLE: # This ratio is a decimal between 0 and 1, and when multiplied by 100 is the % of that filler # item in the available unfilled locations filler_weight_ratio = self.options.filler_weight[filler] / total_fillerweights + + if filler_weight_ratio > highest_filler_ratio: + highest_filler_ratio = filler_weight_ratio + highest_filler = filler + filler_count = round(filler_locations * filler_weight_ratio) + filler_total_count += filler_count + for _ in range(filler_count): self_itempool.append(self.create_item(filler)) + # Back-filling empty locations with 20 Rotten Eggs + if filler_total_count < filler_locations: + for _ in filler_locations - filler_total_count: + self_itempool.append(self.create_item(highest_filler)) + # # Make sure we don't underfill (in case of rounding losses) # while len(self_itempool) < unfilled_locations: # self_itempool.append(self.create_item(self.get_other_filler_item(list(MISC_ITEMS_TABLE.keys())))) + trap_total_count = 0 + highest_trap = None + highest_trap_ratio = 0 + # Total available weight sum if self.options.trap_percentage > 0: total_trapweights = sum(self.options.trap_weight[trap] for trap in TRAPS_TABLE) - if self.options.trap_percentage > 0 && total_trapweights <= 0: + if total_trapweights <= 0: raise Exception("ERROR: Traps are enabled, but all trap weights are zero or undefined") for trap in TRAPS_TABLE: trap_weight_ratio = self.options.trap_weight[trap] / total_trapweights + + if trap_weight_ratio > highest_trap_ratio: + highest_trap_ratio = trap_weight_ratio + highest_trap = trap + trap_count = round(trap_locations * trap_weight_ratio) + + trap_total_count += trap_count + for _ in range(trap_count): self_itempool.append(self.create_item(trap)) + # Back-filling empty locations with 20 Rotten Eggs + if trap_total_count < trap_locations: + for _ in trap_locations - trap_total_count: + self_itempool.append(self.create_item(highest_trap)) + self.multiworld.itempool += self_itempool def set_rules(self):