Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ConsumableItemComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Gadgets", description: "Consumable gadget")]
3 {
4 }
5 
6 // Consumable gadget component
7 class 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")]
13  protected bool m_bAlternativeModelOnAction;
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 
21  protected IEntity m_TargetCharacter;
22 
23  protected int m_iStoredHealedGroup;
24 
25  //------------------------------------------------------------------------------------------------
31  void ApplyItemEffect(IEntity target, ItemUseParameters animParams, IEntity item, bool deleteItem = true)
32  {
33  if (!m_ConsumableEffect)
34  return;
35 
36  m_ConsumableEffect.ApplyEffect(target, target, 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  {
49  SetAlternativeModel(true);
50 
51  if (!m_CharacterOwner || !animParams)
52  return;
53 
54  SetHealedGroup(animParams.GetIntParam(), true);
55  }
56 
57  //------------------------------------------------------------------------------------------------
59  protected void OnApplyToCharacter(IEntity item, bool successful, ItemUseParameters animParams)
60  {
61  ClearInvokers(animParams.GetIntParam());
62 
63  if (!successful)
64  {
65  if (animParams.GetCommandIntArg() == -1)
66  {
67  Print("Consumable item OnItemUseComplete event called with empty SCR_ConsumableEffectAnimationParameters", LogLevel.ERROR);
68  return;
69  }
70 
72  SetAlternativeModel(false);
73 
74  return;
75  }
76 
77  bool deleteItem = true;
78  if (GetConsumableEffect())
79  deleteItem = GetConsumableEffect().GetDeleteOnUse();
80 
81  IEntity target = GetTargetCharacter();
82  if (!target)
83  target = m_CharacterOwner;
84  if (!target)
85  return;
86 
87  ApplyItemEffect(target, animParams, item, deleteItem);
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected void SetHealedGroup(EBandagingAnimationBodyParts group, bool healed)
92  {
93  m_iStoredHealedGroup = group * healed;
94 
95  ChimeraCharacter ownerChar = ChimeraCharacter.Cast(m_CharacterOwner);
96  if (!ownerChar)
97  return;
98 
100  IEntity target = GetTargetCharacter();
101  ChimeraCharacter targetChar;
102  if (target)
103  targetChar = ChimeraCharacter.Cast(target);
104  else
105  targetChar = ChimeraCharacter.Cast(m_CharacterOwner);
106 
107  if (targetChar)
108  targetDamageMan = SCR_CharacterDamageManagerComponent.Cast(targetChar.GetDamageManager());
109 
110  if (!targetDamageMan)
111  return;
112 
113  targetDamageMan.SetGroupIsBeingHealed(targetDamageMan.FindAssociatedHitZoneGroup(group), healed);
114  }
115 
116  //-----------------------------------------------------------------------------
119  void SetAlternativeModel(bool useAlternative)
120  {
121  InventoryItemComponent inventoryItemComp = InventoryItemComponent.Cast( GetOwner().FindComponent(InventoryItemComponent));
122  if (!inventoryItemComp)
123  return;
124 
125  ItemAttributeCollection attributeCollection = inventoryItemComp.GetAttributes();
126  if (!attributeCollection)
127  return;
128 
129  SCR_AlternativeModel additionalModels = SCR_AlternativeModel.Cast( attributeCollection.FindAttribute(SCR_AlternativeModel));
130  if (!additionalModels)
131  return;
132 
133  ResourceName consumableModel;
134  if (useAlternative)
135  consumableModel = additionalModels.GetAlternativeModel();
136  else if (GetOwner())
137  consumableModel = SCR_Global.GetPrefabAttributeResource(GetOwner(), "MeshObject", "Object");
138 
139  Resource resource = Resource.Load(consumableModel);
140  if (!resource)
141  return;
142 
143  BaseResourceObject baseResource = resource.GetResource();
144  if (baseResource)
145  {
146  VObject asset = baseResource.ToVObject();
147  if (asset)
148  GetOwner().SetObject(asset, "");
149  }
150  }
151 
152  //-----------------------------------------------------------------------------
153  // TODO: fix comment
154  // Get visibility of item
155  // \Sets item visible on the outside of the physical character
156  override bool IsVisibleEquipped()
157  {
158  return m_bVisibleEquipped;
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
163  {
164  super.ModeSwitch(mode, charOwner);
165 
166  if (mode == EGadgetMode.IN_HAND)
167  {
169  m_CharController.m_OnItemUseFinishedInvoker.Insert(OnApplyToCharacter);
170  m_CharController.m_OnItemUseBeganInvoker.Insert(OnUseBegan);
171  }
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  override void ModeClear(EGadgetMode mode)
176  {
177  if (mode == EGadgetMode.IN_HAND)
178  {
179  // 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
180  if (m_CharController)
181  GetGame().GetCallqueue().CallLater(ClearInvokers, param1: -1);
182  }
183 
184  super.ModeClear(mode);
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  override void ActivateAction()
189  {
190  if (!m_ConsumableEffect || !m_ConsumableEffect.CanApplyEffect(m_CharacterOwner, GetOwner()))
191  return;
192 
193  m_ConsumableEffect.ActivateEffect(m_CharacterOwner, m_CharacterOwner, GetOwner());
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  protected void ClearInvokers(int targetGroup = -1)
198  {
199  if (targetGroup == -1 && m_iStoredHealedGroup != 0)
201  else
202  SetHealedGroup(targetGroup, false);
203 
204  if (!m_CharController)
205  return;
206 
207  m_CharController.m_OnItemUseFinishedInvoker.Remove(OnApplyToCharacter);
208  m_CharController.m_OnItemUseBeganInvoker.Remove(OnUseBegan);
209 
210  m_CharController = null;
211  }
212 
213  //------------------------------------------------------------------------------------------------
217  {
218  if (m_ConsumableEffect)
219  return m_ConsumableEffect.m_eConsumableType;
220 
221  return SCR_EConsumableType.NONE;
222  }
223 
224  //------------------------------------------------------------------------------------------------
227  SCR_ConsumableEffectBase GetConsumableEffect()
228  {
229  return m_ConsumableEffect;
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  override EGadgetType GetType()
234  {
235  return EGadgetType.CONSUMABLE;
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  override bool CanBeToggled()
240  {
241  return true;
242  }
243 
244  //------------------------------------------------------------------------------------------------
246  void SetTargetCharacter(IEntity target)
247  {
248  m_TargetCharacter = target;
249  }
250 
251  //------------------------------------------------------------------------------------------------
254  {
255  return m_TargetCharacter;
256  }
257 }
ApplyItemEffect
void ApplyItemEffect(IEntity target, ItemUseParameters animParams, IEntity item, bool deleteItem=true)
Definition: SCR_ConsumableItemComponent.c:31
SCR_EConsumableType
SCR_EConsumableType
Type of consumable gadget.
Definition: SCR_ConsumableEffectBase.c:2
ClearInvokers
protected void ClearInvokers(int targetGroup=-1)
Definition: SCR_ConsumableItemComponent.c:197
GetType
override EGadgetType GetType()
Definition: SCR_ConsumableItemComponent.c:233
m_CharController
protected SCR_CharacterControllerComponent m_CharController
Definition: SCR_ConsumableItemComponent.c:18
SetHealedGroup
protected void SetHealedGroup(EBandagingAnimationBodyParts group, bool healed)
Definition: SCR_ConsumableItemComponent.c:91
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ActivateAction
override void ActivateAction()
Definition: SCR_ConsumableItemComponent.c:188
SCR_ConsumableItemComponentClass
Definition: SCR_ConsumableItemComponent.c:2
ItemAttributeCollection
Definition: ItemAttributeCollection.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_bVisibleEquipped
protected bool m_bVisibleEquipped
Definition: SCR_ConsumableItemComponent.c:16
ItemUseParameters
Definition: ItemUseParameters.c:15
SCR_GadgetComponentClass
Definition: SCR_GadgetComponent.c:2
SCR_AlternativeModel
Definition: SCR_AlternativeModel.c:1
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
ModeSwitch
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
Definition: SCR_ConsumableItemComponent.c:162
SetAlternativeModel
void SetAlternativeModel(bool useAlternative)
Definition: SCR_ConsumableItemComponent.c:119
IsVisibleEquipped
override bool IsVisibleEquipped()
Definition: SCR_ConsumableItemComponent.c:156
m_TargetCharacter
protected IEntity m_TargetCharacter
Target character is the target set when it's not m_CharacterOwner.
Definition: SCR_ConsumableItemComponent.c:21
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
m_CharacterOwner
SCR_RplTestComponentClass m_CharacterOwner
SetTargetCharacter
void SetTargetCharacter(IEntity target)
Definition: SCR_ConsumableItemComponent.c:246
GetConsumableType
SCR_EConsumableType GetConsumableType()
Definition: SCR_ConsumableItemComponent.c:216
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
InventoryItemComponent
Definition: InventoryItemComponent.c:12
m_bAlternativeModelOnAction
protected bool m_bAlternativeModelOnAction
Definition: SCR_ConsumableItemComponent.c:13
GetConsumableEffect
SCR_ConsumableEffectBase GetConsumableEffect()
Definition: SCR_ConsumableItemComponent.c:227
SCR_Global
Definition: Functions.c:6
ModeClear
override void ModeClear(EGadgetMode mode)
Definition: SCR_ConsumableItemComponent.c:175
OnUseBegan
protected void OnUseBegan(IEntity item, ItemUseParameters animParams)
OnItemUseBegan event from SCR_CharacterControllerComponent.
Definition: SCR_ConsumableItemComponent.c:46
m_iStoredHealedGroup
protected int m_iStoredHealedGroup
Definition: SCR_ConsumableItemComponent.c:23
EBandagingAnimationBodyParts
EBandagingAnimationBodyParts
Definition: SCR_CharacterHitZone.c:27
CanBeToggled
override bool CanBeToggled()
Definition: SCR_ConsumableItemComponent.c:239
Attribute
SCR_ConsumableItemComponentClass SCR_GadgetComponentClass Attribute("", UIWidgets.Object, category:"Consumable")] protected ref SCR_ConsumableEffectBase m_ConsumableEffect
OnApplyToCharacter
protected void OnApplyToCharacter(IEntity item, bool successful, ItemUseParameters animParams)
OnItemUseComplete event from SCR_CharacterControllerComponent.
Definition: SCR_ConsumableItemComponent.c:59
GetTargetCharacter
IEntity GetTargetCharacter()
Definition: SCR_ConsumableItemComponent.c:253
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180