Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
hescobox.c
Go to the documentation of this file.
1 class HescoBox extends Inventory_Base
2 {
3  static const int FOLDED = 0;
4  static const int UNFOLDED = 1;
5  static const int FILLED = 2;
6  static const int PERCENTUAL_DAMAGE = 1;
7 
8  ref Timer m_Timer;
9  ref protected EffectSound m_DeployLoopSound;
10 
11  protected int m_State;
12 
13  void HescoBox()
14  {
15  m_State = FOLDED;
16 
17  //synchronized variables
18  RegisterNetSyncVariableInt( "m_State", FOLDED, FILLED );
19  RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
20  RegisterNetSyncVariableBool("m_IsDeploySound");
21  }
22 
23  void ~HescoBox()
24  {
25  SEffectManager.DestroyEffect( m_DeployLoopSound );
26  }
27 
28  override bool HasProxyParts()
29  {
30  return true;
31  }
32 
33  override bool CanPutIntoHands( EntityAI parent )
34  {
35  if( !super.CanPutIntoHands( parent ) )
36  {
37  return false;
38  }
39  return CanBeManipulated();
40  }
41 
42  void Synchronize()
43  {
44  SetSynchDirty();
45  }
46 
47  override void OnVariablesSynchronized()
48  {
49  super.OnVariablesSynchronized();
50 
51  //refresh visuals
52  RefreshVisuals();
53 
54  if ( IsDeploySound() )
55  {
57  }
58 
59  if ( CanPlayDeployLoopSound() )
60  {
62  }
63 
65  {
67  }
68  }
69 
70  void RefreshVisuals()
71  {
72  }
73 
74  int GetState()
75  {
76  return m_State;
77  }
78 
79  void SetState( int state )
80  {
81  m_State = state;
82  }
83 
84  bool CanBeFilledAtPosition( vector position )
85  {
86  string surface_type;
87  GetGame().SurfaceGetType( position[0], position[2], surface_type );
88 
89  return GetGame().IsSurfaceDigable(surface_type);
90  }
91 
92  bool CanBeManipulated()
93  {
94  if ( GetState() == FOLDED )
95  {
96  return true;
97  }
98  else
99  {
100  return false;
101  }
102  }
103 
104  void Fold()
105  {
106  this.ShowSelection( "inventory" );
107  this.HideSelection( "placing" );
108  this.HideSelection( "filled" );
109 
110  SetState( FOLDED );
111  RefreshPhysics();
112 
113  if ( GetGame().IsServer() )
114  {
115  SetAllowDamage(true);
116  Synchronize();
117  float fold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
118  DecreaseHealth( "", "", fold_damage );
119  }
120  }
121 
122  void Unfold()
123  {
124  this.HideSelection( "inventory" );
125  this.ShowSelection( "placing" );
126  this.HideSelection( "filled" );
127 
128  SetState( UNFOLDED );
129  RefreshPhysics();
130 
131  if ( GetGame().IsServer() )
132  {
133  SetAllowDamage(true);
134  Synchronize();
135  float unfold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
136  DecreaseHealth( "", "", unfold_damage );
137  }
138  }
139 
140  override void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
141  {
142  super.EEItemLocationChanged (oldLoc, newLoc);
143 
144  //RefreshPhysics();
145  }
146 
147  override void RefreshPhysics()
148  {
149  super.RefreshPhysics();
150 
151  if ( this && !ToDelete() )
152  {
153  RemoveProxyPhysics( "inventory" );
154  RemoveProxyPhysics( "placing" );
155  RemoveProxyPhysics( "filled" );
156 
157  int state = GetState();
158 
159  switch (state)
160  {
161  case UNFOLDED:
162  //ShowSelection( "placing" );
163  AddProxyPhysics( "placing" );
164 
165  return;
166 
167  case FOLDED:
168  AddProxyPhysics( "inventory" );
169  return;
170 
171  case FILLED:
172  AddProxyPhysics( "filled" );
173  return;
174  }
175  }
176  }
177 
178  void Fill()
179  {
180  this.HideSelection( "inventory" );
181  this.HideSelection( "placing" );
182  this.ShowSelection( "filled" );
183 
184  SetState( FILLED );
185  RefreshPhysics();
186 
187  if ( GetGame().IsServer() )
188  {
189  Synchronize();
190  DecreaseHealth( "", "", 5 ); //TODO Daniel implement soft skill bonus via useraction
191  SetAllowDamage(false);
192  }
193  }
194 
195  override void OnStoreSave(ParamsWriteContext ctx)
196  {
197  super.OnStoreSave(ctx);
198 
199  // Save state
200  ctx.Write( m_State );
201  }
202 
203  override bool OnStoreLoad(ParamsReadContext ctx, int version)
204  {
205  if ( !super.OnStoreLoad(ctx, version) )
206  return false;
207 
208  // Load folded/unfolded state
209  int state = FOLDED;
210  if ( !ctx.Read(state) )
211  state = FOLDED;
212 
213  switch (state)
214  {
215  case FOLDED:
216  {
217  Fold();
218  break;
219  }
220  case UNFOLDED:
221  {
222  Unfold();
223  break;
224  }
225  case FILLED:
226  {
227  Fill();
228  break;
229  }
230  }
231  return true;
232  }
233 
234  //================================================================
235  // ADVANCED PLACEMENT
236  //================================================================
237 
238  override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
239  {
240  super.OnPlacementComplete( player, position, orientation );
241 
242  if ( GetGame().IsServer() )
243  {
244  Unfold();
245 
246  SetIsDeploySound( true );
247  }
248  }
249 
250  override bool IsDeployable()
251  {
252  return true;
253  }
254 
255  override string GetDeploySoundset()
256  {
257  return "placeHescoBox_SoundSet";
258  }
259 
260  override string GetLoopDeploySoundset()
261  {
262  return "hescobox_deploy_SoundSet";
263  }
264 
265  void PlayDeployLoopSound()
266  {
267  if ( !GetGame().IsDedicatedServer() )
268  {
269  if ( !m_DeployLoopSound || !m_DeployLoopSound.IsSoundPlaying() )
270  {
272  }
273  }
274  }
275 
276  void StopDeployLoopSound()
277  {
278  if ( !GetGame().IsDedicatedServer() )
279  {
280  m_DeployLoopSound.SetSoundFadeOut(0.5);
281  m_DeployLoopSound.SoundStop();
282  }
283  }
284 
285  override void SetActions()
286  {
287  super.SetActions();
288 
292  }
293 }
GetGame
proto native CGame GetGame()
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
GetState
proto native int GetState()
returns one of STATE_...
Definition: staminahandler.c:29
EEItemLocationChanged
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition: remotedetonator.c:72
Synchronize
void Synchronize(eInjuryHandlerLevels level)
Definition: injuryhandler.c:173
m_Timer
ref Timer m_Timer
Definition: dayzgame.c:690
SetIsDeploySound
void SetIsDeploySound(bool is_deploy_sound)
Definition: itembase.c:4293
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
PlayDeploySound
void PlayDeploySound()
Definition: itembase.c:4324
PlayDeployLoopSound
void PlayDeployLoopSound()
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: explosivesbase.c:133
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: largetent.c:151
ActionFoldObject
Definition: actionfoldobject.c:1
RefreshPhysics
void RefreshPhysics()
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
IsDeploySound
bool IsDeploySound()
Definition: itembase.c:4298
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
CanPutIntoHands
override bool CanPutIntoHands(EntityAI parent)
Definition: explosivesbase.c:257
vector
Definition: enconvert.c:105
SetState
void SetState(bool state)
Definition: staminahandler.c:30
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
IsDeployable
override bool IsDeployable()
Definition: basebuildingbase.c:339
m_DeployLoopSound
protected ref EffectSound m_DeployLoopSound
Definition: trapbase.c:47
OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: modifierbase.c:229
StopDeployLoopSound
void StopDeployLoopSound()
CanPlayDeployLoopSound
bool CanPlayDeployLoopSound()
Definition: itembase.c:4360
Timer
Definition: dayzplayerimplement.c:62
FOLDED
enum eWireMaterial FOLDED
Inventory_Base
Definition: barbedbaseballbat.c:1
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
OnStoreLoad
bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: modifiersmanager.c:270
GetDeploySoundset
override string GetDeploySoundset()
Definition: largetent.c:146
EntityAI
Definition: building.c:5
m_State
protected float m_DrainThreshold protected bool m_State
Definition: staminahandler.c:20