Skip to content

Commit 4e824fe

Browse files
authored
Merge pull request #16 from nuzcraft/part_13
Part 13
2 parents 4710610 + 4e7f904 commit 4e824fe

25 files changed

+1354
-479
lines changed

DEVNOTES.md

Lines changed: 188 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 7 additions & 178 deletions
Large diffs are not rendered by default.

Tests/test_actions.py

Lines changed: 85 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
ItemAction,
1414
DropItem,
1515
TakeStairAction,
16+
EquipAction,
1617
)
1718
from entity import Entity, Actor, Item
1819
from game_map import GameMap, GameWorld
1920
from engine import Engine
2021
from components.ai import BaseAI, HostileEnemy
22+
from components.equipment import Equipment
23+
from components.equippable import Dagger
2124
from components.fighter import Fighter
2225
from components.consumable import Consumable
2326
from components.inventory import Inventory
@@ -69,8 +72,8 @@ def test_perform(self):
6972
class Test_Actions_TakeStairsAction(unittest.TestCase):
7073
def test_perform_with_stairs(self):
7174
actor = Actor(
72-
ai_cls=BaseAI,
73-
fighter=Fighter(hp=10, defense=10, power=10),
75+
ai_cls=BaseAI, equipment=Equipment(),
76+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
7477
inventory=Inventory(capacity=5),
7578
level=Level()
7679
)
@@ -95,8 +98,8 @@ def test_perform_with_stairs(self):
9598

