Reworked Side Bounty Spawning Technique

Every Bounty now stores there own side bounties, however, the bounty director still spawns them in
This commit is contained in:
Rafal Swierczek 2023-10-10 17:59:56 +01:00
parent 7bf1f7b59d
commit fa679b06b4
7 changed files with 22 additions and 93 deletions

Binary file not shown.

View File

@ -93,38 +93,4 @@ void ABountyClass::CollectRewards_Implementation()
UE_LOG(LogTemp, Warning, TEXT("The player has gained $%d for completing the bounty!"), RewardMoney);
}
void ABountyClass::UpdateBountyCheckpoints(TMap<int, TSubclassOf<ACheckpointClass>> ReplacementCheckpoints)
{
if (ReplacementCheckpoints.IsEmpty())
{
UE_LOG(LogTemp, Warning, TEXT("No Replacement Steps found"));
return;
}
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
for (auto ReplacementCheckpoint : ReplacementCheckpoints)
{
BountyCheckpoints[ReplacementCheckpoint.Key]->Destroy();
ReplacementCheckpointClass = ReplacementCheckpoint.Value;
FVector Loc = ReplacementCheckpointClass.GetDefaultObject()->GetCheckpointSpawnTransform().GetLocation();
FRotator Rot = ReplacementCheckpointClass.GetDefaultObject()->GetCheckpointSpawnTransform().GetRotation().Rotator();
ACheckpointClass* SpawnedCheckpoint = Cast<ACheckpointClass>(GetWorld()->SpawnActor<AActor>(ReplacementCheckpoint.Value, Loc, Rot, SpawnParameters));
if (SpawnedCheckpoint == nullptr)
{
UE_LOG(LogTemp, Fatal, TEXT("The new checkpoint hasn't spawned in properly or can't be cast to"));
return;
}
BountyCheckpoints[ReplacementCheckpoint.Key] = SpawnedCheckpoint;
if (ReplacementCheckpoint.Key == 0)
{
BountyCheckpoints[ReplacementCheckpoint.Key]->Active = true;
BountyCheckpoints[ReplacementCheckpoint.Key]->CompletedCheckpoint.AddDynamic(this, &ABountyClass::IncrementBountyCheckpoint);
}
}
}

View File

@ -23,6 +23,9 @@ protected:
// ------- Properties Set in Editor --------------
UPROPERTY(EditDefaultsOnly, Category = "Bounty")
TArray<TSubclassOf<ACheckpointClass>> CheckpointsToSpawn;
UPROPERTY(EditDefaultsOnly, Category = "Bounty")
TArray<TSubclassOf<ABountyClass>> SideBountiesToSpawn;
UPROPERTY(EditDefaultsOnly, Category = "Bounty")
int RewardMoney = 0;
@ -62,6 +65,10 @@ public:
return Completed;
}
TArray<TSubclassOf<ABountyClass>> GetSideBountiesToSpawn()
{
return SideBountiesToSpawn;
}
FString GetBountyTitle()
{
return BountyTitle;
@ -136,7 +143,4 @@ public:
BountyCheckpoints[0]->Destroy();
}
// Called by Bounty Director, replaces specified checkpoints to alter Bounty when player completes a side bounty
void UpdateBountyCheckpoints(TMap<int, TSubclassOf<ACheckpointClass>> ReplacementCheckpoints);
};

View File

