Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GetInUserAction.c
Go to the documentation of this file.
1 class SCR_GetInUserAction : SCR_CompartmentUserAction
2 {
3  protected const LocalizedString OCCUPIED_BY_SUPPLIES = "#AR-UserAction_SeatOccupied";
4 
5  protected SCR_BaseLockComponent m_pLockComp;
6  protected DamageManagerComponent m_DamageManager;
7  protected SCR_ResourceComponent m_ResourceComp;
8  protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
9 
10  //------------------------------------------------------------------------------------------------
11  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
12  {
13  IEntity vehicle = SCR_EntityHelper.GetMainParent(pOwnerEntity, true);
14  if (!vehicle)
15  return;
16 
17  m_pLockComp = SCR_BaseLockComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseLockComponent));
18  m_DamageManager = DamageManagerComponent.Cast(vehicle.FindComponent(DamageManagerComponent));
19 
20  //~ Hotfix to prevent get in action if the vehicle has supplies
21  m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
22  if (m_CompartmentManager && m_CompartmentManager.BlockSuppliesIfOccupied())
23  m_ResourceComp = SCR_ResourceComponent.FindResourceComponent(pOwnerEntity, true);
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
28  {
29  if (!pOwnerEntity || !pUserEntity)
30  return;
31 
32  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
33  if (!character)
34  return;
35 
36  BaseCompartmentSlot targetCompartment = GetCompartmentSlot();
37  if (!targetCompartment)
38  return;
39 
40  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
41  if (!compartmentAccess)
42  return;
43 
44  if (!compartmentAccess.GetInVehicle(pOwnerEntity, targetCompartment, GetRelevantDoorIndex(pUserEntity)))
45  return;
46 
47  super.PerformAction(pOwnerEntity, pUserEntity);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override bool CanBePerformedScript(IEntity user)
52  {
53  if (m_DamageManager && m_DamageManager.GetState() == EDamageState.DESTROYED)
54  return false;
55 
56  BaseCompartmentSlot compartment = GetCompartmentSlot();
57  if (!compartment)
58  return false;
59 
60  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(user);
61  if (!character)
62  return false;
63 
64  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
65  if (!compartmentAccess)
66  return false;
67 
68  //~ TODO: Hotfix until proper solution, only blocks player does not block AI or Editor actions
69  float storedResources;
70  if (m_ResourceComp && m_CompartmentManager && m_CompartmentManager.BlockSuppliesIfOccupied())
71  {
72  if (SCR_ResourceSystemHelper.GetStoredResources(m_ResourceComp, storedResources) && storedResources > 0)
73  {
74  SetCannotPerformReason(OCCUPIED_BY_SUPPLIES);
75  return false;
76  }
77  }
78 
79  IEntity owner = compartment.GetOwner();
80  Vehicle vehicle = Vehicle.Cast(SCR_EntityHelper.GetMainParent(owner, true));
81  if (vehicle)
82  {
83  Faction characterFaction = character.GetFaction();
84  Faction vehicleFaction = vehicle.GetFaction();
85  if (characterFaction && vehicleFaction && characterFaction.IsFactionEnemy(vehicleFaction))
86  {
87  SetCannotPerformReason("#AR-UserAction_SeatHostile");
88  return false;
89  }
90  }
91 
92  if (compartment.GetOccupant())
93  {
94  SetCannotPerformReason("#AR-UserAction_SeatOccupied");
95  return false;
96  }
97 
98  // Check if the position isn't lock.
99  if (m_pLockComp && m_pLockComp.IsLocked(user, compartment))
100  {
101  SetCannotPerformReason(m_pLockComp.GetCannotPerformReason(user));
102  return false;
103  }
104 
105  // Make sure vehicle can be enter via provided door, if not, set reason.
106  if (!compartmentAccess.CanGetInVehicleViaDoor(owner, compartment, GetRelevantDoorIndex(user)))
107  {
108  SetCannotPerformReason("#AR-UserAction_SeatObstructed");
109  return false;
110  }
111 
112  return true;
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  override bool CanBeShownScript(IEntity user)
117  {
118  if (m_DamageManager && m_DamageManager.GetState() == EDamageState.DESTROYED)
119  return false;
120 
121  BaseCompartmentSlot compartment = GetCompartmentSlot();
122  if (!compartment)
123  return false;
124 
125  ChimeraCharacter character = ChimeraCharacter.Cast(user);
126  if (character && character.IsInVehicle())
127  return false;
128 
129  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
130  if (!compartmentAccess)
131  return false;
132 
133  if (compartmentAccess.IsGettingIn() || compartmentAccess.IsGettingOut())
134  return false;
135 
136  return true;
137  }
138 };
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
SCR_ResourceSystemHelper
Definition: SCR_ResourceSystemHelper.c:1
EDamageState
EDamageState
Definition: EDamageState.c:12
m_CompartmentManager
protected SCR_BaseCompartmentManagerComponent m_CompartmentManager
Definition: SCR_VehicleDamageManagerComponent.c:191
SCR_GetInUserAction
Definition: SCR_GetInUserAction.c:1
Faction
Definition: Faction.c:12
DamageManagerComponent
Definition: DamageManagerComponent.c:12
m_DamageManager
DamageManagerComponent m_DamageManager
Definition: SCR_AITargetInfo.c:19
LocalizedString
Definition: LocalizedString.c:21