9699
def test_perform_no_stairs(self):
97100
actor = Actor(
98-
ai_cls=BaseAI,
99-
fighter=Fighter(hp=10, defense=10, power=10),
101+
ai_cls=BaseAI, equipment=Equipment(),
102+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
100103
inventory=Inventory(capacity=5),
101104
level=Level()
102105
)
@@ -181,16 +184,16 @@ def test_target_actor_with_actor(self):
181184
of the action
182185
'''
183186
pl = Actor(
184-
ai_cls=BaseAI,
185-
fighter=Fighter(hp=10, defense=10, power=10),
187+
ai_cls=BaseAI, equipment=Equipment(),
188+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
186189
inventory=Inventory(capacity=5),
187190
level=Level(),
188191
) # player at 0, 0
189192
ent = Actor(
190193
x=1,
191194
y=1,
192-
ai_cls=BaseAI,
193-
fighter=Fighter(hp=10, defense=10, power=10),
195+
ai_cls=BaseAI, equipment=Equipment(),
196+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
194197
inventory=Inventory(capacity=5),
195198
level=Level(),
196199
) # entity at 1, 1
@@ -209,8 +212,8 @@ def test_target_actor_noner(self):
209212
of the action
210213
'''
211214
pl = Actor(
212-
ai_cls=BaseAI,
213-
fighter=Fighter(hp=10, defense=10, power=10),
215+
ai_cls=BaseAI, equipment=Equipment(),
216+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
214217
inventory=Inventory(capacity=5),
215218
level=Level()
216219
) # player at 0, 0
@@ -252,11 +255,11 @@ def test_perform_player_with_target_and_damage(self, mock_add_message):
252255
test that a Melee Action from a player with a target will do damage
253256
put out a message with the correct color
254257
'''
255-
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, fighter=Fighter(
256-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
258+
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
259+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
257260
level=Level()) # player at 0,0
258-
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, fighter=Fighter(
259-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
261+
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
262+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
260263
level=Level()) # blocking entity at 1,1
261264
eng = Engine(player=pl)
262265
gm = GameMap(engine=eng, width=10, height=10)
@@ -283,14 +286,14 @@ def test_perform_enemy_with_target_and_damage(self, mock_add_message):
283286
test that a Melee Action from a enemy with a target will do damage
284287
put out a message with the correct color
285288
'''
286-
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, fighter=Fighter(
287-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
289+
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
290+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
288291
level=Level()) # player at 0,0
289-
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, fighter=Fighter(
290-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
292+
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
293+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
291294
level=Level()) # blocking entity at 1,1
292-
ent2 = Actor(x=2, y=2, ai_cls=HostileEnemy, fighter=Fighter(
293-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
295+
ent2 = Actor(x=2, y=2, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
296+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
294297
level=Level()) # blocking entity at 1,1
295298
eng = Engine(player=pl)
296299
gm = GameMap(engine=eng, width=10, height=10)
@@ -317,11 +320,11 @@ def test_perform_with_target_and_no_damage(self, mock_add_message):
317320
'''
318321
test that a Melee Action with a target will print when no damage is done
319322
'''
320-
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, fighter=Fighter(
321-
hp=10, defense=0, power=5), inventory=Inventory(capacity=5),
323+
pl = Actor(x=0, y=0, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
324+
hp=10, base_defense=0, base_power=5), inventory=Inventory(capacity=5),
322325
level=Level()) # player at 0,0
323-
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, fighter=Fighter(
324-
hp=10, defense=5, power=5), inventory=Inventory(capacity=5),
326+
ent = Actor(x=1, y=1, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
327+
hp=10, base_defense=5, base_power=5), inventory=Inventory(capacity=5),
325328
level=Level()) # blocking entity at 1,1
326329
eng = Engine(player=pl)
327330
gm = GameMap(engine=eng, width=10, height=10)
@@ -429,16 +432,16 @@ def test_perform_melee(self, mock_add_message):
429432
pl = Actor(
430433
x=0,
431434
y=0,
432-
ai_cls=HostileEnemy,
433-
fighter=Fighter(hp=10, defense=0, power=5),
435+
ai_cls=HostileEnemy, equipment=Equipment(),
436+
fighter=Fighter(hp=10, base_defense=0, base_power=5),
434437
inventory=Inventory(capacity=5),
435438
level=Level()
436439
) # player at 0,0
437440
ent = Actor(
438441
x=1,
439442
y=1,
440-
ai_cls=HostileEnemy,
441-
fighter=Fighter(hp=10, defense=0, power=5),
443+
ai_cls=HostileEnemy, equipment=Equipment(),
444+
fighter=Fighter(hp=10, base_defense=0, base_power=5),
442445
inventory=Inventory(capacity=5),
443446
level=Level()
444447
) # blocking entity at 1,1
@@ -485,8 +488,8 @@ def test_init(self):
485488
'''
486489
test that a pickup action can be initialized okay
487490
'''
488-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
489-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
491+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
492+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
490493
level=Level())
491494
action = PickupAction(entity=actor)
492495
self.assertIsInstance(action, PickupAction)
@@ -499,8 +502,8 @@ def test_perform_with_item_and_capacity(self):
499502
'''
500503
actor = Actor(
501504
x=5, y=6,
502-
ai_cls=HostileEnemy,
503-
fighter=Fighter(hp=10, defense=10, power=10),
505+
ai_cls=HostileEnemy, equipment=Equipment(),
506+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
504507
inventory=Inventory(capacity=5),
505508
level=Level()
506509
)
@@ -534,8 +537,8 @@ def test_perform_with_no_item_on_map(self):
534537
'''
535538
actor = Actor(
536539
x=5, y=6,
537-
ai_cls=HostileEnemy,
538-
fighter=Fighter(hp=10, defense=10, power=10),
540+
ai_cls=HostileEnemy, equipment=Equipment(),
541+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
539542
inventory=Inventory(capacity=5),
540543
level=Level()
541544
)
@@ -562,8 +565,8 @@ def test_perform_with_item_in_wrong_spot(self):
562565
'''
563566
actor = Actor(
564567
x=5, y=6,
565-
ai_cls=HostileEnemy,
566-
fighter=Fighter(hp=10, defense=10, power=10),
568+
ai_cls=HostileEnemy, equipment=Equipment(),
569+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
567570
inventory=Inventory(capacity=5),
568571
level=Level()
569572
)
@@ -590,8 +593,8 @@ def test_perform_with_no_capacity(self):
590593
'''
591594
actor = Actor(
592595
x=5, y=6,
593-
ai_cls=HostileEnemy,
594-
fighter=Fighter(hp=10, defense=10, power=10),
596+
ai_cls=HostileEnemy, equipment=Equipment(),
597+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
595598
inventory=Inventory(capacity=0),
596599
level=Level()
597600
)
@@ -618,8 +621,8 @@ def test_init_no_targetxy(self):
618621
test that an item action can get initialized okay
619622
and the target_xy gets set to the x, y of the entity
620623
'''
621-
actor = Actor(x=5, y=6, ai_cls=HostileEnemy, fighter=Fighter(
622-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
624+
actor = Actor(x=5, y=6, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
625+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
623626
level=Level())
624627
item = Item(consumable=Consumable())
625628
item_action = ItemAction(entity=actor, item=item)
@@ -631,8 +634,8 @@ def test_init_with_targetxy(self):
631634
test that an item action can get initialized okay
632635
and the target_xy gets set
633636
'''
634-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
635-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
637+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
638+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
636639
level=Level())
637640
item = Item(consumable=Consumable())
638641
item_action = ItemAction(entity=actor, item=item, target_xy=(5, 6))
@@ -643,8 +646,8 @@ def test_property_target_actor(self):
643646
'''
644647
test that get_actor_at_location is called with the correct inputs
645648
'''
646-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
647-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
649+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
650+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
648651
level=Level())
649652
item = Item(consumable=Consumable())
650653
eng = Engine(player=actor)
@@ -663,8 +666,8 @@ def test_perform(self):
663666
test that the activeate command on the consumable is called
664667
passing in the existing itemAction
665668
'''
666-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
667-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
669+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
670+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
668671
level=Level())
669672
item = Item(consumable=Consumable())
670673
item_action = ItemAction(entity=actor, item=item)
@@ -681,8 +684,8 @@ def test_perform(self):
681684
test that this will call the drop command of the inventory
682685
'''
683686
ent = Actor(
684-
ai_cls=BaseAI,
685-
fighter=Fighter(hp=10, defense=10, power=10),
687+
ai_cls=BaseAI, equipment=Equipment(),
688+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
686689
inventory=Inventory(capacity=1),
687690
level=Level()
688691
)
@@ -697,5 +700,39 @@ def test_perform(self):
697700
patch_drop.assert_called_once_with(item)
698701

