Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions addons/core/scripts/Game/ACE_Core/Global/ACE_BulletTools.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//------------------------------------------------------------------------------------------------
class ACE_BulletTools
{
//------------------------------------------------------------------------------------------------
//! Return default bullet resource names of a muzzle
static array<ResourceName> GetDefaultResourceNamesFromMuzzle(BaseMuzzleComponent muzzle)
{
ResourceName magazineOrProjectilePrefabName = muzzle.GetDefaultMagazineOrProjectileName();
if (magazineOrProjectilePrefabName.IsEmpty())
{
BaseMagazineComponent magazine = muzzle.GetMagazine();
if (!magazine)
return {};

magazineOrProjectilePrefabName = magazine.GetOwner().GetPrefabData().GetPrefabName();
}

array<ResourceName> bulletPrefabNames = GetResourceNamesFromMagazine(magazineOrProjectilePrefabName);
if (bulletPrefabNames)
return bulletPrefabNames;

return {magazineOrProjectilePrefabName};
}

//------------------------------------------------------------------------------------------------
//! Return all bullet resource names of a magazine
static array<ResourceName> GetResourceNamesFromMagazine(ResourceName magazinePrefabName)
{
Resource magazineRes = Resource.Load(magazinePrefabName);
if (!magazineRes.IsValid())
return null;

BaseContainer mazagineSource = magazineRes.GetResource().ToBaseContainer();
if (!mazagineSource)
return null;

IEntityComponentSource magazineComponentSource = ACE_BaseContainerTools.FindComponentSource(mazagineSource, BaseMagazineComponent);
if (!magazineComponentSource)
return null;

ResourceName ammoConfigName;
magazineComponentSource.Get("AmmoConfig", ammoConfigName);

Resource ammoConfigRes = Resource.Load(ammoConfigName);
if (!ammoConfigRes.IsValid())
return null;

BaseContainer ammonConfigSrc = ammoConfigRes.GetResource().ToBaseContainer();
if (!ammonConfigSrc)
return null;

array<ResourceName> ammoNames = {};
ammonConfigSrc.Get("AmmoResourceArray", ammoNames);
return ammoNames;
}

//------------------------------------------------------------------------------------------------
//! Return mass of bullet
static float GetMass(ResourceName bulletPrefabName)
{
return GetFloatProperty(bulletPrefabName, "Mass");
}

//------------------------------------------------------------------------------------------------
//! Return initial speed of bullet
static float GetInitialSpeed(ResourceName bulletPrefabName)
{
return GetFloatProperty(bulletPrefabName, "InitSpeed");
}

//------------------------------------------------------------------------------------------------
protected static float GetFloatProperty(ResourceName bulletPrefabName, string propertyName)
{
Resource bulletRes = Resource.Load(bulletPrefabName);
if (!bulletRes.IsValid())
return 0;

IEntitySource bulletSource = bulletRes.GetResource().ToEntitySource();
if (!bulletSource)
return 0;

IEntityComponentSource shellMovementSource = ACE_BaseContainerTools.FindComponentSource(bulletSource, ShellMoveComponent);
if (!shellMovementSource)
return 0;

float value;
shellMovementSource.Get(propertyName, value);
return value;
}
}