Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
nvgoggles.c
Go to the documentation of this file.
1 class NVGoggles extends PoweredOptic_Base
2 {
3  bool m_IsLowered;
4  Clothing m_Strap;
5  ref Timer m_WorkCheckTimer;
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 
52  PlayerBase player;
53  if ( m_Strap == parent && PlayerBase.CastTo(player, parent.GetHierarchyRootPlayer()) )
54  {
55  if ( parent && Clothing.Cast(parent) )
56  {
57  Clothing.Cast(parent).UpdateNVGStatus(player,false,true);
58  }
59  }
60 
61  m_Strap = null;
62  //SetPlayer(null);
63  }
64 
65  override void OnWorkStart()
66  {
67  PlayerBase player;
68  EntityAI headgear;
69  EntityAI glasses;
70  if ( m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()) )
71  {
72  headgear = player.FindAttachmentBySlotName("Headgear");
73  glasses = player.FindAttachmentBySlotName("Eyewear");
74 
75  //adjust on load - ComponentEnergyManager stores the 'working' state independently
76  if ( !m_IsLowered )
77  {
78  RotateGoggles(false);
79  }
80 
81  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
82  {
83  if ( (headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer() )
84  {
85  player.AddActiveNV(NVTypes.NV_GOGGLES);
86  }
87  }
88  }
89  }
90 
91  override void OnWorkStop()
92  {
93  PlayerBase player;
94  EntityAI headgear;
95  EntityAI glasses;
96  if ( m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()) )
97  {
98  headgear = player.FindAttachmentBySlotName("Headgear");
99  glasses = player.FindAttachmentBySlotName("Eyewear");
100 
101  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
102  {
103  if ( (headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer() )
104  {
105  player.RemoveActiveNV(NVTypes.NV_GOGGLES);
106  }
107  }
108  }
109  }
110 
111  override void OnWork( float consumed_energy )
112  {
113  //adjust on load - ComponentEnergyManager stores the 'working' state independently
114  if ( !m_IsLowered )
115  {
116  RotateGoggles(false);
117  }
118 
119  PlayerBase player;
120  EntityAI headgear;
121  EntityAI glasses;
122  if ( m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()) )
123  {
124  headgear = player.FindAttachmentBySlotName("Headgear");
125  glasses = player.FindAttachmentBySlotName("Eyewear");
126 
127  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
128  {
129  if ( (headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer() )
130  {
131  player.AddActiveNV(NVTypes.NV_GOGGLES);
132  }
133  }
134  }
135  }
136 
137  void LoweredCheck() //check for animation state, if another player lowered them first (or solve by synced variable)
138  {
139  if ( GetAnimationPhase("rotate") != m_IsLowered )
140  {
141  m_IsLowered = GetAnimationPhase("rotate");
142  }
143  }
144 
145  void RotateGoggles(bool state)
146  {
147  //if ( GetAnimationPhase("rotate") != state ) //useless?
148  SetAnimationPhase("rotate",!state);
149  m_IsLowered = !state;
150 
151  PlayerBase player;
152  int slot_id;
153  string slot_name;
154  if ( m_Strap && m_Strap.GetInventory().GetCurrentAttachmentSlotInfo(slot_id,slot_name) && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent())/*&& slot_id == InventorySlots.EYEWEAR*/ )
155  {
156  player.SetNVGLowered(m_IsLowered);
157  }
158 
159  if ( GetCompEM() )
160  {
161  if ( !state && GetCompEM().CanWork() )
162  GetCompEM().SwitchOn();
163  else
164  GetCompEM().SwitchOff();
165  }
166  }
167 
168  void SwitchOnNVGCheck()
169  {
170  //Print("SwitchOnNVGCheck");
171  GetCompEM().SwitchOn();
172  if (GetCompEM().IsSwitchedOn())
173  {
174  m_WorkCheckTimer.Stop();
175  }
176  }
177 
178  override int GetCurrentNVType()
179  {
180  if (IsWorking())
181  {
182  //m_CurrentOpticMode
183  switch (m_CurrentOpticMode)
184  {
185  /*case GameConstants.OPTICS_STATE_DAY:
186  return NVTypes.NV_GOGGLES_WHATEVER;
187 
188  case GameConstants.OPTICS_STATE_NIGHTVISION:
189  return NVTypes.NV_GOGGLES;*/
190  default:
191  return NVTypes.NV_GOGGLES;
192  }
193  Error("Undefined optic mode of " + this);
194  return NVTypes.NONE;
195  }
196  else
197  {
198  return NVTypes.NV_GOGGLES_OFF;
199  }
200  }
201 
202  override bool IsNVG()
203  {
204  return true;
205  }
206 }
GetGame
proto native CGame GetGame()
OnWasAttached
override void OnWasAttached(EntityAI parent, int slot_id)
Definition: torch.c:945
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
IsNVG
bool IsNVG()
Definition: itembase.c:899
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
RemoveAction
void RemoveAction(typename actionName)
Definition: advancedcommunication.c:118
PlayerBase
Definition: playerbaseclient.c:1
Clothing
Definition: armband_colorbase.c:1
NVTypes
NVTypes
Definition: dayzplayercamera_base.c:54
ActionViewOptics
Definition: actionviewoptics.c:1
OnWork
override void OnWork(float consumed_energy)
Definition: smokegrenadebase.c:195
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
OnWasDetached
override void OnWasDetached(EntityAI parent, int slot_id)
Definition: remotedetonator.c:237
Timer
Definition: dayzplayerimplement.c:62
PoweredOptic_Base
Definition: nvgoggles.c:1
ActionViewBinoculars
Definition: actionviewbinoculars.c:1
EEItemAttached
override void EEItemAttached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:520
EEItemDetached
override void EEItemDetached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:529
EntityAI
Definition: building.c:5
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175