Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
grenade_base.c
Go to the documentation of this file.
2 {
7 }
8 
10 class 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 
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 
42  protected EGrenadeType m_GrenadeType;
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  {
67  OnActivateFinished();
68  return;
69  }
70 
71  Unpin();
72  }
73 
74  bool IsPinned()
75  {
76  return m_Pinned;
77  }
78 
79  bool IsPinnable()
80  {
82  if (m_FuseTimer.IsRunning())
83  {
84  return false;
85  }
86 
87  return m_Pinnable;
88  }
89 
90  void ActivateImmediate()
91  {
92  OnActivateImmediate();
93  }
94 
95  void ActivateRandomTime()
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 
112  void SetGrenadeType(EGrenadeType type)
113  {
114  m_GrenadeType = type;
115  }
116 
117  EGrenadeType GetGrenadeType()
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  {
173  InitiateExplosion();
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 
197  OnActivateStarted();
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 
221  override void OnStoreSave(ParamsWriteContext ctx)
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 
294  void Grenade_Base()
295  {
296  m_Pinned = true;
297  m_FuseTimer = new Timer;
298  m_RemainingFuseTime = -1;
299 
300  SetPinnable(true);
301  SetFuseDelay(DEFAULT_FUSE_DELAY);
302  SetGrenadeType(EGrenadeType.FRAGMENTATION);
303 
304  RegisterNetSyncVariableBool("m_Pinned");
305  }
306 }
ItemBase
Definition: inventoryitem.c:730
m_AmmoTypes
protected ref array< string > m_AmmoTypes
Definition: explosivesbase.c:26
GetGame
proto native CGame GetGame()
FRAGMENTATION
@ FRAGMENTATION
Definition: grenade_base.c:3
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
ILLUMINATING
@ ILLUMINATING
Definition: grenade_base.c:5
Grenade_Base
Definition: flashgrenade.c:1
PointLightBase
Definition: staticobj_roadblock_wood_small.c:27
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
FlashGrenadeLight
void FlashGrenadeLight()
Definition: grenade_base.c:17
Explode
override void Explode(int damageType, string ammoType="")
Definition: trap_landmine.c:220
EGrenadeType
EGrenadeType
Definition: grenade_base.c:1
m_DefaultRadius
protected float m_DefaultRadius
Definition: contaminatedarea_dynamic.c:14
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
ExplosivesBase
void ExplosivesBase()
Definition: explosivesbase.c:40
CHEMICAL
@ CHEMICAL
Definition: grenade_base.c:4
ExplosiveLight
Definition: explosivesbase.c:1
NON_LETHAL
@ NON_LETHAL
Definition: grenade_base.c:6
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
OnExplode
protected void OnExplode()
Definition: explosivesbase.c:171
m_DefaultBrightness
enum EGrenadeType m_DefaultBrightness
For backward compatibility.
Timer
Definition: dayzplayerimplement.c:62
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5