-
Notifications
You must be signed in to change notification settings - Fork 0
/
minions.py
47 lines (34 loc) · 1.41 KB
/
minions.py
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
from card import Card
import random
import json
import copy
class Minions:
def card_from_json(self, card_json):
if "deathrattle" in card_json:
deathrattle_type = card_json["deathrattle"]["type"]
if deathrattle_type == "summon":
card = card_json["deathrattle"]["card"]
deathrattle = self.card_from_json(card)
del card_json["deathrattle"]
else:
raise Exception("Deathrattle not implemented")
else:
deathrattle = None
return Card(**card_json, deathrattle=deathrattle)
def __init__(self):
f = open('minions.json')
minion_data = json.loads(f.read())
self.minion_pool = [ self.card_from_json(card_json) for card_json in minion_data['cards'] ]
f.close()
def get_random_minion_list(self, minions_count, max_level=None):
minion_pool = [m for m in self.minion_pool if m.level <= max_level] if max_level else self.minion_pool
return [random.choice(minion_pool) for m in range(minions_count)]
def get_card_list_by_name(self, name_array):
card_list = []
for name in name_array:
self.get_card_by_name(name)
return card_list
def get_card_by_name(self, name):
for minion in self.minion_pool:
if name == minion.name:
return copy.deepcopy(minion)