Files
FLESH/Source/FLESH/Public/FLESHDismembermentComponent.h
2025-04-23 01:18:06 +08:00

260 lines
9.1 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "NiagaraSystem.h"
#include "DismembermentSystem.h"
#include "FLESHDismembermentComponent.generated.h"
// Forward declarations
class USkeletalMeshComponent;
class UNiagaraSystem;
class UMaterialInterface;
class UDismembermentSystem;
/**
* Dismemberment type enum
*/
UENUM(BlueprintType)
enum class EDismembermentType : uint8
{
Cut UMETA(DisplayName = "Cut"), // Clean cut dismemberment
Tear UMETA(DisplayName = "Tear"), // Torn flesh dismemberment
Blast UMETA(DisplayName = "Blast"), // Explosion dismemberment
Crush UMETA(DisplayName = "Crush"), // Crushing dismemberment
Custom UMETA(DisplayName = "Custom") // Custom dismemberment type
};
/**
* Bone patch type for customizing dismemberment effects
*/
UENUM(BlueprintType)
enum class EBonePatchType : uint8
{
Default, // Default patch
Head, // Head specific patch
Arm, // Arm specific patch
Leg, // Leg specific patch
Torso, // Torso specific patch
Custom // Custom patch
};
/**
* Bone patch data structure for customizing dismemberment effects
*/
USTRUCT(BlueprintType)
struct FBonePatchData
{
GENERATED_BODY()
// Patch type
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
EBonePatchType PatchType = EBonePatchType::Default;
// Bone names affected by this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
TArray<FName> BoneNames;
// Custom cut material for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
TObjectPtr<UMaterialInterface> CustomCutMaterial = nullptr;
// Custom blood effect for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
TObjectPtr<UNiagaraSystem> CustomBloodEffect = nullptr;
// Damage multiplier for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment", meta = (ClampMin = "0.0", ClampMax = "10.0"))
float DamageMultiplier = 1.0f;
// Whether this patch has organs
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
bool bHasOrgans = false;
// Organ mesh for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment", meta = (EditCondition = "bHasOrgans"))
TObjectPtr<UStaticMesh> OrganMesh = nullptr;
// Organ material for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment", meta = (EditCondition = "bHasOrgans"))
TObjectPtr<UMaterialInterface> OrganMaterial = nullptr;
// Whether this patch has custom physics
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment")
bool bHasCustomPhysics = false;
// Physics asset for this patch
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FLESH|Dismemberment", meta = (EditCondition = "bHasCustomPhysics"))
TObjectPtr<UPhysicsAsset> CustomPhysicsAsset = nullptr;
// Constructor
FBonePatchData()
{
}
};
/**
* Main component for the FLESH dismemberment system with blueprint support
* Provides easy-to-use blueprint interface for the dismemberment system
*/
UCLASS(ClassGroup=(FLESH), meta=(BlueprintSpawnableComponent))
class FLESH_API UFLESHDismembermentComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UFLESHDismembermentComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
/**
* Perform a cut at the specified location and direction
* @param CutLocation - World location of the cut
* @param CutDirection - Direction of the cut
* @param CutWidth - Width of the cut
* @param CutDepth - Depth of the cut
* @return True if the cut was successful
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool PerformCut(const FVector& CutLocation, const FVector& CutDirection, float CutWidth = 1.0f, float CutDepth = 10.0f);
/**
* Perform a cut using a transformation matrix
* @param CutTransform - Transformation matrix for the cut
* @param CutWidth - Width of the cut
* @param CutDepth - Depth of the cut
* @return True if the cut was successful
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool PerformCutWithMatrix(const FMatrix& CutTransform, float CutWidth = 1.0f, float CutDepth = 10.0f);
/**
* Dismember a specific bone
* @param BoneName - Name of the bone to dismember
* @param DismembermentType - Type of dismemberment to perform
* @return True if the dismemberment was successful
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool DismemberBone(const FName& BoneName, EDismembermentType DismembermentType = EDismembermentType::Cut);
/**
* Apply damage to a specific bone
* @param BoneName - Name of the bone to damage
* @param Damage - Amount of damage to apply
* @param DamageLocation - World location of the damage
* @param DamageDirection - Direction of the damage
* @param DismembermentType - Type of damage for potential dismemberment
* @return True if damage was applied
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool ApplyBoneDamage(const FName& BoneName, float Damage, const FVector& DamageLocation, const FVector& DamageDirection, EDismembermentType DismembermentType = EDismembermentType::Cut);
/**
* Add a bone patch
* @param PatchData - Patch data to add
* @return True if the patch was added
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool AddBonePatch(const FBonePatchData& PatchData);
/**
* Remove a bone patch
* @param PatchType - Type of patch to remove
* @return True if the patch was removed
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool RemoveBonePatch(EBonePatchType PatchType);
/**
* Get a bone patch by type
* @param PatchType - Type of patch to get
* @param OutPatchData - Output patch data
* @return True if the patch was found
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
bool GetBonePatch(EBonePatchType PatchType, FBonePatchData& OutPatchData) const;
/**
* Get all bone patches
* @return Array of all bone patches
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
TArray<FBonePatchData> GetAllBonePatches() const;
/**
* Reset all dismemberment (restore all bones)
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
void ResetDismemberment();
/**
* Set the blood effect for dismemberment
* @param BloodEffect - Niagara system for blood effects
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
void SetBloodEffect(UNiagaraSystem* BloodEffect);
/**
* Set the cut material for dismemberment
* @param CutMaterial - Material to use for cut surfaces
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
void SetCutMaterial(UMaterialInterface* CutMaterial);
/**
* Set whether to show organs
* @param bShow - Whether to show organs
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
void SetShowOrgans(bool bShow);
/**
* Set whether to enable physics
* @param bEnable - Whether to enable physics
*/
UFUNCTION(BlueprintCallable, Category = "FLESH|Dismemberment")
void SetEnablePhysics(bool bEnable);
private:
// The dismemberment system
UPROPERTY()
TObjectPtr<UDismembermentSystem> DismembermentSystem;
// The target skeletal mesh component
UPROPERTY()
TObjectPtr<USkeletalMeshComponent> TargetMesh;
// Default blood effect
UPROPERTY(EditAnywhere, Category = "FLESH|Dismemberment", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UNiagaraSystem> DefaultBloodEffect;
// Default cut material
UPROPERTY(EditAnywhere, Category = "FLESH|Dismemberment", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UMaterialInterface> DefaultCutMaterial;
// Whether to show organs
UPROPERTY(EditAnywhere, Category = "FLESH|Dismemberment", meta = (AllowPrivateAccess = "true"))
bool bShowOrgans = true;
// Whether to enable physics
UPROPERTY(EditAnywhere, Category = "FLESH|Dismemberment", meta = (AllowPrivateAccess = "true"))
bool bEnablePhysics = true;
// Bone patches
UPROPERTY(EditAnywhere, Category = "FLESH|Dismemberment", meta = (AllowPrivateAccess = "true"))
TArray<FBonePatchData> BonePatches;
// Internal function to find a bone patch by type
int32 FindBonePatchIndex(EBonePatchType PatchType) const;
// Internal function to apply a bone patch
void ApplyBonePatch(const FBonePatchData& PatchData);
};