Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
kitchentimer.c
Go to the documentation of this file.
1class KitchenTimer : ClockBase
2{
3 const string RINGING_SOUND = "KitchenTimer_Ring_Loop_SoundSet";
4 const string DESTROYED_SOUND = "AlarmClock_Destroyed_SoundSet";
5 const string HIT_SOUND = "AlarmClock_Hit_SoundSet";
6 const string WORKING_SOUND = "KitchenTimer_Ticking_Loop_SoundSet";
7
8 EffectSound m_RingingStopSound;
9 static ref NoiseParams m_NoisePar;
10 static NoiseSystem m_NoiseSystem;
11
12 int m_AlarmInSecs;
13
14 override void Init()
15 {
16 super.Init();
17
18 if (GetGame().IsServer())
19 {
20 m_NoiseSystem = GetGame().GetNoiseSystem();
21 if ( m_NoiseSystem && !m_NoisePar)
22 {
23 // Create and load noise parameters
25 m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseKitchenTimer");
26 }
27 }
28 }
29
30 override void SetActions()
31 {
32 super.SetActions();
33
36 }
37
38 override string GetExplosiveTriggerSlotName()
39 {
40 return "TriggerKitchenTimer";
41 }
42
43 override string GetToggleSound()
44 {
45 return "";
46 }
47
48 override string GetRingingSound()
49 {
50 return RINGING_SOUND;
51 }
52
53 string GetRingingStopSound()
54 {
55 return "KitchenTimer_Ring_End_SoundSet";
56 }
57
58 override string GetDestroyedSound()
59 {
60 return DESTROYED_SOUND;
61 }
62
63 override string GetHitSound()
64 {
65 return HIT_SOUND;
66 }
67
68 override string GetWorkingSound()
69 {
70 return WORKING_SOUND;
71 }
72
73 int GetMinutesMax()
74 {
75 return 45;
76 }
77
78 int Time01ToSeconds(float time01)
79 {
80 return Math.Lerp(0,GetMinutesMax() * 60, time01);
81 }
82
83
84 float SecondsTo01(int seconds)
85 {
86 return Math.InverseLerp(0,GetMinutesMax() * 60, seconds);
87 }
88
89 override float GetRingingDurationMax()
90 {
91 return 60;
92 }
93
94 override void TurnOff()
95 {
96 super.TurnOff();
98 }
99
100 void OnUpdate()
101 {
102 if (m_AlarmInSecs > 0)
103 {
104 m_AlarmInSecs -= UPDATE_TICK_RATE;
105 float time01 = SecondsTo01(m_AlarmInSecs);
106 SetAnimationPhaseNow("ClockAlarm", time01);
107 if (IsRinging())
108 {
110 }
111 }
112 else if (!IsRinging())
113 {
115 }
116
117 if (IsRinging())
118 {
119 m_RingingDuration += UPDATE_TICK_RATE;
120
121 if (m_RingingDuration >= GetRingingDurationMax())
122 {
123 TurnOff();
124 }
125 else if (m_NoiseSystem)
126 {
127 m_NoiseSystem.AddNoiseTarget(GetPosition(), UPDATE_TICK_RATE, m_NoisePar, NoiseAIEvaluate.GetNoiseReduction(GetGame().GetWeather()));
128 }
129 }
130 }
131
132 override protected void Disarm()
133 {
134 super.Disarm();
136 }
137
138 override protected void OnRingingStopClient()
139 {
141 PlaySoundSet(m_RingingStopSound, GetRingingStopSound(), 0, 0);
142
143 super.OnRingingStopClient();
144
145 }
146
147 override bool OnStoreLoad(ParamsReadContext ctx, int version)
148 {
149 if (!super.OnStoreLoad(ctx, version))
150 return false;
151
152 if (version < 128)
153 {
154 return true;
155 }
156
157 EAlarmClockState state;
158
159 if (!ctx.Read(state))
160 {
161 return false;
162 }
163
164 int time;
165 if (!ctx.Read(time))
166 {
167 return false;
168 }
169
170 SetState(state);
171
172 if (state == EAlarmClockState.SET)
173 {
175 }
176 else if (state == EAlarmClockState.RINGING)
177 {
179 }
180
181 return true;
182 }
183
185 {
186 super.OnStoreSave(ctx);
187
188 ctx.Write(m_State);
189 ctx.Write(m_AlarmInSecs);
190 }
191
192
193
194 //---------------------------------------------------------------------------------------------------------
195 //---------------------------------------------- Public methods -------------------------------------------
196 //---------------------------------------------------------------------------------------------------------
197
198 override void SetAlarmTimeServer(float time01)
199 {
200 SetAnimationPhaseNow("ClockAlarm", time01);
201 m_AlarmInSecs = Time01ToSeconds(time01);
202
203 if (m_AlarmInSecs > 0)
204 {
205 TurnOn();
206 }
207 }
208
209 void SetAlarmTimeServerSecs(int inSecs)
210 {
211 SetAlarmTimeServer(SecondsTo01(inSecs));
212 }
213
214
215 //----------------------------------
216 //------------- DEBUG --------------
217 //----------------------------------
218
219 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
220 {
221 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ALARM_SET_AHEAD, "Set Alarm Ahead", FadeColors.LIGHT_GREY));
222 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
223
224 super.GetDebugActions(outputList);
225 }
226
227 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
228 {
229 if (super.OnAction(action_id, player, ctx))
230 return true;
231
232 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
233 {
234 if (action_id == EActions.ALARM_SET_AHEAD)
235 {
237 }
238 }
239 return false;
240 }
241
242 override string GetDebugText()
243 {
244 string debug_output;
245
246 if (GetGame().IsDedicatedServer())
247 {
248 debug_output = "alarm in: " + m_AlarmInSecs.ToString() + " secs" + "\n";
249 debug_output += "current state: " + typename.EnumToString(EAlarmClockState, m_State) + "\n";
250 debug_output += "ringing for " + m_RingingDuration.ToString()+ " secs" + "\n";
251 debug_output += "ringing max " + GetRingingDurationMax().ToString()+ " secs" + "\n";
252 }
253 else
254 {
255 debug_output = "this is client";
256 }
257
258 return debug_output;
259 }
260
261};
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition entityai.c:97
eBleedingSourceType GetType()
ref NoiseParams m_NoisePar
ActionResetKitchenTimerClockCB ActionSingleUseBaseCB ActionResetKitchenTimer()
void AddAction(typename actionName)
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
override void SetAlarmTimeServer(float time01)
override string GetDebugText()
void SetAlarmTimeServerSecs(int inSecs)
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
override void OnStoreSave(ParamsWriteContext ctx)
void OnRingingStopClient()
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition enmath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
Definition serializer.c:56
bool IsRinging()
Definition clockbase.c:291
EffectSound m_WorkingSound
Definition clockbase.c:23
float m_RingingDuration
Definition clockbase.c:16
void TurnOn()
Definition clockbase.c:301
EAlarmClockState
Definition clockbase.c:2
void MakeRingingStart()
Definition clockbase.c:223
void MakeRingingStop()
Definition clockbase.c:232
EffectSound m_RingingSoundLoop
Definition clockbase.c:19
EActions
Definition eactions.c:2
proto native CGame GetGame()
const int SAT_DEBUG_ACTION
Definition constants.c:454
class JsonUndergroundAreaTriggerData GetPosition
class NoiseSystem NoiseParams()
Definition noise.c:15
enum EObjectTemperatureState m_State
void SetState(bool state)