13
13
ItemAction ,
14
14
DropItem ,
15
15
TakeStairAction ,
16
+ EquipAction ,
16
17
)
17
18
from entity import Entity , Actor , Item
18
19
from game_map import GameMap , GameWorld
19
20
from engine import Engine
20
21
from components .ai import BaseAI , HostileEnemy
22
+ from components .equipment import Equipment
23
+ from components .equippable import Dagger
21
24
from components .fighter import Fighter
22
25
from components .consumable import Consumable
23
26
from components .inventory import Inventory
@@ -69,8 +72,8 @@ def test_perform(self):
69
72
class Test_Actions_TakeStairsAction (unittest .TestCase ):
70
73
def test_perform_with_stairs (self ):
71
74
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 ),
74
77
inventory = Inventory (capacity = 5 ),
75
78
level = Level ()
76
79
)
@@ -95,8 +98,8 @@ def test_perform_with_stairs(self):
95
98
96
99
def test_perform_no_stairs (self ):
97
100
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 ),
100
103
inventory = Inventory (capacity = 5 ),
101
104
level = Level ()
102
105
)
@@ -181,16 +184,16 @@ def test_target_actor_with_actor(self):
181
184
of the action
182
185
'''
183
186
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 ),
186
189
inventory = Inventory (capacity = 5 ),
187
190
level = Level (),
188
191
) # player at 0, 0
189
192
ent = Actor (
190
193
x = 1 ,
191
194
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 ),
194
197
inventory = Inventory (capacity = 5 ),
195
198
level = Level (),
196
199
) # entity at 1, 1
@@ -209,8 +212,8 @@ def test_target_actor_noner(self):
209
212
of the action
210
213
'''
211
214
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 ),
214
217
inventory = Inventory (capacity = 5 ),
215
218
level = Level ()
216
219
) # player at 0, 0
@@ -252,11 +255,11 @@ def test_perform_player_with_target_and_damage(self, mock_add_message):
252
255
test that a Melee Action from a player with a target will do damage
253
256
put out a message with the correct color
254
257
'''
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 ),
257
260
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 ),
260
263
level = Level ()) # blocking entity at 1,1
261
264
eng = Engine (player = pl )
262
265
gm = GameMap (engine = eng , width = 10 , height = 10 )
@@ -283,14 +286,14 @@ def test_perform_enemy_with_target_and_damage(self, mock_add_message):
283
286
test that a Melee Action from a enemy with a target will do damage
284
287
put out a message with the correct color
285
288
'''
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 ),
288
291
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 ),
291
294
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 ),
294
297
level = Level ()) # blocking entity at 1,1
295
298
eng = Engine (player = pl )
296
299
gm = GameMap (engine = eng , width = 10 , height = 10 )
@@ -317,11 +320,11 @@ def test_perform_with_target_and_no_damage(self, mock_add_message):
317
320
'''
318
321
test that a Melee Action with a target will print when no damage is done
319
322
'''
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 ),
322
325
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 ),
325
328
level = Level ()) # blocking entity at 1,1
326
329
eng = Engine (player = pl )
327
330
gm = GameMap (engine = eng , width = 10 , height = 10 )
@@ -429,16 +432,16 @@ def test_perform_melee(self, mock_add_message):
429
432
pl = Actor (
430
433
x = 0 ,
431
434
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 ),
434
437
inventory = Inventory (capacity = 5 ),
435
438
level = Level ()
436
439
) # player at 0,0
437
440
ent = Actor (
438
441
x = 1 ,
439
442
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 ),
442
445
inventory = Inventory (capacity = 5 ),
443
446
level = Level ()
444
447
) # blocking entity at 1,1
@@ -485,8 +488,8 @@ def test_init(self):
485
488
'''
486
489
test that a pickup action can be initialized okay
487
490
'''
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 ),
490
493
level = Level ())
491
494
action = PickupAction (entity = actor )
492
495
self .assertIsInstance (action , PickupAction )
@@ -499,8 +502,8 @@ def test_perform_with_item_and_capacity(self):
499
502
'''
500
503
actor = Actor (
501
504
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 ),
504
507
inventory = Inventory (capacity = 5 ),
505
508
level = Level ()
506
509
)
@@ -534,8 +537,8 @@ def test_perform_with_no_item_on_map(self):
534
537
'''
535
538
actor = Actor (
536
539
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 ),
539
542
inventory = Inventory (capacity = 5 ),
540
543
level = Level ()
541
544
)
@@ -562,8 +565,8 @@ def test_perform_with_item_in_wrong_spot(self):
562
565
'''
563
566
actor = Actor (
564
567
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 ),
567
570
inventory = Inventory (capacity = 5 ),
568
571
level = Level ()
569
572
)
@@ -590,8 +593,8 @@ def test_perform_with_no_capacity(self):
590
593
'''
591
594
actor = Actor (
592
595
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 ),
595
598
inventory = Inventory (capacity = 0 ),
596
599
level = Level ()
597
600
)
@@ -618,8 +621,8 @@ def test_init_no_targetxy(self):
618
621
test that an item action can get initialized okay
619
622
and the target_xy gets set to the x, y of the entity
620
623
'''
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 ),
623
626
level = Level ())
624
627
item = Item (consumable = Consumable ())
625
628
item_action = ItemAction (entity = actor , item = item )
@@ -631,8 +634,8 @@ def test_init_with_targetxy(self):
631
634
test that an item action can get initialized okay
632
635
and the target_xy gets set
633
636
'''
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 ),
636
639
level = Level ())
637
640
item = Item (consumable = Consumable ())
638
641
item_action = ItemAction (entity = actor , item = item , target_xy = (5 , 6 ))
@@ -643,8 +646,8 @@ def test_property_target_actor(self):
643
646
'''
644
647
test that get_actor_at_location is called with the correct inputs
645
648
'''
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 ),
648
651
level = Level ())
649
652
item = Item (consumable = Consumable ())
650
653
eng = Engine (player = actor )
@@ -663,8 +666,8 @@ def test_perform(self):
663
666
test that the activeate command on the consumable is called
664
667
passing in the existing itemAction
665
668
'''
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 ),
668
671
level = Level ())
669
672
item = Item (consumable = Consumable ())
670
673
item_action = ItemAction (entity = actor , item = item )
@@ -681,8 +684,8 @@ def test_perform(self):
681
684
test that this will call the drop command of the inventory
682
685
'''
683
686
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 ),
686
689
inventory = Inventory (capacity = 1 ),
687
690
level = Level ()
688
691
)
@@ -697,5 +700,39 @@ def test_perform(self):
697
700
patch_drop .assert_called_once_with (item )
698
701
699
702
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
+
700
737
if __name__ == '__main__' :
701
738
unittest .main ()
0 commit comments