Dayz  1.11.153731
Dayz Code Explorer by Zeroy
Defibrillator.c
Go to the documentation of this file.
1 class Defibrillator extends ItemBase
2 {
3  static const string CHARGING_SOUND = "defibrillator_charge_SoundSet";
4  static const string CHARGED_AND_READY_SOUND = "defibrillator_ready_SoundSet";
5  static const string SHOCK_SOUND = "defibrillator_shock_SoundSet";
6 
7  bool m_IsCharged = false;
8 
9  static float m_ChargeTime = 5;
10  static float m_EnergyNeededToCharge = 20;
11 
12  ref Timer m_ChargingTimer;
15 
17  {
18  // Read all config parameters
19  //m_ChargeTime = GetTimeNeededToCharge();
20  m_EnergyNeededToCharge = GetEnergyNeededToCharge();
21  }
22 
24  {
25  string cfg_path = "CfgVehicles " + GetType() + " ";
26  return GetGame().ConfigGetFloat (cfg_path + "defibChargeTime");
27  }
28 
30  {
31  string cfg_path = "CfgVehicles " + GetType() + " ";
32  return GetGame().ConfigGetFloat (cfg_path + "defibEnergyNeededPerCharge");
33  }
34 
35  override void OnWorkStart()
36  {
37  if (!GetGame().IsMultiplayer() || GetGame().IsClient())
38  //PlaySound(CHARGING_SOUND, 20);
39  m_ChargingSound = SEffectManager.PlaySoundOnObject(CHARGING_SOUND, this, 0, 0.15);
40 
41  float energy_needed = m_EnergyNeededToCharge / m_ChargeTime;
42  GetCompEM().SetEnergyUsage(energy_needed);
43 
44  if (!m_ChargingTimer)
45  m_ChargingTimer = new Timer( CALL_CATEGORY_GAMEPLAY );
46 
47  if ( !m_ChargingTimer.IsRunning() )
48  {
49  m_ChargingTimer.Run(m_ChargeTime, this, "OnIsCharged", NULL, false);
50  }
51  }
52 
53  override void OnWorkStop()
54  {
55  GetCompEM().SwitchOff();
60 
61  m_IsCharged = false;
62  }
63 
64  void OnIsCharged()
65  {
66  if ( GetCompEM().IsWorking() )
67  {
68  if (!GetGame().IsMultiplayer() || GetGame().IsClient())
69  {
70  //m_ChargedAlarm = PlaySoundLoop(CHARGED_AND_READY_SOUND, 40);
71  m_ChargedAlarm = SEffectManager.PlaySoundOnObject(CHARGED_AND_READY_SOUND, this);
72  m_ChargingSound.SoundStop();
73  }
75  m_IsCharged = true;
76  }
77  }
78 
80  {
81  if (m_ChargedAlarm)
82  {
83  //GetGame().ObjectDelete(m_ChargedAlarm);
84  m_ChargedAlarm.SoundStop();
85  m_ChargedAlarm = NULL;
86  }
87  }
88 
90  {
91  if(m_ChargingSound)
92  {
93  m_ChargingSound.SoundStop();
94  }
95  }
96 
98  {
99  if (m_ChargingTimer)
100  {
101  m_ChargingTimer.Stop();
102  m_ChargingTimer = NULL;
103  }
104  }
105 
106  bool IsCharged()
107  {
108  return m_IsCharged;
109  }
110 
112  {
113  /*
114  bool has_heart_attack = victim.m_ModifiersManager.IsModifierActive(eModifiers.MDF_HEART_ATTACK);
115 
116  if ( has_heart_attack )
117  {
118  victim.m_ModifiersManager.DeactivateModifier ( eModifiers.MDF_HEART_ATTACK );
119  }
120  else
121  {
122  victim.m_ModifiersManager.ActivateModifier ( eModifiers.MDF_HEART_ATTACK );
123  }
124  */
125  /*
126  if (!GetGame().IsMultiplayer() || GetGame().IsClient())
127  {
128  SEffectManager.PlaySoundOnObject(SHOCK_SOUND, this);
129  }*/
130 
131  victim.SetPulseType(!victim.GetPulseType());
132  victim.SetHealth("","Shock",0);
133 
134  GetCompEM().SwitchOff();
135  }
136 
138  {
139  SEffectManager.PlaySoundOnObject(SHOCK_SOUND, this);
140  }
141 
142  override void SetActions()
143  {
144  super.SetActions();
145 
150  }
151 }
ItemBase
Definition: InventoryItem.c:445
GetGame
proto native CGame GetGame()
ItemBase::StopChargingSound
void StopChargingSound()
Definition: Defibrillator.c:89
ItemBase::IsCharged
bool IsCharged()
Definition: Defibrillator.c:106
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
ComponentEnergyManager::ResetEnergyUsage
void ResetEnergyUsage()
Energy manager: Resets energy usage to default (config) value.
Definition: ComponentEnergyManager.c:603
ComponentEnergyManager::SetEnergyUsage
void SetEnergyUsage(float new_usage)
Energy manager: Changes the energy usage per second.
Definition: ComponentEnergyManager.c:597
ItemBase::m_ChargeTime
static float m_ChargeTime
Definition: Defibrillator.c:9
ItemBase::DischargeServer
void DischargeServer(PlayerBase victim)
Definition: Defibrillator.c:111
AddAction
void AddAction(typename actionName)
Definition: AdvancedCommunication.c:86
ItemBase::m_ChargingSound
EffectSound m_ChargingSound
Definition: Defibrillator.c:14
SEffectManager::PlaySoundOnObject
static EffectSound PlaySoundOnObject(string sound_set, Object parent_object, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Definition: EffectManager.c:85
ActionTurnOnWhileInHands
Definition: ActionTurnOnWhileInHands.c:1
ComponentEnergyManager::SwitchOff
void SwitchOff()
Energy manager: Switches OFF the device.
Definition: ComponentEnergyManager.c:350
GetType
override int GetType()
Definition: HudDebugWinCharAgents.c:49
ItemBase::m_IsCharged
bool m_IsCharged
Definition: Defibrillator.c:7
ItemBase::OnWorkStop
override void OnWorkStop()
Definition: Defibrillator.c:53
ItemBase::StopChargingTimer
void StopChargingTimer()
Definition: Defibrillator.c:97
EffectSound::SoundStop
void SoundStop()
Definition: EffectSound.c:300
EffectSound
Definition: EffectSound.c:1
ItemBase::m_ChargingTimer
ref Timer m_ChargingTimer
Definition: Defibrillator.c:12
PlayerBase
Definition: PlayerBaseClient.c:1
ItemBase::m_ChargedAlarm
EffectSound m_ChargedAlarm
Definition: Defibrillator.c:13
ItemBase::SetActions
override void SetActions()
Definition: Defibrillator.c:142
ActionDefibrilateSelf
Definition: ActionDefibrilateSelf.c:9
ItemBase::OnIsCharged
void OnIsCharged()
Definition: Defibrillator.c:64
ItemBase::Defibrillator
void Defibrillator()
Definition: Defibrillator.c:16
GetCompEM
ComponentEnergyManager GetCompEM()
energy manager ENERGY MANAGER:Documentation: Confluence >> Camping & Squatting >> Electricity >> Ener...
Definition: EntityAI.c:1885
ActionTurnOffWhileInHands
Definition: ActionTurnOffWhileInHands.c:1
ActionDefibrilateTarget
Definition: ActionDefibrilateTarget.c:9
ItemBase::StopChargedAlarm
void StopChargedAlarm()
Definition: Defibrillator.c:79
ItemBase::GetTimeNeededToCharge
float GetTimeNeededToCharge()
Definition: Defibrillator.c:23
ItemBase::OnWorkStart
override void OnWorkStart()
Definition: Defibrillator.c:35
CGame::ConfigGetFloat
proto native float ConfigGetFloat(string path)
Get float value from config on path.
SEffectManager
Definition: EffectManager.c:1
ItemBase::GetEnergyNeededToCharge
float GetEnergyNeededToCharge()
Definition: Defibrillator.c:29
ItemBase::DischargeClient
void DischargeClient(PlayerBase victim)
Definition: Defibrillator.c:137