-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.py
65 lines (46 loc) · 1.69 KB
/
entity.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
from copy import copy, deepcopy
def do_nothing(all_entities):
pass
class Action:
def __init__(self, name, description, requires_target, function):
self.name = name
self.description = description
self.requires_target = requires_target
self.function = function
class Order:
def __init__(self, action, target):
self.action = action
self.target = target
class Entity:
def __init__(self, name, max_health, actions):
self.name = name
self.max_health = max_health
self.health = max_health
self.damage_multiplier = 1
self.actions = actions
self.active_actions = copy(actions)
self.stored_order = None
def take_action(self, all_entities):
if self.stored_order.action.requires_target:
self.stored_order.action.function(self.stored_order.target)
else:
self.stored_order.action.function(all_entities)
if self.stored_order.action.function != do_nothing:
self.active_actions.remove(self.stored_order.action)
if len(self.active_actions) <= 0:
self.active_actions = copy(self.actions)
self.stored_order = None
def take_damage(self, damage):
if damage > 0:
damage *= self.damage_multiplier
self.health -= damage
if (self.health < 0):
self.health = 0
elif (self.health > self.max_health):
self.health = self.max_health
def set_damage_multiplier(self, multiplier):
self.damage_multiplier = multiplier
def interrupt_order(self):
self.stored_order.action = Action("Nada", "Nada", False, do_nothing)
def change_target(self, target):
self.stored_order.target = target