Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FlareAnimationComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Flares", description: "Base component for handling animation.")]
5
7{
9
12
13 protected bool m_bStartedProne;
14
15 protected static const string CHARACTER_FIRE_INPUT_NAME = "CharacterFire";
16 protected static const string ANIMATION_EVENT_FIRE = "Fire";
17 protected static const string ANIMATION_EVENT_HIDE = "Weapon_Hide";
18
19 protected static const int GARBAGE_COLLECTION_TIME = 30;
20
21 //------------------------------------------------------------------------------------------------
22 // constructor
32
33 //------------------------------------------------------------------------------------------------
35 protected bool CanContinueTheAnimation()
36 {
37 if (!m_UserController.IsWeaponRaised())
38 return false;
39
40 if (m_UserController.IsPartiallyLowered())
41 return false;
42
43 if (!m_UserController.GetCanFireWeapon())
44 return false;
45
46 bool isProne = m_UserController.GetStance() == ECharacterStance.PRONE;
47 return m_bStartedProne == isProne;
48 }
49
50 //------------------------------------------------------------------------------------------------
51 override protected event void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
52 {
53 super.OnAnimationEvent(animEventType, animUserString, intParam, timeFromStart, timeToEnd);
54
55 if (animEventType == m_iHideFlare && Replication.IsServer())
56 {
57 IEntity owner = GetOwner();
59 if (garbageSystem)
60 garbageSystem.Insert(owner, GARBAGE_COLLECTION_TIME);
61 }
62
64 return;
65
67 {
68 CharacterAnimationComponent animationComponent = m_UserController.GetAnimationComponent();
69 if (!animationComponent)
70 return;
71
72 CharacterCommandHandlerComponent commandHandler = animationComponent.GetCommandHandler();
73 if (commandHandler)
74 commandHandler.CancelItemUse();
75
76 return;
77 }
78
79 if (animEventType != m_iHideFlare && animEventType != m_iFireFlare)
80 return;
81
82 CharacterInputContext inputContext = m_UserController.GetInputContext();
83 if (!inputContext)
84 return;
85
86 if (animEventType == m_iFireFlare)
87 {
88 inputContext.SetWeaponPullTrigger(true);
89 LockItem();
90 // Observe the player in case he does something that would prevent the animation from reaching the point at which we discard this item
91 // As in such case it could cause problems due to the fact that the item is now locked
92 m_UserController.m_OnItemUseEndedInvoker.Insert(OnItemUseEnded);
93 return;
94 }
95
96 if (animEventType != m_iHideFlare)
97 return;
98
99 inputContext.SetWeaponPullTrigger(false);
101 OnWeaponStateChanged(null, false);
102 }
103
104 //------------------------------------------------------------------------------------------------
106 protected void FireFlare()
107 {
108 if (!m_UserController)
109 return;
110
112 return;
113
114 if (m_UserController.IsUsingItem())
115 return;
116
117 m_UserController.SetPartialLower(false);
120 return;
121
122 m_UserController.TryUseItem(GetOwner(), true, false);
123 }
124
125 //------------------------------------------------------------------------------------------------
130 protected void OnItemUseEnded(IEntity item, bool successful, ItemUseParameters animParams)
131 {
132 IEntity owner = GetOwner();
133 if (item != owner)
134 return;
135
137 if (!wpnComp)
138 return;
139
140 BaseMagazineComponent currentMag = wpnComp.GetCurrentMagazine();
141 if (currentMag)
142 return;
143
144 LockItem();
146 }
147
148 //------------------------------------------------------------------------------------------------
152 protected void OnWeaponStateChanged(WeaponComponent weapon, bool active)
153 {
154 if (!active)
155 {
156 GetGame().GetInputManager().RemoveActionListener(CHARACTER_FIRE_INPUT_NAME, EActionTrigger.DOWN, FireFlare);
157 m_iFireFlare = -1;
158 m_iHideFlare = -1;
159 if (!m_UserController)
160 return;
161
162 m_UserController.m_OnItemUseEndedInvoker.Remove(OnItemUseEnded);
163 if (weapon)
164 {
165 BaseMagazineComponent currentMag = weapon.GetCurrentMagazine();
166 if (!currentMag) // If player was somehow able to equip used flare, then we should make sure that he will get rid of it
168 }
169
170 m_UserController = null;
171 return;
172 }
173
174 m_UserController = null;
175 ChimeraCharacter character;
176 IEntity parent = GetOwner().GetParent();
177 while (parent)
178 {
179 character = SCR_ChimeraCharacter.Cast(parent);
180 if (character)
181 break;
182
183 parent = parent.GetParent();
184 }
185
186 if (!character)
187 return;
188
189 m_iHideFlare = GameAnimationUtils.RegisterAnimationEvent(ANIMATION_EVENT_HIDE);
190
191 bool isAi;
192 if (SCR_CharacterHelper.IsPlayerOrAIOwner(character, isAi))
193 m_UserController = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
194
195 if (!m_UserController)
196 return;
197
198 BaseMagazineComponent currentMag = weapon.GetCurrentMagazine();
199 if (!currentMag)
200 {
201 LockItem();
203 return;
204 }
205
206 m_iFireFlare = GameAnimationUtils.RegisterAnimationEvent(ANIMATION_EVENT_FIRE);
207
208 if (!isAi)
209 GetGame().GetInputManager().AddActionListener(CHARACTER_FIRE_INPUT_NAME, EActionTrigger.DOWN, FireFlare);
210 }
211
212 //------------------------------------------------------------------------------------------------
214 protected void LockItem()
215 {
216 SCR_WeaponAttachmentsStorageComponent weaponStorage = SCR_WeaponAttachmentsStorageComponent.Cast(GetOwner().FindComponent(SCR_WeaponAttachmentsStorageComponent));
217 if (!weaponStorage)
218 return;
219
220 weaponStorage.RequestUserLock(m_UserController.GetCharacter(), true);
221 }
222
223 //------------------------------------------------------------------------------------------------
225 protected void DisposeOfFlare(bool doEquipNextFlare = true)
226 {
227 if (!m_UserController)
228 return;
229
230 SCR_ChimeraCharacter character = m_UserController.GetCharacter();
231 if (!character)
232 return;
233
234 CharacterWeaponManagerComponent weaponManager = CharacterWeaponManagerComponent.Cast(character.GetWeaponManager());
235 if (!weaponManager)
236 return;
237
238 WeaponSlotComponent currentSlot = weaponManager.GetCurrentSlot();
239 if (!currentSlot)
240 return;
241
242 GetGame().GetInputManager().RemoveActionListener(CHARACTER_FIRE_INPUT_NAME, EActionTrigger.DOWN, FireFlare);
243 m_UserController.m_OnItemUseEndedInvoker.Remove(OnItemUseEnded);
244 m_UserController.DropWeapon(currentSlot);
245
246 CharacterAnimationComponent animationComponent = m_UserController.GetAnimationComponent();
247 if (!animationComponent)
248 return;
249
250 if (doEquipNextFlare)
252
253 CharacterCommandHandlerComponent commandHandler = animationComponent.GetCommandHandler();
254 if (commandHandler)
255 commandHandler.FinishItemUse(true);
256 }
257
258 //------------------------------------------------------------------------------------------------
260 protected void EquipNextFlare()
261 {
262 if (!m_UserController)
263 return;
264
265 SCR_ChimeraCharacter character = m_UserController.GetCharacter();
266 if (!character)
267 return;
268
269 CharacterWeaponManagerComponent weaponManager = CharacterWeaponManagerComponent.Cast(character.GetWeaponManager());
270 if (!weaponManager)
271 return;
272
273 WeaponSlotComponent currentSlot = weaponManager.GetCurrentSlot();
274 if (!currentSlot)
275 return;
276
277 SCR_InventoryStorageManagerComponent storageManager = SCR_InventoryStorageManagerComponent.Cast(m_UserController.GetInventoryStorageManager());
278 if (!storageManager)
279 return;
280
281 storageManager.TryAssigningNextItemToQuickSlot(GetOwner(), currentSlot.GetWeaponSlotIndex(), false);
282 }
283}
int AnimationEventID
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void EquipNextFlare()
Method used to attempt to cycle to the next flare.
void FireFlare()
Method used to start flare firing procedure.
void OnWeaponStateChanged(WeaponComponent weapon, bool active)
bool CanContinueTheAnimation()
AnimationEventID m_iHideFlare
void LockItem()
Method used to ensure that players wont be able to interact with this item.
void SCR_FlareAnimationComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
AnimationEventID m_iFireFlare
void DisposeOfFlare(bool doEquipNextFlare=true)
Method used to drop the item on the ground.
SCR_FlareAnimationComponentClass m_UserController
void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Main replication API.
Definition Replication.c:14
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
static IEntity GetLocalControlledEntity()
ScriptInvokerWeaponState GetOnWeaponStateChanged()
IEntity GetOwner()
Owner entity of the fuel tank.
ECharacterStance
EActionTrigger