699702

703+
class TestEquipAction(unittest.TestCase):
704+
def test_init(self):
705+
'''
706+
test that the equip action can be initialized
707+
'''
708+
ent = Actor(
709+
ai_cls=BaseAI,
710+
equipment=Equipment(),
711+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
712+
inventory=Inventory(capacity=1),
713+
level=Level()
714+
)
715+
item = Item(equippable=Dagger())
716+
ea = EquipAction(entity=ent, item=item)
717+
self.assertEqual(ea.item, item)
718+
719+
def test_perform(self):
720+
'''
721+
test that perform will call toggle_equip
722+
'''
723+
ent = Actor(
724+
ai_cls=BaseAI,
725+
equipment=Equipment(),
726+
fighter=Fighter(hp=10, base_defense=10, base_power=10),
727+
inventory=Inventory(capacity=1),
728+
level=Level()
729+
)
730+
item = Item(equippable=Dagger())
731+
ea = EquipAction(entity=ent, item=item)
732+
with patch('components.equipment.Equipment.toggle_equip') as patch_toggle_equip:
733+
ea.perform()
734+
patch_toggle_equip.assert_called_once_with(item)
735+
736+
700737
if __name__ == '__main__':
701738
unittest.main()

Tests/test_ai.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from numpy import power
66

77
from components.ai import BaseAI, HostileEnemy, ConfusedEnemy
8+
from components.equipment import Equipment
89
from components.fighter import Fighter
910
from components.inventory import Inventory
1011
from components.level import Level
@@ -20,8 +21,8 @@ def test_entity_set(self):
2021
'''
2122
tests that the entity can be set correctly
2223
'''
23-
actor = Actor(ai_cls=BaseAI, fighter=Fighter(
24-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
24+
actor = Actor(ai_cls=BaseAI, equipment=Equipment(), fighter=Fighter(
25+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
2526
level=Level())
2627
self.assertEqual(actor, actor.ai.entity)
2728

@@ -116,8 +117,8 @@ def test_init(self):
116117
'''
117118
test that the confused enemy can be initized without issues
118119
'''
119-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
120-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
120+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
121+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
121122
level=Level())
122123
ai = ConfusedEnemy(
123124
entity=actor, previous_ai=HostileEnemy, turns_remaining=5)
@@ -128,8 +129,8 @@ def test_perform_switch_ai(self):
128129
'''
129130
test that with 0 or less turns remaining the ai switches back
130131
'''
131-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
132-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
132+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
133+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
133134
level=Level())
134135
ai = ConfusedEnemy(
135136
entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=0)
@@ -146,8 +147,8 @@ def test_perform_bump_action(self):
146147
test that with turns remaining the ai will perform a bump action
147148
in a random direction and reduce the number of turns remaining
148149
'''
149-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
150-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
150+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
151+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
151152
level=Level())
152153
ai = ConfusedEnemy(
153154
entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=5)
@@ -167,8 +168,8 @@ def test_init(self):
167168
test that the hostile enemy class can be initialized without issues
168169
'''
169170
# instantiating an actor will automatically instantiate the ai class under actor.ai
170-
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
171-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
171+
actor = Actor(ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
172+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
172173
level=Level())
173174
self.assertEqual(actor, actor.ai.entity)
174175
self.assertEqual([], actor.ai.path)
@@ -184,8 +185,8 @@ def test_perform_wait(self):
184185
gm.tiles[:, :] = tile_types.floor
185186
gm.entities.add(player)
186187

187-
hostile_ent = Actor(x=0, y=2, ai_cls=HostileEnemy, fighter=Fighter(
188-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
188+
hostile_ent = Actor(x=0, y=2, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
189+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
189190
level=Level())
190191
gm.entities.add(hostile_ent)
191192

@@ -216,8 +217,8 @@ def test_perform_movement(self):
216217
gm.entities.add(player)
217218

218219
# hostile entity is 2 spaces away
219-
hostile_ent = Actor(x=0, y=2, ai_cls=HostileEnemy, fighter=Fighter(
220-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
220+
hostile_ent = Actor(x=0, y=2, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
221+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
221222
level=Level())
222223
gm.entities.add(hostile_ent)
223224

@@ -248,8 +249,8 @@ def test_perform_melee(self):
248249
gm.entities.add(player)
249250

250251
# hostile entity is 1 spaces away
251-
hostile_ent = Actor(x=0, y=1, ai_cls=HostileEnemy, fighter=Fighter(
252-
hp=10, defense=10, power=10), inventory=Inventory(capacity=5),
252+
hostile_ent = Actor(x=0, y=1, ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(
253+
hp=10, base_defense=10, base_power=10), inventory=Inventory(capacity=5),
253254
level=Level())
254255
gm.entities.add(hostile_ent)
255256

0 commit comments

Comments
 (0)