Skip to content

Commit e7f456a

Browse files
committed
added new things
1 parent db69806 commit e7f456a

File tree

6 files changed

+91
-15
lines changed

6 files changed

+91
-15
lines changed

components/equipment.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Optional, TYPE_CHECKING
3+
from typing import Optional, TYPE_CHECKING, Type
44

55
from components.base_component import BaseComponent
66
from equipment_types import EquipmentType
77

88
if TYPE_CHECKING:
99
from entity import Actor, Item
10+
from status_effect import StatusEffect
11+
1012

1113

1214
class Equipment(BaseComponent):
@@ -52,6 +54,26 @@ def dodge_bonus(self) -> int:
5254

5355
return bonus
5456

57+
@property
58+
def extra_immunities(self) -> list[Type[StatusEffect]]:
59+
immunities = []
60+
61+
if self.weapon is not None and self.weapon.equippable is not None:
62+
# Add the extra immunities from the weapon to the list.
63+
for immunity in self.weapon.equippable.extra_immunities:
64+
# Check if the immunity is already in the list.
65+
if immunity not in immunities:
66+
immunities.append(immunity)
67+
68+
if self.armor is not None and self.armor.equippable is not None:
69+
# Add the extra immunities from the armor to the list.
70+
for immunity in self.armor.equippable.extra_immunities:
71+
# Check if the immunity is already in the list.
72+
if immunity not in immunities:
73+
immunities.append(immunity)
74+
75+
return immunities
76+
5577
def item_is_equipped(self, item: Item) -> bool:
5678
return self.weapon == item or self.armor == item
5779

components/equippable.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Type
44

55
from components.base_component import BaseComponent
66
from entity import Actor
77
from equipment_types import EquipmentType
8-
from status_effect import Poisoned, Bleeding
8+
from status_effect import Poisoned, Bleeding, Spored
99

1010
if TYPE_CHECKING:
1111
from entity import Item
1212
from entity import Actor
13+
from status_effect import StatusEffect
1314

1415

1516

@@ -22,12 +23,14 @@ def __init__(
2223
power_bonus: int = 0,
2324
defense_bonus: int = 0,
2425
dodge_bonus: int = 0,
26+
extra_immunities: list[Type[StatusEffect]] = [],
2527
):
2628
self.equipment_type = equipment_type
2729

2830
self.power_bonus = power_bonus
2931
self.defense_bonus = defense_bonus
3032
self.dodge_bonus = dodge_bonus
33+
self.extra_immunities = extra_immunities
3134

3235

3336
def on_equip(self, parent: Actor) -> None:
@@ -90,6 +93,14 @@ def on_attack(self, target: Actor):
9093
# Add the poisoned status effect to the target.
9194
target.fighter.apply_status_effect(Poisoned(duration=8, value=2))
9295

96+
class SilverKinfe(Equippable):
97+
def __init__(self) -> None:
98+
super().__init__(equipment_type=EquipmentType.WEAPON, power_bonus=7)
99+
100+
def on_attack(self, target: Actor):
101+
# Add the bleeding status effect to the target.
102+
target.fighter.apply_status_effect(Bleeding(duration=6, value=2))
103+
93104
class ScrapChestPlate(Equippable):
94105
def __init__(self) -> None:
95106
super().__init__(equipment_type=EquipmentType.ARMOR, defense_bonus=1)
@@ -118,14 +129,22 @@ def __init__(self) -> None:
118129

