Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AttachItemFromInventoryAction.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 #ifndef DISABLE_INVENTORY
6 SCR_InventoryStorageManagerComponent m_InventoryManager;
7 InventoryItemComponent m_ItemComponent;
8 BaseWeaponComponent m_WeaponComponent;
9
10 //------------------------------------------------------------------------------------------------
11 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
12 {
13 GenericEntity owner = GenericEntity.Cast(pOwnerEntity);
14 if (owner)
15 {
16 m_ItemComponent = InventoryItemComponent.Cast(owner.FindComponent(InventoryItemComponent));
17 }
18 }
19
20 //------------------------------------------------------------------------------------------------
21 override protected void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
22 {
23 WeaponAttachmentsStorageComponent storage = WeaponAttachmentsStorageComponent.Cast(m_WeaponComponent.GetOwner().FindComponent(WeaponAttachmentsStorageComponent));
24 if (!m_InventoryManager.CanMoveItemToStorage(GetOwner(), storage, -1))
25 {
27 CharacterControllerComponent ctrl = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
28 if (ctrl && magazine)
29 {
30 bool bEmpty = storage.Get(0) == null;
31 ctrl.ReloadWeaponWith(pOwnerEntity, !bEmpty);
32 }
33 else
34 {
35 manager.TrySwapItemStorages(pOwnerEntity, storage.Get(0));
36 }
37 manager.PlayItemSound(pOwnerEntity, "SOUND_SWITCH");
38 }
39 else
40 {
41 // Check if we want to reload a magazine, and use ReloadWeapopnWith if so.
42 // This prevents a race condition were the old magazine appears to be still in the weapon
43 // due to network lag
45 CharacterControllerComponent ctrl = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
46 if (ctrl && magazine)
47 {
48 bool bEmpty = storage.Get(0) == null;
49 ctrl.ReloadWeaponWith(pOwnerEntity, !bEmpty);
50 }
51 else
52 {
53 manager.EquipWeaponAttachment(pOwnerEntity, pUserEntity);
54 }
55 }
56 }
57
58 //------------------------------------------------------------------------------------------------
59 override bool CanBeShownScript(IEntity user)
60 {
61 if (!m_ItemComponent)
62 return false;
63
64 if (!m_ItemComponent.GetParentSlot())
65 return false;
66
67 if (m_ItemComponent.GetParentSlot().GetStorage().IsInherited(WeaponAttachmentsStorageComponent))
68 return false;
69
71 if(!character)
72 return false;
73
74 CharacterControllerComponent controller = character.GetCharacterController();
75 if(!controller)
76 return false;
77
78 if(!controller.GetInspect())
79 return false;
80
81 if(!m_InventoryManager)
82 m_InventoryManager = SCR_InventoryStorageManagerComponent.Cast(character.FindComponent(SCR_InventoryStorageManagerComponent));
83 if(!m_InventoryManager)
84 return false;
85
86 BaseWeaponManagerComponent weaponManager = controller.GetWeaponManagerComponent();
87 if(!weaponManager)
88 return false;
89
90 m_WeaponComponent = controller.GetWeaponManagerComponent().GetCurrentWeapon();
91 if(!m_WeaponComponent || m_WeaponComponent.GetOwner() == m_ItemComponent.GetParentSlot().GetOwner())
92 return false;
93
94 auto storage = WeaponAttachmentsStorageComponent.Cast(m_WeaponComponent.GetOwner().FindComponent(WeaponAttachmentsStorageComponent));
95 if (!storage)
96 return false;
97
98 bool result = m_InventoryManager.CanMoveItemToStorage(GetOwner(), storage, -1);
99 if (!result)
100 {
101 IEntity existingAttachment = storage.Get(0);
102 if (existingAttachment)
103 result = m_InventoryManager.CanSwapItemStorages(GetOwner(), existingAttachment);
104 }
105
106 if (!result)
107 {
108 // When we get here, it can still be a grenade to be inserted into an attached muzzle
109 BaseMuzzleComponent muzzleComp = m_WeaponComponent.GetCurrentMuzzle();
110 auto xstorage = WeaponAttachmentsStorageComponent.Cast(muzzleComp.GetOwner().FindComponent(WeaponAttachmentsStorageComponent));
111 if (!xstorage)
112 return false;
113 result = m_InventoryManager.CanMoveItemToStorage(GetOwner(), xstorage, -1);
114 if (!result)
115 {
116 IEntity existingAttachment = xstorage.Get(0);
117 if (existingAttachment)
118 {
119 if (existingAttachment == GetOwner())
120 result = false;
121 else
122 result = m_InventoryManager.CanSwapItemStorages(GetOwner(), existingAttachment);
123 }
124 }
125 }
126
127 return result;
128 }
129
130 override bool GetActionNameScript(out string outName)
131 {
132 if (!m_ItemComponent)
133 return false;
134 UIInfo actionInfo = GetUIInfo();
135 UIInfo itemInfo = m_ItemComponent.GetUIInfo();
136 if (actionInfo && itemInfo)
137 {
138 outName = string.Format("%1%2", actionInfo.GetName(), itemInfo.GetName());
139 return true;
140 }
141 else
142 {
143 return false;
144 }
145 }
146 #endif
147};
override void Init()
proto external IEntity GetOwner()
Returns the parent entity of this action.
proto external UIInfo GetUIInfo()
Returns the UIInfo set for this user action or null if none.
proto external Managed FindComponent(typename typeName)
override bool GetActionNameScript(out string outName)
void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
modded version for to be used with the inventory 2.0
static IEntity GetLocalControlledEntity()
UIInfo - allows to define UI elements.
Definition UIInfo.c:14