// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "Item.generated.h" class UBoxComponent; class UWidgetComponent; class USphereComponent; class UCurveFloat; class AShooterCharacter; class USoundCue; class UCurveVector; 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 = "Damaged"), 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") }; 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(); 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(); 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 = "Item Properties", meta = (AllowPrivateAccess = true)) EItemRarity ItemRarity; /* Item rarity - determines number of stars in Pickup Widget */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) TArray ActiveStars; /** 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; /** Background for this item in the inventory */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) UTexture2D* IconBackground; /** 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; 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 USoundCue* GetEquipSound() const { return EquipSound; } FORCEINLINE int32 GetItemCount() const { return ItemCount; } FORCEINLINE int32 GetSlotIndex() const { return SlotIndex; } FORCEINLINE void SetSlotIndex(int32 Index) { SlotIndex = Index; } /** Called from the AShooterCharacter class */ void StartItemCurve(AShooterCharacter* Char); virtual void EnableCustomDepth(); virtual void DisableCustomDepth(); void EnableGlowMaterial(); void DisableGlowMaterial(); };