Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
kitchentimer.c
Go to the documentation of this file.
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
24  m_NoisePar = new NoiseParams;
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();
97  SEffectManager.DestroyEffect(m_WorkingSound);
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  {
109  MakeRingingStop();
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);
128  }
129  }
130  }
131 
132  override protected void Disarm()
133  {
134  super.Disarm();
135  SetAlarmTimeServerSecs(0);
136  }
137 
138  override protected void OnRingingStopClient()
139  {
140  if (m_RingingSoundLoop)
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  {
174  SetAlarmTimeServerSecs(time);
175  }
176  else if (state == EAlarmClockState.RINGING)
177  {
179  }
180 
181  return true;
182  }
183 
184  override void OnStoreSave(ParamsWriteContext ctx)
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.LIGHT_GREY));
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  {
236  SetAlarmTimeServerSecs(20);
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 };
GetGame
proto native CGame GetGame()
KitchenTimer
Definition: kitchentimer.c:1
ClockBase
void ClockBase()
Definition: clockbase.c:27
MakeRingingStop
protected void MakeRingingStop()
Definition: clockbase.c:232
MakeRingingStart
protected void MakeRingingStart()
Definition: clockbase.c:223
m_WorkingSound
EffectSound m_WorkingSound
Definition: clockbase.c:23
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
SetState
void SetState(bool state)
Definition: staminahandler.c:30
NoiseParams
class ObjectSpawnerHandler NoiseParams
IsRinging
bool IsRinging()
Definition: clockbase.c:291
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
m_NoisePar
ref NoiseParams m_NoisePar
Definition: actionopendoors.c:2
ActionSetKitchenTimer
Definition: actionsetkitchentimer.c:13
EActions
EActions
Definition: eactions.c:1
m_NoiseSystem
protected NoiseSystem m_NoiseSystem
Definition: carscript.c:231
NoiseSystem
Definition: noise.c:1
m_RingingSoundLoop
EffectSound m_RingingSoundLoop
Definition: clockbase.c:19
EAlarmClockState
EAlarmClockState
Definition: clockbase.c:1
SAT_DEBUG_ACTION
const int SAT_DEBUG_ACTION
Definition: constants.c:424
m_RingingDuration
float m_RingingDuration
Definition: clockbase.c:16
Math
Definition: enmath.c:6
ActionResetKitchenTimer
ActionTakeABiteCB ActionResetKitchenTimer
TurnOn
void TurnOn()
Definition: clockbase.c:301
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
m_State
protected float m_DrainThreshold protected bool m_State
Definition: staminahandler.c:20