Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
effectparticle.c
Go to the documentation of this file.
1 
5 {
7  protected Particle m_ParticleObj;
8 
13  protected int m_ParticleID;
16  protected vector m_Orientation;
18  protected bool m_ForceRotationRelativeToWorld;
20 
25  protected vector m_ParticleOrientation;
26  protected Object m_Object;
28 
29 
30 
34  void EffectParticle()
35  {
36 
37  }
38 
42  void ~EffectParticle()
43  {
44 
45  }
46 
50  override void InitEffect()
51  {
52  super.InitEffect();
53 
54  // Would be neat, but since particles are often already playing
55  // BEFORE they are even registered as the particle for the Effect
56  // Better to just keep that one I guess..
57  // Event_OnStarted.Remove(Event_OnEffectStarted);
58 
59  // Will be called by the particle events
61  }
62 
63 
67  override string GetDebugName()
68  {
69  string identifier;
70  if (GetParticle())
71  {
72  identifier = GetParticle().GetDebugNameNative();
73  }
74  else
75  {
76  identifier = "NO_PARTICLE";
77  }
78 
79  return string.Format("%1:%2:%3", super.GetDebugName(), m_ParticleID, identifier);
80  }
81 
87  override void ValidateStart()
88  {
89  if (!GetParticle())
90  {
91  ErrorEx(string.Format("No Particle started playing, stopping EffectParticle: %1", GetDebugName()), ErrorExSeverity.WARNING);
92  Stop();
93  }
94  }
95 
96 
97 
102 
107  override EffectType GetEffectType()
108  {
109  return EffectType.PARTICLE;
110  }
111 
116  override bool IsParticle()
117  {
118  return true;
119  }
120 
122 
123 
124 
129 
134  void SetParticle(Particle p)
135  {
136  // Unregister the events on the old
137  if (m_ParticleObj)
138  {
139  ParticleEvents ope = m_ParticleObj.GetEvents();
140  ope.Event_OnParticleStart.Remove(Event_OnEffectStarted);
141  ope.Event_OnParticleStop.Remove(Event_OnEffectEnded);
142  }
143 
144  // Assign the new main Particle
145  m_ParticleObj = p;
146 
147  // Register the events on the new
148  if (m_ParticleObj)
149  {
150  ParticleEvents npe = m_ParticleObj.GetEvents();
151  npe.Event_OnParticleStart.Insert(Event_OnEffectStarted);
152  // We will use Stop instead of End, as old particles were destroyed when they stopped
153  // And this system kinda relies on that
154  npe.Event_OnParticleStop.Insert(Event_OnEffectEnded);
155  }
156  }
157 
162  Particle GetParticle()
163  {
164  return m_ParticleObj;
165  }
166 
168 
169 
170 
176 
181  override void Start()
182  {
183  if (m_ParticleID > 0)
184  {
185  vector pos = GetPosition();
186  vector ori = GetOrientation();
187 
188  if (m_ParentObject)
189  {
190  pos = GetLocalPosition();
191  ori = GetAttachedLocalOri();
192  }
193 
194  SetParticle(ParticleManager.GetInstance().CreateParticle(m_ParticleID, pos, true, GetParent(), ori, IsParticleRotationRelativeToWorld()));
195  }
196 
197  super.Start();
198  }
199 
204  override void Stop()
205  {
206  if ( GetParticle() )
207  {
208  GetParticle().Stop();
209  SetParticle(null);
210  }
211 
212  super.Stop();
213  }
214 
216 
217 
218 
223 
227  void AttachTo(Object obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
228  {
229  // Update the cached variables...
230  SetParent(obj);
231  SetLocalPosition(local_pos);
232  SetAttachedLocalOri(local_ori);
233  ForceParticleRotationRelativeToWorld(force_rotation_to_world);
234 
235  // Now attach it
236  AddAsChild(obj, local_pos, local_ori, force_rotation_to_world);
237  }
238 
242  void ReAttach()
243  {
244  // Skip the updating, as we are going to reuse what was set before
245  AddAsChild( GetParent(), GetLocalPosition(), GetAttachedLocalOri(), IsParticleRotationRelativeToWorld());
246  }
247 
251  protected void AddAsChild(Object obj, vector local_pos, vector local_ori, bool force_rotation_to_world)
252  {
253  Particle p = GetParticle();
254  if (p)
255  {
256  p.AddAsChild(obj, local_pos, local_ori, force_rotation_to_world);
257  }
258  }
259 
261 
262 
263 
268 
274  void Event_OnPlayStart()
275  {
276 
277  }
278 
284  void Event_OnPlayStarted()
285  {
286 
287  }
288 
290 
291 
292 
297 
303  void SetParticleID( int id )
304  {
305  m_ParticleID = id;
306  }
307 
313  int GetParticleID()
314  {
315  return m_ParticleID;
316  }
317 
323  void SetCurrentParticleID( int id )
324  {
325  m_ParticleID = id;
326 
327  Particle p = GetParticle();
328  if (p)
329  {
330  p.SetSource(id);
331  }
332  }
333 
338  int GetCurrentParticleID()
339  {
340  Particle p = GetParticle();
341  if (p)
342  {
343  return p.GetParticleID();
344  }
345  else
346  {
347  return ParticleList.INVALID;
348  }
349  }
350 
356  override void SetCurrentParent( Object parent_obj, bool updateCached = true )
357  {
358  super.SetCurrentParent(parent_obj, updateCached);
359 
360  ReAttach();
361  }
362 
367  override Object GetCurrentParent()
368  {
369  Particle p = GetParticle();
370 
371  if (p)
372  return Object.Cast(p.GetParent());
373  else
374  return super.GetParent();
375  }
376 
382  override void SetCurrentPosition( vector pos, bool updateCached = true )
383  {
384  super.SetCurrentPosition(pos, updateCached);
385 
386  Particle p = GetParticle();
387 
388  if (p)
389  p.SetPosition(pos);
390  }
391 
396  override vector GetCurrentPosition()
397  {
398  Particle p = GetParticle();
399 
400  if (p)
401  return p.GetPosition();
402  else
403  return super.GetPosition();
404  }
405 
411  override void SetCurrentLocalPosition( vector pos, bool updateCached = true )
412  {
413  super.SetCurrentLocalPosition(pos, updateCached);
414 
415  Particle p = GetParticle();
416  if (p)
417  {
418  Object parent = GetParent();
419 
420  if (parent)
421  ReAttach();
422  else
423  p.SetPosition(pos);
424  }
425  }
426 
431  override vector GetCurrentLocalPosition()
432  {
433  Particle p = GetParticle();
434 
435  if (p)
436  {
437  Object parent = GetParent();
438 
439  if (parent)
440  return parent.WorldToModel(p.GetPosition());
441  else
442  return p.GetPosition();
443  }
444  else
445  return super.GetLocalPosition();
446  }
447 
453  void SetOrientation( vector ori )
454  {
455  m_Orientation = ori;
456  }
457 
463  vector GetOrientation()
464  {
465  return m_Orientation;
466  }
467 
472  void SetCurrentOrientation( vector ori, bool updateCached = true )
473  {
474  if ( updateCached)
475  SetOrientation(ori);
476 
477  Particle p = GetParticle();
478 
479  if (p)
480  p.SetOrientation(ori);
481  }
482 
487  vector GetCurrentOrientation()
488  {
489  Particle p = GetParticle();
490 
491  if (p)
492  return p.GetOrientation();
493  else
494  return vector.Zero;
495  }
496 
503  void ForceParticleRotationRelativeToWorld(bool state)
504  {
505  m_ForceRotationRelativeToWorld = state;
506  }
507 
513  bool IsParticleRotationRelativeToWorld()
514  {
515  Particle p = GetParticle();
516 
517  if (p)
518  return p.IsHierarchyPositionOnly();
519  else
520  return m_ForceRotationRelativeToWorld;
521  }
522 
527  bool IsParticleCurrentRotationRelativeToWorld()
528  {
529  Particle p = GetParticle();
530 
531  if (p)
532  return p.IsHierarchyPositionOnly();
533  else
534  return false;
535  }
536 
538 
539 
540 
545 
550  void CheckLifeSpan()
551  {
552  /*
553  if ( !m_ParticleObj )
554  {
555  delete this;
556  }
557 
558  OnCheckUpdate();
559  */
560  }
561 
562  void SetDecalOwner(Object o)
563  {
564  m_Object = o;
565  }
566 
568 }
EffectType
EffectType
Enum to determine what type of effect the Effect is.
Definition: effect.c:2
GetAttachedLocalOri
vector GetAttachedLocalOri()
Get the local orientation set by SetAttachedLocalOri.
Definition: effect.c:611
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
ParticleEvents
Invokers for ParticleBase events, called from events.
Definition: particlebase.c:15
m_Object
private Object m_Object
Definition: actiontargets.c:166
m_ParentObject
protected Object m_ParentObject
Cached parent.
Definition: effect.c:39
EffectParticle
Wrapper class for managing particles through SEffectManager.
Definition: effectparticle.c:4
ErrorEx
enum ShapeType ErrorEx
SetAttachedLocalOri
void SetAttachedLocalOri(vector ori)
Set local orientation for the Effectparticle to attach to when the Effect is started.
Definition: effect.c:601
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
Effect
void Effect()
ctor
Definition: effect.c:70
m_Orientation
vector m_Orientation
Definition: bleedingsource.c:15
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
Object
Definition: objecttyped.c:1
GetLocalPosition
vector GetLocalPosition()
Get the local position of the Effect.
Definition: effect.c:486
Event_OnStopped
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Definition: effect.c:23
Event_OnEffectEnded
ref ScriptInvoker Event_OnEffectEnded
Event used when the actual effect stopped playing.
Definition: effect.c:25
Event_OnEffectStarted
ref ScriptInvoker Event_OnEffectStarted
Event used when the actual effect started playing.
Definition: effect.c:24
GetParent
proto native Widget GetParent()
Get parent of the Effect.
Definition: effect.c:405
SetParent
void SetParent(Object parent_obj)
Set parent of the Effect.
Definition: effect.c:394
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
SetLocalPosition
void SetLocalPosition(vector pos)
Set the local position of the Effect.
Definition: effect.c:476