Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
destructioneffectbase.c
Go to the documentation of this file.
2 {
3  EntityAI m_Entity;
4 
5  bool m_EntityIsTakeable;
6 
7  ParticleSource m_POneTime;
8  ParticleSource m_PPersistent;
9 
10  int m_ParticleOneTime;
11  int m_ParticlePersistent;
12 
13  EffectSound m_SOneTime;
14  EffectSound m_SPersistent;
15 
16  string m_SoundSetOneTime;
17  string m_SoundSetPersistent;
18 
19  bool m_KeepHealthOnReplace;
20  string m_ReplaceWithEntity;
21  int m_ReplaceDelay;
22 
23  bool m_HasExplosionDamage;
24  DamageType m_DamageType;
25  string m_AmmoType;
26 
27 
28  void ~DestructionEffectBase()
29  {
30  if (m_POneTime)
31  {
32  m_POneTime.Stop();
33  }
34  if (m_PPersistent)
35  {
36  m_PPersistent.Stop();
37  }
38 
39  SEffectManager.DestroyEffect(m_SOneTime);
40  SEffectManager.DestroyEffect(m_SPersistent);
41  }
42 
43  private void Init();
44 
45  bool HasExplosionDamage()
46  {
47  return (m_HasExplosionDamage && m_AmmoType);
48  }
49 
50  private void DealExplosionDamage()
51  {
52  DamageSystem.ExplosionDamage(m_Entity, null, m_AmmoType, m_Entity.GetPosition(), m_DamageType);
53  }
54 
55  void OnHealthLevelChanged(notnull EntityAI entity, int oldLevel, int newLevel, string zone)
56  {
57  m_Entity = entity;
58  Init();
59 
60  if (GetGame().IsServer())
61  {
62  entity.SetTakeable(m_EntityIsTakeable);
63 
64  if (oldLevel != -1 || entity.m_Initialized)
65  {
66  if (m_ReplaceWithEntity)
67  {
68  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ReplaceEntityServer, m_ReplaceDelay, false);
69  }
70  if (HasExplosionDamage())
71  {
72  DealExplosionDamage();
73  }
74  OnEntityDestroyedOneTimeServer(entity, oldLevel, zone);
75  }
76  OnEntityDestroyedPersistentServer(entity, zone);
77  }
78  #ifndef SERVER//client OR single
79  {
80  if (oldLevel != -1 || entity.m_Initialized)//one time
81  {
82  m_POneTime = PlayParticle(m_ParticleOneTime);
83 
84  if (m_POneTime)
85  {
86  m_POneTime.SetOwner(this);
87  }
88 
89  OnEntityDestroyedOneTimeClient(entity, oldLevel, zone);
90 
91  m_Entity.PlaySoundSet(m_SOneTime, m_SoundSetOneTime, 0, 0 );
92  m_Entity.PlaySoundSetLoop(m_SPersistent, m_SoundSetPersistent, 0, 0 );
93  }
94  else//Persistent
95  {
96  OnEntityDestroyedPersistentClient(entity, zone);
97  m_Entity.PlaySoundSetLoop(m_SPersistent, m_SoundSetPersistent, 0, 0 );
98  }
99 
100  m_PPersistent = PlayParticle(m_ParticlePersistent, true);
101 
102  if (m_PPersistent)
103  {
104  m_PPersistent.SetOwner(this);
105  }
106  }
107  #endif
108  }
109 
110  private void ReplaceEntityServer()
111  {
112  EntityAI dead_entity = EntityAI.Cast(GetGame().CreateObjectEx(m_ReplaceWithEntity, m_Entity.GetPosition(), ECE_OBJECT_SWAP, RF_ORIGINAL));
113  dead_entity.SetOrientation(m_Entity.GetOrientation());
114  if (m_KeepHealthOnReplace)
115  {
116  dead_entity.SetHealth(m_Entity.GetHealth());
117  }
118  m_Entity.Delete();
119  }
120 
121  private ParticleSource PlayParticle(int particleType, bool attach = false)
122  {
123  if (!m_Entity)
124  {
125  ErrorEx("Missing entity - something went wrong");
126  return null;
127  }
128  if (particleType)
129  {
130  ParticleSource p = ParticleManager.GetInstance().PlayInWorld(particleType, m_Entity.GetPosition());
131  if (attach && p)
132  {
133  p.AddAsChild(m_Entity);//Note: it's also possible to directly play on object: Particle.PlayOnObject
134  }
135  return p;
136  }
137  return null;
138  }
139 
140  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
141  // !!!!!!!!!! Override methods bellow !!!!!!!!!!!!!
142  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
143 
144  // ! Client Event called the moment the entity is destroyed, best for explosion and other one-time effects
145  void OnEntityDestroyedOneTimeClient(EntityAI entity, int oldLevel,string zone);
146 
147  // ! Server Event called the moment the entity is destroyed
148  void OnEntityDestroyedOneTimeServer(EntityAI entity, int oldLevel, string zone);
149 
150  // ! Client Event called at the same moment as the one-time event, but also when the entity is loaded/spawned on client, typically as the player connects to the server or moves close enough so that previously non-existent client entity is now spawned in
151  void OnEntityDestroyedPersistentClient(EntityAI entity, string zone);
152 
153  // ! Server Event called at the same moment as the one time event, but also when the entity is loaded/spawned on Server, typically as the server is starting up
154  void OnEntityDestroyedPersistentServer(EntityAI entity, string zone);
155 
156  // !Relayed from entity when explosion happens
157  void OnExplosionEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal, float energyFactor, float explosionFactor, bool isWater, string ammoType);
158 
159 }
160 
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
RF_ORIGINAL
const int RF_ORIGINAL
Definition: centraleconomy.c:63
ECE_OBJECT_SWAP
const int ECE_OBJECT_SWAP
Definition: centraleconomy.c:38
ErrorEx
enum ShapeType ErrorEx
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
vector
Definition: enconvert.c:105
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
Object
Definition: objecttyped.c:1
m_AmmoType
string m_AmmoType
Definition: impacteffects.c:18
ParticleSource
Entity which has the particle instance as an ObjectComponent.
Definition: particlesource.c:123
DestructionEffectBase
Definition: destructioneffectbase.c:1
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
m_DamageType
int m_DamageType
Definition: areadamagecomponent.c:11
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
EntityAI
Definition: building.c:5
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11