55from random import randint as _randint
66from typing import Optional as _Optional , Any
77
8- from entyty import AbstractEntity
8+ from entyty import _AbstractEntity as AbstractEntity
99
1010import getch
1111import pyglet .window as _window
@@ -450,7 +450,9 @@ def _init_inventory(self):
450450 log (f'Adding starting equipment: { self ._role ._starting_equipment } ' )
451451 for item in self ._role ._starting_equipment + self ._background .equipment :
452452 if isinstance (item , list ):
453- if len (item ) > 1 and (item [1 ] in Armory or item [1 ] in Goods ):
453+ if item == []:
454+ continue
455+ elif len (item ) > 1 and (item [1 ] in Armory or item [1 ] in Goods ):
454456 log (f'Adding { item [0 ]} { item [1 ]} ' )
455457 for _ in range (item [0 ]):
456458 self .inventory .add_item (item [1 ])
@@ -570,7 +572,7 @@ class BaseCharacter(BaseActor):
570572 """
571573 log ('Initializing BaseCharacter class.' )
572574 AbstractEntity .dispatcher .register_event_type ('on_turn_end' )
573-
575+ dispatcher = AbstractEntity . dispatcher
574576 def __init__ (self , name , background : str , alignment : str , grid = None ):
575577 from entyty import GridEntity
576578 character_class = self .__class__ .__name__
@@ -591,6 +593,7 @@ def __init__(self, name, background: str, alignment: str, grid=None):
591593 self ._create_properties ()
592594 self ._actions = {'move' : {i : {'direction' : None , 'from' : None , 'distance' : None , 'to' : None } for i in range (self .speed // 5 )},
593595 'attack' : {'target' : None , 'weapon' : None , 'result' : None }, 'free' : [], 'quick' : []}
596+ self ._action_history = []
594597 self ._is_turn = False
595598 self ._nearby_items = {}
596599 self ._target = None
@@ -620,7 +623,7 @@ def _create_properties(self):
620623 setattr (self .__class__ , 'grid_entity' , property (lambda self : self ._grid_entity ))
621624 properties = {
622625 'movements' : self .grid_entity .movements ,
623- 'movements_remaining' : self .grid_entity ._movements_remaining ,
626+ 'movements_remaining' : self .grid_entity .movements_remaining ,
624627 'movement_queue' : self .grid_entity .movement_queue ,
625628 'cell' : self .grid_entity .cell ,
626629 'cell_name' : self .grid_entity .cell_name ,
@@ -634,6 +637,7 @@ def _create_properties(self):
634637 for attr , value in properties .items ():
635638 setattr (self , attr , value )
636639 setattr (self .__class__ , attr , property (lambda self , attr = attr : getattr (self .grid_entity , attr )))
640+ self ._push_handlers (on_turn_end = self .grid_entity .end_turn )
637641 else :
638642 for attr in ['movements' , 'movements_remaining' , 'movement_queue' , 'cell' , 'cell_name' , 'cell_history' , 'last_cell' , 'x' , 'y' , 'position' , 'path' ]:
639643 delattr (self , attr )
@@ -675,7 +679,9 @@ def _on_turn_change(self, actor):
675679 self ._is_turn = True
676680
677681 def end_turn (self ):
678- self .dispatcher .dispatch_event ('on_turn_end' , self .actions )
682+ self ._action_history .append (self .actions )
683+ self .grid_entity .end_turn ()
684+ self .actions = None
679685
680686 def _join_grid (self , grid ):
681687 from entyty import GridEntity
@@ -697,10 +703,13 @@ def _set_target(self, target):
697703
698704 def move (self , direction ):
699705 if direction in ['north_west' , 'north' , 'north_east' , 'east' , 'south_east' , 'south' , 'south_west' , 'west' ]:
700- self .grid_entity .move_in_direction (direction )
706+ mvmnt_index = self .grid_entity .move_in_direction (direction )
701707 self .actions ['move' ] = self .grid_entity .actions ['move' ]
702- return f'--> { self .actions ["move" ][len (self .actions ["move" ]) - 1 ]["to" ]} '
703-
708+ if mvmnt_index is not None :
709+ return f'{ self .actions ["move" ][mvmnt_index ]["from" ]} --> { self .actions ["move" ][mvmnt_index ]["to" ]} '
710+ else :
711+ return f'Cannot move { direction } .'
712+
704713 def attack (self ):
705714 if 'attack' in self ._actions .keys ():
706715 print ('Already attacked this turn.' )
0 commit comments