forked from YogurtTheHorse/RogueBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bossmanager.py
93 lines (68 loc) · 1.77 KB
/
bossmanager.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
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
import databasemanager
import random
from datetime import datetime
SECONDS_WAIT = 60 * 60
def current():
boss = databasemanager.get_variable('boss')
if boss is None:
return create()
if need_to_reborn(boss):
return create(boss)
return migration(boss)
def migration(old_boss):
if 'coins' not in old_boss:
new_boss = {
'id': old_boss.get('id', 1),
'name': old_boss.get('name'),
'alive': old_boss.get('alive'),
'hp': old_boss.get('hp'),
'max_hp': old_boss.get('hp'),
'coins': 10000,
'die_seconds': old_boss.get('die_seconds')
}
save(new_boss)
return new_boss
return old_boss
def create(old_boss=None):
boss_id = 1
if old_boss is not None:
boss_id = old_boss['id']
# Костыли, велосипеды
# Тараканы, мотыльки
room_name, hp, max_coins = random.choice([
('black_knight', 129500, 51000 ),
('hellkite_dragon', 175500, 71000),
('moonlight_butterfly', 49500, 21000),
('naping_dragon', 77500, 31000),
('cthulhu', 575900, 251000),
('lich_king', 325000, 141000)
])
new_boss = {
'id': boss_id + 1,
'name': room_name,
'alive': True,
'hp': hp,
'max_hp': hp,
'coins': random.randrange(1000, max_coins, 1),
'die_seconds': None
}
save(new_boss)
return new_boss
def die(boss):
new_boss = {
'id': boss['id'],
'name': boss['name'],
'alive': False,
'hp': 0,
'max_hp': boss['max_hp'],
'coins': boss['coins'],
'die_seconds': (datetime.now() - datetime(1970,1,1)).total_seconds()
}
save(new_boss)
def save(boss):
databasemanager.set_variable('boss', boss)
def need_to_reborn(boss):
if boss['die_seconds'] is None:
return False
seconds_passed = (datetime.now() - datetime(1970,1,1)).total_seconds() - boss['die_seconds']
return boss['alive'] is False and seconds_passed > SECONDS_WAIT