-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthPoint.py
70 lines (67 loc) · 2.96 KB
/
HealthPoint.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
# coding: utf-8
from typing import List, TypeVar
from obsub import event
from sortedcontainers import SortedListWithKey
from AbilityBag import AbilityBag
from Abilities import get_ability
from Ability import Ability
T = TypeVar('T', bound='HealthPoint')
class HealthPoint(object):
def __init__(self, name : str,
common_abilities : List[str],
healthy_abilities : List[str],
damaged_abilities : List[str]) -> None:
self.name = name
self._list_common_abilities = list(common_abilities)
self._list_healthy_abilities = list(healthy_abilities)
self._list_damaged_abilities = list(damaged_abilities)
self._healthy_abilities = AbilityBag(self._list_common_abilities)
self._damaged_abilities = AbilityBag(self._list_common_abilities)
self._healthy_abilities.add_abilities(self._list_healthy_abilities)
self._damaged_abilities.add_abilities(self._list_damaged_abilities)
self.description = self.make_description()
self.__is_healthy = True
def _get_health(self) -> bool:
return self.__is_healthy
def _set_health(self, health) -> None:
if self.__is_healthy != health:
self.before_health_change()
self.__is_healthy = health
self.after_health_change()
@event
def before_health_change(self): pass
@event
def after_health_change(self): pass
is_healthy = property(_get_health, _set_health)
def make_description(self) -> str:
healthy_description = '\n'.join(x.description
for x in self._healthy_abilities.abilities()
if not x.hidden)
damaged_description = '\n'.join(x.description
for x in self._damaged_abilities.abilities()
if not x.hidden)
descriptions = []
if healthy_description:
descriptions.append('Healthy:\n' + healthy_description)
if damaged_description:
descriptions.append('Damaged:\n' + damaged_description)
return '\n'.join(descriptions)
def get_abilities(self) -> AbilityBag:
if self.is_healthy:
return self._healthy_abilities
else:
return self._damaged_abilities
def copy(self : T) -> T:
return HealthPoint(self.name,
self._list_common_abilities,
self._list_healthy_abilities,
self._list_damaged_abilities)
def __repr__(self) -> str:
return "HealthPoint: {0}({1})".format(self.name,
"healthy" if self.is_healthy
else "damaged")
def summary(self) -> str:
return '[color=white]{0}({1}[color=white])'.format(
self.name,
"[color=green]healthy" if self.is_healthy
else "[color=red]damaged")