Skip to content

Commit

Permalink
AR 1.2 INT compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkensor committed May 16, 2024
1 parent 328c7ef commit d810fde
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class EPF_BaseInventoryStorageComponentSaveData : EPF_ComponentSaveData
override EPF_EApplyResult ApplyTo(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes)
{
BaseInventoryStorageComponent storageComponent = BaseInventoryStorageComponent.Cast(component);
InventoryStorageManagerComponent storageManager = InventoryStorageManagerComponent.Cast(storageComponent.GetOwner().FindComponent(InventoryStorageManagerComponent));
InventoryStorageManagerComponent storageManager = InventoryStorageManagerComponent.Cast(owner.FindComponent(InventoryStorageManagerComponent));
if (!storageManager) storageManager = EPF_GlobalInventoryStorageManagerComponent.GetInstance();

bool isNotBaked = !EPF_BitFlags.CheckFlags(EPF_Component<EPF_PersistenceComponent>.Find(owner).GetFlags(), EPF_EPersistenceFlags.BAKED);
Expand Down Expand Up @@ -178,9 +178,11 @@ class EPF_BaseInventoryStorageComponentSaveData : EPF_ComponentSaveData
if (!slotEntity)
return EPF_EApplyResult.ERROR;

// Teleport to target position so it is within valid range and if insert fails becomes visible overflow
EPF_WorldUtils.Teleport(slotEntity, owner.GetOrigin(), owner.GetYawPitchRoll()[0]);

// Unable to add it to the storage parent, so put it on the ground at the parent origin
if (!storageManager.TryInsertItemInStorage(slotEntity, storageComponent, slot.m_iSlotIndex))
EPF_WorldUtils.Teleport(slotEntity, storageComponent.GetOwner().GetOrigin(), storageComponent.GetOwner().GetYawPitchRoll()[0]);
storageManager.TryInsertItemInStorage(slotEntity, storageComponent, slot.m_iSlotIndex);
}

// Delte any items not found in the storage data for non bakes that always save all slots
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ class EPF_CompartmentAccessComponentSaveData : EPF_ComponentSaveData
compartmentManager.GetCompartments(outCompartments);
if (m_iSlotIdx < outCompartments.Count())
{
compartment.MoveInVehicle(compartmentHolder, outCompartments.Get(m_iSlotIdx));
return EPF_EApplyResult.OK;
EPF_DeferredApplyResult.AddPending(this, "CompartmentAccessComponentSaveData::GetInVehicle");
compartment.GetInVehicle(compartmentHolder, outCompartments.Get(m_iSlotIdx), true, -1, ECloseDoorAfterActions.INVALID, true);
GetGame().GetCallqueue().CallLater(Complete, 500);
return EPF_EApplyResult.AWAIT_COMPLETION;
}
}

Expand All @@ -87,6 +89,11 @@ class EPF_CompartmentAccessComponentSaveData : EPF_ComponentSaveData
return EPF_EApplyResult.OK;
}

protected void Complete()
{
EPF_DeferredApplyResult.SetFinished(this, "CompartmentAccessComponentSaveData::GetInVehicle");
}

//------------------------------------------------------------------------------------------------
override bool Equals(notnull EPF_ComponentSaveData other)
{
Expand Down
30 changes: 6 additions & 24 deletions src/Scripts/Game/Components/EPF_VehicleControllerSaveData.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[EPF_ComponentSaveDataType(VehicleControllerComponent), EPF_ComponentSaveDataType(VehicleControllerComponent_SA), BaseContainerProps()]
[EPF_ComponentSaveDataType(VehicleControllerComponent), BaseContainerProps()]
class EPF_VehicleControllerSaveDataClass : EPF_ComponentSaveDataClass
{
}
Expand All @@ -11,17 +11,8 @@ class EPF_VehicleControllerSaveData : EPF_ComponentSaveData
//------------------------------------------------------------------------------------------------
override EPF_EReadResult ReadFrom(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes)
{
VehicleControllerComponent_SA vehicleController_SA = VehicleControllerComponent_SA.Cast(component);
if (vehicleController_SA)
{
m_bEngineOn = vehicleController_SA.IsEngineOn();
}
else
{
VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component);
if (vehicleController)
m_bEngineOn = vehicleController.IsEngineOn();
}
VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component);
m_bEngineOn = vehicleController.IsEngineOn();

if (!m_bEngineOn)
return EPF_EReadResult.DEFAULT;
Expand All @@ -32,18 +23,9 @@ class EPF_VehicleControllerSaveData : EPF_ComponentSaveData
//------------------------------------------------------------------------------------------------
override EPF_EApplyResult ApplyTo(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes)
{
VehicleControllerComponent_SA vehicleController_SA = VehicleControllerComponent_SA.Cast(component);
if (vehicleController_SA)
{
if (m_bEngineOn)
vehicleController_SA.ForceStartEngine();
}
else
{
VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component);
if (vehicleController && m_bEngineOn)
vehicleController.StartEngine();
}
VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component);
if (m_bEngineOn)
vehicleController.ForceStartEngine();

return EPF_EApplyResult.OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/Game/EPF_DbFind.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EPF_ComponentFieldBuilder
//------------------------------------------------------------------------------------------------
EDF_DbFindFieldCollectionHandlingBuilder Field(string fieldPath)
{
return EDF_DbFindFieldCollectionHandlingBuilder.Cast(m_pBuilder.Field(fieldPath));
return m_pBuilder.Field(fieldPath);
}

//------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/Game/EPF_NetworkUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EPF_NetworkUtils
if (rplId.IsValid())
{
RplComponent entityRpl = RplComponent.Cast(Replication.FindItem(rplId));
if (entityRpl) entity = IEntity.Cast(entityRpl.GetEntity());
if (entityRpl) entity = entityRpl.GetEntity();
}

