18 private ref ScriptInvoker m_OnCompartmentEntered;
19 private ref ScriptInvoker m_OnCompartmentLeft;
24 protected const int WAIT_FOR_VEHICLE_MAX_TRIES = 10;
25 protected static int s_iWaitForVehicleTries = 0;
28 ScriptInvoker GetOnCompartmentEntered(
bool createNew =
true)
30 if (!m_OnCompartmentEntered && createNew)
31 m_OnCompartmentEntered =
new ScriptInvoker();
32 return m_OnCompartmentEntered;
36 ScriptInvoker GetOnCompartmentLeft(
bool createNew =
true)
38 if (!m_OnCompartmentLeft && createNew)
39 m_OnCompartmentLeft =
new ScriptInvoker();
40 return m_OnCompartmentLeft;
46 if (!m_OnPlayerEnterCompartment && createNew)
49 return m_OnPlayerEnterCompartment;
55 if (!m_OnPlayerExitCompartment && createNew)
58 return m_OnPlayerExitCompartment;
62 override void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
64 if (m_OnCompartmentEntered)
65 m_OnCompartmentEntered.Invoke( targetEntity, manager, mgrID, slotID, move );
68 ChimeraCharacter character = ChimeraCharacter.Cast(
GetOwner());
70 if (!playerManager || !character)
78 int playerId = playerManager.GetPlayerIdFromControlledEntity(character);
82 if (m_OnPlayerEnterCompartment)
83 m_OnPlayerEnterCompartment.Invoke(character, targetEntity);
87 override void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
89 if (m_OnCompartmentLeft)
90 m_OnCompartmentLeft.Invoke( targetEntity, manager, mgrID, slotID, move );
93 ChimeraCharacter character = ChimeraCharacter.Cast(
GetOwner());
95 if (!playerManager || !character)
99 int playerId = playerManager.GetPlayerIdFromControlledEntity(character);
103 if (m_OnPlayerExitCompartment)
104 m_OnPlayerExitCompartment.Invoke(character, targetEntity);
110 IEntity vehicle = GetVehicle();
115 if (!vehicleFactionAff)
118 vehicleFactionAff.OnOccupantLifeStateChanged(previousLifeState, newLifeState);
127 BaseCompartmentSlot FindFreeAndAccessibleCompartment(IEntity vehicle,
ECompartmentType compartmentType, BaseCompartmentSlot customSlot =
null)
129 BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(vehicle.FindComponent(BaseCompartmentManagerComponent));
130 if (!compartmentManager)
133 array<BaseCompartmentSlot> compartments = {};
134 compartmentManager.GetCompartments(compartments);
138 if (!customSlot.IsCompartmentAccessible())
140 if (customSlot.IsGetInLockedFor(
GetOwner()))
142 if (customSlot.GetOccupant())
144 if (compartmentType != customSlot.GetType())
150 foreach (BaseCompartmentSlot compartment: compartments)
152 if (!compartment.IsCompartmentAccessible())
154 if (compartment.IsGetInLockedFor(
GetOwner()))
156 if (compartment.GetOccupant())
158 if (compartmentType != compartment.GetType())
165 BaseCompartmentSlot childSlot;
166 IEntity child = vehicle.GetChildren();
169 childSlot = FindFreeAndAccessibleCompartment(child, compartmentType);
173 child = child.GetSibling();
186 bool MoveInVehicle(IEntity vehicle,
ECompartmentType compartmentType, BaseCompartmentSlot customSlot =
null)
192 BaseCompartmentSlot slot = FindFreeAndAccessibleCompartment(vehicle, compartmentType, customSlot);
197 IEntity slotEntity = slot.GetOwner();
198 RplComponent slotRplComponent = RplComponent.Cast(slotEntity.FindComponent(RplComponent));
199 RplId slotEntityID = slotRplComponent.Id();
200 int slotID = slot.GetCompartmentSlotID();
201 Rpc(MoveInVehicleOwner, slotEntityID, slotID);
204 slot.SetCompartmentAccessible(
false);
205 GetGame().GetCallqueue().CallLater(slot.SetCompartmentAccessible, 1,
false,
true);
209 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
210 protected void MoveInVehicleOwner(RplId slotEntityID,
int slotID)
212 RplComponent slotRplComponent = RplComponent.Cast(Replication.FindItem(slotEntityID));
213 if (!slotRplComponent)
215 if (s_iWaitForVehicleTries >= WAIT_FOR_VEHICLE_MAX_TRIES)
218 s_iWaitForVehicleTries = 0;
222 GetGame().GetCallqueue().CallLater(MoveInVehicleOwner, 1000,
false, slotEntityID, slotID);
223 s_iWaitForVehicleTries++;
227 s_iWaitForVehicleTries = 0;
229 IEntity slotEntity = slotRplComponent.GetEntity();
231 BaseCompartmentManagerComponent slotCompartmentManager = BaseCompartmentManagerComponent.Cast(slotEntity.FindComponent(BaseCompartmentManagerComponent));
232 BaseCompartmentSlot slot = slotCompartmentManager.FindCompartment(slotID);
235 MoveInVehicle(slotEntity, slot);
244 bool MoveInVehicleAny(IEntity vehicle)
274 IEntity GetVehicle(out
int compartmentID)
284 ChimeraCharacter
char = ChimeraCharacter.Cast(
GetOwner());
300 [
Obsolete(
"Use GetType() on the compartment instance directly.")]
301 static ECompartmentType GetCompartmentType(notnull BaseCompartmentSlot compartment)
303 return compartment.GetType();