Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
universallight.c
Go to the documentation of this file.
1 class UniversalLight extends Switchable_Base
2 {
3  UniversallightLight m_Light;
4 
5  static int REFLECTOR_ID = 1;
6  static int GLASS_ID = 2;
7 
8  static string LIGHT_OFF_GLASS = "dz\\gear\\tools\\data\\flashlight_glass.rvmat";
9  static string LIGHT_OFF_REFLECTOR = "dz\\weapons\\attachments\\data\\m4_flashlight.rvmat";
10  static string LIGHT_ON_GLASS = "dz\\gear\\tools\\data\\flashlight_glass_on.rvmat";
11  static string LIGHT_ON_REFLECTOR = "dz\\weapons\\attachments\\data\\m4_flashlight_on.rvmat";
12 
13  ref array<int> m_AttachmentSlotsCheck;
14 
15  void UniversalLight()
16  {
17  InitAttachmentsSlotsToCheck(m_AttachmentSlotsCheck);
18  }
19 
20  override ScriptedLightBase GetLight()
21  {
22  return m_Light;
23  }
24 
25  override bool CanPutAsAttachment( EntityAI parent )
26  {
27  if ( !super.CanPutAsAttachment(parent) ) {return false;}
28 
29  bool req_attachment = false;
30  bool rail_attachment_found = false;
31  int slot_id;
32  ItemBase attachment;
33  for ( int i = 0; i < parent.GetInventory().GetAttachmentSlotsCount(); i++ )
34  {
35  slot_id = parent.GetInventory().GetAttachmentSlotId(i);
36  if ( m_AttachmentSlotsCheck.Find(slot_id) != -1 )
37  {
38  req_attachment = true;
39  attachment = ItemBase.Cast(parent.GetInventory().FindAttachment(slot_id));
40  if ( attachment && attachment.ConfigIsExisting("hasRailFunctionality") && attachment.ConfigGetBool("hasRailFunctionality") )
41  rail_attachment_found = true;
42  }
43  }
44  return !req_attachment || (req_attachment && rail_attachment_found);
45  }
46 
47  override void OnWorkStart()
48  {
49  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
50  {
51  m_Light = UniversallightLight.Cast( ScriptedLightBase.CreateLight(UniversallightLight, "0 0 0", 0.08) ); // Position is zero because light is attached on parent immediately.
52  m_Light.AttachOnMemoryPoint(this, "beamStart", "beamEnd");
53  SetObjectMaterial(GLASS_ID, LIGHT_ON_GLASS);
54  SetObjectMaterial(REFLECTOR_ID, LIGHT_ON_REFLECTOR);
55  }
56  }
57 
58  override void OnWork( float consumed_energy )
59  {
60  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
61  {
62  Battery9V battery = Battery9V.Cast( GetCompEM().GetEnergySource() );
63 
64  if (battery && m_Light)
65  {
66  float efficiency = battery.GetEfficiency0To1();
67 
68  if ( efficiency < 1 )
69  {
70  m_Light.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
71  }
72  else
73  {
74  m_Light.SetIntensity( 1, 0 );
75  }
76  }
77  }
78  }
79 
80  override void OnWorkStop()
81  {
82  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
83  {
84  if (m_Light)
85  m_Light.FadeOut();
86 
87  m_Light = NULL;
88 
89  SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
90  SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
91  }
92  }
93 
94  // Inventory manipulation
95  override void OnInventoryExit(Man player)
96  {
97  super.OnInventoryExit(player);
98 
99  if ( GetCompEM().IsWorking() )
100  {
101  if (player)
102  {
103  vector ori_rotate = player.GetOrientation();
104  ori_rotate = ori_rotate + Vector(270,0,0);
105  SetOrientation(ori_rotate);
106  }
107  }
108  }
109 
110  override void SetActions()
111  {
112  super.SetActions();
115  }
116 
117  override bool IsLightSource()
118  {
119  return true;
120  }
121 
123  void InitAttachmentsSlotsToCheck(out array<int> AttSlots)
124  {
125  if (!AttSlots)
126  {
127  AttSlots = new array<int>;
128  AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardM4"));
129  AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardAK"));
130  AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardMP5"));
131  }
132  }
133 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Switchable_Base
Definition: chainsaw.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
Battery9V
Definition: battery9v.c:1
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
CanPutAsAttachment
override bool CanPutAsAttachment(EntityAI parent)
Definition: itembase.c:4021
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
OnInventoryExit
override protected void OnInventoryExit(Man player)
Definition: fireworksbase.c:79
vector
Definition: enconvert.c:105
OnWork
override void OnWork(float consumed_energy)
Definition: smokegrenadebase.c:195
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ScriptedLightBase
Definition: pointlightbase.c:1
SetActions
void SetActions()
Definition: advancedcommunication.c:79
IsLightSource
bool IsLightSource()
Definition: itembase.c:918
ActionTurnOffWhileInHands
Definition: actionturnoffwhileinhands.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
GetLight
ScriptedLightBase GetLight()
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175