Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_HeadgearInventoryItemComponent.c
Go to the documentation of this file.
2{
3 [Attribute(defvalue: "0.44", desc: "Kinetic Impulse Multiplier\nKinetic damage * Kinetic Impulse Multiplier = force", params: "0 inf 0.01")]
5
6 [Attribute(defvalue: "2.48", desc: "Explosive Impulse Multiplier\nExplosive damage * Explosive Impulse Multiplier = force", params: "0 inf 0.01")]
8
9 [Attribute(defvalue: "0.017", desc: "Melee Impulse Multiplier\nMelee damage * Melee Impulse Multiplier = force", params: "0 inf 0.01")]
11
12 [Attribute(defvalue: "1", desc: "Amount of force that is required to have a chance on detaching the headgear.\nValue below 0 means that this item cannot be detached", params: "-1 inf 0.01")]
13 protected float m_fForceThreshold;
14
15 [Attribute(defvalue: "37", desc: "Chance (%) to detach the headgear when threashold is crossed,\n 0 means that there is no chance on that happening", params: "0 100")]
16 protected int m_fChanceToDetach;
17
18 //------------------------------------------------------------------------------------------------
22 {
23 switch (type)
24 {
25 case EDamageType.KINETIC:
27
28 case EDamageType.EXPLOSIVE:
30
31 case EDamageType.MELEE:
33 }
34
35 return 0;
36 }
37
38 //------------------------------------------------------------------------------------------------
41 {
42 return m_fForceThreshold;
43 }
44
45 //------------------------------------------------------------------------------------------------
48 {
49 return m_fChanceToDetach;
50 }
51}
52
53class SCR_HeadgearInventoryItemComponent : InventoryItemComponent
54{
56 protected bool m_bLock;
57
59 protected static const float FORCE_IMPULSE_LIMIT = 10;
60
61 //------------------------------------------------------------------------------------------------
62 override protected void OnPostInit(IEntity owner)
63 {
64 NwkMovementComponent networkedMovementComp = NwkMovementComponent.Cast(owner.FindComponent(NwkMovementComponent));
65 if (networkedMovementComp)
66 networkedMovementComp.EnableSimulation(false);
67 }
68
69 //------------------------------------------------------------------------------------------------
77 void DetachHelmet(float damageValue, EDamageType damageType, vector impactDirection, vector impactPosition, notnull ChimeraCharacter character)
78 {
79 if (m_bLock)
80 return;
81
82 IEntity hat = GetOwner();
83 if (!hat)
84 return;
85
87 if (!data)
88 return;
89
90 CompartmentAccessComponent compartmentAccessComp = character.GetCompartmentAccessComponent();
91 if (!compartmentAccessComp)
92 return;
93
94 BaseCompartmentSlot compartment = compartmentAccessComp.GetCompartment();
95 if (compartment)
96 return;//dont do that in the vehicle
97
98 float threshold = data.GetForceThreshold();
99 if (threshold < 0)
100 return;
101
102 int probability = data.GetChanceToDetach();
103 if (probability <= 0)
104 return;
105
106 Physics hatPhysics = hat.GetPhysics();
107 if (!hatPhysics || !hatPhysics.IsDynamic())
108 return;
109
110 float force = damageValue * data.GetDamageTypeImpulseMultiplier(damageType);
111 if (force < threshold)
112 return;
113
114 int probablilityTest = Math.RandomIntInclusive(0, 100);
115 if (probablilityTest == 0 || probablilityTest > probability)
116 return;
117
118 m_bLock = true;
119 CharacterControllerComponent controller = character.GetCharacterController();
120 if (!controller)
121 return;
122
123 SCR_InventoryStorageManagerComponent storageMgr = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
124 if (!storageMgr)
125 return;
126
127 SCR_CharacterInventoryStorageComponent characterStorage = storageMgr.GetCharacterStorage();
128 if (!characterStorage)
129 return;
130
131 force = Math.Min(force, FORCE_IMPULSE_LIMIT);
132
133 hat.ClearFlags(EntityFlags.TRACEABLE);
135 callback.m_vPosition = character.EyePosition();
136 callback.m_vForceOffset = callback.m_vPosition - impactPosition;
137 callback.m_vForceImpulse = impactDirection * force + vector.Up * 3; // up*3 to add a bit of upward force to make it seem like its jumping of the head
138 callback.m_ItemComponent = this;
139 storageMgr.TryRemoveItemFromStorage(hat, characterStorage, callback);
140 }
141
142 //------------------------------------------------------------------------------------------------
148 void ApplyForce(vector positionFrom, vector offset, vector force)
149 {
150 m_bLock = false;
151 IEntity hat = GetOwner();
152 NwkMovementComponent networkedMovementComp = NwkMovementComponent.Cast(hat.FindComponent(NwkMovementComponent));
153 if (!networkedMovementComp)
154 return;
155
156 Physics phys = hat.GetPhysics();
157 if (!phys)
158 return;
159
160 // start networked synchronization of the moving helmet
161 networkedMovementComp.EnableSimulation(true);
162 hat.SetOrigin(positionFrom);
163 hat.Update();
164
165 phys.ChangeSimulationState(SimulationState.SIMULATION);
166 phys.ApplyImpulse(force);
167 phys.ApplyImpulseAt(offset, force * 0.0002); // tiny amount of offset force to add a bit of rotation
169 if (system)
170 system.RegisterEntity(hat, this);
171 }
172
173 //------------------------------------------------------------------------------------------------
175 void OnPhysicsStateChanged(bool isActive)
176 {
177 if (isActive)
178 return;
179
180 IEntity owner = GetOwner();
181 if (!owner)
182 return;
183
184 Physics phys = owner.GetPhysics();
185 if (!phys)
186 return;
187
189 if (system)
190 system.UnregisterEntity(owner);
191
192 phys.ChangeSimulationState(SimulationState.NONE);
193 NwkMovementComponent networkedMovementComp = NwkMovementComponent.Cast(owner.FindComponent(NwkMovementComponent));
194 if (networkedMovementComp)
195 networkedMovementComp.EnableSimulation(false);
196
197 owner.SetFlags(EntityFlags.TRACEABLE);
198 // force snap to ground to ensure that everyone will see this item in the same place
199 PlaceOnGround();
200 }
201}
SCR_CharacterSoundComponentClass GetComponentData()
EDamageType type
Get all prefabs that have the spawner data
SCR_HeadgearInventoryItemComponentClass m_bLock
Lock that is used to ensure that detaching procedure will not start twice.
void DetachHelmet(float damageValue, EDamageType damageType, vector impactDirection, vector impactPosition, notnull ChimeraCharacter character)
void ApplyForce(vector positionFrom, vector offset, vector force)
void OnPhysicsStateChanged(bool isActive)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external void SetOrigin(vector orig)
proto external Physics GetPhysics()
proto external int Update()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Definition Math.c:13
static SCR_PhysicsObserverSystem GetInstance()
void UnregisterEntity(notnull IEntity ent)
void RegisterEntity(notnull IEntity ent, InventoryItemComponent iic=null)
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EDamageType
Definition EDamageType.c:13
SimulationState