[박치영] Equipment Component 생성 및 버그 수정

main
pcyoung 2023-12-12 16:40:20 +09:00
parent 1c73b094ff
commit 1b2cd5570c
18 changed files with 194 additions and 75 deletions

Binary file not shown.

View File

@ -25,7 +25,7 @@ ACombatAIController::ACombatAIController()
AffiliationFilter.bDetectFriendlies = true;
AffiliationFilter.bDetectNeutrals = true;
SightConfig->DetectionByAffiliation = AffiliationFilter;
SightConfig->AutoSuccessRangeFromLastSeenLocation = 1000.f;
SightConfig->AutoSuccessRangeFromLastSeenLocation = 2500.f;
PerceptionComponent->ConfigureSense(*SightConfig);
DamageConfig = CreateDefaultSubobject<UAISenseConfig_Damage>(TEXT("DamageConfig"));

View File

@ -27,7 +27,7 @@ public: //Delegate Func
void OnCombatToggle(bool IsCombatEnabled);
public:
void SetTargetActor(AActor* NewTargetActor);
private:
protected:
UPROPERTY()
TObjectPtr<class AMasterAI> MasterAI;
UPROPERTY()

View File

@ -0,0 +1,11 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AI/CombatBossAIController.h"
#include "Perception/AISenseConfig_Sight.h"
ACombatBossAIController::ACombatBossAIController()
{
SightConfig->LoseSightRadius = 5000.f;
SightConfig->AutoSuccessRangeFromLastSeenLocation = 5000.f;
}

View File

@ -0,0 +1,18 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AI/CombatAIController.h"
#include "CombatBossAIController.generated.h"
/**
*
*/
UCLASS()
class D1_API ACombatBossAIController : public ACombatAIController
{
GENERATED_BODY()
public:
ACombatBossAIController();
};

View File

@ -4,6 +4,7 @@
#include "AI/MasterAI.h"
#include "AIController.h"
#include "BrainComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
@ -535,6 +536,10 @@ void AMasterAI::PerformDeath()
return;
SetDead(true);
//AI가 가끔 Death 수행하지 않을 때 대비
if(const AAIController* aiController = Cast<AAIController>(GetController()))
aiController->BrainComponent->StopLogic(TEXT("Death"));
if(!DeathAnimations.IsEmpty())
{
const int randomIdx = FMath::RandRange(0, DeathAnimations.Num() - 1);

View File

@ -19,6 +19,7 @@
#include "Engine/DamageEvents.h"
#include "NiagaraFunctionLibrary.h"
#include "Actor/BaseConsumable.h"
#include "Components/EquipmentComponent.h"
#include "DamageType/AttackDamageType.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Kismet/KismetMathLibrary.h"
@ -96,6 +97,9 @@ ACombatPlayerCharacter::ACombatPlayerCharacter()
//Setting TargetComponent
TargetingComponent = CreateDefaultSubobject<UTargetingComponent>(TEXT("TargetingComponent"));
//Setting EquipmentComponent
EquipmentComponent = CreateDefaultSubobject<UEquipmentComponent>(TEXT("EquipmentComponent"));
//Setting MovementSpeed
MovementSpeedMode = EMovementSpeedMode::Jogging;
WalkingSpeed = 200.f;
@ -126,24 +130,7 @@ void ACombatPlayerCharacter::BeginPlay()
}
}
//Player have Weapon until first time : probably temp coding
FActorSpawnParameters spawnParam;
spawnParam.Owner = this;
spawnParam.Instigator = this;
for (auto Equipment : StartingEquipments)
{
ABaseEquippable* SpawnItem = Cast<ABaseEquippable>(GetWorld()->SpawnActor(Equipment, &GetActorTransform(), spawnParam));
if (SpawnItem)
{
SpawnItem->OnEquipped();
EquippedItems.Add(SpawnItem);
if(ABaseConsumable* consumableItem = Cast<ABaseConsumable>(SpawnItem))
{
if(UUI_PotionAmountText* PotionAmountText = Cast<UUI_PotionAmountText>(PotionUI))
PotionAmountText->InitializePotionData(consumableItem); //TODO : [UMG] 관련 부분 구조 변경 필요
}
}
}
EquipmentComponent->InitializeEquipment();
//Setting Timeline - if you set on Constructor, Can not get Curve
FOnTimelineFloat TimelineFloatCallback;
@ -400,25 +387,6 @@ bool ACombatPlayerCharacter::PerformCustomAction(FGameplayTag ActionTag, FGamepl
return true;
}
bool ACombatPlayerCharacter::UseItemByTag(FGameplayTag ItemTag)
{
for (auto Item : EquippedItems)
{
if(IsValid(Item))
{
IGameplayTagAssetInterface* TagItem = Cast<IGameplayTagAssetInterface>(Item);
if(!TagItem)
continue;
if(TagItem->HasMatchingGameplayTag(ItemTag))
{
Item->PerformItemAction();
return true;
}
}
}
return false;
}
void ACombatPlayerCharacter::SetMovementSpeedMode(EMovementSpeedMode NewSpeedMode)
{
if (NewSpeedMode == MovementSpeedMode)
@ -622,7 +590,7 @@ void ACombatPlayerCharacter::StopBlocking(const FInputActionValue& Value)
void ACombatPlayerCharacter::UseItem(const FInputActionValue& Value)
{
if(CanUseItem())
UseItemByTag(FCombatGameplayTags::Get().Item_Consumable);
EquipmentComponent->PerformActionFromItem(FCombatGameplayTags::Get().Item_Consumable);
}
void ACombatPlayerCharacter::CharacterStateBegin(FGameplayTag CharState)
@ -1098,20 +1066,3 @@ bool ACombatPlayerCharacter::WasHitBlocked()
return false;
}
ABaseEquippable* ACombatPlayerCharacter::GetEquippedItemByTag(FGameplayTag itemTag)
{
for (auto Item : EquippedItems)
{
if(IsValid(Item))
{
IGameplayTagAssetInterface* TagItem = Cast<IGameplayTagAssetInterface>(Item);
if(!TagItem)
continue;
if(TagItem->HasMatchingGameplayTag(itemTag))
return Item;
}
}
return nullptr;
}

