Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GadgetComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Gadgets", description: "Gadget base", color: "0 0 255 255")]
5
6//------------------------------------------------------------------------------------------------
8enum EGadgetType
9{
10 NONE = 1,
11 MAP = 1 << 1,
12 COMPASS = 1 << 2,
13 BINOCULARS = 1 << 3,
14 FLASHLIGHT = 1 << 4,
15 RADIO = 1 << 5,
17 WRISTWATCH = 1 << 7,
18 CONSUMABLE = 1 << 8,
19 BUILDING_TOOL = 1 << 9,
20 SPECIALIST_ITEM = 1 << 10,
21 NIGHT_VISION = 1 << 11,
22 DETONATOR = 1 << 12,
23 GPS = 1 << 13,
24}
25
27enum EGadgetMode
28{
29 ON_GROUND = 0, // ground
30 IN_STORAGE, // within storage but not slotted
31 IN_SLOT, // in equipment slot
32 IN_HAND, // held in left hand
33 LAST
34}
35
36// @NOTE(Leo) : short term animation solution
37// from conversation with @Théo Escamez: //for now we have 4 items> compass adrianov, compass SY183, Radio ANPRC68 and Radio R148
39enum EGadgetAnimVariable
40{
41 NONE = 0,
43 SY183 = 2,
45 R148 = 4,
46 MX991 = 5,
48 M22 = 7,
49 B12 = 8,
50 MAP = 9
51}
52
54class SCR_GadgetComponent : ScriptGameComponent
55{
56 [Attribute("", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EGadgetAnimVariable), desc: "Gadget anim variable", category: "Gadget")]
57 protected EGadgetAnimVariable m_eAnimVariable;
58
59 [Attribute(SCR_EUseContext.NONE.ToString(), uiwidget: UIWidgets.Flags, desc: "From what context this gadget can be toggled.\nValue NONE is always selected but it is ignored when there is any other value selected", enums: ParamEnumArray.FromEnum(SCR_EUseContext), category: "Gadget")]
60 protected SCR_EUseContext m_eUseMask;
61
62 [Attribute("0 0 0", UIWidgets.Coords, desc: "Adjusted position of prefab within equipment slot, for when items placed intto a same slot have different sizes like flashlights", category: "Gadget")]
63 protected vector m_vEquipmentSlotOffset;
64
65 [Attribute("0.5", UIWidgets.Auto, desc: "Weapon no fire time set while equipped\n[s]", category: "Gadget")]
66 protected float m_fWeaponNoFireTime;
67
68 [Attribute("1", desc: "Can this item be held in hand", category: "Gadget")]
69 protected bool m_bCanBeHeld;
70
71 bool m_bFocused;
72 protected bool m_bActivated = false; // current state if the gadget can be toggled on
73 protected EGadgetMode m_iMode = EGadgetMode.ON_GROUND; // curent gadget mode
74 protected ChimeraCharacter m_CharacterOwner; // current entity in posession of this gadget
75
76 //------------------------------------------------------------------------------------------------
78 EGadgetAnimVariable GetAnimVariable()
79 {
80 return m_eAnimVariable;
81 }
82
83 //------------------------------------------------------------------------------------------------
85 float GetWeaponNoFireTime()
86 {
87 return m_fWeaponNoFireTime;
88 }
89
90 //------------------------------------------------------------------------------------------------
93 bool IsToggledOn()
94 {
95 return m_bActivated;
96 }
97
98 //------------------------------------------------------------------------------------------------
101 void OnToggleActive(bool state);
102
103 //------------------------------------------------------------------------------------------------
105 void OnParentSlotChanged(InventoryStorageSlot oldSlot, InventoryStorageSlot newSlot)
106 {
107 IEntity parentOwner = GetOwner().GetRootParent();
108 if (!SCR_ChimeraCharacter.Cast(parentOwner))
109 {
110 if (!newSlot)
111 SCR_GadgetManagerComponent.SetGadgetModeStashed(this, EGadgetMode.ON_GROUND);
112 else if (!oldSlot)
113 SCR_GadgetManagerComponent.SetGadgetModeStashed(this, EGadgetMode.IN_STORAGE);
114 }
115 }
116
117 //------------------------------------------------------------------------------------------------
121 void OnModeChanged(EGadgetMode mode, IEntity charOwner)
122 {
123 // Clear last mode
124 ModeClear(m_iMode);
125
126 // Update current mode
127 m_iMode = mode;
128
129 // Set new mode
130 ModeSwitch(mode, charOwner);
131 }
132
133 //------------------------------------------------------------------------------------------------
137 protected void ModeSwitch(EGadgetMode mode, IEntity charOwner)
138 {
139 UpdateVisibility(mode);
140
141 // if removing from inventory
142 if (mode == EGadgetMode.ON_GROUND)
143 m_CharacterOwner = null;
144 else
145 m_CharacterOwner = ChimeraCharacter.Cast(charOwner);
146 }
147
148 //------------------------------------------------------------------------------------------------
151 protected void ModeClear(EGadgetMode mode);
152
153 //------------------------------------------------------------------------------------------------
156 void OnSlotOccludedStateChanged(bool occluded);
157
158 //------------------------------------------------------------------------------------------------
161 {
162 ConnectToGadgetsSystem();
163 }
164
165 //------------------------------------------------------------------------------------------------
168 {
169 DisconnectFromGadgetsSystem();
170 }
171
172
173 //------------------------------------------------------------------------------------------------
175 // \param[in] inHand states whether the gadget is currently held in hand
176 void UpdateVisibility(EGadgetMode mode)
177 {
178 // mode1
179 InventoryItemComponent itemComponent = InventoryItemComponent.Cast(GetOwner().FindComponent(InventoryItemComponent));
180 if (!itemComponent)
181 return;
182
183 // if in hand or visible while slotted
184 if ( mode == EGadgetMode.IN_HAND || (mode == EGadgetMode.IN_SLOT && IsVisibleEquipped()) )
185 {
186 // slotted, Set positioning of visible slotted gadgets on character -> configured in item prefab to allow gadgets of different sizes
187 if (mode != EGadgetMode.IN_HAND)
188 {
189 InventoryStorageSlot slot = itemComponent.GetParentSlot();
190 ItemAnimationAttributes animAttr = ItemAnimationAttributes.Cast(itemComponent.FindAttribute(ItemAnimationAttributes));
191 if (slot && animAttr)
192 {
193 vector matLS[4];
194 animAttr.GetAdditiveTransformLS(matLS);
195 matLS[3] = matLS[3] + m_vEquipmentSlotOffset;
196 slot.SetAdditiveTransformLS(matLS);
197 }
198
199 EquipmentStorageSlot equipSlot = EquipmentStorageSlot.Cast(slot);
200 if (equipSlot && equipSlot.IsOccluded())
201 {
202 itemComponent.HideOwner(); // slotted but occluded
203 return;
204 }
205 }
206
207 itemComponent.ShowOwner();
208 }
209 // if slotted and not visible or not slotted
210 else
211 {
212 if (mode == EGadgetMode.ON_GROUND)
213 itemComponent.ShowOwner();
214 else
215 itemComponent.HideOwner();
216 }
217 }
218
219 //------------------------------------------------------------------------------------------------
222 void ToggleActive(bool state, SCR_EUseContext context)
223 {
224 if (!m_CharacterOwner)
225 return;
226
227 if (m_eUseMask == SCR_EUseContext.NONE || (m_eUseMask & context) == 0)
228 return;
229
230 RplComponent rplComponent = RplComponent.Cast(m_CharacterOwner.FindComponent(RplComponent));
231 if (!rplComponent || !rplComponent.IsOwner())
232 return; // NOT owner of the character in possession of this gadget
233
234 // Client side
235 rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
236 if (rplComponent && rplComponent.IsProxy())
237 OnToggleActive(state); // activate client side to avoid server delay
238
239 // Sync
240 SCR_GadgetManagerComponent.GetGadgetManager(m_CharacterOwner).AskToggleGadget(this, state);
241 }
242
243 //------------------------------------------------------------------------------------------------
245 void ActivateAction();
246
247 //------------------------------------------------------------------------------------------------
250 void ToggleFocused(bool enable)
251 {
252 m_bFocused = enable;
253
254 if (m_CharacterOwner != SCR_PlayerController.GetLocalControlledEntity())
255 return;
256
257 SCR_PlayerController controller = SCR_PlayerController.Cast(GetGame().GetPlayerController());
258 if (controller)
259 controller.SetGadgetFocus(enable);
260 }
261
262 //------------------------------------------------------------------------------------------------
265 ChimeraCharacter GetCharacterOwner()
266 {
267 return m_CharacterOwner;
268 }
269
270 //------------------------------------------------------------------------------------------------
273 EGadgetType GetType()
274 {
275 return EGadgetType.NONE;
276 }
277
278 //------------------------------------------------------------------------------------------------
281 EGadgetMode GetMode()
282 {
283 return m_iMode;
284 }
285
286 //------------------------------------------------------------------------------------------------
289 bool CanBeHeld()
290 {
291 return m_bCanBeHeld;
292 }
293
294 //------------------------------------------------------------------------------------------------
297 SCR_EUseContext GetUseMask()
298 {
299 return m_eUseMask;
300 }
301
302 //------------------------------------------------------------------------------------------------
305 bool CanBeRaised()
306 {
307 return false;
308 }
309
310 //------------------------------------------------------------------------------------------------
313 bool IsUsingADSControls()
314 {
315 return false;
316 }
317
318 //------------------------------------------------------------------------------------------------
321 bool IsVisibleEquipped()
322 {
323 return false;
324 }
325
326 //------------------------------------------------------------------------------------------------
329 //Called by Gadgets system
330 void Update(float timeSlice);
331
332 //------------------------------------------------------------------------------------------------
334 protected void ConnectToGadgetsSystem()
335 {
336 World world = GetOwner().GetWorld();
337 GadgetsSystem gadgetSystem = GadgetsSystem.Cast(world.FindSystem(GadgetsSystem));
338 if (!gadgetSystem)
339 return;
340
341 gadgetSystem.Register(this);
342 }
343
344 //------------------------------------------------------------------------------------------------
345 protected void DisconnectFromGadgetsSystem()
346 {
347 World world = GetOwner().GetWorld();
348 GadgetsSystem gadgetSystem = GadgetsSystem.Cast(world.FindSystem(GadgetsSystem));
349 if (!gadgetSystem)
350 return;
351
352 gadgetSystem.Unregister(this);
353 }
354
355 //------------------------------------------------------------------------------------------------
356 override bool RplSave(ScriptBitWriter writer)
357 {
358 writer.WriteIntRange(m_iMode, 0, EGadgetMode.LAST-1);
359
360 return true;
361 }
362
363 //------------------------------------------------------------------------------------------------
364 override bool RplLoad(ScriptBitReader reader)
365 {
366 reader.ReadIntRange(m_iMode, 0, EGadgetMode.LAST-1);
367
368 UpdateVisibility(m_iMode);
369
370 return true;
371 }
372
373 //------------------------------------------------------------------------------------------------
374 override void OnDelete(IEntity owner)
375 {
376 DisconnectFromGadgetsSystem();
377
378 super.OnDelete(owner);
379 }
380
381 //------------------------------------------------------------------------------------------------
382 override void OnPostInit(IEntity owner)
383 {
384 SetEventMask(owner, EntityEvent.INIT);
385
386 InventoryItemComponent invComp = InventoryItemComponent.Cast(GetOwner().FindComponent(InventoryItemComponent));
387 if (invComp)
388 invComp.m_OnParentSlotChangedInvoker.Insert(OnParentSlotChanged);
389 }
390}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_RplTestComponentClass m_CharacterOwner
SCR_AIGroupInfoComponentClass LAST
override bool RplLoad(ScriptBitReader reader)
override bool RplSave(ScriptBitWriter writer)
void ModeClear(EGadgetMode mode)
void ActivateAction()
Action listener callback.
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
override EGadgetType GetType()
override void OnToggleActive(bool state)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override bool IsVisibleEquipped()
override void ActivateGadgetUpdate()
override void DeactivateGadgetUpdate()
override bool CanBeRaised()
@ CONSUMABLE
@ RADIO_BACKPACK
SCR_EUseContext
SCR_GadgetComponentClass FLASHLIGHT_SOVIET_01
SCR_GadgetComponentClass B12
SCR_GadgetComponentClass M22
SCR_GadgetComponentClass BUILDING_TOOL
SCR_GadgetComponentClass MAP
SCR_GadgetComponentClass GPS
SCR_GadgetComponentClass IN_STORAGE
SCR_GadgetComponentClass ANPRC68
SCR_GadgetComponentClass R148
SCR_GadgetComponentClass WRISTWATCH
SCR_GadgetComponentClass NIGHT_VISION
SCR_GadgetComponentClass IN_HAND
SCR_GadgetComponentClass RADIO
SCR_GadgetComponentClass ON_GROUND
Gadget mode.
SCR_GadgetComponentClass FLASHLIGHT
SCR_GadgetComponentClass IN_SLOT
SCR_GadgetComponentClass BINOCULARS
SCR_GadgetComponentClass SPECIALIST_ITEM
SCR_GadgetComponentClass MX991
SCR_GadgetComponentClass COMPASS
SCR_GadgetComponentClass DETONATOR
void ToggleActive()
Toggle map light.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ChimeraCharacter GetCharacterOwner()
Returns the top most owner of this object or the operator of this turret.
override bool IsUsingADSControls()
enum EVehicleType IEntity
void Register(SCR_GadgetComponent component)
void Unregister(SCR_GadgetComponent component)
proto external BaseWorld GetWorld()
proto external IEntity GetRootParent()
IEntity GetOwner()
Owner entity of the fuel tank.
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto external PlayerController GetPlayerController()