-
Notifications
You must be signed in to change notification settings - Fork 1
/
_helper_functions.py
60 lines (45 loc) · 1.81 KB
/
_helper_functions.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
from collections import Counter
from components.actor.equipment import EquipmentComponent
from components.actor.job import JobComponent
from components.soul import SoulComponent
from components.stats import StatsComponent
def generate_stats(ent, world, include_upkeep=True):
ent_stats = Counter(world.component_for_entity(ent, StatsComponent).__dict__)
if ent is not 1: # This is maybe temporary...
return ent_stats
# Stat changes based on equipment.
if world.has_component(ent, EquipmentComponent):
for item_id in world.component_for_entity(ent, EquipmentComponent).equipment:
if world.has_component(item_id, StatsComponent):
item_stats = Counter(world.component_for_entity(item_id, StatsComponent).__dict__)
ent_stats.update(item_stats)
# Stat changes based on job.
if include_upkeep:
ent_stats.update(Counter(world.component_for_entity(ent, JobComponent).upkeep))
# Stat changes based on soul.
if world.has_component(ent, SoulComponent):
ent_soul = Counter(world.component_for_entity(ent, SoulComponent).soul)
ent_stats.update(ent_soul)
return dict(ent_stats)
def as_decimal(number, signed=False):
string = str(number)
if string == '0':
string = '0.0'
elif len(string) == 1:
string = "0." + string
else:
string = string[:-1] + '.' + string[-1]
if signed:
if number >= 0:
string = '+' + string
return string
def as_integer(number, signed=False):
string = str(number)
if string != '0':
string = string[:-1]
elif string[-1] != '0':
print('HOLD UP: This digit should be 0, not {}'.format(string[-1]))
if signed:
if number >= 0:
string = '+' + string
return string