1
1
function OnGlobalMessage (self , message , object )
2
-
3
- -- print("capturablegotglobalmessage")
4
-
5
2
if message == self .deactivationMessage or message == " DEACTIVATEALLCAPTURABLES" then
6
3
self .Deactivated = true ;
7
4
self .dominantTeam = self .Team ;
@@ -10,11 +7,9 @@ function OnGlobalMessage(self, message, object)
10
7
elseif message == self .activationMessage or message == " ACTIVATEALLCAPTURABLES" then
11
8
self .Deactivated = false ;
12
9
end
13
-
14
10
end
15
11
16
12
function OnMessage (self , message , object )
17
-
18
13
if message == self .deactivationMessage or message == " DEACTIVATEALLCAPTURABLES" then
19
14
self .Deactivated = true ;
20
15
self .dominantTeam = self .Team ;
@@ -23,11 +18,9 @@ function OnMessage(self, message, object)
23
18
elseif message == self .activationMessage or message == " ACTIVATEALLCAPTURABLES" then
24
19
self .Deactivated = false ;
25
20
end
26
-
27
21
end
28
22
29
23
function Create (self )
30
-
31
24
self .Team = self :NumberValueExists (" StartTeam" ) and self :GetNumberValue (" StartTeam" ) or 0 ;
32
25
33
26
self .useGlobalMessaging = self :GetNumberValue (" SendCaptureMessageGlobally" ) == 1 and true or false ;
@@ -76,25 +69,22 @@ function Create(self)
76
69
77
70
self .teamHasBrainTable = {};
78
71
72
+ self .shouldSendCaptureMessage = false ;
79
73
end
80
74
81
- function Update (self )
82
-
75
+ function ThreadedUpdate (self )
83
76
if self .actorCheckTimer :IsPastSimMS (self .actorCheckDelay ) then
84
-
85
77
self .actorCheckTimer :Reset ();
86
-
78
+
87
79
self .actorTeamNumTable = { [- 1 ] = 0 ,
88
80
[0 ] = 0 ,
89
81
[1 ] = 0 ,
90
82
[2 ] = 0 ,
91
83
[3 ] = 0 };
92
84
93
85
self .teamHasBrainTable = {};
94
-
95
-
86
+
96
87
if self .captureArea then
97
-
98
88
for box in self .captureArea .Boxes do
99
89
for actor in MovableMan :GetMOsInBox (box , - 1 , true ) do
100
90
if IsActor (actor ) then
@@ -105,9 +95,7 @@ function Update(self)
105
95
end
106
96
end
107
97
end
108
-
109
98
else -- fallback
110
-
111
99
local actorList = MovableMan :GetMOsInRadius (self .Pos , self .Diameter * 2 , - 1 , true );
112
100
for actor in actorList do
113
101
if IsActor (actor ) then
@@ -117,7 +105,6 @@ function Update(self)
117
105
self .teamHasBrainTable [actor .Team ] = true ;
118
106
end
119
107
end
120
-
121
108
end
122
109
123
110
local largestNum = 0 ;
@@ -148,7 +135,6 @@ function Update(self)
148
135
end
149
136
150
137
local brainOnlyRestrictionCheck = self .dominantTeam == self .Team or (self .dominantTeam ~= self .Team and not (self .onlyBrainCanCapture and not self .teamHasBrainTable [self .dominantTeam ]));
151
-
152
138
if self .dominantTeam ~= self .Team and not (self .onlyBrainCanCapture and not self .teamHasBrainTable [self .dominantTeam ]) then
153
139
if not self .FXcapturing then
154
140
self .FXstartCapture = not self .Deactivated and true or false ;
@@ -162,9 +148,7 @@ function Update(self)
162
148
end
163
149
164
150
if not self .Contested and not self .Deactivated and brainOnlyRestrictionCheck then
165
-
166
151
if self .dominantTeam ~= self .capturingTeam then
167
-
168
152
if self .captureProgress > 0 then
169
153
self .captureProgress = math.max (0 , self .captureProgress - TimerMan .DeltaTimeSecs * self .captureRate );
170
154
else
@@ -174,9 +158,7 @@ function Update(self)
174
158
self .Team = - 1 ;
175
159
end
176
160
end
177
-
178
161
else
179
-
180
162
if self .captureProgress < 1 then
181
163
self .captureProgress = math.min (1 , self .captureProgress + TimerMan .DeltaTimeSecs * self .captureRate );
182
164
if self .Team == - 1 and self .dominantTeam == self .Team then
@@ -187,25 +169,19 @@ function Update(self)
187
169
if self .dominantTeam ~= self .Team then
188
170
self .Team = self .dominantTeam ;
189
171
self .FXcaptureSuccess = true ;
190
- print (" shouldhavesentmessage: " .. self .messageOnCapture )
191
- if self .useGlobalMessaging then
192
- MovableMan :SendGlobalMessage (self .messageOnCapture , self .dominantTeam );
193
- else
194
- self .Activity :SendMessage (self .messageOnCapture , self .dominantTeam );
195
- end
172
+ self :RequestSyncedUpdate ();
173
+ self .shouldSendCaptureMessage = true ;
196
174
if self .deactivateOnCapture then
197
175
self .Deactivated = true ;
198
176
end
199
177
end
200
178
end
201
-
202
179
end
203
180
204
181
if self .instantReset and self .dominantTeam == self .Team then
205
182
self .captureProgress = self .Team ~= - 1 and 1 or 0 ;
206
183
self .capturingTeam = self .Team ;
207
184
end
208
-
209
185
end
210
186
211
187
PrimitiveMan :DrawTextPrimitive (self .Pos + Vector (0 , - 20 ), tostring (" Team: " .. self .Team ), true , 1 );
@@ -219,10 +195,20 @@ function Update(self)
219
195
end
220
196
end
221
197
222
- function OnSave (self )
198
+ function SyncedUpdate (self )
199
+ if self .shouldSendCaptureMessage then
200
+ print (" shouldhavesentmessage: " .. self .messageOnCapture )
201
+ if self .useGlobalMessaging then
202
+ MovableMan :SendGlobalMessage (self .messageOnCapture , self .dominantTeam );
203
+ else
204
+ self .Activity :SendMessage (self .messageOnCapture , self .dominantTeam );
205
+ end
206
+ self .shouldSendCaptureMessage = false ;
207
+ end
208
+ end
223
209
210
+ function OnSave (self )
224
211
self :SetNumberValue (" captureProgress" , self .captureProgress );
225
212
self :SetNumberValue (" dominantTeam" , self .dominantTeam );
226
213
self :SetNumberValue (" capturingTeam" , self .capturingTeam );
227
-
228
214
end
0 commit comments