Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_HandSlotStorageComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Inventory", description: "")]
5
6class SCR_HandSlotStorageComponent : SCR_UniversalInventoryStorageComponent
7{
10 protected RplComponent m_RplComponent;
13
14 protected static const string ANIM_EVENT_NAME_FIRE = "Character_RefreshIK";
15 protected static const string VAR_CAN_BE_HELD_NAME = "m_bCanBeHeld";
16
18 {
20 for (int i, count = GetSlotsCount(); i < count; i++)
21 {
22 slot = SCR_HandSlotStorageSlot.Cast(GetSlot(i));
23 if (!slot)
24 continue;
25
26 if (slot.GetAttachedEntity())
27 continue;
28
29 return slot;
30 }
31
32 return null;
33 }
34
35 //------------------------------------------------------------------------------------------------
36 override bool CanStoreItem(IEntity item, int slotID)
37 {
38 SCR_GadgetComponent gadget = SCR_GadgetComponent.Cast(item.FindComponent(SCR_GadgetComponent));
39 if (!gadget || !gadget.CanBeHeld())
40 return false;
41
42 if (m_CharacterInventory && !m_CharacterInventory.CanUseItem(item, ESlotFunction.TYPE_GADGET))
43 return false;
44
45 return GetEmptySlotForItem(item);
46 }
47
48 //------------------------------------------------------------------------------------------------
49 override bool CanStoreResource(ResourceName resourceName, int slotID)
50 {
51 Resource entityResource = Resource.Load(resourceName);
52 if (!entityResource.IsValid())
53 return false;
54
55 BaseResourceObject resourceObj = entityResource.GetResource();
56 if (!resourceObj)
57 return false;
58
59 IEntitySource entitySrc = resourceObj.ToEntitySource();
60 if (!entitySrc)
61 return false;
62
63 IEntityComponentSource componentSrc;
64 for (int i, componentsCount = entitySrc.GetComponentCount(); i < componentsCount; i++)
65 {
66 componentSrc = entitySrc.GetComponent(i);
67 if (!componentSrc)
68 continue;
69
70 if (!componentSrc.GetClassName().ToType().IsInherited(SCR_GadgetComponent))
71 continue;
72
73 bool canBeHeld;
74 return componentSrc.Get(VAR_CAN_BE_HELD_NAME, canBeHeld) && canBeHeld && GetEmptySlotForItem(null);
75 }
76
77 return false;
78 }
79
80 //------------------------------------------------------------------------------------------------
81 override bool CanReplaceItem(IEntity nextItem, int slotID)
82 {
83 if (!nextItem.FindComponent(SCR_GadgetComponent))
84 return false;
85
86 return true;
87 }
88
89 //------------------------------------------------------------------------------------------------
91 {
92 return m_HandSlotItem;
93 }
94
95 //------------------------------------------------------------------------------------------------
96 override protected void OnAddedToSlot(IEntity item, int slotID)
97 {
98 super.OnAddedToSlot(item, slotID);
99
101 if (iic)
102 iic.HideOwner();
103
104 if (!m_RplComponent)
106
107 if (m_RplComponent && !m_RplComponent.IsOwner())
108 return;
109
110 m_HandSlotItem = item;
112 {
114 return;
115 }
116
117 ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
118 if (!character || !SCR_CharacterHelper.IsPlayerOrAIOwner(character))
119 return;
120
121 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
122 if (!controller)
123 return;
124
125 m_iGestureAnimationEndEvent = GameAnimationUtils.RegisterAnimationEvent(ANIM_EVENT_NAME_FIRE);
127 {
128 controller.GetOnAnimationEvent().Remove(OnAnimationEvent);
129 controller.GetOnAnimationEvent().Insert(OnAnimationEvent);
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected void DelayedOnAddedToSlot(IEntity item)
135 {
137 {
138 ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
139 if (!character)
140 return;
141
142 CharacterControllerComponent controller = character.GetCharacterController();
143 if (!controller)
144 return;
145
146 SCR_InventoryStorageManagerComponent storageManager = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
147 if (!storageManager)
148
149 m_CharacterInventory = storageManager.GetCharacterStorage();
151 return;
152 }
153
154 if (!item)
155 {
156 item = Get(0);//there will always be only one handslot and if for some reason item is null then check if we actually dont have an entity in that slot
157 m_HandSlotItem = item;
158 if (!item)
159 return;
160 }
161
163 if (iic)
164 iic.ShowOwner();
165
166 //~ Equipt item
167 m_CharacterInventory.UseItem(item, ESlotFunction.TYPE_GADGET);
168 }
169
170 //------------------------------------------------------------------------------------------------
173 {
175
177 }
178
179
180 //------------------------------------------------------------------------------------------------
181 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
182 protected void RPC_DoSkipAnimation()
183 {
185 }
186
187 //------------------------------------------------------------------------------------------------
190 {
192 ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
193 if (!character)
194 return;
195
196 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
197 if (!controller)
198 return;
199
200 controller.GetOnAnimationEvent().Remove(OnAnimationEvent);
202 }
203
204 //------------------------------------------------------------------------------------------------
211 protected void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
212 {
213 if (animEventType != m_iGestureAnimationEndEvent)
214 return;
215
216 ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
217 if (!character)
218 return;
219
220 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
221 if (!controller)
222 return;
223
224 controller.GetOnAnimationEvent().Remove(OnAnimationEvent);
226 }
227
228 //------------------------------------------------------------------------------------------------
229 override protected void OnRemovedFromSlot(IEntity item, int slotID)
230 {
231 m_HandSlotItem = null;
232 super.OnRemovedFromSlot(item, slotID);
233 }
234
235 //------------------------------------------------------------------------------------------------
237 {
238 super.OnManagerChanged(manager);
239
240 SCR_InventoryStorageManagerComponent scrMgr = SCR_InventoryStorageManagerComponent.Cast(manager);
241 if (scrMgr)
242 m_CharacterInventory = scrMgr.GetCharacterStorage();
243 }
244}
int AnimationEventID
ResourceName resourceName
Definition SCR_AIGroup.c:66
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
override bool CanStoreItem(IEntity item, int slotID)
RplComponent m_RplComponent
IEntity GetSlot(IEntity occupant)
void SkipAnimation_S()
Authority method used to inform others that this entity should skip the wait for the pick up animatio...
SCR_CharacterInventoryStorageComponent m_CharacterInventory
void SkipAnimation()
When animation is not used then this will remove itself from animation event script invoker and conti...
AnimationEventID m_iGestureAnimationEndEvent
IEntity GetHandSlotItem()
SCR_HandSlotStorageComponentClass m_bSkipNextWaitForAnimation
void DelayedOnAddedToSlot(IEntity item)
IEntity m_HandSlotItem
void RPC_DoSkipAnimation()
void SCR_UniversalInventoryStorageComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static RplComponent GetEntityRplComponent(notnull IEntity entity)
IEntity GetOwner()
Owner entity of the fuel tank.
event void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
void OnRemovedFromSlot(IEntity item, int slotID)
event bool CanStoreResource(ResourceName resourceName, int slotID)
Implemented logics for can insert here, Manager will provide slotID of -1 in case slot is irrelevant.
proto external int GetSlotsCount()
Returns the number of slots in this storage.
event bool CanReplaceItem(IEntity nextItem, int slotID)
Implemented logics for can replace to nextItem at slotID,.
void OnAddedToSlot(IEntity item, int slotID)
void OnManagerChanged(InventoryStorageManagerComponent manager)
InventoryStorageSlot GetEmptySlotForItem(IEntity item)
Usually any slot that item can be inserted to.
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
proto T Get(int n)