// Fill out your copyright notice in the Description page of Project Settings. #include "Characters/ExoPlayerCharacter.h" #include "Characters/Components/ShootingComponent.h" #include "GameFramework/CharacterMovementComponent.h" #include "Items/AmmoBoxBase.h" #include "Items/HealthBoxBase.h" #include "Player/InteractionComponent.h" AExoPlayerCharacter::AExoPlayerCharacter() { GetCharacterMovement()->bSnapToPlaneAtStart = true; InteractionComponent = CreateDefaultSubobject(TEXT("Interaction Component")); ShootingComponent = CreateDefaultSubobject(TEXT("Shooting Component")); bUseControllerRotationPitch = false; bUseControllerRotationYaw = true; bUseControllerRotationRoll = false; } void AExoPlayerCharacter::BeginPlay() { Super::BeginPlay(); GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AExoPlayerCharacter::OnActorBeginOverlap); } void AExoPlayerCharacter::OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { if (OtherActor && OtherActor != this) { if (OtherActor->IsA(AHealthBoxBase::StaticClass())) { AHealthBoxBase* HealthBox = Cast(OtherActor); if (HealthBox) { AddHealthPoints(HealthBox->HealthValue); HealthBox->Destroy(); UE_LOG(LogTemp, Warning, TEXT("Zebrano apteczkę")); } } else if (OtherActor->IsA(AAmmoBoxBase::StaticClass())) { AAmmoBoxBase* AmmoBox = Cast(OtherActor); if (AmmoBox) { if (ShootingComponent->AddAmmo(AmmoBox->AmmoType, AmmoBox->AmmoValue)) { AmmoBox->Destroy(); UE_LOG(LogTemp, Warning, TEXT("Zebrano amunicję")); } } } } } void AExoPlayerCharacter::AddHealthPoints(float addValue) { CurrentHealth += addValue; if (CurrentHealth > MaxHealth) CurrentHealth = MaxHealth; }