View File

@ -131,7 +131,6 @@ public:
virtual float PerformAction(FGameplayTag ActionTag, FGameplayTag StateTag, int32 MontageIndex, bool bRandomIndex = false);
virtual float PerformAttack(FGameplayTag AttackType, int32 AttackIndex, bool bRandomIndex = false);
virtual bool PerformCustomAction(FGameplayTag ActionTag, FGameplayTag StateTag, UAnimMontage* InMontage, float fMontagePlayRate, bool bAutoReset) override;
virtual bool UseItemByTag(FGameplayTag ItemTag) override;
// Inherited via IGameplayTagAssetInterface
virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const override { TagContainer = OwnedGameplayTags; }
@ -204,9 +203,6 @@ protected: //Check Func
FGameplayTag GetDesiredAttackType();
bool WasHitBlocked();
UFUNCTION(BlueprintCallable)
class ABaseEquippable* GetEquippedItemByTag(FGameplayTag itemTag);
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UCombatComponent> CombatComponent;
@ -216,11 +212,8 @@ public:
TObjectPtr<UStatsComponent> StatsComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UTargetingComponent> TargetingComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Equipment", meta = (AllowPrivateAccess = "true"))
TArray<TSubclassOf<class ABaseEquippable>> StartingEquipments;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Equipment", meta = (AllowPrivateAccess = "true"))
TArray<TObjectPtr<ABaseEquippable>> EquippedItems;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UEquipmentComponent> EquipmentComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
FName PelvisBoneName;

View File

