Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
inventoryitem.c
Go to the documentation of this file.
1 class InventoryItem extends EntityAI
2 {
3  static private const float SOUND_CONTACT_SKIP = 0.33;//second
4 
5 #ifdef DIAG_DEVELOPER
6  static private ref array<ref string> s_ImpactSoundsInfo = new array<ref string>();
7 #endif
8 
9  private SoundLookupTable m_SoundImpactTable;
10  private float m_SoundContactTickTime;
11  private bool m_IsMeleeWeapon = false;
12 
13  proto native InventoryItemType GetInventoryItemType();
14 
16  proto native void SwitchOn(bool onOff);
18  proto native bool IsOn();
19 
21  proto native void EnableCollisionsWithCharacter(bool state);
22  proto native bool HasCollisionsWithCharacter();
23 
24  proto native MeleeCombatData GetMeleeCombatData();
25 
26  proto native void ThrowPhysically(DayZPlayer player, vector force, bool collideWithCharacters = true);
27 
29  // This method performs an OR operation with the config 'forceFarBubble'. If set in the config
30  // this method has no effect.
31  proto native void ForceFarBubble(bool state);
32 
33  void InventoryItem()
34  {
35  InitImpactSoundData();
36 
37  if (ConfigIsExisting("isMeleeWeapon"))
38  m_IsMeleeWeapon = ConfigGetBool("isMeleeWeapon");
39  }
40 
41 
42  void OnRightClick()
43  {
44 
45  }
46 
47  event bool OnUseFromInventory(Man owner)
48  {
49  return false;
50  }
51 
53  string GetTooltip()
54  {
55  string temp;
56  if (!DescriptionOverride(temp))
57  temp = ConfigGetString("descriptionShort");
58  return temp;
59  }
60 
61  override bool IsInventoryItem()
62  {
63  return true;
64  }
65 
66  int GetMeleeMode()
67  {
68  return 0;
69  }
70 
71  int GetMeleeHeavyMode()
72  {
73  return 1;
74  }
75 
76  int GetMeleeSprintMode()
77  {
78  return 2;
79  }
80 
81  override bool IsMeleeWeapon()
82  {
83  return m_IsMeleeWeapon;
84  }
85 
86  bool IsMeleeFinisher()
87  {
88  return false;
89  }
90 
91  // -------------------------------------------------------------------------------
92  void PlayImpactSound(float weight, float velocity, int surfaceHash)
93  {
94  if (!m_SoundImpactTable)
95  return;
96 
97  SoundObjectBuilder soundBuilder = m_SoundImpactTable.GetSoundBuilder(surfaceHash);
98  if (soundBuilder != null)
99  {
100  soundBuilder.AddVariable("weight", weight);
101  soundBuilder.AddVariable("speed", velocity);
102  soundBuilder.AddEnvSoundVariables(GetPosition());
103 
104  SoundObject soundObject = soundBuilder.BuildSoundObject();
105  if (soundObject != null)
106  {
107  soundObject.SetKind(WaveKind.WAVEEFFECTEX);
108  PlaySound(soundObject, soundBuilder);
109  }
110  }
111  }
112 
113  // -------------------------------------------------------------------------------
114  protected void InitImpactSoundData()
115  {
116  #ifndef SERVER
117  string soundImpactType = "default";
118  if ( ConfigIsExisting("soundImpactType") )
119  soundImpactType = ConfigGetString("soundImpactType");
120 
121  m_SoundImpactTable = AnimSoundLookupTableBank.GetInstance().GetImpactTable(soundImpactType + "_Impact_LookupTable");
122  #endif
123  }
124 
125  // -------------------------------------------------------------------------------
127  {
128  if (so == null)
129  return null;
130 
131  so.SetPosition(GetPosition());
132  AbstractWave wave = GetGame().GetSoundScene().Play3D(so, sob);
133 
134  return wave;
135  }
136 
137  // -------------------------------------------------------------------------------
138  void PlaySoundByAnimEvent(EAnimSoundEventID id)
139  {
140  AnimSoundEvent soundEvent = GetInventoryItemType().GetSoundEvent(id);
141  if (soundEvent)
142  {
143  SoundObjectBuilder builder = soundEvent.GetSoundBuilder();
144  SoundObject soundObject = builder.BuildSoundObject();
145  if (soundObject)
146  PlaySound(soundObject, builder);
147  }
148  }
149 
150 
151  // -------------------------------------------------------------------------------
152  string GetImpactSurfaceType(IEntity other, Contact impact)
153  {
154  string surface;
155  int liquid = -1;
156  return GetImpactSurfaceTypeEx(other, impact, liquid);
157  }
158 
159  // -------------------------------------------------------------------------------
160  string GetImpactSurfaceTypeEx(IEntity other, Contact impact, out int liquid)
161  {
162  vector mins, maxs;
163  GetWorldBounds(mins, maxs);
164  vector size = maxs - mins;
165 
166  vector add = impact.RelativeVelocityBefore.Normalized() * size.Length();
167  string surfaceImpact;
168  if (DayZPhysics.GetHitSurfaceAndLiquid(
169  Object.Cast(other),
170  impact.Position + add,
171  impact.Position - add,
172  surfaceImpact,
173  liquid))
174  {
175  return surfaceImpact;
176  }
177  string surface;
178  GetGame().SurfaceUnderObjectEx(this, surface, surfaceImpact, liquid);
179 
180  return surfaceImpact;
181  }
182 
184  string GetRuinedMeleeAmmoType()
185  {
186  return "MeleeSoft";
187  }
188 
189  // -------------------------------------------------------------------------------
190  float ProcessImpactSound(IEntity other, Contact extra, float weight, out int surfaceHash)
191  {
192  int liquidType = -1;
193  return ProcessImpactSoundEx(other, extra, weight, surfaceHash,liquidType);
194  }
195 
196 
197  // -------------------------------------------------------------------------------
198  float ProcessImpactSoundEx(IEntity other, Contact extra, float weight, out int surfaceHash, out int liquidType)
199  {
200  float impactVelocity = extra.RelativeVelocityBefore.Length();
201  if ( impactVelocity < 0.3 )
202  return 0.0;
203 
204  float tickTime = GetGame().GetTickTime();
205  if ( m_SoundContactTickTime + SOUND_CONTACT_SKIP > tickTime )
206  return 0.0;
207 
208  string surfaceName = GetImpactSurfaceTypeEx(other, extra, liquidType);
209  if ( surfaceName == "" )
210  return 0.0;
211 
212 #ifdef DIAG_DEVELOPER
213  string infoText = "Surface: " + surfaceName + ", Weight: " + weight + ", Speed: " + impactVelocity;
214 
215  if ( s_ImpactSoundsInfo.Count() == 10 )
216  s_ImpactSoundsInfo.Remove(9);
217 
218  s_ImpactSoundsInfo.InsertAt(infoText, 0);
219 #endif
220 
221  m_SoundContactTickTime = tickTime;
222 
223  surfaceHash = surfaceName.Hash();
224  return impactVelocity;
225  }
226 
227 #ifdef DIAG_DEVELOPER
228  static void DrawImpacts()
229  {
230  DbgUI.Begin("Item impact sounds", 10, 200);
231 
232  for ( int i = 0; i < s_ImpactSoundsInfo.Count(); ++i )
233  {
234  string line = (i + 1).ToString() + ". " + s_ImpactSoundsInfo.Get(i);
235  DbgUI.Text(line);
236  }
237 
238  DbgUI.End();
239  }
240 #endif
241 };
GetGame
proto native CGame GetGame()
DbgUI
Definition: dbgui.c:59
EAnimSoundEventID
EAnimSoundEventID
Definition: eanimsoundeventid.c:1
SoundObject
class SoundObjectBuilder SoundObject(SoundParams soundParams)
GetMeleeCombatData
proto native MeleeCombatData GetMeleeCombatData()
processes melee hit
InventoryItem
Definition: itembase.c:13
ToString
proto string ToString()
DayZPlayer
Definition: dayzplayerimplement.c:72
IEntity
Definition: enentity.c:164
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
vector
Definition: enconvert.c:105
MeleeCombatData
Definition: gameplay.c:159
Object
Definition: objecttyped.c:1
WaveKind
WaveKind
Definition: sound.c:1
Contact
Definition: enphysics.c:300
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
AnimSoundLookupTableBank
class AnimSoundObjectBuilderBank AnimSoundLookupTableBank()
Definition: dayzanimeventmaps.c:179
DayZPhysics
Definition: dayzphysics.c:123
SoundObjectBuilder
Definition: sound.c:45
PlaySound
void PlaySound()
Definition: hungersoundhandler.c:38
SoundLookupTable
Definition: dayzanimeventmaps.c:2
InventoryItemType
Definition: inventoryitemtype.c:1
AbstractWave
Definition: sound.c:118
EntityAI
Definition: building.c:5