Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DetachMagazineUserAction.c
Go to the documentation of this file.
2 {
3  protected SCR_InventoryStorageManagerComponent m_InventoryManager;
4 
5  override bool CanBeShownScript(IEntity user)
6  {
7  if (!super.CanBeShownScript(user))
8  return false;
9 
11  {
12  ChimeraCharacter character = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
13  if(!character)
14  return false;
15 
16  m_InventoryManager = SCR_InventoryStorageManagerComponent.Cast(character.FindComponent(SCR_InventoryStorageManagerComponent));
17  }
18 
19  if(!m_InventoryManager || !m_WeaponComponent.GetCurrentMagazine())
20  return false;
21 
22  BaseMuzzleComponent muzzleComp = m_WeaponComponent.GetCurrentMuzzle();
23  if (GetOwner() != muzzleComp.GetOwner())
24  return false;
25 
26  IEntity currentMag = m_WeaponComponent.GetCurrentMagazine().GetOwner();
27  InventoryItemComponent magInventory = InventoryItemComponent.Cast(currentMag.FindComponent(InventoryItemComponent));
28  BaseInventoryStorageComponent magStorage = magInventory.GetParentSlot().GetStorage();
29  WeaponAttachmentsStorageComponent wasc = WeaponAttachmentsStorageComponent.Cast(magStorage);
30  if (!wasc)
31  return false; // Must be a WeaponAttachmentsStorageComponent
32 
33  return m_InventoryManager.CanRemoveItemFromStorage(currentMag, magStorage);
34  }
35 
36  override protected void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
37  {
38  IEntity currentMag = m_WeaponComponent.GetCurrentMagazine().GetOwner();
39  InventoryItemComponent magInventory = InventoryItemComponent.Cast(currentMag.FindComponent(InventoryItemComponent));
40  BaseInventoryStorageComponent magStorage = magInventory.GetParentSlot().GetStorage();
41 
42  WeaponAttachmentsStorageComponent wasc = WeaponAttachmentsStorageComponent.Cast(magStorage);
43  if (!wasc)
44  {
45  Print("ERROR: Magazine is no longer in the weapon", LogLevel.ERROR);
46  return; // Must be a WeaponAttachmentsStorageComponent
47  }
48 
49  BaseInventoryStorageComponent suitableStorage = m_InventoryManager.FindStorageForItem(currentMag);
50 
51  if (suitableStorage)
52  m_InventoryManager.TryMoveItemToStorage(currentMag, suitableStorage);
53  else
54  m_InventoryManager.TryRemoveItemFromStorage(currentMag, magStorage);
55 
56  m_InventoryManager.PlayItemSound(pOwnerEntity, "SOUND_UNEQUIP");
57  }
58 
59  override bool GetActionNameScript(out string outName)
60  {
61  if (!m_WeaponComponent)
62  return false;
63 
64  IEntity currentMag = m_WeaponComponent.GetCurrentMagazine().GetOwner();
65  if (!currentMag)
66  return false;
67 
68  InventoryItemComponent magItem = InventoryItemComponent.Cast(currentMag.FindComponent(InventoryItemComponent));
69  if (!magItem)
70  return false;
71 
72  UIInfo actionInfo = GetUIInfo();
73  UIInfo itemInfo = magItem.GetUIInfo();
74  if (actionInfo && itemInfo)
75  {
76  outName = string.Format("%1%2", actionInfo.GetName(), itemInfo.GetName());
77  return true;
78  }
79  else
80  {
81  return false;
82  }
83  }
84 };
SCR_DetachMagazineUserAction
Definition: SCR_DetachMagazineUserAction.c:1
SCR_PlayerController
Definition: SCR_PlayerController.c:31
UIInfo
UIInfo - declare object, allows to define UI elements.
Definition: UIInfo.c:13
m_InventoryManager
SCR_InventoryStorageManagerComponent m_InventoryManager
Definition: SCR_AttachementAction.c:15
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_InspectionUserAction
Definition: SCR_InspectionUserAction.c:1
InventoryItemComponent
Definition: InventoryItemComponent.c:12
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12