@ -34,14 +34,7 @@ void ABountyDirector::BeginPlay()
if (!IsValid(BountyAttachmentPoint)) UE_LOG(LogTemp, Fatal, TEXT("There's no Bounty Attachment UArrowComponent on Players Char "));
break;
}
// Setup up starting Side Bounty indexes
for (int Index = 0; Index < 3; Index++)
{
CurrentSideBountyIndexes.Add(Index);
}
ActiveSideBounties.SetNum(3);
SpawnBountyAndItsSideBounties();
UpdateBountyDisplay();
}
@ -66,22 +59,16 @@ void ABountyDirector::SpawnBountyAndItsSideBounties()
// WHEN MARCEL STOPS PLAYING WITH THE CHARACTER, ADD THIS BOUNTY TO PLAYERS ARRAY OF ACTIVE BOUNTIES!!!!!
ActiveBounty->CompletedFirstCheckpoint.AddDynamic(this, &ABountyDirector::DestroyActiveSideBounties);
// Spawn in Side Bounties which are linked to the Main Bounty
int ActiveSideBountyIndex = 0;
for (int CurrentSideBountyIndex : CurrentSideBountyIndexes)
ActiveSideBounties.Reset();
for (TSubclassOf<ABountyClass> SideBountyClass : ActiveBounty->GetSideBountiesToSpawn())
{
if (SideBountyClassArray.Num() <= CurrentSideBountyIndex || !IsValid(SideBountyClassArray[CurrentSideBountyIndex])) continue;
AActor* SideBountyActor = GetWorld()->SpawnActor<AActor>(SideBountyClassArray[CurrentSideBountyIndex], PlayerChar->GetActorLocation(), PlayerChar->GetActorRotation(), SpawnParams);
if (!IsValid(SideBountyClass)) continue;
AActor* SideBountyActor = GetWorld()->SpawnActor<AActor>(SideBountyClass, PlayerChar->GetActorLocation(), PlayerChar->GetActorRotation(), SpawnParams);
SideBountyActor->AttachToComponent(BountyAttachmentPoint, AttachmentTransformRules);
ASideBountyClass* SideBounty = Cast<ASideBountyClass>(SideBountyActor);
SideBounty->AttachToComponent(BountyAttachmentPoint, AttachmentTransformRules);
ActiveSideBounties[ActiveSideBountyIndex] = SideBounty;
SideBounty->ActiveSBC_Index = ActiveSideBountyIndex;
ActiveSideBounties[ActiveSideBountyIndex]->CompletedSideBounty.AddDynamic(this, &ABountyDirector::SideBountyCompleted);
if (!IsValid(SideBounty)) UE_LOG(LogTemp, Fatal, TEXT("A SideBounty for %s has been set to a wrong type"), *ActiveBounty->GetBountyTitle());
ActiveSideBounties.Add(SideBounty);
// ONCE AGAIN WHEN MARCEL STOPS PLAYING WITH THE CHARACTER, ADD THIS SIDE BOUNTY TO PLAYERS ARRAY OF ACTIVE BOUNTIES!!!!!
ActiveSideBountyIndex++;
}
}
@ -103,10 +90,6 @@ void ABountyDirector::FinishActiveBounty()
// Increment Main and Side Bounty Indexes
CurrentBountyIndex++;
for (int i = 0; i < 3; i++)
{
CurrentSideBountyIndexes[i] += 3;
}
// Game Completion Check
if (CurrentBountyIndex >= BountyClassArray.Num())
@ -136,17 +119,5 @@ void ABountyDirector::DestroyActiveSideBounties()
UpdateBountyDisplay();
}
void ABountyDirector::SideBountyCompleted(int SideBountyIndex)
{
UE_LOG(LogTemp,Warning,TEXT("Updating Main Bounties Checkpoints"));
ActiveBounty->UpdateBountyCheckpoints(ActiveSideBounties[SideBountyIndex]->GetReplacementCheckpoints());
// WHEN MARCEL STOPS PLAYING WITH PLAYER CHAR, REMOVE THIS SIDE BOUNTY FROM ACTIVE BOUNTIES
ActiveSideBounties[SideBountyIndex]->CollectRewards();
ActiveSideBounties[SideBountyIndex]->DestroyCheckpoints();
ActiveSideBounties[SideBountyIndex]->Destroy();
UpdateBountyDisplay();
}

View File

@ -23,14 +23,8 @@ class ENDLESSVENDETTA_API ABountyDirector : public AActor
UPROPERTY(EditDefaultsOnly, Category = "Bounty")
TArray<TSubclassOf<ABountyClass>> BountyClassArray;
// Ordered Array of Side Bounties, in three's
UPROPERTY(EditDefaultsOnly, Category = "Bounty")
TArray<TSubclassOf<ASideBountyClass>> SideBountyClassArray;
int CurrentBountyIndex = 0;
TArray<int> CurrentSideBountyIndexes;
UPROPERTY(VisibleAnywhere, Category = "Bounty")
ABountyClass* ActiveBounty;
@ -54,11 +48,7 @@ protected:
based on data from ActiveBC and ActiveSBC */
UFUNCTION(BlueprintImplementableEvent, Category = "bounty")
void UpdateBountyDisplay();
// Ran when a Side Bounty is completed and wants to update the active bounties checkpoints
UFUNCTION()
void SideBountyCompleted(int SideBountyIndex);
UFUNCTION()
void DestroyActiveSideBounties();
@ -93,6 +83,4 @@ public:
{
return (SideBountyIndex > 2 || SideBountyIndex < 0 || !IsValid(ActiveSideBounties[SideBountyIndex])) ? FString("N/A") : ActiveSideBounties[SideBountyIndex]->GetBountyDesc();
}
};