DayZ 1.24
Loading...
Searching...
No Matches
InventoryItem.c
Go to the documentation of this file.
1class InventoryItem extends EntityAI
2{
3 static private const float SOUND_CONTACT_SKIP = 0.33;//second
4
5#ifdef DIAG_DEVELOPER
7#endif
8
11 private bool m_IsMeleeWeapon = false;
12
14
19
23
25
27
29 // This method performs an OR operation with the config 'forceFarBubble'. If set in the config
30 // this method has no effect.
32
34 {
35 InitImpactSoundData();
36
37 if (ConfigIsExisting("isMeleeWeapon"))
38 m_IsMeleeWeapon = ConfigGetBool("isMeleeWeapon");
39 }
40
41
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
67 {
68 return 0;
69 }
70
72 {
73 return 1;
74 }
75
77 {
78 return 2;
79 }
80
81 override bool IsMeleeWeapon()
82 {
83 return m_IsMeleeWeapon;
84 }
85
87 {
88 return false;
89 }
90
91 // -------------------------------------------------------------------------------
93 {
94 if (!m_SoundImpactTable)
95 return;
96
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);
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 // -------------------------------------------------------------------------------
139 {
140 AnimSoundEvent soundEvent = GetInventoryItemType().GetSoundEvent(id);
141 if (soundEvent)
142 {
143 SoundObjectBuilder builder = soundEvent.GetSoundBuilder();
144 SoundObject soundObject = builder.BuildSoundObject();
145 if (soundObject)
147 }
148 }
149
150
151 // -------------------------------------------------------------------------------
153 {
154 string surface;
155 int liquid = -1;
156 return GetImpactSurfaceTypeEx(other, impact, liquid);
157 }
158
159 // -------------------------------------------------------------------------------
161 {
163 GetWorldBounds(mins, maxs);
164 vector size = maxs - mins;
165
166 vector add = impact.RelativeVelocityBefore.Normalized() * size.Length();
167 string surfaceImpact;
169 Object.Cast(other),
170 impact.Position + add,
171 impact.Position - add,
173 liquid))
174 return surfaceImpact;
175 string surface;
176 GetGame().SurfaceUnderObjectEx(this, surface, surfaceImpact, liquid);
177
178 return surfaceImpact;
179 }
180
183 {
184 return "MeleeSoft";
185 }
186
187 // -------------------------------------------------------------------------------
189 {
190 int liquidType = -1;
191 return ProcessImpactSoundEx(other, extra, weight, surfaceHash, liquidType);
192 }
193
194
195 // -------------------------------------------------------------------------------
197 {
198 float impactVelocity = extra.RelativeVelocityBefore.Length();
199 if (impactVelocity < 0.3)
200 return 0.0;
201
202 float tickTime = GetGame().GetTickTime();
203 if (m_SoundContactTickTime + SOUND_CONTACT_SKIP > tickTime)
204 return 0.0;
205
206 string surfaceName = GetImpactSurfaceTypeEx(other, extra, liquidType);
207 if (surfaceName == "")
208 return 0.0;
209
210#ifdef DIAG_DEVELOPER
211 string infoText = "Surface: " + surfaceName + ", Weight: " + weight + ", Speed: " + impactVelocity;
212
213 if (s_ImpactSoundsInfo.Count() == 10)
214 s_ImpactSoundsInfo.Remove(9);
215
216 s_ImpactSoundsInfo.InsertAt(infoText, 0);
217#endif
218
219 m_SoundContactTickTime = tickTime;
220
221 surfaceHash = surfaceName.Hash();
222 return impactVelocity;
223 }
224
225#ifdef DIAG_DEVELOPER
226 static void DrawImpacts()
227 {
228 DbgUI.Begin("Item impact sounds", 10, 200);
229
230 for (int i = 0; i < s_ImpactSoundsInfo.Count(); ++i)
231 {
232 string line = (i + 1).ToString() + ". " + s_ImpactSoundsInfo.Get(i);
233 DbgUI.Text(line);
234 }
235
236 DbgUI.End();
237 }
238#endif
239};
class AnimSoundObjectBuilderBank AnimSoundLookupTableBank()
EAnimSoundEventID
proto string ToString()
void PlaySound()
WaveKind
Definition Sound.c:2
class SoundObjectBuilder SoundObject(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
static proto bool GetHitSurfaceAndLiquid(Object other, vector begPos, vector endPos, string surface, out int liquidType)
Definition DbgUI.c:60
string GetImpactSurfaceTypeEx(IEntity other, Contact impact, out int liquid)
proto native bool IsOn()
Some inventoryItem devices can be switched on/off (radios, transmitters)
string GetRuinedMeleeAmmoType()
returns ammo (projectile) used in melee if the item is destroyed. Override higher for specific use
void InitImpactSoundData()
int GetMeleeHeavyMode()
SoundLookupTable m_SoundImpactTable
void InventoryItem()
proto native void ThrowPhysically(DayZPlayer player, vector force, bool collideWithCharacters=true)
float ProcessImpactSound(IEntity other, Contact extra, float weight, out int surfaceHash)
void OnRightClick()
string GetTooltip()
Get tooltip text.
override bool IsMeleeWeapon()
proto native bool HasCollisionsWithCharacter()
AbstractWave PlaySound(SoundObject so, SoundObjectBuilder sob)
proto native void SwitchOn(bool onOff)
Some inventoryItem devices can be switched on/off (radios, transmitters)
void PlaySoundByAnimEvent(EAnimSoundEventID id)
proto native void EnableCollisionsWithCharacter(bool state)
collisions with character
proto native MeleeCombatData GetMeleeCombatData()
bool IsMeleeFinisher()
event bool OnUseFromInventory(Man owner)
int GetMeleeSprintMode()
proto native InventoryItemType GetInventoryItemType()
int GetMeleeMode()
void PlayImpactSound(float weight, float velocity, int surfaceHash)
override bool IsInventoryItem()
proto native void ForceFarBubble(bool state)
Sets the item to use the server configured 'networkRangeFar' instead of 'networkRangeNear'.
float ProcessImpactSoundEx(IEntity other, Contact extra, float weight, out int surfaceHash, out int liquidType)
float m_SoundContactTickTime
string GetImpactSurfaceType(IEntity other, Contact impact)
SoundObjectBuilder GetSoundBuilder(int parameterHash)
proto native CGame GetGame()
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)