@ -0,0 +1,107 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Components/EquipmentComponent.h"
#include "CombatPlayerCharacter.h"
#include "Actor/BaseConsumable.h"
#include "Actor/BaseEquippable.h"
#include "UI/UI_PotionAmountText.h"
// Sets default values for this component's properties
UEquipmentComponent::UEquipmentComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UEquipmentComponent::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void UEquipmentComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UEquipmentComponent::InitializeEquipment()
{
for (auto equipment : StartingEquipment)
{
if(!IsValid(equipment.Get()))
continue;
AActor* owner = GetOwner();
if(!IsValid(owner))
continue;
APawn* ownerPawn = Cast<APawn>(owner);
if(!IsValid(ownerPawn))
continue;
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = owner;
SpawnParameters.Instigator = ownerPawn;
ABaseEquippable* EquipInstance = Cast<ABaseEquippable>(GetWorld()->SpawnActor(equipment, &owner->GetActorTransform(), SpawnParameters));
if(EquipInstance)
{
EquippedItems.AddUnique(EquipInstance);
EquipInstance->OnEquipped();
//Player have Weapon until first time : probably temp coding
if(ACombatPlayerCharacter* Player = Cast<ACombatPlayerCharacter>(GetOwner()))
{
if(ABaseConsumable* consumableItem = Cast<ABaseConsumable>(EquipInstance))
{
if(UUI_PotionAmountText* PotionAmountText = Cast<UUI_PotionAmountText>(Player->PotionUI))
PotionAmountText->InitializePotionData(consumableItem); //TODO : [UMG] 관련 부분 구조 변경 필요
}
}
}
}
}
bool UEquipmentComponent::PerformActionFromItem(FGameplayTag ItemTag)
{
for (auto Item : EquippedItems)
{
if(IsValid(Item))
{
IGameplayTagAssetInterface* TagItem = Cast<IGameplayTagAssetInterface>(Item);
if(!TagItem)
continue;
if(TagItem->HasMatchingGameplayTag(ItemTag))
{
Item->PerformItemAction();
return true;
}
}
}
return false;
}
ABaseEquippable* UEquipmentComponent::GetEquippedItemByTag(FGameplayTag itemTag)
{
for (auto Item : EquippedItems)
{
if(IsValid(Item))
{
IGameplayTagAssetInterface* TagItem = Cast<IGameplayTagAssetInterface>(Item);
if(!TagItem)
continue;
if(TagItem->HasMatchingGameplayTag(itemTag))
return Item;
}
}
return nullptr;
}

View File

@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "EquipmentComponent.generated.h"
struct FGameplayTag;
class ABaseEquippable;
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class D1_API UEquipmentComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UEquipmentComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
public:
void InitializeEquipment();
bool PerformActionFromItem(FGameplayTag ItemTag);
UFUNCTION(BlueprintCallable)
ABaseEquippable* GetEquippedItemByTag(FGameplayTag itemTag);
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Initialization")
TArray<TSubclassOf<ABaseEquippable>> StartingEquipment;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Default")
TArray<TObjectPtr<ABaseEquippable>> EquippedItems;
};

View File

@ -164,7 +164,7 @@ void UTargetingComponent::UpdateTargetingControlRotation()
if(!WorldPointer)
return;
FRotator CameraRotation = FMath::RInterpTo(OwnerController->K2_GetActorRotation(), TargetRotation, UGameplayStatics::GetWorldDeltaSeconds(WorldPointer), TargetRotationInterpSpeed);
OwnerController->SetControlRotation(UKismetMathLibrary::MakeRotator(OwnerController->K2_GetActorRotation().Roll, CameraRotation.Pitch, CameraRotation.Yaw));
OwnerController->SetControlRotation(UKismetMathLibrary::MakeRotator(OwnerController->K2_GetActorRotation().Roll, UKismetMathLibrary::Clamp(CameraRotation.Pitch, -25.f, 30.f), CameraRotation.Yaw));
}
else
DisableLockOn();

View File

@ -20,8 +20,3 @@ bool ICombatInterface::PerformCustomAction(FGameplayTag ActionTag, FGameplayTag
{
return false;
}
bool ICombatInterface::UseItemByTag(FGameplayTag ItemTag)
{
return false;
}

View File

@ -54,6 +54,4 @@ public:
virtual float PerformAttack(FGameplayTag AttackType, int32 AttackIndex, bool bRandomIndex = false);
UFUNCTION(Category="CombatActions")
virtual bool PerformCustomAction(FGameplayTag ActionTag, FGameplayTag StateTag, UAnimMontage* InMontage, float fMontagePlayRate = 1.f, bool bAutoReset = false);
UFUNCTION(Category="CombatActions")
virtual bool UseItemByTag(FGameplayTag ItemTag);
};