NearAttackableAction.py 1.1KB

1234567891011121314151617181920212223242526272829
  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.synergy.Simulation import Simulation
  5. from intelligine.cst import ALIVE, ATTACKABLE
  6. class NearAttackableAction(Action):
  7. _listen = NearAttackableEvent
  8. def __init__(self, object_id, parameters):
  9. super().__init__(object_id, parameters)
  10. def prepare(self, context):
  11. pass
  12. def run(self, obj, collection, context, synergy_manager):
  13. # TODO: TEST
  14. for obj_id_attackable in self._parameters['objects_ids_attackable']:
  15. obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
  16. obj_attackable.hurted(randint(0, 2))
  17. if obj_attackable.get_life_points() <= 0:
  18. try:
  19. context.metas.list.remove(Simulation.STATE, obj_id_attackable, ALIVE)
  20. context.metas.list.remove(Simulation.STATE, obj_id_attackable, ATTACKABLE)
  21. except ValueError: # Ant maybed killed by other ant at same turn
  22. pass