Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
trap_tripwire.c
Go to the documentation of this file.
1 // Wire type is used in the case of decrafting to give back the correct base Ingredient
3 {
4  WIRE = 0,
6  ROPE = 2
7 }
8 
10 {
11  // Current state of the tripwire
12  static const int FOLDED = 3;
13  static const int DEPLOYED = 2;
14  static const int TRIGGERED = 1;
15 
16  int m_State = FOLDED;
17  private int m_WireMaterial;
18 
19  protected bool m_ResultOfAdvancedPlacing;
22 
23  void TripwireTrap()
24  {
25  m_DamagePlayers = 0; //How much damage player gets when caught
26  m_InitWaitTime = 0.0; //After this time after deployment, the trap is activated
27  m_DefectRate = 15;
28  m_NeedActivation = false;
29  m_AnimationPhaseGrounded = "inventory";
30  m_AnimationPhaseSet = "placing";
31  m_AnimationPhaseTriggered = "triggered";
32  m_InfoActivationTime = string.Format("#STR_TripwireTrap0%1#STR_TripwireTrap1", m_InitWaitTime.ToString()); // nefunguje dynamicke vyrazy mimo funkcii
33 
34  RegisterNetSyncVariableInt("m_State");
35  }
36 
37  override void OnVariablesSynchronized()
38  {
39  super.OnVariablesSynchronized();
40 
41  if ( IsPlaceSound() )
42  {
44  }
45  }
46 
47  override void OnStoreSave(ParamsWriteContext ctx)
48  {
49  super.OnStoreSave(ctx);
50 
51  ctx.Write( m_State );
52  }
53 
54  //----------------------------------------------------------------
55  override bool OnStoreLoad(ParamsReadContext ctx, int version)
56  {
57  if ( !super.OnStoreLoad(ctx, version) )
58  return false;
59 
60  int state = FOLDED;
61  if ( !ctx.Read( state ) )
62  state = FOLDED;
63 
64  SetState( state );
65  RefreshState();
66 
67  return true;
68  }
69 
70  override void CreateTrigger()
71  {
72  m_TrapTrigger = TripWireTrigger.Cast(GetGame().CreateObjectEx("TripWireTrigger", GetPosition(), SPAWN_FLAGS));
73  vector mins = "-0.75 0.3 -0.01";
74  vector maxs = "0.75 0.32 0.01";
75  m_TrapTrigger.SetOrientation(GetOrientation());
76  m_TrapTrigger.SetExtents(mins, maxs);
77  m_TrapTrigger.SetParentObject(this);
78 
80  }
81 
82  override void OnSteppedOn(EntityAI victim)
83  {
84  if (!victim)
85  {
86  return;
87  }
88 
89  if (!victim.GetAllowDamage())
90  {
91  return;
92  }
93 
94  // We must deal some damage, here 5 shock as melee damage in order to trigger hit animation
95  if (GetGame().IsServer())
96  {
97  victim.ProcessDirectDamage(DT_CLOSE_COMBAT, this, "", "TripWireHit", "0 0 0", 1);
98  SetState(TRIGGERED);
99  SetInactive(false);
100  }
101 
102  // We play the trap trigger sound
103  #ifndef SERVER
104  EffectSound sound = SEffectManager.PlaySound("TripwireTrap_Trigger_SoundSet", GetPosition());
105  sound.SetAutodestroy(true);
106  #endif
107  }
108 
109  override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
110  {
111  super.OnItemLocationChanged(old_owner, new_owner);
112 
113  PlayerBase player = PlayerBase.Cast(new_owner);
114  if (player)
115  {
116  StartDeactivate(player);
117  return;
118  }
119  }
120 
121  override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
122  {
123  super.EEItemLocationChanged(oldLoc, newLoc);
124 
126  {
127  if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.GROUND)
128  {
129  SetActive();
130  m_TrapTrigger.SetPosition(m_TriggerPosition);
131  m_TrapTrigger.SetOrientation(m_TriggerOrientation);
132  }
133 
135  }
136 
137  if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.CARGO)
138  {
139  SetInactive();
140  DeleteTrigger();
141  SetState(FOLDED);
142  RefreshState();
143  }
144  }
145 
146  override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
147  {
148  super.EEHealthLevelChanged(oldLevel, newLevel, zone);
149 
150  if (GetGame().IsServer())
151  {
152  if (newLevel == GameConstants.STATE_RUINED)
153  {
154  SetState(TRIGGERED);
155  RefreshState();
156  }
157  }
158  }
159 
160  override void SetInactive(bool stop_timer = true)
161  {
162  super.SetInactive(stop_timer);
163 
164  // de-attach attachments after "activating them"
165  for (int att = 0; att < GetInventory().AttachmentCount(); att++)
166  {
167  ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
168  if (attachment)
169  {
170  if (attachment.IsLockedInSlot())
171  {
172  attachment.UnlockFromParent();
173  }
174 
175  attachment.OnActivatedByItem(this);
176  GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
177  }
178  }
179  }
180 
181  void SetState(int state_ID)
182  {
183  m_State = state_ID;
184  }
185 
186  int GetState()
187  {
188  return m_State;
189  }
190 
191  void SetWireType( int wireType )
192  {
193  m_WireMaterial = wireType;
194  }
195 
197  {
198  return m_WireMaterial;
199  }
200 
201 
202  override void RefreshState()
203  {
204  super.RefreshState();
205 
206  if (GetState() == FOLDED)
207  {
208  FoldTripWire();
209  }
210  }
211 
212  override void SetupTrapPlayer( PlayerBase player, bool set_position = true )
213  {
214  super.SetupTrapPlayer( player, set_position );
215  SetState(DEPLOYED);
216  }
217 
218  override void StartDeactivate(PlayerBase player)
219  {
220  super.StartDeactivate(player);
221 
222  DeleteTrigger();
223  SetState(FOLDED);
224  }
225 
226  // We do not want players to attach charges before trap is deployed
227  override bool CanReceiveAttachment( EntityAI attachment, int slotId )
228  {
229  if ( GetState() != DEPLOYED )
230  return false;
231 
232  return super.CanReceiveAttachment( attachment, slotId );
233  }
234 
235  // As players cannot attch charges, we do not display the attachment slot before it is necessary
236  override bool CanDisplayAttachmentSlot( int slot_id )
237  {
238  if ( GetState() != DEPLOYED )
239  return false;
240 
241  return super.CanDisplayAttachmentSlot( slot_id );
242  }
243 
244  override void EEItemAttached(EntityAI item, string slot_name)
245  {
246  super.EEItemAttached(item, slot_name);
247 
248  SetTakeable(false);
249  }
250 
251  override void EEItemDetached(EntityAI item, string slot_name)
252  {
253  super.EEItemDetached(item, slot_name);
254 
255  SetTakeable(false);
256  }
257 
258  override void EEKilled(Object killer)
259  {
260  if (m_TrapTrigger)
261  {
262  StartDeactivate(null);
263  }
264 
265  super.EEKilled(killer);
266  }
267 
268  // We reset the animation phases to see the tripwire as folded
270  {
271  if ( m_AnimationPhaseGrounded != "" )
272  {
273  SetAnimationPhase( m_AnimationPhaseSet, 1 );
274 
276  {
277  SetAnimationPhase( m_AnimationPhaseTriggered, 1 );
278  }
279 
280  SetAnimationPhase( m_AnimationPhaseGrounded, 0 );
281  }
282  }
283 
284  override void OnInventoryEnter( Man player )
285  {
286  SetState( FOLDED );
287  }
288 
289  #ifdef PLATFORM_WINDOWS
290  // How one sees the tripwire when in vicinity
291  override int GetViewIndex()
292  {
293  if ( MemoryPointExists( "invView2" ) )
294  {
296  GetInventory().GetCurrentInventoryLocation( il );
297  InventoryLocationType type = il.GetType();
298  switch ( type )
299  {
300  case InventoryLocationType.CARGO:
301  {
302  return 0;
303  }
304  case InventoryLocationType.ATTACHMENT:
305  {
306  return 1;
307  }
308  case InventoryLocationType.HANDS:
309  {
310  return 0;
311  }
312  case InventoryLocationType.GROUND:
313  {
314  // Different view index depending on deployment state
315  if ( GetState() == DEPLOYED )
316  return 1;
317  else if ( GetState() == TRIGGERED )
318  return 2;
319 
320  // When folded
321  return 0;
322  }
323  case InventoryLocationType.PROXYCARGO:
324  {
325  return 0;
326  }
327  default:
328  {
329  if ( GetState() == DEPLOYED )
330  return 1;
331  else if ( GetState() == TRIGGERED )
332  return 2;
333 
334  // When folded
335  return 0;
336  }
337  }
338  }
339  return 0;
340  }
341  #endif
342 
343  //================================================================
344  // ADVANCED PLACEMENT
345  //================================================================
346 
347  // On placement complete, set state, play sound, create trigger and synch to client
348  override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
349  {
350  SetIsPlaceSound(true);
351  if (GetGame().IsServer())
352  {
353  SetState(DEPLOYED);
354 
355  m_TriggerPosition = position;
356  m_TriggerOrientation = orientation;
358  }
359  }
360 
361  override void OnPlacementCancelled(Man player)
362  {
363  super.OnPlacementCancelled(player);
364 
365  SetState(FOLDED);
366 
368  }
369 
370  override bool IsDeployable()
371  {
372  return true;
373  }
374 
375  // Tripwire cannot be taken if deployed with attachment
376  override bool IsTakeable()
377  {
378  return GetState() != DEPLOYED || (GetInventory().AttachmentCount() == 0 && GetState() == DEPLOYED);
379  }
380 
381  override string GetDeploySoundset()
382  {
383  return "tripwire_deploy_SoundSet";
384  }
385 
386  override string GetLoopDeploySoundset()
387  {
388  return "tripwiretrap_deploy_SoundSet";
389  }
390 
391  override void SetActions()
392  {
393  super.SetActions();
394 
397  }
398 
399  // ====================================
400  // =========== DEPRECATED ===========
401  // ====================================
402 
404  {
405  if ( GetInventory().AttachmentCount() > 0)
406  {
407  ItemBase attachment = ItemBase.Cast( GetInventory().GetAttachmentFromIndex(0) );
408 
409  if ( attachment )
410  {
411  // Hide all proxies
412  for (int i = 1; i <= 3; i++)
413  {
414  HideSelection("s" + i + "_charge");
415  }
416 
417  // Now show the one we need to see
418  string proxy_to_show = string.Format("s%1_charge", GetState() );
419  //Print(proxy_to_show);
420  ShowSelection( proxy_to_show );
421  }
422  }
423  }
424 
425 #ifdef DEVELOPER
426  //================================================================
427  // DEBUG
428  //================================================================
429 
430  //Debug menu Spawn Ground Special
431  override void OnDebugSpawn()
432  {
433  SetState(DEPLOYED);
434  StartActivate(null);
435  }
436 
437  override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
438  {
439  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
440  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
441  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
442 
443  super.GetDebugActions(outputList);
444  }
445 
446  override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
447  {
448  if (super.OnAction(action_id, player, ctx))
449  return true;
450  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
451  {
452  if (action_id == EActions.ACTIVATE_ENTITY)
453  {
454  StartActivate(null);
455  }
456  else if (action_id == EActions.DEACTIVATE_ENTITY)
457  {
458  SetInactive();
459  }
460  }
461  return false;
462  }
463 
464 #endif
465 }
466 
468 {
469 
470 }
ItemBase
Definition: inventoryitem.c:730
OnSteppedOn
override void OnSteppedOn(EntityAI victim)
Definition: trap_tripwire.c:82
GetGame
proto native CGame GetGame()
EEHealthLevelChanged
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition: trap_tripwire.c:146
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
m_State
int m_State
Definition: trap_tripwire.c:16
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
DeleteTrigger
void DeleteTrigger()
Definition: trapbase.c:511
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: trap_tripwire.c:37
m_TriggerOrientation
protected vector m_TriggerOrientation
Definition: trap_tripwire.c:21
SetActive
void SetActive()
Definition: trapbase.c:437
BARBED_WIRE
@ BARBED_WIRE
Definition: trap_tripwire.c:5
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_TrapTrigger
protected TrapTrigger m_TrapTrigger
Definition: trapbase.c:44
SetWireType
void SetWireType(int wireType)
Definition: trap_tripwire.c:191
IsPlaceSound
bool IsPlaceSound()
Definition: itembase.c:4288
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: trap_tripwire.c:386
DeferredEnableTrigger
void DeferredEnableTrigger()
Definition: trapbase.c:520
UpdateProxySelections
void UpdateProxySelections()
Definition: trap_tripwire.c:403
m_AnimationPhaseSet
string m_AnimationPhaseSet
Definition: trapbase.c:33
m_DamagePlayers
float m_DamagePlayers
Definition: trapbase.c:20
OnInventoryEnter
override void OnInventoryEnter(Man player)
Definition: trap_tripwire.c:284
SPAWN_FLAGS
enum SoundTypeTrap SPAWN_FLAGS
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
SetupTrapPlayer
override void SetupTrapPlayer(PlayerBase player, bool set_position=true)
Definition: trap_tripwire.c:212
OnDebugSpawn
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
Definition: hatchback_02.c:404
GetDeploySoundset
override string GetDeploySoundset()
Definition: trap_tripwire.c:381
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
OnItemLocationChanged
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition: trap_tripwire.c:109
m_ResultOfAdvancedPlacing
protected bool m_ResultOfAdvancedPlacing
Definition: trap_tripwire.c:19
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
CreateTrigger
override void CreateTrigger()
Definition: trap_tripwire.c:70
SetInactive
override void SetInactive(bool stop_timer=true)
Definition: trap_tripwire.c:160
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: trap_tripwire.c:348
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
FoldTripWire
void FoldTripWire()
Definition: trap_tripwire.c:269
PlayPlaceSound
void PlayPlaceSound()
Definition: itembase.c:4348
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
EEItemLocationChanged
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition: trap_tripwire.c:121
GetDebugActions
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition: edible_base.c:744
OnStoreLoad
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: trap_tripwire.c:55
SetIsPlaceSound
void SetIsPlaceSound(bool is_place_sound)
Definition: itembase.c:4283
GetWireType
int GetWireType()
Definition: trap_tripwire.c:196
m_AnimationPhaseGrounded
string m_AnimationPhaseGrounded
Definition: trapbase.c:32
EActions
EActions
Definition: eactions.c:1
OnAction
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition: edible_base.c:755
m_TriggerPosition
protected vector m_TriggerPosition
Definition: trap_tripwire.c:20
TripwireTrapDeployed
Definition: trap_tripwire.c:467
StartActivate
override void StartActivate(PlayerBase player)
Definition: trap_landmine.c:44
SetState
void SetState(int state_ID)
Definition: trap_tripwire.c:181
SetActions
override void SetActions()
Definition: trap_tripwire.c:391
RefreshState
override void RefreshState()
Definition: trap_tripwire.c:202
EEKilled
override void EEKilled(Object killer)
Definition: trap_tripwire.c:258
GameConstants
Definition: constants.c:612
m_InfoActivationTime
string m_InfoActivationTime
Definition: trapbase.c:40
TripwireTrap
void TripwireTrap()
Definition: trap_tripwire.c:23
eWireMaterial
eWireMaterial
Definition: trap_tripwire.c:2
IsTakeable
override bool IsTakeable()
Definition: trap_tripwire.c:376
ROPE
@ ROPE
Definition: trap_tripwire.c:6
FOLDED
enum eWireMaterial FOLDED
SAT_DEBUG_ACTION
const int SAT_DEBUG_ACTION
Definition: constants.c:424
m_NeedActivation
bool m_NeedActivation
Definition: trapbase.c:18
GetState
int GetState()
returns one of STATE_...
Definition: trap_tripwire.c:186
CanReceiveAttachment
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition: trap_tripwire.c:227
m_DefectRate
float m_DefectRate
Definition: trapbase.c:19
m_AnimationPhaseTriggered
string m_AnimationPhaseTriggered
Definition: trapbase.c:34
EEItemDetached
override void EEItemDetached(EntityAI item, string slot_name)
Definition: trap_tripwire.c:251
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
EEItemAttached
override void EEItemAttached(EntityAI item, string slot_name)
Definition: trap_tripwire.c:244
m_InitWaitTime
float m_InitWaitTime
Definition: trapbase.c:17
StartDeactivate
override void StartDeactivate(PlayerBase player)
Definition: trap_tripwire.c:218
WIRE
@ WIRE
Definition: trap_tripwire.c:4
EntityAI
Definition: building.c:5
OnPlacementCancelled
override void OnPlacementCancelled(Man player)
Definition: trap_tripwire.c:361
IsDeployable
override bool IsDeployable()
Definition: trap_tripwire.c:370
TrapBase
Definition: trap_bear.c:1
CanDisplayAttachmentSlot
override bool CanDisplayAttachmentSlot(int slot_id)
Definition: trap_tripwire.c:236
m_WireMaterial
private int m_WireMaterial
Definition: trap_tripwire.c:17
OnStoreSave
override void OnStoreSave(ParamsWriteContext ctx)
Definition: trap_tripwire.c:47
GetOrientation
vector GetOrientation()
Definition: areadamagemanager.c:306