// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/AudioComponent.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
//#include "Engine/ActorChannel.h"
#include "OpenDoor.generated.h"



UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);
	float TotalMass() const;
	void FindAudioComponent();
	void FindPressurePlateComponent();
	
	//Tracks if Sound has been Played
	bool OpenDoorSoundHasBeenPlayed = false;
	bool CloseDoorSoundHasBeenPlayed = true;

private:

	float InitialYaw;
	float CurrentYaw;
	float DoorLastOpened = 0.f;
	bool HasSoundBeenPlayed = false;
	
	UPROPERTY(EditAnywhere)
	float MassToOpenDoor = 50.f; 

	UPROPERTY(EditAnywhere)
	float TargetAngleOfOpenDoor =90.f;

	UPROPERTY(EditAnywhere)
	float OpenDoorRotationSpeed = 2.f;

	UPROPERTY(EditAnywhere)
	float CloseDoorRotationSpeed = 0.5f;

	UPROPERTY(EditAnywhere)
	float DoorDelay = 2.f; //2 second delay

	UPROPERTY(EditAnywhere)
	ATriggerVolume* PressurePlate = nullptr;

	UPROPERTY(EditAnywhere)
	AActor* ActorThatOpens = nullptr;

	UPROPERTY()
	UAudioComponent* AudioComponent = nullptr;

};
