// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "Engine/DataTable.h" #include "Materials/MaterialInstance.h" #include "Materials/MaterialInstanceDynamic.h" #include "Engine/HitResult.h" #include "Item.generated.h" class UBoxComponent; class UWidgetComponent; class USphereComponent; class UCurveFloat; class AShooterCharacter; class USoundCue; class UCurveVector; class UDataTable; UENUM(BlueprintType) enum class EItemRarity : uint8 { EIR_Damaged UMETA(DisplayName = "Damaged"), EIR_Common UMETA(DisplayName = "Common"), EIR_Uncommon UMETA(DisplayName = "Uncommon"), EIR_Rare UMETA(DisplayName = "Rare"), EIR_Legendary UMETA(DisplayName = "Legendary"), EIR_MAX UMETA(DisplayName = "DefaultMAX") }; UENUM(BlueprintType) enum class EItemState : uint8 { EIS_Pickup UMETA(DisplayName = "Pickup"), EIS_EquipInterping UMETA(DisplayName = "EquipInterping"), EIS_PickedUp UMETA(DisplayName = "PickedUp"), EIS_Equipped UMETA(DisplayName = "Equipped"), EIS_Falling UMETA(DisplayName = "Falling"), EIS_MAX UMETA(DisplayName = "DefaultMAX") }; UENUM(BlueprintType) enum class EItemType : uint8 { EIT_Ammo UMETA(DisplayName = "Ammo"), EIT_Weapon UMETA(DisplayName = "Weapon"), EIT_MAX UMETA(DisplayName = "DefaultMAX") }; USTRUCT(BlueprintType) struct FItemRarityTable : public FTableRowBase { GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite) FLinearColor GlowColor; UPROPERTY(EditAnywhere, BlueprintReadWrite) FLinearColor LightColor; UPROPERTY(EditAnywhere, BlueprintReadWrite) FLinearColor DarkColor; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 NumberOfStars; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* IconBackground; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 CustomDepthStencil; UPROPERTY(EditAnywhere, BlueprintReadWrite) float DamageMultiplier; }; UCLASS() class SHOOTER_API AItem : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AItem(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; // Sets the ActiveStars array of bools based on rarity void setActiveStars(); /** Sets properties of the Item's components based on State */ virtual void SetItemProperties(EItemState State); /** Called when ItemInterpTimer is finished*/ void FinishInterping(); /* Line trace collides with box to show HUD widgets */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UBoxComponent* CollisionBox; /* Popup widget for when the player looks at the item */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UWidgetComponent* PickupWidget; /* Enables item tracing when overlapped */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) USphereComponent* AreaSphere; void PlayPickupSound(bool bForcePlaySound = false); virtual void InitializeCustomDepth(); virtual void OnConstruction(const FTransform& Transform) override; void ResetPulseTimer(); void StartPulseTimer(); void UpdatePulse(); public: // Called every frame virtual void Tick(float DeltaTime) override; /* Called when overlapping AreaSphere */ UFUNCTION() void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); /* Called when end overlapping AreaSphere */ UFUNCTION() void OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); /** Handles item interpolation when in the EquipInterping state */ void ItemInterp(float DeltaTime); /** Get interp location based on the item type */ FVector GetInterpLocation(); // Called in AShooterCharacter::GetPickupItem void PlayEquipSound(bool bForcePlaySound = false); private: /* Skeletal mesh for the item */ UPROPERTY(VisibleAnywhere, BlueprintReadonly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) USkeletalMeshComponent* ItemMesh; UPROPERTY(VisibleAnywhere, BlueprintReadonly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float AreaSphereRadius; /* The name which appears on the Pickup Widget */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) FString ItemName; /* Item count (Ammo, etc...) */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) int32 ItemCount; /* Item rarity - determines number of stars in Pickup Widget */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) EItemRarity ItemRarity; /** State of the Item */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) EItemState ItemState; /** The curve asset to use for the item's Z location when interping */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UCurveFloat* ItemZCurve; /** Starting location when interping begins */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) FVector ItemInterpStartLocation; /** Target interp location in front of the camera */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) FVector CameraTargetLocation; /** true when interping */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) bool bInterping; /** Plays when we start interping */ FTimerHandle ItemInterpTimer; /** Duration of the curve and timer */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float ZCurveTime; /** Pointer to the character */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) AShooterCharacter* Character; /** X and Y for the item while interping in the EquipInterping state */ float ItemIntepX; float ItemIntepY; /** Initial Yaw offset between the camera and the interping item */ float InterpInitialYawOffset; /** Curve used to scale the item when interping */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UCurveFloat* ItemScaleCurve; /** Sound played when item is picked up */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) USoundCue* PickupSound; /** Sound played when item is equipped */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) USoundCue* EquipSound; /** Enum for the type of item this Item is */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) EItemType ItemType; /** Index of the interp location this item is interping to */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) int32 InterpLocIndex; /** Index for the material we'd like to change at runtime */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) int32 MaterialIndex; /** Dynamic instance that we can change at runtime */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UMaterialInstanceDynamic* DynamicMaterialInstance; /** Material instance used with the dynamic material instance */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UMaterialInstance* MaterialInstance; bool bCanChangeCustomDepth; /** Curve to drive the dynamic material parameters */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UCurveVector* PulseCurve; /** Curve to drive the dynamic material parameters */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UCurveVector* InterpPulseCurve; FTimerHandle PulseTimer; /** Time for the pulse timer */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float PulseCurveTime; UPROPERTY(VisibleAnywhere, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float GlowAmount; UPROPERTY(VisibleAnywhere, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float FresnelExponent; UPROPERTY(VisibleAnywhere, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float FresnelReflectFraction; /** Icon for this item in the inventory */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) UTexture2D* IconItem; /** Icon for this item's ammo in the inventory */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) UTexture2D* IconAmmo; /** Slot in the inventory array */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) int32 SlotIndex; /** True when the character's inventory is full */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) bool bCharacterInventoryFull; /* Item rarity - determines number of stars in Pickup Widget */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) TArray ActiveStars; /** Item Rarity data table */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) UDataTable* ItemRarityDataTable; /** Color in the glow material */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) FLinearColor GlowColor; /** Light color in the pickup widget */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) FLinearColor LightColor; /** Dark color in the pickup widget */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) FLinearColor DarkColor; /** Number of stars in the pickup widget */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) int32 NumberOfStars; /** Background icon for the inventory */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) UTexture2D* IconBackground; /** Damage multiplier applied on the weapon damage */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) float DamageMultiplier; public: FORCEINLINE UWidgetComponent* GetPickupWidget() const { return PickupWidget; } FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; } FORCEINLINE UBoxComponent* GetCollisionBox() const { return CollisionBox; } FORCEINLINE EItemState GetItemState() const { return ItemState; } void SetItemState(EItemState State); FORCEINLINE USkeletalMeshComponent* GetItemMesh() const { return ItemMesh; } FORCEINLINE USoundCue* GetPickupSound() const { return PickupSound; } FORCEINLINE void SetPickupSound(USoundCue* Sound) { PickupSound = Sound; } FORCEINLINE USoundCue* GetEquipSound() const { return EquipSound; } FORCEINLINE void SetEquipSound(USoundCue* Sound) { EquipSound = Sound; } FORCEINLINE int32 GetItemCount() const { return ItemCount; } FORCEINLINE int32 GetSlotIndex() const { return SlotIndex; } FORCEINLINE void SetSlotIndex(int32 Index) { SlotIndex = Index; } FORCEINLINE void SetCharacter(AShooterCharacter* Char) { Character = Char; } FORCEINLINE void SetCharacterInventoryFull(bool bFull) { bCharacterInventoryFull = bFull; } FORCEINLINE void SetItemName(FString Name) { ItemName = Name; } FORCEINLINE void SetIconItem(UTexture2D* Icon) { IconItem = Icon; } FORCEINLINE void SetIconAmmo(UTexture2D* Icon) { IconAmmo = Icon; } FORCEINLINE UMaterialInstance* GetMaterialInstance() const { return MaterialInstance; } FORCEINLINE void SetMaterialInstance(UMaterialInstance* Instance) { MaterialInstance = Instance; } FORCEINLINE UMaterialInstanceDynamic* GetDynamicMaterialInstance() const { return DynamicMaterialInstance; } FORCEINLINE void SetDynamicMaterialInstance(UMaterialInstanceDynamic* Instance) { DynamicMaterialInstance = Instance; } FORCEINLINE FLinearColor GetGlowColor() const { return GlowColor; } FORCEINLINE void SetMaterialIndex(int32 Index) { MaterialIndex = Index; } FORCEINLINE int32 GetMaterialIndex() const { return MaterialIndex; } FORCEINLINE float GetDamageMultiplier() const { return DamageMultiplier; } /** Called from the AShooterCharacter class */ void StartItemCurve(AShooterCharacter* Char, bool bForcePlaySound = false); virtual void EnableCustomDepth(); virtual void DisableCustomDepth(); void EnableGlowMaterial(); void DisableGlowMaterial(); };