File size: 3,933 Bytes
5c239ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import random
import json


def load_lists(list_names, base_dir="lists"):
    lists = {}

    for name in list_names:
        with open(f"{base_dir}/{name}.json", "r") as f:
            lists[name] = json.load(f)

    return lists


def rand_name(names):
    return random.choices(names)[0]


def rand_hp():
    # Weights from https://bulbapedia.bulbagarden.net/wiki/HP_(TCG)

    hp_range = list(range(30, 340 + 1, 10))

    weights = [156, 542, 1264, 1727, 1477, 1232, 1008, 640, 436, 515, 469, 279, 188,
               131, 132, 132, 56, 66, 97, 74, 23, 24, 25, 7, 15, 6, 0, 12, 18, 35, 18, 3]

    return random.choices(hp_range, weights)[0]


def rand_type(types=['Grass', 'Fire', 'Water', 'Lightning', 'Fighting',
                     'Psychic', 'Colorless', 'Darkness', 'Metal', 'Dragon', 'Fairy'], can_be_none=False):
    if can_be_none:
        return random.choices([random.choices(types)[0], None])[0]
    else:
        return random.choices(types)[0]


def rand_species(species):
    random_species = random.choices(species)[0]

    return f'{random_species.capitalize()}'


def rand_length():
    # Weights from https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_height

    feet_ranges = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '16',
                   '17', '18', '19', '20', '21', '22', '23', '24', '26', '28', '30', '32', '34', '35', '47', '65', '328']

    weights = [30, 220, 230, 176, 130, 109, 63, 27, 17, 17, 5, 5, 6,
               4, 3, 2, 2, 2, 1, 2, 3, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1]

    return {
        "feet": random.choices(feet_ranges, weights)[0],
        "inches": random.randrange(0, 11 + 1, 1)
    }


def rand_weight():
    # Weights from https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_weight

    weight_ranges = [{"start": 1, "end": 22}, {"start": 22, "end": 44}, {"start": 44, "end": 55}, {"start": 55, "end": 110}, {"start": 110, "end": 132}, {"start": 132, "end": 218}, {"start": 218, "end": 220}, {"start": 221, "end": 226}, {
        "start": 226, "end": 331}, {"start": 331, "end": 441}, {"start": 441, "end": 451}, {"start": 452, "end": 661}, {"start": 661, "end": 677}, {"start": 677, "end": 793}, {"start": 794, "end": 903}, {"start": 903, "end": 2204}]

    # 'weights' as in statistical weightings
    weights = [271, 145, 53, 204, 57, 122, 1, 11, 57, 28, 7, 34, 4, 17, 5, 31]

    start, end = random.choices(weight_ranges, weights)[0].values()

    random_weight = random.randrange(start, end + 1, 1)

    return f'{random_weight} lbs.'


def rand_attack(attacks, name):
    random_attack = random.choices(attacks)[0]
    random_attack['text'] = random_attack['text'].replace('<name>', name)

    return random_attack


def rand_attacks(attacks, name, n=2):
    attack1 = rand_attack(attacks, name)

    if n > 1:
        attack2 = rand_attack(attacks, name)
        while attack1['text'] == attack2['text']:
            attack2 = rand_attack(attacks, name)
        return [attack1, attack2]
    else:
        return [attack1]

    return attacks


def rand_retreat():
    return random.randrange(0, 4, 1)


def rand_description(descriptions):
    return random.choices(descriptions)[0]


def rand_rarity():
    return random.choices(['●', '◆', '★'], [10, 5, 1])[0]


def rand_details(lists=load_lists(['attacks', 'descriptions', 'names', 'species'])):
    name = rand_name(lists["names"])

    return {
        "name": name,
        "hp": rand_hp(),
        "energy_type": rand_type(),
        "species": rand_species(lists["species"]),
        "length": rand_length(),
        "weight": rand_weight(),
        "attacks": rand_attacks(lists["attacks"], name),
        "weakness": rand_type(can_be_none=True),
        "resistance": rand_type(can_be_none=True),
        "retreat": rand_retreat(),
        "description": rand_description(lists["descriptions"]),
        "rarity": rand_rarity(),
    }