Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ConsumableItemComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Gadgets", description: "Consumable gadget")]
5
6// Consumable gadget component
7class SCR_ConsumableItemComponent : SCR_GadgetComponent
8{
9 [Attribute("", UIWidgets.Object, category: "Consumable" )]
10 protected ref SCR_ConsumableEffectBase m_ConsumableEffect;
11
12 [Attribute("0", UIWidgets.CheckBox, "Switch model on use, f.e. from packaged version", category: "Consumable")]
14
15 [Attribute("0", UIWidgets.CheckBox, "Show the model of the item on the character after using", category: "Consumable")]
16 protected bool m_bVisibleEquipped;
17
19
22
23 protected int m_iStoredHealedGroup;
24
25 //------------------------------------------------------------------------------------------------
31 void ApplyItemEffect(IEntity target, IEntity user, ItemUseParameters animParams, IEntity item, bool deleteItem = true)
32 {
33 if (!m_ConsumableEffect)
34 return;
35
36 m_ConsumableEffect.ApplyEffect(target, user, item, animParams);
37
38 ModeClear(EGadgetMode.IN_HAND);
39
40 if (deleteItem)
41 RplComponent.DeleteRplEntity(GetOwner(), false);
42 }
43
44 //------------------------------------------------------------------------------------------------
46 protected void OnUseBegan(IEntity item, ItemUseParameters animParams)
47 {
50
51 if (!m_CharacterOwner || !animParams)
52 return;
53
56
57 SetHealedGroup(animParams.GetIntParam(), true);
58 }
59
60 //------------------------------------------------------------------------------------------------
62 protected void OnApplyToCharacter(IEntity item, bool successful, ItemUseParameters animParams)
63 {
64 ClearInvokers(animParams.GetIntParam());
65
66 if (!successful)
67 {
68 if (animParams.GetCommandIntArg() == -1)
69 {
70 Print("Consumable item OnItemUseComplete event called with empty SCR_ConsumableEffectAnimationParameters", LogLevel.ERROR);
71 return;
72 }
73
74 if (item && !item.IsDeleted() && m_bAlternativeModelOnAction)
76
77 return;
78 }
79
80 bool deleteItem = true;
82 deleteItem = GetConsumableEffect().GetDeleteOnUse();
83
84 IEntity target = GetTargetCharacter();
85 if (!target)
86 target = m_CharacterOwner;
88 return;
89
90 ApplyItemEffect(target, m_CharacterOwner, animParams, item, deleteItem);
91 }
92
93 //------------------------------------------------------------------------------------------------
94 protected void SetHealedGroup(EBandagingAnimationBodyParts group, bool healed)
95 {
96 m_iStoredHealedGroup = group * healed;
97
99 if (!targetChar)
100 {
101 targetChar = m_CharacterOwner;
102
103 if (!targetChar)
104 return;
105 }
106
107 SCR_CharacterDamageManagerComponent targetDamageMan = SCR_CharacterDamageManagerComponent.Cast(targetChar.GetDamageManager());
108 if (!targetDamageMan)
109 return;
110
111 targetDamageMan.SetGroupIsBeingHealed(targetDamageMan.FindAssociatedHitZoneGroup(group), healed);
112 }
113
114 //-----------------------------------------------------------------------------
117 void SetAlternativeModel(bool useAlternative)
118 {
119 InventoryItemComponent inventoryItemComp = InventoryItemComponent.Cast( GetOwner().FindComponent(InventoryItemComponent));
120 if (!inventoryItemComp)
121 return;
122
123 ItemAttributeCollection attributeCollection = inventoryItemComp.GetAttributes();
124 if (!attributeCollection)
125 return;
126
127 SCR_AlternativeModel additionalModels = SCR_AlternativeModel.Cast( attributeCollection.FindAttribute(SCR_AlternativeModel));
128 if (!additionalModels)
129 return;
130
131 ResourceName consumableModel;
132 if (useAlternative)
133 consumableModel = additionalModels.GetAlternativeModel();
134 else if (GetOwner())
135 consumableModel = SCR_Global.GetPrefabAttributeResource(GetOwner(), "MeshObject", "Object");
136
137 Resource resource = Resource.Load(consumableModel);
138 if (!resource)
139 return;
140
141 BaseResourceObject baseResource = resource.GetResource();
142 if (baseResource)
143 {
144 VObject asset = baseResource.ToVObject();
145 if (asset)
146 GetOwner().SetObject(asset, "");
147 }
148 }
149
150 //-----------------------------------------------------------------------------
151 // TODO: fix comment
152 // Get visibility of item
153 // \Sets item visible on the outside of the physical character
154 override bool IsVisibleEquipped()
155 {
156 return m_bVisibleEquipped;
157 }
158
159 //------------------------------------------------------------------------------------------------
160 override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
161 {
162 super.ModeSwitch(mode, charOwner);
163
164 if (mode == EGadgetMode.IN_HAND)
165 {
167 m_CharController.m_OnItemUseFinishedInvoker.Insert(OnApplyToCharacter);
168 m_CharController.m_OnItemUseBeganInvoker.Insert(OnUseBegan);
169 }
170 }
171
172 //------------------------------------------------------------------------------------------------
173 override void ModeClear(EGadgetMode mode)
174 {
175 if (mode == EGadgetMode.IN_HAND)
176 {
177 // CallLater to ensure the invokers are removed after the m_OnItemUseFinishedInvoker is called. This is ensured because m_OnItemUseFinishedInvoker is called on end of fixedFrame
179 GetGame().GetCallqueue().CallLater(ClearInvokers, param1: -1);
180 }
181
182 super.ModeClear(mode);
183 }
184
185 //------------------------------------------------------------------------------------------------
186 override void ActivateAction()
187 {
188 if (!m_ConsumableEffect || !m_ConsumableEffect.CanApplyEffect(m_CharacterOwner, GetOwner()))
189 return;
190
191 m_ConsumableEffect.ActivateEffect(m_CharacterOwner, m_CharacterOwner, GetOwner());
192 }
193
194 //------------------------------------------------------------------------------------------------
195 protected void ClearInvokers(int targetGroup = -1)
196 {
197 if (targetGroup == -1 && m_iStoredHealedGroup != 0)
199 else
200 SetHealedGroup(targetGroup, false);
201
202 if (!m_CharController)
203 return;
204
205 m_CharController.m_OnItemUseFinishedInvoker.Remove(OnApplyToCharacter);
206 m_CharController.m_OnItemUseBeganInvoker.Remove(OnUseBegan);
207
208 m_CharController = null;
209 }
210
211 //------------------------------------------------------------------------------------------------
212 override void OnDelete(IEntity owner)
213 {
214 // Force clear these as we need to ensure that this item is not going to be blocking any healed groups
215 // This is necessary because for proxies this item will be streamed out before ModeClear will be able to call CearInvokers
216 ClearInvokers(-1);
217
218 super.OnDelete(owner);
219 }
220
221 //------------------------------------------------------------------------------------------------
225 {
226 if (m_ConsumableEffect)
227 return m_ConsumableEffect.m_eConsumableType;
228
229 return SCR_EConsumableType.NONE;
230 }
231
232 //------------------------------------------------------------------------------------------------
235 SCR_ConsumableEffectBase GetConsumableEffect()
236 {
237 return m_ConsumableEffect;
238 }
239
240 //------------------------------------------------------------------------------------------------
241 override EGadgetType GetType()
242 {
243 return EGadgetType.CONSUMABLE;
244 }
245
246 //------------------------------------------------------------------------------------------------
249 {
250 m_TargetCharacter = target;
251 }
252
253 //------------------------------------------------------------------------------------------------
259}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_RplTestComponentClass m_CharacterOwner
void ModeClear(EGadgetMode mode)
void ActivateAction()
Action listener callback.
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
override EGadgetType GetType()
EBandagingAnimationBodyParts
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_EConsumableType
Type of consumable gadget.
void ClearInvokers(int targetGroup=-1)
SCR_ConsumableEffectBase GetConsumableEffect()
SCR_EConsumableType GetConsumableType()
int m_iStoredHealedGroup
bool m_bVisibleEquipped
void SetTargetCharacter(IEntity target)
void SetHealedGroup(EBandagingAnimationBodyParts group, bool healed)
void OnUseBegan(IEntity item, ItemUseParameters animParams)
OnItemUseBegan event from SCR_CharacterControllerComponent.
void OnApplyToCharacter(IEntity item, bool successful, ItemUseParameters animParams)
OnItemUseComplete event from SCR_CharacterControllerComponent.
IEntity m_TargetCharacter
Target character is the target set when it's not m_CharacterOwner.
SCR_CharacterControllerComponent m_CharController
IEntity GetTargetCharacter()
void ApplyItemEffect(IEntity target, IEntity user, ItemUseParameters animParams, IEntity item, bool deleteItem=true)
bool m_bAlternativeModelOnAction
void SetAlternativeModel(bool useAlternative)
override bool IsVisibleEquipped()
proto external Managed FindComponent(typename typeName)
proto external bool IsDeleted()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void SetGroupIsBeingHealed(ECharacterHitZoneGroup hitZoneGroup, bool setIsBeingHealed)
ECharacterHitZoneGroup FindAssociatedHitZoneGroup(EBandagingAnimationBodyParts bodyPartToBandage)
static ResourceName GetPrefabAttributeResource(notnull IEntity entity, string containerType, string attributeName)
Definition Functions.c:1953
Visual object.
Definition VObject.c:14
IEntity GetOwner()
Owner entity of the fuel tank.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
Tuple param1