NearAttackableAction.py 1.1KB

12345678910111213141516171819202122232425262728
  1. from synergine.synergy.event.Action import Action
  2. from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
  3. from random import randint
  4. from intelligine.cst import ALIVE, ATTACKABLE
  5. class NearAttackableAction(Action):
  6. _listen = NearAttackableEvent
  7. def __init__(self, object_id, parameters):
  8. super().__init__(object_id, parameters)
  9. def prepare(self, context):
  10. pass
  11. def run(self, obj, collection, context, synergy_manager):
  12. # TODO: TEST
  13. for obj_id_attackable in self._parameters['objects_ids_attackable']:
  14. obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
  15. obj_attackable.hurted(randint(0, 2))
  16. if obj_attackable.get_life_points() <= 0:
  17. try:
  18. # TODO: Doit etre dans l'objet, lui sais cz qu'il perd comme etat
  19. context.metas.states.remove_list(obj_id_attackable, [ALIVE, ATTACKABLE])
  20. except ValueError: # Ant maybed killed by other ant at same turn
  21. pass