diff --git a/hwanyoung2/Intermediate/CachedAssetRegistry.bin b/hwanyoung2/Intermediate/CachedAssetRegistry.bin index bd7eec5f..fe9c3ae4 100644 Binary files a/hwanyoung2/Intermediate/CachedAssetRegistry.bin and b/hwanyoung2/Intermediate/CachedAssetRegistry.bin differ diff --git a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h index 2cdb059b..bd5fdc95 100644 --- a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h +++ b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h @@ -2,6 +2,8 @@ #pragma once +#include "Interactable.h" + #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" #include "HYPlayerCharacController.generated.h" diff --git a/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.cpp b/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.cpp index e172502c..771f7976 100644 --- a/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.cpp +++ b/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.cpp @@ -4,6 +4,7 @@ #include "HYCharacAbilitySystemComponent.h" #include "HYPlayerCharacAttributeSet.h" #include "HYCharacGameplayAbility.h" +#include "HYPlayerCharacController.h" #include "Camera/CameraComponent.h" #include "Components/CapsuleComponent.h" #include "Components/InputComponent.h" @@ -12,6 +13,9 @@ #include "GameFramework/SpringArmComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "Interactable.h" +#include "InventoryItem.h" + ////////////////////////////////////////////////////////////////////////// @@ -153,6 +157,52 @@ void Ahwanyoung2Character::BeginPlay() } } +void Ahwanyoung2Character::CheckForInteractables() +{ + // Creates a LineTrace (similar to RayCast) to check for a hit + FHitResult HitResult; + + // The range of area the system should check for interactables + int32 Range = 500; //this can be changed + + //The start of the trace is the transform of the follow camera + FVector StartTrace = FollowCamera->GetComponentLocation(); + + //And the end of the trace is the 500 units ahead of the start trace + FVector EndTrace = (FollowCamera->GetForwardVector() * Range) + StartTrace; + + //Keeps track of parameters passed into collision function, assuming that + //there are multiple collided actors that is passed through the collision function + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(this); //we are ignoring this, which is the character + + //Similarly to how GetComponent<>() function works, we get the controller + //object attached to the character and cast it as player character controller class + AHYPlayerCharacController* IController = Cast(GetController()); + + if (IController) { + //Checking if something is hit by the line cast within the range + if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace, + ECC_Visibility, QueryParams)) { + + //Cast the actor to AInteractable + AInteractable* Interactable = Cast(HitResult.GetActor()); + + if (Interactable) { + IController->CurrentInteractable = Interactable; + return; + } + } + + IController->CurrentInteractable = nullptr; + } +} + + +void Ahwanyoung2Character::Tick(float DeltaTime) +{ +} + ////////////////////////////////////////////////////////////////////////// // Input @@ -221,65 +271,65 @@ int32 Ahwanyoung2Character::GetAbilityLevel(EAbilityInputID AbilityID) const return int32(); } -void Ahwanyoung2Character::RemoveCharacterAbilities() -{ - //if the object doesn't have the authority, ability system component is not valid - //or character abilities are not given in the ability system component, - //we don't do anything and just return - if (GetLocalRole() != ROLE_Authority || - !AbilitySystemComponent.IsValid() || - !AbilitySystemComponent->CharacterAbilitiesGiven) - { - return; - } +//void Ahwanyoung2Character::RemoveCharacterAbilities() +//{ +// //if the object doesn't have the authority, ability system component is not valid +// //or character abilities are not given in the ability system component, +// //we don't do anything and just return +// if (GetLocalRole() != ROLE_Authority || +// !AbilitySystemComponent.IsValid() || +// !AbilitySystemComponent->CharacterAbilitiesGiven) +// { +// return; +// } +// +// TArray AbilitiesToRemove; +// for (const FGameplayAbilitySpec& Spec : AbilitySystemComponent->GetActivatableAbilities()) +// { +// if (Spec.SourceObject == this && CharacterAbilities.Contains(Spec.Ability->GetClass())) +// { +// AbilitiesToRemove.Add(Spec.Handle); //spec.handle is an instance of the ability +// } +// } +// +// for (int32 i = 0; i < AbilitiesToRemove.Num(); i++) +// { +// AbilitySystemComponent->ClearAbility(AbilitiesToRemove[i]); +// } +// +// AbilitySystemComponent->CharacterAbilitiesGiven = false; +//} - TArray AbilitiesToRemove; - for (const FGameplayAbilitySpec& Spec : AbilitySystemComponent->GetActivatableAbilities()) - { - if (Spec.SourceObject == this && CharacterAbilities.Contains(Spec.Ability->GetClass())) - { - AbilitiesToRemove.Add(Spec.Handle); //spec.handle is an instance of the ability - } - } - - for (int32 i = 0; i < AbilitiesToRemove.Num(); i++) - { - AbilitySystemComponent->ClearAbility(AbilitiesToRemove[i]); - } - - AbilitySystemComponent->CharacterAbilitiesGiven = false; -} - -void Ahwanyoung2Character::Die() -{ - RemoveCharacterAbilities(); - - GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); - GetCharacterMovement()->GravityScale = 0; - GetCharacterMovement()->Velocity = FVector(0); //disabling character movement when death - - OnCharacterDied.Broadcast(this); - - if (AbilitySystemComponent.IsValid()) - { - AbilitySystemComponent->CancelAbilities(); - - FGameplayTagContainer EffectsTagsToRemove; - EffectsTagsToRemove.AddTag(EffectRemoveOnDeathTag); - int32 NumEffectsRemoved = AbilitySystemComponent->RemoveActiveEffectsWithTags(EffectsTagsToRemove); - AbilitySystemComponent->AddLooseGameplayTag(DeadTag); - } - - //playing death anim: - if (DeathMontage) - { - PlayAnimMontage(DeathMontage); - } - else - { - FinishDying(); - } -} +//void Ahwanyoung2Character::Die() +//{ +// RemoveCharacterAbilities(); +// +// GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); +// GetCharacterMovement()->GravityScale = 0; +// GetCharacterMovement()->Velocity = FVector(0); //disabling character movement when death +// +// OnCharacterDied.Broadcast(this); +// +// if (AbilitySystemComponent.IsValid()) +// { +// AbilitySystemComponent->CancelAbilities(); +// +// FGameplayTagContainer EffectsTagsToRemove; +// EffectsTagsToRemove.AddTag(EffectRemoveOnDeathTag); +// int32 NumEffectsRemoved = AbilitySystemComponent->RemoveActiveEffectsWithTags(EffectsTagsToRemove); +// AbilitySystemComponent->AddLooseGameplayTag(DeadTag); +// } +// +// //playing death anim: +// if (DeathMontage) +// { +// PlayAnimMontage(DeathMontage); +// } +// else +// { +// FinishDying(); +// } +//} void Ahwanyoung2Character::FinishDying() { @@ -461,3 +511,4 @@ void Ahwanyoung2Character::SetGaugeP(float GaugeP) AttributeSetBase->SetGaugeP(GaugeP); } } + diff --git a/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.h b/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.h index 36e43d09..ff8f01a0 100644 --- a/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.h +++ b/hwanyoung2/Source/hwanyoung2/hwanyoung2Character.h @@ -27,7 +27,12 @@ class Ahwanyoung2Character : public ACharacter, public IAbilitySystemInterface /** Follow camera */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) class UCameraComponent* FollowCamera; - + + /** Collection sphere */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) + class USphereComponent* CollectionSphere; + +#pragma region Controller /** MappingContext */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputMappingContext* DefaultMappingContext; @@ -44,7 +49,9 @@ class Ahwanyoung2Character : public ACharacter, public IAbilitySystemInterface UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* LookAction; +#pragma endregion move this to PlayerCharacController.h + public: UPROPERTY(BlueprintAssignable, Category = "Hwanyoung|Character") @@ -56,10 +63,10 @@ public: UFUNCTION(BlueprintCallable, Category = "Hwanyoung|Character") virtual int32 GetAbilityLevel(EAbilityInputID AbilityID) const; - //this function is called only in the server: - virtual void RemoveCharacterAbilities(); - //this is also called only in the server: - virtual void Die(); + ////this function is called only in the server: + //virtual void RemoveCharacterAbilities(); + ////this is also called only in the server: + //virtual void Die(); UFUNCTION(BlueprintCallable, Category = "Hwanyoung|Character") virtual void FinishDying(); @@ -102,6 +109,13 @@ public: UFUNCTION(BlueprintCallable, Category = "HY_Character|Camera") FVector GetStartingCameraBoomLocation(); + /** Returns CameraBoom subobject **/ + class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } + /** Returns FollowCamera subobject **/ + class UCameraComponent* GetFollowCamera() const { return FollowCamera; } + + virtual void Tick(float DeltaTime) override; + protected: //pointers to the attribute set and ability system component @@ -139,19 +153,19 @@ protected: FGameplayTag EffectRemoveOnDeathTag; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Character") - FText CharacterName; + FText CharacterName; UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Hwanyoung|Animation") - UAnimMontage* DeathMontage; + UAnimMontage* DeathMontage; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilties") - TSubclassOf DefaultAttributes; + TSubclassOf DefaultAttributes; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilities") - TArray> StartupEffects; + TArray> StartupEffects; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilities") - TArray> CharacterAbilities; + TArray> CharacterAbilities; virtual void AddCharacterAbilities(); virtual void InitializeAttributes(); @@ -172,20 +186,20 @@ protected: /** Called for looking input */ void Look(const FInputActionValue& Value); - + + /** Called for checking for the closest Interactable in sight and in range*/ + void CheckForInteractables(); + protected: // APawn interface virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; - + // To add mapping context virtual void BeginPlay(); -public: - /** Returns CameraBoom subobject **/ - class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } - /** Returns FollowCamera subobject **/ - class UCameraComponent* GetFollowCamera() const { return FollowCamera; } + // Checks for the closest Interactable in sight and in range + void CheckForInteractables(); };