DayZ 1.24
Loading...
Searching...
No Matches
NVGoggles.c
Go to the documentation of this file.
1class NVGoggles extends PoweredOptic_Base
2{
6
7 void NVGoggles()
8 {
9 RotateGoggles(true);
10 m_WorkCheckTimer = new Timer;
11 }
12
13 override void SetActions()
14 {
15 super.SetActions();
16
19 }
20
21 override void EEItemAttached(EntityAI item, string slot_name)
22 {
23 super.EEItemAttached(item, slot_name);
24
25 if (GetCompEM().CanWork() && m_IsLowered)
26 m_WorkCheckTimer.Run(0.1, this, "SwitchOnNVGCheck", null, true);
27 //GetCompEM().SwitchOn();
28 }
29
30 override void EEItemDetached(EntityAI item, string slot_name)
31 {
32 super.EEItemDetached(item, slot_name);
33
34 GetCompEM().SwitchOff();
35 }
36
37 override void OnWasAttached(EntityAI parent, int slot_id)
38 {
39 super.OnWasAttached(parent, slot_id);
40 RotateGoggles(true);
41
42 m_Strap = Clothing.Cast(parent);
43 /*if (m_Strap)
44 SetPlayer(PlayerBase.Cast(m_Strap.GetHierarchyParent()));*/
45 }
46
47 override void OnWasDetached(EntityAI parent, int slot_id)
48 {
49 super.OnWasDetached(parent, slot_id);
50 RotateGoggles(true);
51
53 if (m_Strap == parent && PlayerBase.CastTo(player, parent.GetHierarchyRootPlayer()))
54 {
55 if (parent && Clothing.Cast(parent))
56 Clothing.Cast(parent).UpdateNVGStatus(player, false, true);
57 }
58
59 m_Strap = null;
60 //SetPlayer(null);
61 }
62
63 override void OnWorkStart()
64 {
68 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
69 {
70 headgear = player.FindAttachmentBySlotName("Headgear");
71 glasses = player.FindAttachmentBySlotName("Eyewear");
72
73 //adjust on load - ComponentEnergyManager stores the 'working' state independently
74 if (!m_IsLowered)
75 RotateGoggles(false);
76
77 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
78 {
79 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
80 player.AddActiveNV(NVTypes.NV_GOGGLES);
81 }
82 }
83 }
84
85 override void OnWorkStop()
86 {
90 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
91 {
92 headgear = player.FindAttachmentBySlotName("Headgear");
93 glasses = player.FindAttachmentBySlotName("Eyewear");
94
95 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
96 {
97 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
98 player.RemoveActiveNV(NVTypes.NV_GOGGLES);
99 }
100 }
101 }
102
103 override void OnWork(float consumed_energy)
104 {
105 //adjust on load - ComponentEnergyManager stores the 'working' state independently
106 if (!m_IsLowered)
107 RotateGoggles(false);
108
112 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
113 {
114 headgear = player.FindAttachmentBySlotName("Headgear");
115 glasses = player.FindAttachmentBySlotName("Eyewear");
116
117 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
118 {
119 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
120 player.AddActiveNV(NVTypes.NV_GOGGLES);
121 }
122 }
123 }
124
125 void LoweredCheck() //check for animation state, if another player lowered them first (or solve by synced variable)
126 {
127 if (GetAnimationPhase("rotate") != m_IsLowered)
128 m_IsLowered = GetAnimationPhase("rotate");
129 }
130
132 {
133 //if ( GetAnimationPhase("rotate") != state ) //useless?
134 SetAnimationPhase("rotate", !state);
135 m_IsLowered = !state;
136
138 int slot_id;
139 string slot_name;
140 if (m_Strap && m_Strap.GetInventory().GetCurrentAttachmentSlotInfo(slot_id, slot_name) && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent())/*&& slot_id == InventorySlots.EYEWEAR*/)
141 player.SetNVGLowered(m_IsLowered);
142
143 if (GetCompEM())
144 {
145 if (!state && GetCompEM().CanWork())
146 GetCompEM().SwitchOn();
147 else
148 GetCompEM().SwitchOff();
149 }
150 }
151
153 {
154 //Print("SwitchOnNVGCheck");
155 GetCompEM().SwitchOn();
156 if (GetCompEM().IsSwitchedOn())
157 m_WorkCheckTimer.Stop();
158 }
159
160 override int GetCurrentNVType()
161 {
162 if (IsWorking())
163 {
164 //m_CurrentOpticMode
165 switch (m_CurrentOpticMode)
166 {
167 /*case GameConstants.OPTICS_STATE_DAY:
168 return NVTypes.NV_GOGGLES_WHATEVER;
169
170 case GameConstants.OPTICS_STATE_NIGHTVISION:
171 return NVTypes.NV_GOGGLES;*/
172 default:
173 return NVTypes.NV_GOGGLES;
174 }
175 Error("Undefined optic mode of " + this);
176 return NVTypes.NONE;
177 }
178 else
179 return NVTypes.NV_GOGGLES_OFF;
180 }
181
182 override bool IsNVG()
183 {
184 return true;
185 }
186}
void AddAction(typename actionName)
void RemoveAction(typename actionName)
void SwitchOnNVGCheck()
Definition NVGoggles.c:152
override void SetActions()
Definition NVGoggles.c:13
override void EEItemAttached(EntityAI item, string slot_name)
Definition NVGoggles.c:21
override void OnWasDetached(EntityAI parent, int slot_id)
Definition NVGoggles.c:47
Clothing m_Strap
Definition NVGoggles.c:4
override void EEItemDetached(EntityAI item, string slot_name)
Definition NVGoggles.c:30
override int GetCurrentNVType()
Definition NVGoggles.c:160
override void OnWasAttached(EntityAI parent, int slot_id)
Definition NVGoggles.c:37
void RotateGoggles(bool state)
Definition NVGoggles.c:131
ref Timer m_WorkCheckTimer
Definition NVGoggles.c:5
override bool IsNVG()
Definition NVGoggles.c:182
override void OnWorkStop()
Definition NVGoggles.c:85
override void OnWork(float consumed_energy)
Definition NVGoggles.c:103
override void OnWorkStart()
Definition NVGoggles.c:63
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90