Files
BallisticsDocs/Source/EasyBallistics/Public/EBWeaponData.h
T
2025-07-10 01:02:24 -07:00

619 lines
20 KiB
C++

// Copyright 2016 Mookie. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "Engine/SkeletalMesh.h"
#include "Engine/StaticMesh.h"
#include "Animation/AnimSequence.h"
#include "Animation/AnimBlueprint.h"
#include "Sound/SoundCue.h"
#include "NiagaraSystem.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraDataInterface.h"
#include "EBBulletProperties.h"
#include "EBBarrel.h"
#include "EBWeaponData.generated.h"
/**
* Weapon Type Classification
*/
UENUM(BlueprintType)
enum class EWeaponType : uint8
{
Rifle UMETA(DisplayName = "Rifle"),
Pistol UMETA(DisplayName = "Pistol"),
Shotgun UMETA(DisplayName = "Shotgun"),
SMG UMETA(DisplayName = "SMG"),
LMG UMETA(DisplayName = "LMG"),
Sniper UMETA(DisplayName = "Sniper"),
Launcher UMETA(DisplayName = "Launcher"),
Melee UMETA(DisplayName = "Melee"),
Special UMETA(DisplayName = "Special")
};
/**
* Weapon Audio Configuration
*/
USTRUCT(BlueprintType)
struct FWeaponAudio
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
USoundCue* FireSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
USoundCue* EmptyFireSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
USoundCue* ReloadSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
USoundCue* EquipSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
USoundCue* UnequipSound;
FWeaponAudio()
{
FireSound = nullptr;
EmptyFireSound = nullptr;
ReloadSound = nullptr;
EquipSound = nullptr;
UnequipSound = nullptr;
}
};
/**
* Niagara Effect Parameters for Dynamic Control
*/
USTRUCT(BlueprintType)
struct FNiagaraEffectParams
{
GENERATED_USTRUCT_BODY()
/** Effect intensity multiplier */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters", meta = (ClampMin = "0.0", ClampMax = "5.0"))
float Intensity = 1.0f;
/** Effect scale multiplier */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters", meta = (ClampMin = "0.1", ClampMax = "10.0"))
float Scale = 1.0f;
/** Effect color tint */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters")
FLinearColor ColorTint = FLinearColor::White;
/** Custom float parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters")
TMap<FString, float> FloatParameters;
/** Custom vector parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters")
TMap<FString, FVector> VectorParameters;
/** Custom boolean parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parameters")
TMap<FString, bool> BoolParameters;
};
/**
* Advanced Niagara Weapon Visual Effects Configuration
*/
USTRUCT(BlueprintType)
struct FWeaponVFX
{
GENERATED_USTRUCT_BODY()
// === MUZZLE EFFECTS ===
/** Primary muzzle flash effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Muzzle")
UNiagaraSystem* MuzzleFlash;
/** Muzzle flash parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Muzzle")
FNiagaraEffectParams MuzzleFlashParams;
/** Muzzle smoke effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Muzzle")
UNiagaraSystem* MuzzleSmoke;
/** Muzzle smoke parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Muzzle")
FNiagaraEffectParams MuzzleSmokeParams;
/** Suppressed muzzle effect (when suppressor attached) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Muzzle")
UNiagaraSystem* SuppressedMuzzleFlash;
// === SHELL EJECTION ===
/** Ejected shell/casing effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Shells")
UNiagaraSystem* EjectedShell;
/** Shell ejection parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Shells")
FNiagaraEffectParams EjectedShellParams;
/** Shell ejection velocity */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Shells")
FVector ShellEjectionVelocity = FVector(200.0f, 100.0f, 50.0f);
/** Shell physics material for bouncing sounds */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Shells")
UPhysicalMaterial* ShellPhysicsMaterial;
// === PROJECTILE EFFECTS ===
/** Bullet tracer effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Projectile")
UNiagaraSystem* TracerEffect;
/** Tracer parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Projectile")
FNiagaraEffectParams TracerParams;
/** Bullet trail/wake effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Projectile")
UNiagaraSystem* BulletTrail;
/** Supersonic crack effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Projectile")
UNiagaraSystem* SonicCrack;
// === IMPACT EFFECTS ===
/** Default hit impact effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Impact")
UNiagaraSystem* HitImpact;
/** Impact parameters */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Impact")
FNiagaraEffectParams HitImpactParams;
/** Material-specific impact effects */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Impact")
TMap<UPhysicalMaterial*, UNiagaraSystem*> MaterialImpactEffects;
/** Penetration effect (when bullet goes through) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Impact")
UNiagaraSystem* PenetrationEffect;
/** Ricochet effect */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Impact")
UNiagaraSystem* RicochetEffect;
// === ADVANCED SETTINGS ===
/** Enable dynamic weather effects (rain interaction, etc.) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Advanced")
bool bEnableWeatherEffects = true;
/** Enable heat distortion from barrel */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Advanced")
bool bEnableHeatDistortion = true;
/** Heat buildup effect from sustained fire */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Advanced")
UNiagaraSystem* BarrelHeatEffect;
/** Weapon attachment glow/energy effects */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Advanced")
UNiagaraSystem* AttachmentGlowEffect;
/** LOD settings for performance */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VFX|Advanced")
float EffectLODDistance = 1000.0f;
FWeaponVFX()
{
// Initialize all effects to null
MuzzleFlash = nullptr;
MuzzleSmoke = nullptr;
SuppressedMuzzleFlash = nullptr;
EjectedShell = nullptr;
TracerEffect = nullptr;
BulletTrail = nullptr;
SonicCrack = nullptr;
HitImpact = nullptr;
PenetrationEffect = nullptr;
RicochetEffect = nullptr;
BarrelHeatEffect = nullptr;
AttachmentGlowEffect = nullptr;
ShellPhysicsMaterial = nullptr;
ShellEjectionVelocity = FVector(200.0f, 100.0f, 50.0f);
bEnableWeatherEffects = true;
bEnableHeatDistortion = true;
EffectLODDistance = 1000.0f;
}
};
/**
* Weapon Animation Configuration
*/
USTRUCT(BlueprintType)
struct FWeaponAnimations
{
GENERATED_USTRUCT_BODY()
/** First person weapon animations */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|FP")
UAnimSequence* FP_Fire;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|FP")
UAnimSequence* FP_Reload;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|FP")
UAnimSequence* FP_Equip;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|FP")
UAnimSequence* FP_Idle;
/** Third person character animations */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|TP")
UAnimSequence* TP_Fire;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|TP")
UAnimSequence* TP_Reload;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|TP")
UAnimSequence* TP_Equip;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations|TP")
UAnimSequence* TP_Idle;
/** Animation blueprint for complex animations */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
TSubclassOf<UAnimInstance> WeaponAnimBP;
FWeaponAnimations()
{
FP_Fire = nullptr;
FP_Reload = nullptr;
FP_Equip = nullptr;
FP_Idle = nullptr;
TP_Fire = nullptr;
TP_Reload = nullptr;
TP_Equip = nullptr;
TP_Idle = nullptr;
WeaponAnimBP = nullptr;
}
};
/**
* Weapon Data Asset - Industry Standard Approach
*
* This is how AAA games handle weapons:
* - Single persistent weapon actor
* - All weapon variations as data assets
* - Hot-swap meshes, stats, behavior
* - No actor spawning/despawning
* - Inventory is just array of data references
*/
UCLASS(BlueprintType, Blueprintable)
class EASYBALLISTICS_API UEBWeaponData : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
UEBWeaponData();
// ========================================
// WEAPON IDENTITY
// ========================================
/** Weapon display name */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Identity")
FText WeaponName;
/** Weapon description */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Identity")
FText WeaponDescription;
/** Weapon type classification */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Identity")
EWeaponType WeaponType;
/** Weapon icon for UI */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Identity")
UTexture2D* WeaponIcon;
/** Weapon rarity/tier */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Identity")
int32 WeaponTier = 1;
// ========================================
// VISUAL COMPONENTS
// ========================================
/** First person weapon mesh */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Visuals")
USkeletalMesh* FirstPersonMesh;
/** Third person weapon mesh */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Visuals")
USkeletalMesh* ThirdPersonMesh;
/** Static mesh fallback */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Visuals")
UStaticMesh* StaticMesh;
/** Material overrides for weapon customization */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Visuals")
TArray<UMaterialInterface*> MaterialOverrides;
// ========================================
// BALLISTICS & PERFORMANCE
// ========================================
/** Bullet properties for this weapon */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics")
UEBBulletPropertiesAsset* BulletProperties;
/** Damage per shot */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "1", ClampMax = "1000"))
float Damage = 30.0f;
/** Fire rate (rounds per minute) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "1", ClampMax = "1200"))
float FireRate = 600.0f;
/** Muzzle velocity in cm/s */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "10000", ClampMax = "200000"))
float MuzzleVelocity = 91440.0f;
/** Weapon accuracy (0-1, 1 = perfect) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "0.0", ClampMax = "1.0"))
float Accuracy = 0.95f;
/** Recoil strength */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "0.0", ClampMax = "10.0"))
float RecoilStrength = 1.0f;
/** Range in meters */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Ballistics", meta = (ClampMin = "10", ClampMax = "2000"))
float EffectiveRange = 300.0f;
// ========================================
// MAGAZINE & AMMO
// ========================================
/** Magazine capacity */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Magazine", meta = (ClampMin = "1", ClampMax = "200"))
int32 MagazineSize = 30;
/** Reserve ammo capacity */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Magazine", meta = (ClampMin = "0", ClampMax = "1000"))
int32 MaxReserveAmmo = 120;
/** Reload time in seconds */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Magazine", meta = (ClampMin = "0.5", ClampMax = "10.0"))
float ReloadTime = 2.5f;
/** Time for tactical reload (magazine not empty) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Magazine", meta = (ClampMin = "0.5", ClampMax = "10.0"))
float TacticalReloadTime = 2.0f;
// ========================================
// FIRE MODES
// ========================================
/** Available fire modes */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Fire Modes")
TArray<EFireMode> AvailableFireModes;
/** Default fire mode */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Fire Modes")
EFireMode DefaultFireMode = EFireMode::FM_Auto;
/** Burst count for burst fire */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Fire Modes", meta = (ClampMin = "2", ClampMax = "10"))
int32 BurstCount = 3;
// ========================================
// ATTACHMENTS & CUSTOMIZATION
// ========================================
/** Socket names for attachments */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attachments")
FName MuzzleSocketName = TEXT("MuzzleSocket");
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attachments")
FName ScopeSocketName = TEXT("ScopeSocket");
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attachments")
FName GripSocketName = TEXT("GripSocket");
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attachments")
FName LaserSocketName = TEXT("LaserSocket");
/** Supported attachment types */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attachments")
TArray<FString> SupportedAttachments;
// ========================================
// AUDIO & VFX
// ========================================
/** Audio configuration */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Audio & VFX")
FWeaponAudio AudioConfig;
/** Niagara visual effects configuration */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Audio & VFX")
FWeaponVFX VFXConfig;
// ========================================
// NIAGARA ADVANCED FEATURES
// ========================================
/** Global Niagara parameters for this weapon */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
FNiagaraEffectParams GlobalEffectParams;
/** Enable GPU simulation for high particle counts */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
bool bUseGPUSimulation = true;
/** Enable distance-based LOD for effects */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
bool bEnableEffectLOD = true;
/** Custom data interface for weapon stats */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
TSubclassOf<UNiagaraDataInterface> WeaponDataInterface;
/** Heat tracking for barrel effects */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
float MaxHeatLevel = 100.0f;
/** Heat decay rate per second */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
float HeatDecayRate = 10.0f;
/** Heat gain per shot */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Niagara Advanced")
float HeatPerShot = 5.0f;
/** Animation configuration */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Audio & VFX")
FWeaponAnimations AnimationConfig;
// ========================================
// ADVANCED SETTINGS
// ========================================
/** Weapon weight (affects movement speed) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced", meta = (ClampMin = "0.5", ClampMax = "20.0"))
float WeaponWeight = 3.5f;
/** ADS (Aim Down Sights) time */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced", meta = (ClampMin = "0.1", ClampMax = "2.0"))
float ADSTime = 0.3f;
/** Sprint-to-fire time */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced", meta = (ClampMin = "0.1", ClampMax = "1.0"))
float SprintToFireTime = 0.25f;
/** Draw/Equip time */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced", meta = (ClampMin = "0.2", ClampMax = "3.0"))
float EquipTime = 0.75f;
/** Whether weapon can be dual-wielded */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced")
bool bCanDualWield = false;
/** Whether weapon has safety */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced")
bool bHasSafety = true;
/** Whether weapon supports suppressors */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Advanced")
bool bSuppressorCompatible = true;
// ========================================
// DEBUG SETTINGS
// ========================================
/** Enable debug logging for weapon firing */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bEnableFireDebug = false;
/** Size of debug arrows for ballistic visualization */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug", meta = (ClampMin = "10.0", ClampMax = "500.0"))
float DebugArrowSize = 100.0f;
/** Show impact information in debug display */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugImpactInfo = false;
/** Enable trajectory debug visualization */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugTrajectory = false;
/** Enable physics debug visualization (drag, gravity, wind) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugPhysics = false;
/** Enable performance debug information */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugPerformance = false;
/** Enable ballistics debug visualization */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugBallistics = false;
/** Enable spalling debug visualization */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bDebugSpalling = false;
// ========================================
// UTILITY FUNCTIONS
// ========================================
/** Get fire rate in shots per second */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
float GetFireRatePerSecond() const { return FireRate / 60.0f; }
/** Get time between shots */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
float GetTimeBetweenShots() const { return 60.0f / FireRate; }
/** Get DPS (Damage Per Second) */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
float GetDPS() const { return Damage * GetFireRatePerSecond(); }
/** Check if fire mode is supported */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
bool IsFireModeSupported(EFireMode FireMode) const { return AvailableFireModes.Contains(FireMode); }
/** Get weapon type as string */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
FString GetWeaponTypeString() const;
/** Get current heat level (0-1) */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
float GetHeatLevel() const { return CurrentHeat / MaxHeatLevel; }
/** Add heat from firing */
UFUNCTION(BlueprintCallable, Category = "Weapon Data")
void AddHeat(float Amount = -1.0f);
/** Update heat decay */
UFUNCTION(BlueprintCallable, Category = "Weapon Data")
void UpdateHeat(float DeltaTime);
/** Is weapon overheated */
UFUNCTION(BlueprintPure, Category = "Weapon Data")
bool IsOverheated() const { return CurrentHeat >= MaxHeatLevel; }
// ========================================
// DEBUG UTILITY FUNCTIONS
// ========================================
/** Enable/disable specific bullet debug category */
UFUNCTION(BlueprintCallable, Category = "Debug")
void SetBulletDebugCategory(const FString& CategoryName, bool bEnabled);
/** Enable/disable all bullet debug categories */
UFUNCTION(BlueprintCallable, Category = "Debug")
void SetAllBulletDebugCategories(bool bEnabled);
/** Get current debug configuration as string */
UFUNCTION(BlueprintPure, Category = "Debug")
FString GetBulletDebugInfo() const;
/** Apply debug settings to connected barrel component */
UFUNCTION(BlueprintCallable, Category = "Debug")
void ApplyDebugSettingsToBarrel(class UEBBarrel* Barrel) const;
private:
/** Current heat level for effects */
float CurrentHeat = 0.0f;
/** Get primary data asset ID */
virtual FPrimaryAssetId GetPrimaryAssetId() const override
{
return FPrimaryAssetId("WeaponData", GetFName());
}
};