Ejemplo n.º 1
0
def character_move(
    character_id: str, target_scene: list
) -> (str, list, list, int):
    """
    通用角色移动控制
    Keyword arguments:
    character_id -- 角色id
    target_scene -- 寻路目标场景(在地图系统下的绝对坐标)
    Return arguments:
    str:null -- 未找到路径
    str:end -- 当前位置已是路径终点
    list -- 路径
    list -- 本次移动到的位置
    int -- 本次移动花费的时间
    """
    now_position = cache_contorl.character_data[character_id].position
    scene_hierarchy = map_handle.judge_scene_affiliation(
        now_position, target_scene
    )
    if scene_hierarchy == "common":
        map_path = map_handle.get_common_map_for_scene_path(
            now_position, target_scene
        )
        now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
            map_path, now_position
        )
        target_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
            map_path, target_scene
        )
        return identical_map_move(
            character_id, map_path, now_map_scene_id, target_map_scene_id
        )
    return difference_map_move(character_id, target_scene)
Ejemplo n.º 2
0
def difference_map_move(character_id: str,
                        target_scene: list) -> (str, list, list, int):
    """
    角色跨地图层级移动
    Keyword arguments:
    character_id -- 角色id
    target_scene -- 寻路目标场景(在地图系统下的绝对坐标)
    Return arguments:
    str:null -- 未找到路径
    str:end -- 当前位置已是路径终点
    list -- 路径
    list -- 本次移动到的位置
    int -- 本次移动花费的时间
    """
    character_data = cache.character_data[character_id]
    now_position = character_data.position
    is_affiliation = map_handle.judge_scene_affiliation(
        now_position, target_scene)
    now_true_position = map_handle.get_scene_path_for_true(now_position)
    now_true_map = map_handle.get_map_for_path(now_true_position)
    if is_affiliation == "subordinate":
        now_true_affiliation = map_handle.judge_scene_is_affiliation(
            now_true_position, target_scene)
        if now_true_affiliation == "subordinate":
            now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
                now_true_map, now_true_position)
            return identical_map_move(character_id, now_true_map,
                                      now_map_scene_id, "0")
        now_map = map_handle.get_map_for_path(target_scene)
        now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
            now_map, now_position)
        return identical_map_move(character_id, now_map, now_map_scene_id, "0")
    relation_map_list = map_handle.get_relation_map_list_for_scene_path(
        now_true_position)
    now_scene_real_map = relation_map_list[-1]
    now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
        now_scene_real_map, now_true_position)
    common_map = map_handle.get_common_map_for_scene_path(
        now_true_position, target_scene)
    if now_scene_real_map != common_map:
        if now_map_scene_id == "0":
            now_true_position = now_scene_real_map.copy()
            relation_map_list = map_handle.get_relation_map_list_for_scene_path(
                now_true_position)
            now_scene_real_map = relation_map_list[-1]
    target_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
        common_map, target_scene)
    if now_scene_real_map == common_map:
        now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
            common_map, now_true_position)
    else:
        now_map_scene_id = map_handle.get_map_scene_id_for_scene_path(
            now_scene_real_map, now_true_position)
        target_map_scene_id = "0"
        common_map = now_scene_real_map
    return identical_map_move(character_id, common_map, now_map_scene_id,
                              target_map_scene_id)