119130
def on_hit(self, target: Actor, damage: int):
120131
# Add the bleeding status effect to the target.
121-
target.fighter.apply_status_effect(Bleeding(duration=6, value=damage // 2))
122-
# make the target take 4 damage
123-
target.fighter.take_damage(4)
132+
target.fighter.apply_status_effect(Bleeding(duration=6, value= 2 + (damage // 2)))
133+
# make the target take damage
134+
target.fighter.take_damage(4 + (damage // 2))
124135

125136
class AcidMetalChestPlate(Equippable):
126137
def __init__(self) -> None:
127138
super().__init__(equipment_type=EquipmentType.ARMOR, defense_bonus=5)
128139

129140
def on_hit(self, target: Actor, damage: int):
130141
# Add the poisoned status effect to the target.
131-
target.fighter.apply_status_effect(Poisoned(duration=6, value=2))
142+
target.fighter.apply_status_effect(Poisoned(duration=6, value=2))
143+
144+
class HazmatSuit(Equippable):
145+
def __init__(self) -> None:
146+
super().__init__(equipment_type=EquipmentType.ARMOR, defense_bonus=3, extra_immunities=[Poisoned, Spored])
147+
148+
class LeadHazmatSuit(Equippable):
149+
def __init__(self) -> None:
150+
super().__init__(equipment_type=EquipmentType.ARMOR, defense_bonus=5, extra_immunities=[Poisoned, Spored])

components/fighter.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ def __init__(self, hp: int, base_dodge: int, base_defence, base_power: int, immu
2323
self.base_defence = base_defence
2424
self.base_power = base_power
2525
self.status_effects = []
26-
self.immune_effects = immune_effects if immune_effects else []
26+
self.base_immune_effects = immune_effects if immune_effects else []
2727
self.last_actor_hurt_by = ""
2828

29-
3029
@property
3130
def dodge(self) -> int:
3231
return self.base_dodge + self.dodge_bonus
@@ -59,6 +58,14 @@ def defense_bonus(self) -> int:
5958
return self.parent.equipment.defense_bonus
6059
else:
6160
return 0
61+
62+
@property
63+
def immune_effects(self) -> list[type[StatusEffect]]:
64+
if self.parent.equipment:
65+
# Merge the base immunities with the extra immunities from the equipment. Avoiding duplicates.
66+
return list(set(self.base_immune_effects + self.parent.equipment.extra_immunities))
67+
else:
68+
return self.base_immune_effects
6269

6370
@property
6471
def hp(self) -> int:
@@ -86,7 +93,6 @@ def heal(self, amount: int) -> int:
8693
return amount_recovered
8794

8895
def apply_status_effect(self, effect: StatusEffect) -> None:
89-
9096
# If the fighter is immune to the effect, then don't apply it.
9197
for immune_effect in self.immune_effects:
9298
if isinstance(effect, immune_effect):
@@ -96,8 +102,8 @@ def apply_status_effect(self, effect: StatusEffect) -> None:
96102
if status_effect.name == effect.name:
97103
status_effect.duration += effect.duration
98104
return
105+
99106
self.status_effects.append(copy.deepcopy(effect))
100-
101107
self.engine.message_log.add_message(f"{self.parent.name} is now {effect.name}!", color.status_effect_applied)
102108

103109
def update_status_effects(self) -> None:

entity_factories.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@
6868
color=(0, 204, 102),
6969
name="Acid Mold",
7070
ai_cls=HostileEnemy,
71-
fighter=Fighter(hp=19, base_defence=2, base_power=6, base_dodge=5, immune_effects=[Poisoned]),
71+
fighter=Fighter(hp=14, base_defence=2, base_power=6, base_dodge=5, immune_effects=[Poisoned]),
7272
inventory=Inventory(capacity=0),
7373
level=Level(xp_given=50),
7474
equipment=Equipment(),
7575
inspect_message="It's a slime mold, but it's acidic. Don't touch it! It's hurts to the touch.",
76-
effect=Poisoned(duration=4, value=1),
76+
effect=Poisoned(duration=2, value=1),
7777
)
7878
ALL_ENTITIES.append(acid_mold)
7979
mama_mold = Actor(
@@ -310,4 +310,30 @@
310310
inspect_message="It's a hunter humanoid that looks a lot more scarier! Dark fur, red blood eyes and long fangs make it look like a monster.",
311311
)
312312
wild_hunter_humanoid.ai.setup(HostileEnemy, 5)
313-
ALL_ENTITIES.append(wild_hunter_humanoid)
313+
ALL_ENTITIES.append(wild_hunter_humanoid)
314+
silver_kinfe = Item(
315+
char="/",
316+
color=(102, 255, 255),
317+
name="Silver kinfe",
318+
equippable=equippable.SilverKinfe(),
319+
inspect_message="It's a silver kinfe, polished to the most extreme! It's fine kinfe for bleeding foes!",
320+
value=175,
321+
)
322+
ALL_ENTITIES.append(silver_kinfe)
323+
hazmat_suit = Item(
324+
char="[",
325+
color=(102, 255, 255),
326+
name="Hazmat suit",
327+
equippable=equippable.HazmatSuit(),
328+
inspect_message="It's a suit that's made of a special material. It's made to protect you from poison and spores. It's very effective at that!",
329+
value=200,
330+
)
331+
ALL_ENTITIES.append(hazmat_suit)
332+
lead_hazmat_suit = Item(
333+
char="[",
334+
color=(102, 255, 255),
335+
name="Lead hazmat suit",
336+
equippable=equippable.LeadHazmatSuit(),
337+
inspect_message="It's a hazmat suit that's made of lead. It's tougher than the normal hazmat suit, but it's also more expensive!",
338+
value=250,
339+
)

input_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
787787
key = event.sym
788788
index = key - tcod.event.KeySym.a
789789

790-
if 0 <= index <= 2:
790+
if 0 <= index <= self.items.__len__() - 1:
791791
item = copy.deepcopy(self.items[index])
792792

793793
if self.engine.game_world.credits >= item.value:

npc_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
("acid_kinfe", 5),
2626
("spikey_chest_plate", 5),
2727
("fireball_gun", 5),
28+
("hazmat_suit", 5),
29+
("lead_hazmat_suit", 5),
30+
("silver_kinfe", 5),
2831
]
2932

3033

0 commit comments

Comments
 (0)