Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
grenade_base.c
Go to the documentation of this file.
8
10class GrenadeLight : ExplosiveLight {}
11
13{
14 protected static float m_DefaultBrightness = 50;
15 protected static float m_DefaultRadius = 20;
16
18 {
19 SetVisibleDuringDaylight(true);
20 SetRadiusTo(m_DefaultRadius);
21 SetBrightnessTo(m_DefaultBrightness);
22 SetFlareVisible(false);
23 SetAmbientColor(1.0, 1.0, 1.0);
24 SetDiffuseColor(1.0, 1.0, 1.0);
25 SetLifetime(0.35);
26 SetDisableShadowsWithinRadius(-1);
27 }
28}
29
30class Grenade_Base : ExplosivesBase
31{
32 protected const float DEFAULT_FUSE_DELAY = 10;
33
34 protected ref Timer m_FuseTimer;
35 protected float m_FuseDelay;
36 protected float m_RemainingFuseTime;
37
38 protected bool m_Pinned;
39 protected bool m_Pinnable;
40 //protected bool m_Explodable; //! DEPRECATED; not used anywhere
41
43
44 void Pin()
45 {
46 if (!m_Pinned && m_Pinnable)
47 {
48 OnPin();
49 }
50 }
51
52 void Unpin()
53 {
54 if (m_Pinned)
55 {
56 OnUnpin();
57 }
58 }
59
61 override void OnActivatedByTripWire();
62
63 override void OnActivatedByItem(notnull ItemBase item)
64 {
65 if (item == this)
66 {
68 return;
69 }
70
71 Unpin();
72 }
73
74 bool IsPinned()
75 {
76 return m_Pinned;
77 }
78
80 {
82 if (m_FuseTimer.IsRunning())
83 {
84 return false;
85 }
86
87 return m_Pinnable;
88 }
89
91 {
93 }
94
96 {
97 float delay = Math.RandomFloat(1, 20);
98 delay *= 1000;
99 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(ActivateImmediate, delay, false);
100 }
101
102 void SetPinnable(bool state)
103 {
104 m_Pinnable = state;
105 }
106
107 void SetFuseDelay(float delay)
108 {
109 m_FuseDelay = delay;
110 }
111
113 {
114 m_GrenadeType = type;
115 }
116
118 {
119 return m_GrenadeType;
120 }
121
122 protected void Activate()
123 {
124 if (!m_FuseTimer.IsRunning())
125 {
127 if (m_RemainingFuseTime > 0)
128 {
129 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_RemainingFuseTime));
130 m_FuseTimer.Run(m_RemainingFuseTime, this, "OnActivateFinished");
131 }
132 else
133 {
134 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_FuseDelay));
135 m_FuseTimer.Run(m_FuseDelay, this, "OnActivateFinished");
136 }
137
138 }
139 }
140
141 protected void Deactivate()
142 {
143 if (m_FuseTimer.IsRunning())
144 {
145 m_RemainingFuseTime = m_FuseTimer.GetRemaining();
146 m_FuseTimer.Stop();
147 OnDeactivate();
148 }
149 }
150
151 protected override void InitiateExplosion()
152 {
153 switch (GetGrenadeType())
154 {
155 case EGrenadeType.FRAGMENTATION:
156 case EGrenadeType.ILLUMINATING:
157 for (int i = 0; i < m_AmmoTypes.Count(); i++)
158 {
159 Explode(DamageType.EXPLOSION, m_AmmoTypes[i]);
160 }
161 break;
162 case EGrenadeType.CHEMICAL:
163 case EGrenadeType.NON_LETHAL:
164 break;
165 }
166
167 OnExplode();
168 }
169
171 protected void ExplodeGrenade(EGrenadeType grenade_type)
172 {
174 }
175
176 protected void OnPin()
177 {
178 m_Pinned = true;
179 if (GetGame().IsServer())
180 {
181 ForceFarBubble(false);
182 SetSynchDirty();
183 }
184
185 Deactivate();
186 }
187
188 protected void OnUnpin()
189 {
190 m_Pinned = false;
191 if (GetGame().IsServer())
192 {
193 ForceFarBubble(true);
194 SetSynchDirty();
195 }
196
198 }
199
200 protected void OnActivateStarted();
201 protected void OnActivateFinished()
202 {
203 if (GetGame().IsServer())
204 {
205 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
206 SetTakeable(false);
207 }
208 }
209
210 protected void OnActivateImmediate()
211 {
212 if (GetGame().IsServer())
213 {
214 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
215 SetTakeable(false);
216 }
217 }
218
219 protected void OnDeactivate();
220
222 {
223 super.OnStoreSave(ctx);
224
225 if (GetGame().SaveVersion() >= 107)
226 {
227 ctx.Write(m_Pinned);
228 }
229 }
230
231 override bool OnStoreLoad(ParamsReadContext ctx, int version)
232 {
233 if (!super.OnStoreLoad(ctx, version))
234 return false;
235
236 bool pinned;
237 if (version >= 107)
238 {
239 if (!ctx.Read(pinned))
240 {
241 return false;
242 }
243
244 m_Pinned = pinned;
245 }
246
247 return true;
248 }
249
250 override bool CanBeArmed()
251 {
252 return false;
253 }
254
255 override bool CanBeDisarmed()
256 {
257 return false;
258 }
259
260 override bool CanExplodeInFire()
261 {
262 return true;
263 }
264
265 override void SetActions()
266 {
267 super.SetActions();
268
269 AddAction(ActionUnpin);
270 AddAction(ActionPin);
271 }
272
273 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
274 {
275 super.EEItemLocationChanged(oldLoc, newLoc);
276
278 if (newLoc.GetType() != InventoryLocationType.HANDS && !IsPinned())
279 {
280 Activate();
281 }
282 }
283
284 override void OnWasAttached(EntityAI parent, int slot_id)
285 {
286 super.OnWasAttached(parent, slot_id);
287
288 if (parent.IsAnyInherited({TrapBase,ImprovisedExplosive}))
289 {
290 Deactivate();
291 }
292 }
293
295 {
296 m_Pinned = true;
297 m_FuseTimer = new Timer;
299
300 SetPinnable(true);
302 SetGrenadeType(EGrenadeType.FRAGMENTATION);
303
304 RegisterNetSyncVariableBool("m_Pinned");
305 }
306
308 {
309 AddExplosionEffectForSurface("Hit_Snow", ParticleList.EXPLOSION_GRENADE_SNOW);
310 AddExplosionEffectForSurface("Hit_Ice", ParticleList.EXPLOSION_GRENADE_ICE);
311 }
312}
void AddAction(typename actionName)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
void OnActivateFinished()
const float DEFAULT_FUSE_DELAY
void ActivateRandomTime()
override void InitSpecificsExplosionEffectForSurface()
override void SetActions()
override bool CanExplodeInFire()
override bool CanBeDisarmed()
void SetFuseDelay(float delay)
void OnActivateImmediate()
override bool CanBeArmed()
bool IsPinnable()
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
float m_RemainingFuseTime
ref Timer m_FuseTimer
void SetGrenadeType(EGrenadeType type)
void SetPinnable(bool state)
override void OnActivatedByItem(notnull ItemBase item)
bool IsPinned()
override void OnStoreSave(ParamsWriteContext ctx)
EGrenadeType m_GrenadeType
EGrenadeType GetGrenadeType()
void ActivateImmediate()
void Deactivate()
float m_FuseDelay
override void InitiateExplosion()
void ExplodeGrenade(EGrenadeType grenade_type)
DEPRECATED - for backward compatibility only.
override void OnActivatedByTripWire()
DEPRECATED use OnActivatedByItem.
void OnActivateStarted()
void OnDeactivate()
override void OnWasAttached(EntityAI parent, int slot_id)
void Grenade_Base()
InventoryLocation.
Definition enmath.c:7
Serialization general interface. Serializer API works with:
Definition serializer.c:56
DamageType
exposed from C++ (do not change)
void OnExplode()
void AddExplosionEffectForSurface(string surface, int effectID)
ref array< string > m_AmmoTypes
proto native CGame GetGame()
void FlashGrenadeLight()
EGrenadeType
Definition grenade_base.c:2
@ CHEMICAL
Definition grenade_base.c:4
@ FRAGMENTATION
Definition grenade_base.c:3
@ NON_LETHAL
Definition grenade_base.c:6
@ ILLUMINATING
Definition grenade_base.c:5
enum EGrenadeType m_DefaultBrightness
For backward compatibility.
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
InventoryLocationType
types of Inventory Location
override void SetTakeable(bool pState)
Definition itembase.c:9184
override void Explode(int damageType, string ammoType="")