|
@@ -11,6 +11,7 @@ from synergine2.simulation import SubjectMechanism
|
11
|
11
|
from synergine2.simulation import Intention
|
12
|
12
|
from synergine2.simulation import Simulation
|
13
|
13
|
from synergine2.simulation import Event
|
|
14
|
+from synergine2_cocos2d.user_action import UserAction
|
14
|
15
|
from synergine2_xyz.simulation import XYZSimulation
|
15
|
16
|
|
16
|
17
|
|
|
@@ -19,6 +20,7 @@ class MoveToIntention(Intention):
|
19
|
20
|
self,
|
20
|
21
|
move_to: typing.Tuple[int, int],
|
21
|
22
|
start_time: float,
|
|
23
|
+ gui_action: typing.Any,
|
22
|
24
|
) -> None:
|
23
|
25
|
self.move_to = move_to
|
24
|
26
|
self.path = [] # type: typing.List[typing.Tuple[int, int]]
|
|
@@ -26,6 +28,7 @@ class MoveToIntention(Intention):
|
26
|
28
|
self.last_intention_time = start_time
|
27
|
29
|
self.just_reach = False
|
28
|
30
|
self.initial = True
|
|
31
|
+ self.gui_action = gui_action
|
29
|
32
|
|
30
|
33
|
|
31
|
34
|
class RequestMoveBehaviour(SimulationBehaviour):
|
|
@@ -54,7 +57,11 @@ class RequestMoveBehaviour(SimulationBehaviour):
|
54
|
57
|
|
55
|
58
|
try:
|
56
|
59
|
subject = self.simulation.subjects.index[subject_id]
|
57
|
|
- subject.intentions.set(self.move_intention_class(move_to, start_time=time.time()))
|
|
60
|
+ subject.intentions.set(self.move_intention_class(
|
|
61
|
+ move_to,
|
|
62
|
+ start_time=time.time(),
|
|
63
|
+ gui_action=data['gui_action'],
|
|
64
|
+ ))
|
58
|
65
|
except KeyError:
|
59
|
66
|
# TODO: log error here
|
60
|
67
|
pass
|
|
@@ -102,6 +109,7 @@ class MoveToMechanism(SubjectMechanism):
|
102
|
109
|
'last_intention_time': move.last_intention_time,
|
103
|
110
|
'just_reach': move.just_reach,
|
104
|
111
|
'initial': move.initial,
|
|
112
|
+ 'gui_action': move.gui_action,
|
105
|
113
|
}
|
106
|
114
|
|
107
|
115
|
except IndexError: # TODO: Specialize ? No movement left
|
|
@@ -116,6 +124,7 @@ class FinishMoveEvent(Event):
|
116
|
124
|
subject_id: int,
|
117
|
125
|
from_position: typing.Tuple[int, int],
|
118
|
126
|
to_position: typing.Tuple[int, int],
|
|
127
|
+ gui_action: typing.Any,
|
119
|
128
|
*args,
|
120
|
129
|
**kwargs
|
121
|
130
|
):
|
|
@@ -123,6 +132,7 @@ class FinishMoveEvent(Event):
|
123
|
132
|
self.subject_id = subject_id
|
124
|
133
|
self.from_position = from_position
|
125
|
134
|
self.to_position = to_position
|
|
135
|
+ self.gui_action = gui_action
|
126
|
136
|
|
127
|
137
|
def repr_debug(self) -> str:
|
128
|
138
|
return '{}: subject_id:{}, from_position:{} to_position: {}'.format(
|
|
@@ -139,6 +149,7 @@ class StartMoveEvent(Event):
|
139
|
149
|
subject_id: int,
|
140
|
150
|
from_position: typing.Tuple[int, int],
|
141
|
151
|
to_position: typing.Tuple[int, int],
|
|
152
|
+ gui_action: typing.Any,
|
142
|
153
|
*args,
|
143
|
154
|
**kwargs
|
144
|
155
|
):
|
|
@@ -146,6 +157,7 @@ class StartMoveEvent(Event):
|
146
|
157
|
self.subject_id = subject_id
|
147
|
158
|
self.from_position = from_position
|
148
|
159
|
self.to_position = to_position
|
|
160
|
+ self.gui_action = gui_action
|
149
|
161
|
|
150
|
162
|
def repr_debug(self) -> str:
|
151
|
163
|
return '{}: subject_id:{}, from_position:{} to_position: {}'.format(
|
|
@@ -167,7 +179,8 @@ class MoveToBehaviour(SubjectBehaviour):
|
167
|
179
|
subject: Subject,
|
168
|
180
|
) -> None:
|
169
|
181
|
super().__init__(config, simulation, subject)
|
170
|
|
- self._duration = float(self.config.resolve('game.move.walk_ref_time'))
|
|
182
|
+ self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
|
|
183
|
+ self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
|
171
|
184
|
|
172
|
185
|
def run(self, data):
|
173
|
186
|
move_to_data = data[self.move_to_mechanism]
|
|
@@ -184,7 +197,11 @@ class MoveToBehaviour(SubjectBehaviour):
|
184
|
197
|
return False
|
185
|
198
|
|
186
|
199
|
def _can_move_to_next_step(self, move_to_data: dict) -> bool:
|
187
|
|
- return time.time() - move_to_data['last_intention_time'] >= self._duration
|
|
200
|
+ # TODO: Relation vers cocos ! Deplacer UserAction ?
|
|
201
|
+ if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
|
|
202
|
+ return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
|
|
203
|
+ if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
|
|
204
|
+ return time.time() - move_to_data['last_intention_time'] >= self._run_duration
|
188
|
205
|
|
189
|
206
|
def _is_fresh_new_step(self, move_to_data: dict) -> bool:
|
190
|
207
|
return move_to_data['just_reach'] or move_to_data['initial']
|
|
@@ -208,10 +225,20 @@ class MoveToBehaviour(SubjectBehaviour):
|
208
|
225
|
self.subject.position = new_position
|
209
|
226
|
move.last_intention_time = time.time()
|
210
|
227
|
move.just_reach = True
|
211
|
|
- event = FinishMoveEvent(self.subject.id, previous_position, new_position)
|
|
228
|
+ event = FinishMoveEvent(
|
|
229
|
+ self.subject.id,
|
|
230
|
+ previous_position,
|
|
231
|
+ new_position,
|
|
232
|
+ gui_action=move.gui_action,
|
|
233
|
+ )
|
212
|
234
|
else:
|
213
|
235
|
move.just_reach = False
|
214
|
|
- event = StartMoveEvent(self.subject.id, previous_position, new_position)
|
|
236
|
+ event = StartMoveEvent(
|
|
237
|
+ self.subject.id,
|
|
238
|
+ previous_position,
|
|
239
|
+ new_position,
|
|
240
|
+ gui_action=move.gui_action,
|
|
241
|
+ )
|
215
|
242
|
|
216
|
243
|
move.initial = False
|
217
|
244
|
# Note: Need to explicitly set to update shared data
|