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


#include "MainBountyClass.h"

void AMainBountyClass::IncrementBountyCheckpoint()
{
	Super::IncrementBountyCheckpoint();
	CompletedACheckpoint.Broadcast();
	// FString TipToDisplay = "";
	// if (!Completed) TipToDisplay = BountyCheckpoints[0]->GetCheckpointTip();
	// Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->CheckpointCompletedUI("", false);
}

void AMainBountyClass::ActivateFirstCheckpoint()
{
	Super::ActivateFirstCheckpoint();
	if (IsValid(OpenWorldcheckpoint)) OpenWorldcheckpoint->SpawnWaypoint(MainBountyStruct.TargetName);
	if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr) return;
	BountyCheckpoints[0]->SpawnWaypoint(MainBountyStruct.TargetName);
}

void AMainBountyClass::DeActivateFirstCheckpoint()
{
	Super::DeActivateFirstCheckpoint();
	if (IsValid(OpenWorldcheckpoint)) OpenWorldcheckpoint->DestroyWaypoint();
}

	void AMainBountyClass::SpawnOpenWorldCheckpoint()
{
	if (!IsValid(OpenWorldCheckpointClass)) return;
	
	FActorSpawnParameters SpawnParameters;
	SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	FVector Loc = OpenWorldCheckpointClass.GetDefaultObject()->GetCheckpointSpawnTransform().GetLocation();
	FRotator Rot = OpenWorldCheckpointClass.GetDefaultObject()->GetCheckpointSpawnTransform().GetRotation().Rotator();
	
	OpenWorldcheckpoint = GetWorld()->SpawnActor<ACheckpointClass>(OpenWorldCheckpointClass, Loc, Rot, SpawnParameters);
	ActivateFirstCheckpoint();
}

void AMainBountyClass::SpawnCheckpoints()
{
	Super::SpawnCheckpoints();
	ActivateFirstCheckpoint();
}








void AMainBountyClass::SpawnAmmoDrops()
{
	UE_LOG(LogTemp, Display, TEXT("Bought Ammo Drops, but its not implemented yet"));
	// FActorSpawnParameters SpawnParameters;
	// SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	// for (FTransform Spawn : AmmoDropSpawnTransforms)
	// {
	// 	GetWorld()->SpawnActor<AActor>(AmmoDropClass, Spawn.GetLocation(), Spawn.GetRotation().Rotator(), SpawnParameters);
	// }
}

void AMainBountyClass::SpawnHealthDrops()
{
	UE_LOG(LogTemp, Display, TEXT("Bought Health Drops, but its not implemented yet"));
	// FActorSpawnParameters SpawnParameters;
	// SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	// for (FTransform Spawn : HealthDropSpawnTransforms)
	// {
	// 	GetWorld()->SpawnActor<AActor>(HealthDropClass, Spawn.GetLocation(), Spawn.GetRotation().Rotator(), SpawnParameters);
	// }
}