Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TurretAssemblyAction.c
Go to the documentation of this file.
2 {
3  NONE,
7 };
8 
10 {
11  private IEntity m_Owner;
12  private ETurretState m_CurrentState;
13 
14  //------------------------------------------------------------------------------------------------
15  override bool CanBeShownScript(IEntity user)
16  {
17  return CanBePerformedScript(user);
18  }
19 
20  //------------------------------------------------------------------------------------------------
22  override bool CanBePerformedScript(IEntity user)
23  {
24  m_CurrentState = ETurretState.NONE;
25  return false;
26  /*
27  // Check if user has inventory
28  SCR_InventoryManagerComponent userInventory = SCR_InventoryManagerComponent.Cast(user.FindComponent(SCR_InventoryManagerComponent));
29  if (!userInventory)
30  return false;
31 
32  GenericEntity genOwner = GenericEntity.Cast(m_Owner);
33 
34  // Check if turret has an occupant
35  auto controller = TurretControllerComponent.Cast(genOwner.FindComponent(TurretControllerComponent));
36  if (!controller)
37  return false;
38  auto compartment = controller.GetCompartmentSlot();
39  if (compartment && compartment.GetOccupant())
40  return false;
41 
42  // Check if destroyed
43  auto damageManagerComponent = DamageManagerComponent.Cast(genOwner.FindComponent(DamageManagerComponent));
44  if (damageManagerComponent && damageManagerComponent.GetState() != EDamageState.ALIVE)
45  {
46  m_CurrentState = ETurretState.DESTROYED;
47  return false;
48  }
49 
50  // Disassembly
51  bool turretHasWeapon = false;
52  bool turretHasSights = false;
53 
54  // Check Turret Weapon
55  auto genericWeaponSlotComponent = genOwner.FindComponent(WeaponSlotComponent);
56  if (!genericWeaponSlotComponent)
57  return false;
58  auto weaponSlotComponent = WeaponSlotComponent.Cast(genericWeaponSlotComponent);
59  IEntity weaponEntityInSlot = weaponSlotComponent.GetWeaponEntity();
60  IEntity sightsEntityInSlot;
61  if (weaponEntityInSlot)
62  {
63  turretHasWeapon = true;
64 
65  // Check Turret Sights
66  GenericComponent genericWeaponComponent = weaponEntityInSlot.FindComponent(WeaponComponent);
67  auto attachmentSlot = AttachmentSlotComponent.Cast(genericWeaponComponent.FindComponent(AttachmentSlotComponent));
68  if (attachmentSlot)
69  {
70  sightsEntityInSlot = attachmentSlot.GetAttachedEntity();
71  if (sightsEntityInSlot)
72  turretHasSights = true;
73  }
74  }
75 
76  // Check if user can carry items
77  if (turretHasWeapon)
78  {
79  bool canCarryBase = false;
80  bool canCarryCannon = false;
81  bool canCarrySights = !turretHasSights;
82 
83  // Check Turret Base
84  canCarryBase = userInventory.CanInsert(m_Owner);
85 
86  // Check Turret Cannon
87  canCarryCannon = userInventory.CanInsert(weaponEntityInSlot);
88 
89  // Check Turret Sights
90  if(turretHasSights)
91  canCarrySights = userInventory.CanInsert(sightsEntityInSlot);
92 
93  if (canCarryBase && canCarryCannon && canCarrySights)
94  {
95  m_CurrentState = ETurretState.ASSEMBLED;
96  return true;
97  }
98 
99  return false;
100  }
101 
102  // Assembly
103  bool userHasWeapon = false;
104  bool userHasSights = false;
105 
106  // Check for suitable Turret Weapon
107  IEntity weaponInInventory = userInventory.OnGetWeapon(weaponSlotComponent.GetWeaponSlotType());
108  if (weaponInInventory)
109  {
110  userHasWeapon = true;
111 
112  // Check for suitable Turret Sights
113  GenericComponent genericWeaponComponent = weaponInInventory.FindComponent(WeaponComponent);
114  auto attachmentSlot = AttachmentSlotComponent.Cast(genericWeaponComponent.FindComponent(AttachmentSlotComponent));
115  IEntity sightsInInventory = userInventory.OnGetAttachment(attachmentSlot.GetAttachmentSlotType());
116  if (sightsInInventory)
117  userHasSights = true;
118  }
119 
120  if (userHasWeapon && userHasSights)
121  {
122  m_CurrentState = ETurretState.DISASSEMBLED;
123  return true;
124  }
125 
126  return false;
127  */
128  }
129 
130  //---------------------------------------------------------
131  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
132  {
133  /*
134  GenericEntity genOwner = GenericEntity.Cast(m_Owner);
135  auto genericWeaponSlotComponent = genOwner.FindComponent(WeaponSlotComponent);
136  auto weaponSlotComponent = WeaponSlotComponent.Cast(genericWeaponSlotComponent);
137  auto controller = TurretControllerComponent.Cast(genOwner.FindComponent(TurretControllerComponent));
138 
139  if (m_CurrentState == ETurretState.ASSEMBLED)
140  {
141  // Get Turret Weapon entity
142  IEntity weaponEntityInSlot = weaponSlotComponent.GetWeaponEntity();
143  GenericEntity genericWeapon = GenericEntity.Cast(weaponEntityInSlot);
144  IEntity sightsEntityInSlot;
145 
146  if(weaponEntityInSlot)
147  {
148  // Get Turret Sights entity
149  GenericComponent genericWeaponComponent = genericWeapon.FindComponent(WeaponComponent);
150  auto attachmentSlot = AttachmentSlotComponent.Cast(genericWeaponComponent.FindComponent(AttachmentSlotComponent));
151  sightsEntityInSlot = attachmentSlot.GetAttachedEntity();
152  }
153 
154  // Request disassembly action
155  if(controller.DisassembleTurret(pUserEntity) && weaponEntityInSlot)
156  {
157  GenericEntity genericUserEntity = GenericEntity.Cast(pUserEntity);
158  BaseInventoryManagerComponent baseInventoryManager = BaseInventoryManagerComponent.Cast(genericUserEntity.FindComponent(BaseInventoryManagerComponent));
159  SCR_InventoryManagerComponent inventoryManager = SCR_InventoryManagerComponent.Cast(baseInventoryManager);
160 
161  // Turret Weapon
162  vector itemTransform[4]; // transform of item before it was picked up
163  weaponEntityInSlot.GetWorldTransform(itemTransform);
164  BaseSoundComponent soundComponent = BaseSoundComponent.Cast(genericWeapon.FindComponent(BaseSoundComponent));
165  if (soundComponent)
166  {
167  soundComponent.SetTransformation(itemTransform);
168  soundComponent.PlayStr(SCR_SoundEvent.SOUND_PICK_UP);
169  }
170 
171  // Turret Sights
172  sightsEntityInSlot.GetWorldTransform(itemTransform);
173  GenericEntity genericSights = GenericEntity.Cast(sightsEntityInSlot);
174  soundComponent = BaseSoundComponent.Cast(genericSights.FindComponent(BaseSoundComponent));
175  if (soundComponent)
176  {
177  soundComponent.SetTransformation(itemTransform);
178  soundComponent.PlayStr(SCR_SoundEvent.SOUND_PICK_UP);
179  }
180 
181  // Turret Base
182  GenericComponent genericItemComponent = m_Owner.FindComponent(SCR_InventoryItemComponent);
183  pOwnerEntity.GetWorldTransform(itemTransform);
184  GenericEntity genericEntity = GenericEntity.Cast(pOwnerEntity);
185  soundComponent = BaseSoundComponent.Cast(genericEntity.FindComponent(BaseSoundComponent));
186  if (soundComponent)
187  {
188  soundComponent.SetTransformation(itemTransform);
189  soundComponent.PlayStr(SCR_SoundEvent.SOUND_PICK_UP);
190  }
191  }
192  }
193  else if (m_CurrentState == ETurretState.DISASSEMBLED)
194  {
195  SCR_InventoryManagerComponent userInventory = SCR_InventoryManagerComponent.Cast(pUserEntity.FindComponent(SCR_InventoryManagerComponent));
196  IEntity newWeapon = userInventory.OnGetWeapon(weaponSlotComponent.GetWeaponSlotType());
197  IEntity newSights = userInventory.OnGetAttachment(weaponSlotComponent.GetWeaponSlotType());
198 
199  // Request assembly action
200  controller.AssembleTurret(pUserEntity, newWeapon, newSights);
201 
202  }
203  */
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  override bool GetActionNameScript(out string outName)
208  {
209  switch(m_CurrentState)
210  {
211  case ETurretState.NONE:
212  case ETurretState.DESTROYED:
213  return false;
214  case ETurretState.DISASSEMBLED:
215  outName = "#AR-UserAction_Assemble-UC";
216  return true;
217  case ETurretState.ASSEMBLED:
218  outName = "#AR-UserAction_Disassemble-UC";
219  return true;
220  }
221 
222  return false;
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
227  {
228  m_Owner = pOwnerEntity;
229  m_CurrentState = ETurretState.NONE;
230  }
231 };
DISASSEMBLED
@ DISASSEMBLED
Definition: SCR_TurretAssemblyAction.c:5
ScriptedUserAction
Definition: ScriptedUserAction.c:12
ETurretState
ETurretState
Definition: SCR_TurretAssemblyAction.c:1
NONE
@ NONE
Definition: SCR_TurretAssemblyAction.c:3
SCR_TurretAssemblyAction
Definition: SCR_TurretAssemblyAction.c:9
ASSEMBLED
@ ASSEMBLED
Definition: SCR_TurretAssemblyAction.c:6
DESTROYED
@ DESTROYED
Definition: SCR_TurretAssemblyAction.c:4
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner