Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FireplaceComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted", color: "0 0 255 255")]
3{
4 [Attribute("{C0E2E7DC28B71E2C}Particles/Enviroment/Campfire_medium_normal.ptc", UIWidgets.ResourceNamePicker, "Prefab of fire particle used for a fire action.", "ptc")]
6
7 [Attribute("0 0.2 0", UIWidgets.EditBox, "Particle offset in local space from the origin of the entity")]
9
10 //------------------------------------------------------------------------------------------------
13 {
14 return m_sParticle;
15 }
16
17 //------------------------------------------------------------------------------------------------
23}
24
25class SCR_FireplaceComponent : SCR_BaseInteractiveLightComponent
26{
30 protected float m_fTimer;
31 protected float m_fCompDataLV;
32
33 protected static const float FLICKER_STEP = 0.05;
34 protected static const float FLICKER_THRESHOLD = 0.35;
35 protected static const float FLICKER_FREQUENCY = 1 / 30;
36
37 //------------------------------------------------------------------------------------------------
38 override void ToggleLight(bool turnOn, bool skipTransition = false, bool playSound = true)
39 {
40 if (m_bIsOn == turnOn)
41 return;
42
43 super.ToggleLight(turnOn, skipTransition, playSound);
44
45 // don't continue if DS server is running in console (particles, decals)
46 if (System.IsConsoleApp())
47 return;
48
49 if (turnOn)
50 {
51 TurnOn();
52 }
53 else
54 {
55 TurnOff();
56 }
57 }
58
59 //------------------------------------------------------------------------------------------------
61 void TurnOn()
62 {
64 if (!m_pFireParticle && componentData)
65 {
67 spawnParams.TargetWorld = GetOwner().GetWorld();
68 spawnParams.Parent = GetOwner();
69 Math3D.MatrixIdentity4(spawnParams.Transform);
70 spawnParams.Transform[3] = componentData.GetParticleOffset();
71
72 m_pFireParticle = ParticleEffectEntity.SpawnParticleEffect(componentData.GetParticle(), spawnParams);
73 }
74 else if (m_pFireParticle)
75 {
76 m_pFireParticle.Play();
77 }
78
79 // Show decals
80 if (m_DecalEntity)
81 m_DecalEntity.SetFlags(EntityFlags.VISIBLE, false);
82
83 if (componentData)
84 m_fCompDataLV = componentData.GetLightLV();
85
86 SetEventMask(GetOwner(), EntityEvent.VISIBLE);
87 }
88
89 //------------------------------------------------------------------------------------------------
91 void TurnOff()
92 {
93 // Hide decals
94 if (m_DecalEntity)
95 m_DecalEntity.ClearFlags(EntityFlags.VISIBLE, false);
96
97 //Reset fire particles
99 {
100 m_pFireParticle.Stop();
101 }
102
103 ClearEventMask(GetOwner(), EntityEvent.VISIBLE);
104 }
105
106 //------------------------------------------------------------------------------------------------
107 override void OnPostInit(IEntity owner)
108 {
109 BaseSlotComponent decalComponent = BaseSlotComponent.Cast(GetOwner().FindComponent(BaseSlotComponent));
110 if (decalComponent)
111 m_DecalEntity = decalComponent.GetAttachedEntity();
112
114 if (m_ComponentData)
115 m_fCurLV = m_ComponentData.GetLightLV();
116
117 if (m_DecalEntity)
118 m_DecalEntity.ClearFlags(EntityFlags.VISIBLE, false);
119
120 super.OnPostInit(owner);
121 }
122
123 //------------------------------------------------------------------------------------------------
124 override void EOnVisible(IEntity owner, int frameNumber)
125 {
126 super.EOnVisible(owner, frameNumber);
127
128 if (GetOwner().GetWorld().IsEditMode() || !IsOn() || m_aLights.IsEmpty())
129 return;
130
131 float timeSlice = GetOwner().GetWorld().GetTimeSlice();
132
133 m_fTimer += timeSlice;
134
135 if (m_fTimer < FLICKER_FREQUENCY)
136 return;
137
138 m_fTimer = 0;
139 bool canFlickerBrighter = m_fCurLV < m_fCompDataLV * (1 + FLICKER_THRESHOLD);
140 bool canFlickerDimmer = m_fCurLV > m_fCompDataLV * (1 - FLICKER_THRESHOLD);
141
142 if (canFlickerBrighter && canFlickerDimmer)
143 {
144 if (Math.RandomIntInclusive(0, 1) == 0)
145 m_fCurLV += FLICKER_STEP;
146 else
147 m_fCurLV -= FLICKER_STEP;
148 }
149 else if (canFlickerBrighter)
150 m_fCurLV += FLICKER_STEP;
151 else
152 m_fCurLV -= FLICKER_STEP;
153
154 array<ref SCR_BaseLightData> lightData = m_ComponentData.GetLightData();
155 for (int i = Math.Min(m_aLights.Count(), lightData.Count()) -1; i >= 0; i--)
156 {
157 auto ld = lightData[i]; // make sure that data is loaded
158 if (ld)
159 m_aLights[i].SetColor(Color.FromVector(ld.GetLightColor()), m_fCurLV);
160 }
161 }
162
163 //------------------------------------------------------------------------------------------------
164 override bool RplLoad(ScriptBitReader reader)
165 {
166 // Can't relay on RplLoad method of base class as with the fireplace we have to execute ToggleLight method in both on / off state.
167 bool isOn = false;
168 reader.ReadBool(isOn);
169 ToggleLight(isOn, true);
170
171 return true;
172 }
173
174 override void OnDelete(IEntity owner)
175 {
176 super.OnDelete(owner);
177
178 RemoveLights();
179
180 if (m_pFireParticle)
181 RplComponent.DeleteRplEntity(m_pFireParticle, false);
182 }
183}
override bool RplLoad(ScriptBitReader reader)
SCR_BaseInteractiveLightComponentClass m_aLights
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void TurnOn()
float m_fCompDataLV
override void ToggleLight(bool turnOn, bool skipTransition=false, bool playSound=true)
IEntity m_DecalEntity
SCR_FireplaceComponentClass m_pFireParticle
override void EOnVisible(IEntity owner, int frameNumber)
SCR_FuelConsumptionComponentClass m_ComponentData
void ParticleEffectEntity(IEntitySource src, IEntity parent)
Definition Color.c:13
proto external BaseWorld GetWorld()
Definition Math.c:13
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
void TurnOff()
Remove every particle associed with this effect.