DayZ 1.24
Loading...
Searching...
No Matches
Spotlight.c
Go to the documentation of this file.
1class Spotlight extends ItemBase
2{
3 private bool m_IsFolded;
4 private bool m_EvaluateDeployment;
5 SpotlightLight m_Light;
6
8 static vector m_LightLocalOrientation = "0 0 0";
9
10 // Spotlight can be extended and compressed
11 static const string SEL_REFLECTOR_COMP_U = "reflector";
12 static const string SEL_CORD_FOLDED_U = "cord_folded";
13 static const string SEL_CORD_PLUGGED_U = "cord_plugged";
14 static const string SEL_CORD_PLUGGED_F = "spotlight_folded_cord_plugged";
15 static const string SEL_CORD_FOLDED_F = "spotlight_folded_cord_folded";
16
17 static const string SEL_INVENTORY = "inventory";
18 static const string SEL_PLACING = "placing";
19 static const string SEL_GLASS_F = "glass_folded";
20 static const string SEL_GLASS_U = "glass_unfolded";
21 static const string SEL_REFLECTOR_F = "reflector_folded";
22 static const string SEL_REFLECTOR_U = "reflector_unfolded";
23
24 static const int ID_GLASS_UNFOLDED = 3;
25 static const int ID_REFLECTOR_UNFOLDED = 4;
26 static const int ID_GLASS_FOLDED = 5;
27 static const int ID_REFLECTOR_FOLDED = 6;
28
29 static string LIGHT_OFF_GLASS = "dz\\gear\\camping\\Data\\spotlight_glass.rvmat";
30 static string LIGHT_OFF_REFLECTOR = "dz\\gear\\camping\\Data\\spotlight.rvmat";
31 static string LIGHT_ON_GLASS = "dz\\gear\\camping\\Data\\spotlight_glass_on.rvmat";
32 static string LIGHT_ON_REFLECTOR = "dz\\gear\\camping\\Data\\spotlight_glass_on.rvmat";
33
34 //sound
35 const string SOUND_TURN_ON = "spotlight_turn_on_SoundSet";
36 const string SOUND_TURN_OFF = "spotlight_turn_off_SoundSet";
37
38 protected EffectSound m_SoundTurnOn;
41
42 //Spotlight, folded and unfolded
43 void Spotlight()
44 {
45 m_EvaluateDeployment = false;
46
47 RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
48 RegisterNetSyncVariableBool("m_IsDeploySound");
49 RegisterNetSyncVariableBool("m_IsFolded");
50 }
51
57
58 override bool IsElectricAppliance()
59 {
60 return true;
61 }
62
63 override void OnInitEnergy()
64 {
65 if (GetCompEM().IsPlugged())
66 {
67 if (!GetHierarchyRoot())
68 Unfold();
69 else
70 Fold(true);
71 }
72 else
73 Fold();
74
76 }
77
78 override void EOnInit(IEntity other, int extra)
79 {
80 if (!IsHologram())
81 {
83 HideSelection(SEL_CORD_FOLDED_F);
84 }
85 else
86 Unfold();
87 }
88
89 //--- POWER EVENTS
90 override void OnSwitchOn()
91 {
92 super.OnSwitchOn();
93
95 }
96
97 override void OnSwitchOff()
98 {
99 super.OnSwitchOff();
100
101 SoundTurnOff();
102
103 if (m_Light)
104 {
105 m_Light.FadeOut(0.05);
106 m_Light = null;
107 }
108 }
109
110 override void OnWorkStart()
111 {
112#ifndef SERVER
113 m_Light = SpotlightLight.Cast(ScriptedLightBase.CreateLight(SpotlightLight, "0 0 0"));
114 m_Light.AttachOnObject(this, m_LightLocalPosition, m_LightLocalOrientation);
115#endif
116
118 }
119
120 override void OnWorkStop()
121 {
122#ifndef SERVER
123 if (m_Light)
124 m_Light.FadeOut();
125#endif
126
128 }
129
130 // Called when this device is picked up
132 {
133 super.OnItemLocationChanged(old_owner, new_owner);
134
135 //skips folding of currently deployed spotlight
136 if (m_EvaluateDeployment || IsBeingPlaced())
137 {
138 m_EvaluateDeployment = false;
139 if (m_Light)
140 m_Light.AttachOnObject(this, m_LightLocalPosition, m_LightLocalOrientation);
141
142 Unfold();
143
144 return;
145 }
146
147 // When the item is picked up by a player
149 if (player && player.GetItemInHands() == this)
150 Fold(GetCompEM().IsPlugged());
151 }
152
154 {
155 Unfold();
157 }
158
159 protected void UpdateAllSelections()
160 {
161 bool isPlugged = GetCompEM().IsPlugged();
162 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
163 bool isInHands = player && player.GetItemInHands() == this;
164 HideAllSelections();
165
166 m_LightLocalPosition = GetSelectionPositionLS("beamStart");
167
168 if (IsFolded() || isInHands)
169 {
170 HideSelection(SEL_REFLECTOR_COMP_U);
171
172 ShowSelection(SEL_INVENTORY);
173 ShowSelection(SEL_GLASS_F);
174 ShowSelection(SEL_REFLECTOR_F);
175
176 if (isPlugged)
177 ShowSelection(SEL_CORD_PLUGGED_F);
178 else
179 ShowSelection(SEL_CORD_FOLDED_F);
180
181 if (!IsHologram())
182 {
183 if (GetCompEM().IsWorking())
184 {
185 SetObjectMaterial(ID_GLASS_UNFOLDED, LIGHT_ON_GLASS);
186 SetObjectMaterial(ID_REFLECTOR_UNFOLDED, LIGHT_ON_REFLECTOR);
187 SetObjectMaterial(ID_GLASS_FOLDED, LIGHT_ON_GLASS);
188 SetObjectMaterial(ID_REFLECTOR_FOLDED, LIGHT_ON_REFLECTOR);
189 }
190 else
191 {
192 SetObjectMaterial(ID_GLASS_UNFOLDED, LIGHT_OFF_GLASS);
193 SetObjectMaterial(ID_REFLECTOR_UNFOLDED, LIGHT_OFF_REFLECTOR);
194 SetObjectMaterial(ID_GLASS_FOLDED, LIGHT_OFF_GLASS);
195 SetObjectMaterial(ID_REFLECTOR_FOLDED, LIGHT_OFF_REFLECTOR);
196 }
197 }
198 }
199 else
200 {
201 ShowSelection(SEL_PLACING);
202 ShowSelection(SEL_REFLECTOR_U);
203 ShowSelection(SEL_GLASS_U);
204 ShowSelection(SEL_REFLECTOR_COMP_U);
205
206 if (isPlugged)
207 ShowSelection(SEL_CORD_PLUGGED_U);
208 else
209 ShowSelection(SEL_CORD_FOLDED_U);
210
211 if (!IsHologram())
212 {
213 if (GetCompEM().IsWorking())
214 {
215 SetObjectMaterial(ID_GLASS_UNFOLDED, LIGHT_ON_GLASS);
216 SetObjectMaterial(ID_REFLECTOR_UNFOLDED, LIGHT_ON_REFLECTOR);
217 }
218 else
219 {
220 SetObjectMaterial(ID_GLASS_UNFOLDED, LIGHT_OFF_GLASS);
221 SetObjectMaterial(ID_REFLECTOR_UNFOLDED, LIGHT_OFF_REFLECTOR);
222 }
223 }
224 }
225 }
226
228 {
229 Fold();
231 }
232
234 {
235 super.OnVariablesSynchronized();
236
237 if (IsDeploySound())
239
242
245 }
246
247 void Fold(bool keep_connected = false)
248 {
249 m_IsFolded = true;
250 if (!keep_connected)
251 {
252 GetCompEM().SwitchOff();
253 GetCompEM().UnplugThis();
254 }
255
257 SetSynchDirty();
258 }
259
260 void Unfold()
261 {
262 m_IsFolded = false;
264 SetSynchDirty();
265 }
266
268 {
269 super.OnStoreSave(ctx);
270
271 // Save folded/unfolded state
272 ctx.Write(m_IsFolded);
273 }
274
275 override bool OnStoreLoad(ParamsReadContext ctx, int version)
276 {
277 if (!super.OnStoreLoad(ctx, version))
278 return false;
279
280 // Load folded/unfolded state
281 bool b_is_folded = false;
282 if (!ctx.Read(b_is_folded))
283 b_is_folded = true;
284
285 if (b_is_folded)
286 Fold();
287 else
288 Unfold();
289
290 return true;
291 }
292
293 override bool CanPutInCargo(EntityAI parent)
294 {
295 if (!super.CanPutInCargo(parent))
296 return false;
297
298 return !GetCompEM().IsPlugged();
299 }
300
302 {
303 if (!super.CanPutIntoHands(parent))
304 return false;
305 // Commented out so Reposition action is possible to execute
306 return true;
307 }
308
309 bool IsFolded()
310 {
311 return m_IsFolded;
312 }
313
314 //================================================================
315 // SOUNDS
316 //================================================================
317 protected void SoundTurnOn()
318 {
319 PlaySoundSet(m_SoundTurnOn, SOUND_TURN_ON, 0, 0);
320 }
321
322 protected void SoundTurnOff()
323 {
324 PlaySoundSet(m_SoundTurnOff, SOUND_TURN_OFF, 0, 0);
325 }
326
327 //================================================================
328 // ADVANCED PLACEMENT
329 //================================================================
330 override void OnPlacementStarted(Man player)
331 {
332 super.OnPlacementStarted(player);
333
336 SEL_CORD_FOLDED_F
337 };
338
340 foreach (string selection : selections)
341 {
342 if (GetGame().IsMultiplayer() && GetGame().IsServer())
343 playerPB.GetHologramServer().SetSelectionToRefresh(selection);
344 else
345 playerPB.GetHologramLocal().SetSelectionToRefresh(selection);
346 }
347 }
348
349 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
350 {
351 super.OnPlacementComplete(player, position, orientation);
352
353 if (GetGame().IsServer())
354 SetIsDeploySound(true);
355
356 Unfold();
357 m_EvaluateDeployment = true;
358 }
359
360 override void OnPlacementCancelled(Man player)
361 {
362 super.OnPlacementCancelled(player);
363
364 Fold(true);
365 }
366
367 override bool IsDeployable()
368 {
369 return true;
370 }
371
372 override string GetDeploySoundset()
373 {
374 return "placeSpotlight_SoundSet";
375 }
376
377 override string GetLoopDeploySoundset()
378 {
379 return "spotlight_deploy_SoundSet";
380 }
381
383 {
384 if (!GetGame().IsDedicatedServer() && !m_DeployLoopSound)
385 {
387 m_DeployLoopSound.SetAutodestroy(true);
388 }
389 }
390
392 {
393 if (!GetGame().IsDedicatedServer())
394 {
395 m_DeployLoopSound.SetSoundFadeOut(0.5);
396 m_DeployLoopSound.SoundStop();
397 }
398 }
399
400 override int GetViewIndex()
401 {
402 if (MemoryPointExists("invView2") && !m_IsFolded)
403 return 1;
404
405 return 0;
406 }
407
424}
void AddAction(typename actionName)
void RemoveAction(typename actionName)
ExplosiveLight m_Light
light
void SetIsDeploySound(bool is_deploy_sound)
Definition ItemBase.c:8972
bool CanPlayDeployLoopSound()
Definition ItemBase.c:9039
override bool IsHologram()
Definition ItemBase.c:5641
void PlayDeploySound()
Definition ItemBase.c:9003
bool IsDeploySound()
Definition ItemBase.c:8977
override bool IsBeingPlaced()
Definition ItemBase.c:5625
ref EffectSound m_DeployLoopSound
Definition TrapBase.c:47
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
SpotlightLight m_Light
Definition Spotlight.c:5
override bool CanPutIntoHands(EntityAI player)
Definition Spotlight.c:301
override void OnSwitchOn()
Definition Spotlight.c:90
EffectSound m_SoundTurnOn
override void OnIsPlugged(EntityAI source_device)
Definition Spotlight.c:153
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition Spotlight.c:275
EffectSound m_SoundTurnOff
override void OnWorkStart()
Definition Spotlight.c:110
override int GetViewIndex()
Definition Spotlight.c:400
void SoundTurnOn()
override void OnPlacementStarted(Man player)
Definition Spotlight.c:330
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition Spotlight.c:131
void Unfold()
Definition Spotlight.c:260
override bool IsElectricAppliance()
Definition Spotlight.c:58
bool m_IsFolded
Definition Spotlight.c:3
void PlayDeployLoopSound()
Definition BarbedWire.c:144
override void SetActions()
Definition Spotlight.c:408
override void OnInitEnergy()
Definition Spotlight.c:63
void SoundTurnOff()
override string GetDeploySoundset()
Definition Spotlight.c:372
void Fold()
override void OnWorkStop()
Definition Spotlight.c:120
static vector m_LightLocalPosition
Definition Spotlight.c:7
override void OnStoreSave(ParamsWriteContext ctx)
Definition Spotlight.c:267
void ~Spotlight()
Definition Spotlight.c:52
override void OnPlacementCancelled(Man player)
Definition Spotlight.c:360
void Spotlight()
Definition Spotlight.c:43
override void OnVariablesSynchronized()
Definition Spotlight.c:233
bool m_EvaluateDeployment
Definition Spotlight.c:4
bool IsFolded()
Definition Spotlight.c:309
override void OnIsUnplugged(EntityAI last_energy_source)
Definition Spotlight.c:227
EffectSound m_DeployLoopSound
Definition BarbedWire.c:15
override void OnSwitchOff()
Definition Spotlight.c:97
override bool CanPutInCargo(EntityAI parent)
Definition Spotlight.c:293
void UpdateAllSelections()
Definition MetalWire.c:30
override string GetLoopDeploySoundset()
Definition Spotlight.c:377
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition Spotlight.c:349
static const string SEL_CORD_PLUGGED_F
Definition Spotlight.c:14
void Fold(bool keep_connected=false)
Definition Spotlight.c:247
void StopDeployLoopSound()
Definition BarbedWire.c:153
override bool IsDeployable()
Definition Spotlight.c:367
override void EOnInit(IEntity other, int extra)
Definition Spotlight.c:78
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()