22 protected float m_fEmissiveIntensity;
25 protected ref array<ref SCR_LenseColor> m_LenseArray;
27 [
Attribute(
"0.5", UIWidgets.EditBox,
desc:
"In meters, light ignores objects up to set distance to avoid unwanted shadows",
params:
"0.1 5",
category:
"Light near plane")]
28 protected float m_fLightNearPlaneHand;
30 [
Attribute(
"1.2", UIWidgets.EditBox,
desc:
"In meters, light ignores objects up to set distance to avoid unwanted shadows",
params:
"0.1 5",
category:
"Light near plane")]
31 protected float m_fLightNearPlaneStrapped;
33 [
Attribute(
"0.1", UIWidgets.EditBox,
desc:
"In meters, light ignores objects up to set distance to avoid unwanted shadows",
params:
"0.1 5",
category:
"Light near plane")]
34 protected float m_fLightNearPlaneVehicle;
36 [
Attribute(
"0 0 -0.03", UIWidgets.EditBox,
desc:
"When strapped light entity is being aligned with weapon to adjust light angle, this entity is offset to avoid it visibly floating",
category:
"Flashlight")]
37 protected vector m_vFlashlightAdjustOffset;
39 protected bool m_bLastLightState;
40 protected bool m_bIsSlottedVehicle;
41 protected int m_iCurrentLenseColor;
42 protected vector m_vAnglesCurrent;
43 protected vector m_vAnglesTarget;
44 protected vector m_ItemMat[4];
45 protected LightEntity m_Light;
48 protected CharacterControllerComponent m_CharController;
51 override void OnToggleActive(
bool state)
57 if (soundManagerEntity)
70 protected void UpdateLightState()
81 protected void SwitchLenses(
int filter)
83 m_iCurrentLenseColor = filter;
85 m_Light.SetColor(Color.FromVector(m_LenseArray[m_iCurrentLenseColor].m_vLenseColor), m_LenseArray[m_iCurrentLenseColor].m_fLightValue);
90 protected void EnableLight()
93 m_Light.SetEnabled(
true);
95 if (m_EmissiveMaterial)
96 m_EmissiveMaterial.SetEmissiveMultiplier(m_fEmissiveIntensity);
100 if (m_iMode == EGadgetMode.IN_SLOT)
101 SetShadowNearPlane(
true);
102 else if (m_iMode == EGadgetMode.IN_HAND)
103 SetShadowNearPlane(
false);
108 protected void DisableLight()
111 m_Light.SetEnabled(
false);
113 if (m_EmissiveMaterial)
114 m_EmissiveMaterial.SetEmissiveMultiplier(0);
116 DeactivateGadgetUpdate();
123 protected void SetShadowNearPlane(
bool state,
bool isLeavingVehicle =
false)
126 m_bIsSlottedVehicle =
false;
130 nearPlane = m_fLightNearPlaneStrapped;
131 if (m_CompartmentComp && m_CompartmentComp.IsInCompartment() && !isLeavingVehicle)
133 nearPlane = m_fLightNearPlaneVehicle;
134 m_bIsSlottedVehicle =
true;
135 DeactivateGadgetUpdate();
137 else if (m_bActivated)
139 ActivateGadgetUpdate();
144 nearPlane = m_fLightNearPlaneHand;
148 m_Light.SetNearPlane(nearPlane);
152 protected void AdjustTransform(vector offset = vector.Zero)
160 if (slot && animAttr)
163 animAttr.GetAdditiveTransformLS(matLS);
164 matLS[3] = matLS[3] + m_vEquipmentSlotOffset + offset;
165 slot.SetAdditiveTransformLS(matLS);
172 protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
177 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
178 IEntity occupant = compSlot.GetOccupant();
181 SetShadowNearPlane(
true);
190 protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
195 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
196 IEntity occupant = compSlot.GetOccupant();
198 SetShadowNearPlane(
true,
true);
202 override protected void ModeSwitch(EGadgetMode mode, IEntity charOwner)
204 super.ModeSwitch(mode, charOwner);
207 if (!inventoryItemComp)
210 if (mode == EGadgetMode.ON_GROUND || !charOwner)
215 if (mode == EGadgetMode.ON_GROUND || mode == EGadgetMode.IN_STORAGE)
217 inventoryItemComp.SetTraceable(
true);
219 m_bLastLightState = m_bActivated;
224 if (mode == EGadgetMode.ON_GROUND)
225 m_bLastLightState =
false;
228 else if (mode == EGadgetMode.IN_SLOT)
230 inventoryItemComp.SetTraceable(
false);
233 if (m_CompartmentComp)
235 m_CompartmentComp.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
236 m_CompartmentComp.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
239 SetShadowNearPlane(
true);
241 else if (mode == EGadgetMode.IN_HAND)
243 inventoryItemComp.SetTraceable(
true);
245 SetShadowNearPlane(
false);
247 if (m_bLastLightState)
253 override protected void ModeClear(EGadgetMode mode)
255 if (mode == EGadgetMode.IN_SLOT)
257 if (m_CompartmentComp)
259 m_CompartmentComp.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
260 m_CompartmentComp.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
263 SetShadowNearPlane(
false);
266 super.ModeClear(mode);
270 override protected void ToggleActive(
bool state)
272 if (m_iMode == EGadgetMode.IN_STORAGE && !m_bActivated)
276 if (!m_bActivated && m_CompartmentComp &&
PilotCompartmentSlot.Cast(m_CompartmentComp.GetCompartment()))
279 super.ToggleActive(state);
283 override void ActivateAction()
288 ToggleActive(!m_bActivated);
292 override protected void ActivateGadgetUpdate()
294 super.ActivateGadgetUpdate();
296 AdjustTransform(m_vFlashlightAdjustOffset);
300 override protected void DeactivateGadgetUpdate()
302 super.DeactivateGadgetUpdate();
304 if (m_iMode == EGadgetMode.IN_SLOT)
309 override EGadgetType GetType()
311 return EGadgetType.FLASHLIGHT;
315 override bool CanBeToggled()
321 override bool IsVisibleEquipped()
327 override bool RplSave(ScriptBitWriter writer)
329 if (!super.RplSave(writer))
332 writer.WriteBool(m_bActivated);
338 override bool RplLoad(ScriptBitReader reader)
340 if (!super.RplLoad(reader))
343 reader.ReadBool(m_bActivated);
351 override bool OnTicksOnRemoteProxy()
357 override void EOnActivate(IEntity owner)
359 super.EOnActivate(owner);
366 override void Update(
float timeSlice)
370 DeactivateGadgetUpdate();
379 m_vAnglesCurrent =
GetOwner().GetLocalYawPitchRoll();
380 m_vAnglesTarget = ( Math.RAD2DEG *
m_CharController.GetInputContext().GetAimingAngles() - Math3D.MatrixToAngles(m_ItemMat) ) + m_vAnglesCurrent;
382 m_vAnglesTarget[1] = Math.Clamp(m_vAnglesTarget[1], 0, 30);
383 m_vAnglesTarget[2] = 0;
385 m_vAnglesTarget[0] = Math.Lerp(m_vAnglesCurrent[0], m_vAnglesTarget[0], timeSlice*4);
386 m_vAnglesTarget[1] = Math.Lerp(m_vAnglesCurrent[1], m_vAnglesTarget[1], timeSlice*4);
387 GetOwner().SetYawPitchRoll(m_vAnglesTarget);
391 override void EOnInit(IEntity owner)
393 m_Light = LightEntity.Cast( owner.GetChildren() );
397 if (m_LenseArray.Count() == 0)
400 defColor.m_sDescription =
"CONFIGURE ME";
401 m_LenseArray.Insert(defColor);