Core: fix ItemLinks setting advancement flag

This commit is contained in:
Fabian Dill 2022-06-17 05:26:11 +02:00
parent 50c75e9684
commit b86ee20f3f
1 changed files with 6 additions and 8 deletions

14
Main.py
View File

@ -1,4 +1,3 @@
import copy
import collections import collections
from itertools import zip_longest, chain from itertools import zip_longest, chain
import logging import logging
@ -145,13 +144,12 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
# temporary home for item links, should be moved out of Main # temporary home for item links, should be moved out of Main
for group_id, group in world.groups.items(): for group_id, group in world.groups.items():
def find_common_pool(players: Set[int], shared_pool: Set[str]): def find_common_pool(players: Set[int], shared_pool: Set[str]):
advancement = set() classifications = collections.defaultdict(int)
counters = {player: {name: 0 for name in shared_pool} for player in players} counters = {player: {name: 0 for name in shared_pool} for player in players}
for item in world.itempool: for item in world.itempool:
if item.player in counters and item.name in shared_pool: if item.player in counters and item.name in shared_pool:
counters[item.player][item.name] += 1 counters[item.player][item.name] += 1
if item.advancement: classifications[item.name] |= item.classification
advancement.add(item.name)
for player in players.copy(): for player in players.copy():
if all([counters[player][item] == 0 for item in shared_pool]): if all([counters[player][item] == 0 for item in shared_pool]):
@ -169,18 +167,18 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
else: else:
for player in players: for player in players:
del(counters[player][item]) del(counters[player][item])
return counters, advancement return counters, classifications
common_item_count, common_advancement_items = find_common_pool(group["players"], group["item_pool"]) common_item_count, classifications = find_common_pool(group["players"], group["item_pool"])
if not common_item_count: if not common_item_count:
continue continue
new_itempool = [] new_itempool = []
for item_name, item_count in next(iter(common_item_count.values())).items(): for item_name, item_count in next(iter(common_item_count.values())).items():
advancement = item_name in common_advancement_items
for _ in range(item_count): for _ in range(item_count):
new_item = group["world"].create_item(item_name) new_item = group["world"].create_item(item_name)
new_item.advancement = advancement # mangle together all original classification bits
new_item.classification |= classifications[item_name]
new_itempool.append(new_item) new_itempool.append(new_item)
region = Region("Menu", RegionType.Generic, "ItemLink", group_id, world) region = Region("Menu", RegionType.Generic, "ItemLink", group_id, world)