return entity;
Expand Down
23 changes: 10 additions & 13 deletions src/Scripts/Game/EPF_PersistenceComponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
m_iLastSaved = System.GetUnixTime();

IEntity owner = GetOwner();
if (!owner)
{
Debug.Error("Failed to save entity, because it was already deleted.");
return null;
}

EPF_PersistenceComponentClass settings = EPF_PersistenceComponentClass.Cast(GetComponentData(owner));
EPF_EntitySaveData saveData = EPF_EntitySaveData.Cast(settings.m_tSaveDataType.Spawn());

Expand Down Expand Up @@ -386,7 +392,7 @@
}

// For vehicles we want to get notified when they encounter their first contact or start to be driven
if (settings.m_pSaveData.m_bTrimDefaults && (owner.FindComponent(VehicleControllerComponent) || owner.FindComponent(VehicleControllerComponent_SA)))
if (settings.m_pSaveData.m_bTrimDefaults && (owner.FindComponent(VehicleControllerComponent)))
{
SetEventMask(owner, EntityEvent.CONTACT);
EventHandlerManagerComponent ev = EPF_Component<EventHandlerManagerComponent>.Find(owner);
Expand Down Expand Up @@ -609,18 +615,9 @@
override event protected void EOnPhysicsMove(IEntity owner)
{
// Check for if engine is one as there is tiny jitter movement during engine startup we want to ignore.
VehicleControllerComponent_SA vehicleController_SA = EPF_Component<VehicleControllerComponent_SA>.Find(owner);
if (vehicleController_SA)
{
if (vehicleController_SA.IsEngineOn())
FlagAsMoved();
}
else
{
VehicleControllerComponent vehicleController = EPF_Component<VehicleControllerComponent>.Find(owner);
if (vehicleController && vehicleController.IsEngineOn())
FlagAsMoved();
}
VehicleControllerComponent vehicleController = EPF_Component<VehicleControllerComponent>.Find(owner);
if (vehicleController && vehicleController.IsEngineOn())
FlagAsMoved();
}

//------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/Game/EPF_PersistenceManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class EPF_PersistenceManager
}
}

IEntity entity = GetGame().SpawnEntityPrefab(resource, params: spawnParams);
IEntity entity = GetGame().SpawnEntityPrefab(resource, null, spawnParams);
if (!entity)
{
Debug.Error(string.Format("Failed to spawn entity '%1:%2'. Ignored.", saveData.Type().ToString(), saveData.GetId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class EPF_CharacterInventoryStorageComponentSaveData : EPF_BaseInventoryStorageC
m_aQuickSlotEntities = {};

SCR_CharacterInventoryStorageComponent inventoryStorage = SCR_CharacterInventoryStorageComponent.Cast(component);
foreach (int idx, IEntity item : inventoryStorage.GetQuickSlotItems())
foreach (int idx, auto quickslot: inventoryStorage.GetQuickSlotItems())
{
string persistentId = EPF_PersistenceComponent.GetPersistentId(item);
auto quickslotEntity = SCR_QuickslotEntityContainer.Cast(quickslot);
if (!quickslotEntity)
continue;

string persistentId = EPF_PersistenceComponent.GetPersistentId(quickslotEntity.GetEntity());
if (!persistentId) continue;

EPF_PersistentQuickSlotItem slot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ modded class SCR_CharacterInventoryStorageComponent
array<RplId> rplIds();
rplIds.Reserve(m_aQuickSlots.Count());

foreach (IEntity quickSlotItem : m_aQuickSlots)
foreach (auto quickSlot : m_aQuickSlots)
{
RplId rplId = RplId.Invalid();

if (quickSlotItem)
auto quickslotEntity = SCR_QuickslotEntityContainer.Cast(quickSlot);
if (quickslotEntity)
{
RplComponent replication = RplComponent.Cast(quickSlotItem.FindComponent(RplComponent));
auto replication = EPF_Component<RplComponent>.Find(quickslotEntity.GetEntity());
if (replication) rplId = replication.Id();
}

Expand All @@ -68,12 +69,21 @@ modded class SCR_CharacterInventoryStorageComponent
if (m_aQuickSlotsHistory.Count() < slotsCount)
m_aQuickSlotsHistory.Resize(slotsCount);

Print("EPF_Rpc_UpdateQuickSlotItems");

foreach (int idx, RplId rplId : rplIds)
{
IEntity slotEntity = EPF_NetworkUtils.FindEntityByRplId(rplId);
m_aQuickSlots.Set(idx, slotEntity);
PrintFormat("idx: %1, rplId:%2, entity:%3", idx, rplId, slotEntity);

if (slotEntity)
m_aQuickSlotsHistory.Set(idx, GetItemType(slotEntity));
{
super.StoreItemToQuickSlot(slotEntity, idx, true);
}
else
{
super.RemoveItemFromQuickSlotAtIndex(idx);
}
}
}

Expand All @@ -87,6 +97,7 @@ modded class SCR_CharacterInventoryStorageComponent
[RplRpc(RplChannel.Reliable, RplRcver.Owner)]
protected void Rpc_SetQuickBarItems(array<RplId> quickBarRplIds)
{
EPF_Rpc_UpdateQuickSlotItems(quickBarRplIds);
// Delay to allow items to be loaded. Alt: Wait until all RPL ids are known and keep it in queue on repeat until then
GetGame().GetCallqueue().CallLater(EPF_Rpc_UpdateQuickSlotItems, 500, param1: quickBarRplIds);
}
}

0 comments on commit d810fde

Please sign in to comment.