File size: 3,268 Bytes
0e96e93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45e3bfa
0e96e93
 
 
 
 
 
 
 
 
 
0882770
 
 
 
 
0e96e93
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import re
from tinydb import TinyDB, Query
from src.gr_func import _get_medicine_elixir_config,material_table


def get_need_material(medicine_select, medicine_level_select="ALL",material_max_num=16) ->list:
    material = Query()
    m = _get_medicine_elixir_config(medicine_select)
    func1_type = m["func1_type"]
    func1_power = m["func1_power"]
    func2_type = m["func2_type"]
    func2_power = m["func2_power"]
    if medicine_level_select == "ALL":
        a = material_table.search((material.main_func_t == func1_type) | (material.auxi_func_t == func1_type) | (
                    material.main_func_t == func2_type) | (material.auxi_func_t == func2_type))
    else:
        a = material_table.search((material.level == medicine_level_select) & (
                    (material.main_func_t == func1_type) | (material.auxi_func_t == func1_type) | (
                        material.main_func_t == func2_type) | (material.auxi_func_t == func2_type)))

    def get_num(material0):
        global material_second_f
        name = material0["name"]
        if material0["main_func_t"] == func1_type:
            material_second_f = (func2_type,False)
            num = func1_power / material0["main_func_p"]
        elif material0["auxi_func_t"] == func1_type:
            material_second_f = (func2_type,True)
            num = func1_power / material0["auxi_func_p"]
        elif material0["main_func_t"] == func2_type:
            material_second_f = (func1_type,False)
            num = func2_power / material0["main_func_p"]
        elif material0["auxi_func_t"] == func2_type:
            material_second_f = (func1_type,True)
            num = func2_power / material0["auxi_func_p"]
        num = int(num) + 1 if num > int(num) else int(num)
        return (name,num,material_second_f)
    rtn = list(map(get_num, a))
    rtn = list(filter(lambda x:x[1]<=material_max_num, rtn))

    def check_material(material0):
        if material0[1] > material_max_num:
            return False
        material_t = material.main_func_t if material0[2][1] else material.auxi_func_t
        a = material_table.search(material_t == material0[2][0])
        if a == []:
            return False
        return True

    rtn = list(filter(check_material, rtn))
    rtn = list(map(lambda x: (x[0],x[1]), rtn))
    return rtn

grade_str = "一二三四五六七八九"

def sort_yaocai(text,medicine_select,material_num):
    material_need_dict = {}
    if medicine_select != "无":
        material_need_list = get_need_material(medicine_select,material_max_num=material_num)
        for name,num in material_need_list:
            material_need_dict[name[:-4]] = num
        print(material_need_dict)
    regex = re.compile("名字:.+\n品级:.+\n.+\n.+\n拥有数量:\d+")
    yaocai_l = regex.findall(text)
    rtn = []
    for yaocai in yaocai_l:
        yaocai = yaocai.split("\n")
        name = yaocai[0][3:]
        num = int(yaocai[-1][5:])
        grade = grade_str.index(yaocai[1][3])+1

        flag = material_need_dict.get(name)
        if flag is not None:
            if num >= flag:
                flag = "+"
            else:
                num = f"{num}({flag})"
                flag = "-"
        rtn.append((name,grade,num,flag))
    return rtn