Browse Source

use refactored code for soldier death

Bastien Sevajol 6 years ago
parent
commit
19db648fa4
2 changed files with 15 additions and 10 deletions
  1. 5 7
      opencombat/simulation/behaviour.py
  2. 10 3
      opencombat/simulation/event.py

+ 5 - 7
opencombat/simulation/behaviour.py View File

@@ -120,13 +120,11 @@ class EngageOpponent(AliveSubjectBehaviour):
120 120
 
121 121
         # Must be check if target is not already dead (killed same cycle)
122 122
         if kill and COLLECTION_ALIVE in target_subject.collections:
123
-            # TODO: refact ? All in same place for dead ?
124
-            target_subject.collections.remove(COLLECTION_ALIVE)
125
-            # FIXME: Must be automatic when manipulate subject collections !
126
-            self.simulation.collections[COLLECTION_ALIVE].remove(target_subject_id)
127
-            self.simulation.collections[COLLECTION_ALIVE] = self.simulation.collections[COLLECTION_ALIVE]
128
-            events.append(DieEvent(shooter_subject_id=self.subject.id, shoot_subject_id=target_subject_id))
129
-            target_subject.intentions.remove_all()
123
+            DieEvent.apply_subject_death(target_subject)
124
+            events.append(DieEvent(
125
+                shooter_subject_id=self.subject.id,
126
+                shoot_subject_id=target_subject_id,
127
+            ))
130 128
 
131 129
         return events
132 130
 

+ 10 - 3
opencombat/simulation/event.py View File

@@ -1,11 +1,13 @@
1 1
 # coding: utf-8
2
-
3
-
4
-# TODO: Reprendre les events Move, pour les lister tous ici
5 2
 import typing
6 3
 
7 4
 from synergine2.simulation import Event
8 5
 
6
+from opencombat.const import COLLECTION_ALIVE
7
+
8
+if typing.TYPE_CHECKING:
9
+    from opencombat.simulation.subject import TileSubject
10
+
9 11
 
10 12
 class NewVisibleOpponent(Event):
11 13
     def __init__(
@@ -38,6 +40,11 @@ class FireEvent(Event):
38 40
 
39 41
 
40 42
 class DieEvent(Event):
43
+    @classmethod
44
+    def apply_subject_death(cls, subject: 'TileSubject') -> None:
45
+        subject.remove_collection(COLLECTION_ALIVE)
46
+        subject.intentions.remove_all()
47
+
41 48
     def __init__(
42 49
         self,
43 50
         shooter_subject_id: int,