-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_effect.py
80 lines (59 loc) · 2.38 KB
/
status_effect.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
from __future__ import annotations
from copy import deepcopy
from typing import TYPE_CHECKING
import color
from components.ai import ConfusedEnemy
if TYPE_CHECKING:
from entity import Actor
class StatusEffect:
def __init__(self, name: str, duration: int):
self.name = name
self.duration = duration
def apply(self, entity: Actor, target: Actor):
raise NotImplementedError()
def remove(self, entity: Actor):
raise NotImplementedError()
class Grappled(StatusEffect):
def __init__(self, duration=1):
super().__init__("grappled", duration)
def apply(self, entity: Actor, target: Actor):
engine = entity.parent.engine
# check if the entity is the player
if target is engine.player and not target.status.grappled:
engine.message_log.add_message("You are being grappled!", color.yellow)
# Make sure to use deepcopy of the status effect to avoid changing the original
target.status.set_active_status_effect(deepcopy(self))
def remove(self, entity: Actor):
pass
class Confused(StatusEffect):
def __init__(self, duration=1):
super().__init__("confused", duration)
def apply(self, entity: Actor, target: Actor):
engine = entity.parent.engine
# Avoid stacking confusion
if target.status.confused:
return
if target is engine.player and not target.status.confused:
engine.message_log.add_message("You are feeling confused!", color.yellow)
target.ai = ConfusedEnemy(target)
target.status.set_active_status_effect(deepcopy(self))
def remove(self, entity: Actor):
engine = entity.parent.engine
if entity == engine.player:
engine.message_log.add_message(
"You are regaining your senses!", color.white
)
entity.restore_ai()
class BloodDrain(StatusEffect):
def __init__(self, heal_amount: int, duration=0):
self.heal_amount = heal_amount
super().__init__("blood drain", duration)
def apply(self, entity: Actor, target: Actor):
engine = entity.parent.engine
entity.fighter.heal(self.heal_amount)
if target is engine.player:
engine.message_log.add_message(
f"{entity.name} is draining your blood!", color.yellow
)
def remove(self, entity: Actor):
pass