-
Notifications
You must be signed in to change notification settings - Fork 0
/
characterProperties.py
215 lines (169 loc) · 7.86 KB
/
characterProperties.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from typing import ClassVar, Optional
@dataclass
class IntBounds:
min: int
max: int
def __post_init__(self):
if self.min > self.max:
self.min, self.max = self.max, self.min
def __add__(self, other):
if isinstance(other, int):
other = IntBounds(other, other)
elif isinstance(other, list):
other = IntBounds(*other)
if isinstance(other, IntBounds):
return IntBounds(min=self.min + other.min, max=self.max + other.max)
raise NotImplementedError()
def __contains__(self, item: int) -> bool:
return self.min <= item <= self.max
def as_range(self) -> range:
return range(self.min, self.max + 1)
@dataclass(frozen=True)
class BaseProperty:
full_name: str
rating_bounds: ClassVar[IntBounds]
@classmethod
def is_valid_rating(cls, rating) -> bool:
return isinstance(rating, int) and rating in cls.rating_bounds
@dataclass(frozen=True)
class Tier(BaseProperty):
full_name = "Tier"
rating_bounds: ClassVar[IntBounds] = IntBounds(1, 5)
class PropertyEnum(Enum):
@classmethod
def get_by_name(cls, name: str) -> Optional[PropertyEnum]:
return next((member for member in cls if member.name == name or member.value.full_name == name),
cls.INVALID)
@classmethod
def get_valid_members(cls):
return (cls._member_map_[name] for name in cls._member_names_ if name != cls.INVALID.name)
@dataclass(frozen=True)
class Attribute(BaseProperty):
rating_bounds: ClassVar[IntBounds] = IntBounds(1, 12)
short_name: str
@dataclass(frozen=True)
class InvalidAttribute(Attribute):
full_name: ClassVar[str] = "INVALID"
rating_bounds: ClassVar[IntBounds] = IntBounds(0, 0)
short_name: ClassVar[str] = "N/A"
def is_valid_rating(self, rating) -> bool:
return False
class Attributes(PropertyEnum):
# full or short names must be unique, to avoid Enum's unique() to remove duplicates.
Strength = Attribute(full_name="Strength", short_name="S")
Toughness = Attribute(full_name="Toughness", short_name="T")
Agility = Attribute(full_name="Agility", short_name="A")
Initiative = Attribute(full_name="Initiative", short_name="I")
Willpower = Attribute(full_name="Willpower", short_name="Wil")
Intellect = Attribute(full_name="Intellect", short_name="Int")
Fellowship = Attribute(full_name="Fellowship", short_name="Fel")
# noinspection PyArgumentList
INVALID = InvalidAttribute()
@classmethod
def get_by_name(cls, name: str) -> Attributes:
member = super().get_by_name(name)
if member is cls.INVALID:
member = next((member for member in cls if member.value.short_name == name), cls.INVALID)
return member
@dataclass(frozen=True)
class Skill(BaseProperty):
rating_bounds: ClassVar[IntBounds] = IntBounds(0, 8)
related_attribute: Attributes
@property
def total_rating_bounds(self):
return self.rating_bounds + Attribute.rating_bounds
def is_valid_total_rating(self, rating) -> bool:
return isinstance(rating, int) and rating in self.total_rating_bounds
@dataclass(frozen=True)
class InvalidSkill(Skill):
full_name: ClassVar[str] = "INVALID"
rating_bounds: ClassVar[IntBounds] = IntBounds(0, 0)
related_attribute: ClassVar[Attributes] = Attributes.INVALID
@property
def total_rating_bounds(self):
return self.rating_bounds
def is_valid_rating(self, rating) -> bool:
return False
def is_valid_total_rating(self, rating) -> bool:
return False
class Skills(PropertyEnum):
# full names must be unique, to avoid Enum's unique() to remove duplicates.
Athletics = Skill(full_name="Athletics", related_attribute=Attributes.Strength)
Awareness = Skill(full_name="Awareness", related_attribute=Attributes.Intellect)
BallisticSkill = Skill(full_name="Ballistic Skill", related_attribute=Attributes.Agility)
Cunning = Skill(full_name="Cunning", related_attribute=Attributes.Fellowship)
Deception = Skill(full_name="Deception", related_attribute=Attributes.Fellowship)
Insight = Skill(full_name="Insight", related_attribute=Attributes.Fellowship)
Intimidation = Skill(full_name="Intimidation", related_attribute=Attributes.Willpower)
Investigation = Skill(full_name="Investigation", related_attribute=Attributes.Intellect)
Leadership = Skill(full_name="Leadership", related_attribute=Attributes.Willpower)
Medicae = Skill(full_name="Medicae", related_attribute=Attributes.Intellect)
Persuasion = Skill(full_name="Persuasion", related_attribute=Attributes.Willpower)
Pilot = Skill(full_name="Pilot", related_attribute=Attributes.Agility)
PsychicMastery = Skill(full_name="Psychic Mastery", related_attribute=Attributes.Willpower)
Scholar = Skill(full_name="Scholar", related_attribute=Attributes.Intellect)
Stealth = Skill(full_name="Stealth", related_attribute=Attributes.Agility)
Survival = Skill(full_name="Survival", related_attribute=Attributes.Willpower)
Tech = Skill(full_name="Tech", related_attribute=Attributes.Intellect)
WeaponSkill = Skill(full_name="Weapon Skill", related_attribute=Attributes.Initiative)
# noinspection PyArgumentList
INVALID = InvalidSkill()
@dataclass(frozen=True)
class Trait:
# full names must be unique, to avoid Enum's unique() to remove duplicates.
full_name: str
related_attribute: Attributes
attribute_offset: int
tier_modifier: int
def get_rating_bounds(self, related_tier: int) -> IntBounds:
return Attribute.rating_bounds + self.get_total_attribute_offset(related_tier)
def get_total_attribute_offset(self, related_tier: int) -> int:
return self.attribute_offset + self.tier_modifier * related_tier
def is_valid_rating(self, rating, related_tier: int) -> bool:
return isinstance(rating, int) and rating in self.get_rating_bounds(related_tier)
@dataclass(frozen=True)
class InvalidTrait(Trait):
full_name: ClassVar[str] = "INVALID"
related_attribute: ClassVar[Attributes] = Attributes.INVALID
attribute_offset: ClassVar[int] = 0
tier_modifier: ClassVar[int] = 0
def is_valid_rating(self, rating, related_tier: int) -> bool:
return False
class Traits(PropertyEnum):
Conviction = Trait(full_name="Conviction",
related_attribute=Attributes.Willpower,
attribute_offset=0,
tier_modifier=0)
Defence = Trait(full_name="Defence",
related_attribute=Attributes.Initiative,
attribute_offset=-1,
tier_modifier=0)
Determination = Trait(full_name="Determination",
related_attribute=Attributes.Toughness,
attribute_offset=0,
tier_modifier=0)
Influence = Trait(full_name="Influence",
related_attribute=Attributes.Fellowship,
attribute_offset=-1,
tier_modifier=0)
MaxShock = Trait(full_name="Max Shock",
related_attribute=Attributes.Willpower,
attribute_offset=0,
tier_modifier=1)
MaxWounds = Trait(full_name="Max Wounds",
related_attribute=Attributes.Toughness,
attribute_offset=0,
tier_modifier=2)
Resilience = Trait(full_name="Resilience",
related_attribute=Attributes.Toughness,
attribute_offset=1,
tier_modifier=0)
Resolve = Trait(full_name="Resolve",
related_attribute=Attributes.Willpower,
attribute_offset=-1,
tier_modifier=0)
# noinspection PyArgumentList
INVALID = InvalidTrait()