Beispiel #1
0
def write_node(node: Node) -> dict:
    """
    :param node:
    :return:
    """

    data = {
        "name": node.name,
        "heal": node.heal
    }

    if isinstance(node, GenericNode):
        data["node_type"] = 0

    elif isinstance(node, DockNode):
        data["node_type"] = 1
        data["dock_index"] = node.dock_index
        data["connected_area_asset_id"] = node.default_connection.area_asset_id
        data["connected_dock_index"] = node.default_connection.dock_index
        data["dock_type"] = node.default_dock_weakness.dock_type.value
        data["dock_weakness_index"] = node.default_dock_weakness.index

    elif isinstance(node, PickupNode):
        data["node_type"] = 2
        data["pickup_index"] = node.pickup_index.index
        data["major_location"] = node.major_location

    elif isinstance(node, TeleporterNode):
        data["node_type"] = 3
        data["destination_world_asset_id"] = node.default_connection.world_asset_id
        data["destination_area_asset_id"] = node.default_connection.area_asset_id
        data["teleporter_instance_id"] = node.teleporter_instance_id
        data["keep_name_when_vanilla"] = node.keep_name_when_vanilla
        data["editable"] = node.editable

    elif isinstance(node, EventNode):
        data["node_type"] = 4
        data["event_index"] = node.resource().index

    elif isinstance(node, TranslatorGateNode):
        data["node_type"] = 5
        data["gate_index"] = node.gate.index

    elif isinstance(node, LogbookNode):
        data["node_type"] = 6
        data["string_asset_id"] = node.string_asset_id
        data["lore_type"] = list(LoreType).index(node.lore_type)

        if node.lore_type == LoreType.LUMINOTH_LORE:
            data["extra"] = node.required_translator.index

        elif node.lore_type in {LoreType.LUMINOTH_WARRIOR, LoreType.SKY_TEMPLE_KEY_HINT}:
            data["extra"] = node.hint_index
        else:
            data["extra"] = 0

    else:
        raise Exception("Unknown node class: {}".format(node))

    return data
Beispiel #2
0
def _extra_requirement_for_node(game: GameDescription,
                                node: Node) -> Optional[RequirementSet]:
    extra_requirement = None

    if is_resource_node(node):
        node_resource = node.resource()
        if node_resource in game.dangerous_resources:
            extra_requirement = RequirementSet(
                [RequirementList.with_single_resource(node_resource)])

    return extra_requirement
Beispiel #3
0
 def _can_advance(self,
                  node: Node,
                  ) -> bool:
     """
     Calculates if we can advance past a given node
     :param node:
     :return:
     """
     # We can't advance past a resource node if we haven't collected it
     if node.is_resource_node:
         return self._state.has_resource(node.resource())
     else:
         return True
Beispiel #4
0
    def _potential_nodes_from(self, node: Node) -> Iterator[Tuple[Node, Requirement, bool]]:
        extra_requirement = _extra_requirement_for_node(self._game, node)
        requirement_to_leave = node.requirement_to_leave(self._state.patches, self._state.resources)

        for target_node, requirement in self._game.world_list.potential_nodes_from(node, self.state.patches):
            if target_node is None:
                continue

            if requirement_to_leave != Requirement.trivial():
                requirement = RequirementAnd([requirement, requirement_to_leave])

            if extra_requirement is not None:
                requirement = RequirementAnd([requirement, extra_requirement])

            satisfied = requirement.satisfied(self._state.resources, self._state.energy)
            yield target_node, requirement, satisfied
Beispiel #5
0
def write_node(node: Node) -> dict:
    """
    :param node:
    :return:
    """

    data = {"name": node.name, "heal": node.heal}

    if isinstance(node, GenericNode):
        data["node_type"] = 0

    elif isinstance(node, DockNode):
        data["node_type"] = 1
        data["dock_index"] = node.dock_index
        data["connected_area_asset_id"] = node.default_connection.area_asset_id
        data["connected_dock_index"] = node.default_connection.dock_index
        data["dock_type"] = node.default_dock_weakness.dock_type.value
        data["dock_weakness_index"] = node.default_dock_weakness.index

    elif isinstance(node, PickupNode):
        data["node_type"] = 2
        data["pickup_index"] = node.pickup_index.index

    elif isinstance(node, TeleporterNode):
        data["node_type"] = 3
        data[
            "destination_world_asset_id"] = node.default_connection.world_asset_id
        data[
            "destination_area_asset_id"] = node.default_connection.area_asset_id
        data["teleporter_instance_id"] = node.teleporter_instance_id

    elif isinstance(node, EventNode):
        data["node_type"] = 4
        data["event_index"] = node.resource().index

    else:
        raise Exception("Unknown node class: {}".format(node))

    return data
Beispiel #6
0
def write_node(node: Node) -> dict:
    """
    :param node:
    :return:
    """

    data = {
        "name": node.name,
        "heal": node.heal,
        "coordinates": {
            "x": node.location.x,
            "y": node.location.y,
            "z": node.location.z
        } if node.location else None,
    }

    if isinstance(node, GenericNode):
        data["node_type"] = "generic"

    elif isinstance(node, DockNode):
        data["node_type"] = "dock"
        data["dock_index"] = node.dock_index
        data["connected_area_asset_id"] = node.default_connection.area_asset_id
        data["connected_dock_index"] = node.default_connection.dock_index
        data["dock_type"] = node.default_dock_weakness.dock_type.value
        data["dock_weakness_index"] = node.default_dock_weakness.index

    elif isinstance(node, PickupNode):
        data["node_type"] = "pickup"
        data["pickup_index"] = node.pickup_index.index
        data["major_location"] = node.major_location

    elif isinstance(node, TeleporterNode):
        data["node_type"] = "teleporter"
        data[
            "destination_world_asset_id"] = node.default_connection.world_asset_id
        data[
            "destination_area_asset_id"] = node.default_connection.area_asset_id
        data["teleporter_instance_id"] = node.teleporter_instance_id
        data["scan_asset_id"] = node.scan_asset_id
        data["keep_name_when_vanilla"] = node.keep_name_when_vanilla
        data["editable"] = node.editable

    elif isinstance(node, EventNode):
        data["node_type"] = "event"
        data["event_index"] = node.resource().index
        if not node.name.startswith("Event -"):
            raise ValueError(
                f"'{node.name}' is an Event Node, but naming doesn't start with 'Event -'"
            )

    elif isinstance(node, TranslatorGateNode):
        data["node_type"] = "translator_gate"
        data["gate_index"] = node.gate.index

    elif isinstance(node, LogbookNode):
        data["node_type"] = "logbook"
        data["string_asset_id"] = node.string_asset_id
        data["lore_type"] = node.lore_type.value

        if node.lore_type == LoreType.LUMINOTH_LORE:
            data["extra"] = node.required_translator.index

        elif node.lore_type in {
                LoreType.LUMINOTH_WARRIOR, LoreType.SKY_TEMPLE_KEY_HINT
        }:
            data["extra"] = node.hint_index
        else:
            data["extra"] = 0

    elif isinstance(node, PlayerShipNode):
        data["node_type"] = "player_ship"
        data["is_unlocked"] = write_requirement(node.is_unlocked)

    else:
        raise ValueError("Unknown node class: {}".format(node))

    if node.name.startswith("Event -") and data["node_type"] != "event":
        raise ValueError(
            f"'{node.name}' is not an Event Node, but naming suggests it is.")

    return data