2025-02-13 19:44:57 +01:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Characters/ExoPlayerCharacter.h"
|
2025-04-23 23:03:06 +02:00
|
|
|
|
|
|
|
|
#include "Blueprint/UserWidget.h"
|
2025-03-07 11:11:22 +01:00
|
|
|
#include "Characters/Components/ShootingComponent.h"
|
2025-02-13 19:44:57 +01:00
|
|
|
#include "GameFramework/CharacterMovementComponent.h"
|
2025-04-18 01:53:08 +02:00
|
|
|
#include "Items/AmmoBoxBase.h"
|
|
|
|
|
#include "Items/HealthBoxBase.h"
|
2025-03-07 11:11:22 +01:00
|
|
|
#include "Player/InteractionComponent.h"
|
2025-05-08 17:46:09 +02:00
|
|
|
#include "Widget/WBP_PlayerUI.h"
|
|
|
|
|
|
2025-02-13 19:44:57 +01:00
|
|
|
|
|
|
|
|
AExoPlayerCharacter::AExoPlayerCharacter()
|
|
|
|
|
{
|
|
|
|
|
GetCharacterMovement()->bSnapToPlaneAtStart = true;
|
|
|
|
|
|
2025-03-07 11:11:22 +01:00
|
|
|
InteractionComponent = CreateDefaultSubobject<UInteractionComponent>(TEXT("Interaction Component"));
|
|
|
|
|
ShootingComponent = CreateDefaultSubobject<UShootingComponent>(TEXT("Shooting Component"));
|
|
|
|
|
|
2025-04-22 23:28:59 +02:00
|
|
|
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
|
|
|
|
|
Weapon->SetupAttachment(GetMesh());
|
|
|
|
|
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
|
|
|
Weapon->bCastDynamicShadow = false;
|
|
|
|
|
Weapon->CastShadow = false;
|
|
|
|
|
Weapon->SetRelativeLocation(FVector(-50.f, 0.f, -90.f));
|
|
|
|
|
|
2025-03-13 08:09:12 +01:00
|
|
|
bUseControllerRotationPitch = false;
|
2025-02-13 19:44:57 +01:00
|
|
|
bUseControllerRotationYaw = true;
|
|
|
|
|
bUseControllerRotationRoll = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AExoPlayerCharacter::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
Super::BeginPlay();
|
2025-04-18 01:53:08 +02:00
|
|
|
|
|
|
|
|
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AExoPlayerCharacter::OnActorBeginOverlap);
|
2025-04-23 23:03:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-08 17:46:09 +02:00
|
|
|
PlayerHud = CreateWidget<UWBP_PlayerUI>(GetWorld(),PlayerHudClass);
|
|
|
|
|
if (PlayerHud)
|
2025-04-23 23:03:06 +02:00
|
|
|
{
|
2025-05-08 17:46:09 +02:00
|
|
|
PlayerHud->AddToViewport();
|
|
|
|
|
PlayerHud->AddToPlayerScreen();
|
|
|
|
|
|
2025-04-23 23:03:06 +02:00
|
|
|
if (PlayerHud)
|
|
|
|
|
{
|
2025-05-08 17:46:09 +02:00
|
|
|
PlayerHud->SetHp(CurrentHealth,MaxHealth);
|
2025-05-22 17:21:59 +02:00
|
|
|
PlayerHud->SetAmmoNumber(10);
|
|
|
|
|
PlayerHud->SetAmmoType(EAmmoType::Revolver);
|
|
|
|
|
for (int i=0;i<4;i++)
|
|
|
|
|
PlayerHud->AddDebuf(NULL,0.25f*i);
|
2025-05-08 17:46:09 +02:00
|
|
|
}
|
2025-04-23 23:03:06 +02:00
|
|
|
}
|
2025-02-13 19:44:57 +01:00
|
|
|
}
|
2025-04-18 01:53:08 +02:00
|
|
|
|
|
|
|
|
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<AHealthBoxBase>(OtherActor);
|
|
|
|
|
if (HealthBox)
|
|
|
|
|
{
|
|
|
|
|
AddHealthPoints(HealthBox->HealthValue);
|
|
|
|
|
HealthBox->Destroy();
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Zebrano apteczkę"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (OtherActor->IsA(AAmmoBoxBase::StaticClass()))
|
|
|
|
|
{
|
|
|
|
|
AAmmoBoxBase* AmmoBox = Cast<AAmmoBoxBase>(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;
|
2025-05-08 17:46:09 +02:00
|
|
|
|
|
|
|
|
if (PlayerHud)
|
|
|
|
|
PlayerHud->SetHp(CurrentHealth,MaxHealth);
|
2025-04-18 01:53:08 +02:00
|
|
|
}
|