1313 ItemAction ,
1414 DropItem ,
1515 TakeStairAction ,
16+ EquipAction ,
1617)
1718from entity import Entity , Actor , Item
1819from game_map import GameMap , GameWorld
1920from engine import Engine
2021from components .ai import BaseAI , HostileEnemy
22+ from components .equipment import Equipment
23+ from components .equippable import Dagger
2124from components .fighter import Fighter
2225from components .consumable import Consumable
2326from components .inventory import Inventory
@@ -69,8 +72,8 @@ def test_perform(self):
6972class 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+
700737if __name__ == '__main__' :
701738 unittest .main ()
0 commit comments