Start implementing object oriented scaffold for world types

(There's still a lot of work ahead, such as:
registering locations and items to the World, as well as methods to create_item_from_name()
many more method names for various stages
embedding Options into the world type
and many more...)
This commit is contained in:
Fabian Dill
2021-06-11 14:22:44 +02:00
parent 753a5f7cb2
commit 568a71cdbe
10 changed files with 233 additions and 244 deletions

View File

@@ -4,15 +4,24 @@ from .Locations import exclusion_table, events_table
from .Regions import link_minecraft_structures
from .Rules import set_rules
from BaseClasses import Region, Entrance, Location, MultiWorld, Item
from BaseClasses import MultiWorld
from Options import minecraft_options
from ..AutoWorld import World
class MinecraftWorld(World):
game: str = "Minecraft"
client_version = (0, 3)
def get_mc_data(world: MultiWorld, player: int):
exits = ["Overworld Structure 1", "Overworld Structure 2", "Nether Structure 1", "Nether Structure 2", "The End Structure"]
exits = ["Overworld Structure 1", "Overworld Structure 2", "Nether Structure 1", "Nether Structure 2",
"The End Structure"]
return {
'world_seed': Random(world.rom_seeds[player]).getrandbits(32), # consistent and doesn't interfere with other generation
'world_seed': Random(world.rom_seeds[player]).getrandbits(32),
# consistent and doesn't interfere with other generation
'seed_name': world.seed_name,
'player_name': world.get_player_names(player),
'player_id': player,
@@ -20,25 +29,27 @@ def get_mc_data(world: MultiWorld, player: int):
'structures': {exit: world.get_entrance(exit, player).connected_region.name for exit in exits}
}
def generate_mc_data(world: MultiWorld, player: int):
def generate_mc_data(world: MultiWorld, player: int):
import base64, json
from Utils import output_path
data = get_mc_data(world, player)
filename = f"AP_{world.seed_name}_P{player}_{world.get_player_names(player)}.apmc"
with open(output_path(filename), 'wb') as f:
with open(output_path(filename), 'wb') as f:
f.write(base64.b64encode(bytes(json.dumps(data), 'utf-8')))
def fill_minecraft_slot_data(world: MultiWorld, player: int):
def fill_minecraft_slot_data(world: MultiWorld, player: int):
slot_data = get_mc_data(world, player)
for option_name in minecraft_options:
option = getattr(world, option_name)[player]
slot_data[option_name] = int(option.value)
return slot_data
# Generates the item pool given the table and frequencies in Items.py.
def minecraft_gen_item_pool(world: MultiWorld, player: int):
# Generates the item pool given the table and frequencies in Items.py.
def minecraft_gen_item_pool(world: MultiWorld, player: int):
pool = []
for item_name, item_data in item_table.items():
for count in range(item_frequencies.get(item_name, 1)):
@@ -47,8 +58,8 @@ def minecraft_gen_item_pool(world: MultiWorld, player: int):
prefill_pool = {}
prefill_pool.update(events_table)
exclusion_pools = ['hard', 'insane', 'postgame']
for key in exclusion_pools:
if not getattr(world, f"include_{key}_advancements")[player]:
for key in exclusion_pools:
if not getattr(world, f"include_{key}_advancements")[player]:
prefill_pool.update(exclusion_table[key])
for loc_name, item_name in prefill_pool.items():
@@ -62,9 +73,9 @@ def minecraft_gen_item_pool(world: MultiWorld, player: int):
world.itempool += pool
# Generate Minecraft world.
# Generate Minecraft world.
def gen_minecraft(world: MultiWorld, player: int):
link_minecraft_structures(world, player)
minecraft_gen_item_pool(world, player)
set_rules(world, player)