diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index 8ecec9f..438b110 100644 Binary files a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset and b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset differ diff --git a/Content/Blueprints/Items/BP_HealthBox.uasset b/Content/Blueprints/Items/BP_HealthBox.uasset new file mode 100644 index 0000000..5a47dae Binary files /dev/null and b/Content/Blueprints/Items/BP_HealthBox.uasset differ diff --git a/Content/Blueprints/Items/RevolverAmmoBox.uasset b/Content/Blueprints/Items/RevolverAmmoBox.uasset new file mode 100644 index 0000000..37ee539 Binary files /dev/null and b/Content/Blueprints/Items/RevolverAmmoBox.uasset differ diff --git a/Content/Blueprints/Items/RevolverGun.uasset b/Content/Blueprints/Items/RevolverGun.uasset index 2201e69..c7e49ba 100644 Binary files a/Content/Blueprints/Items/RevolverGun.uasset and b/Content/Blueprints/Items/RevolverGun.uasset differ diff --git a/Content/Blueprints/Items/RifleAmmoBox.uasset b/Content/Blueprints/Items/RifleAmmoBox.uasset new file mode 100644 index 0000000..64c14d8 Binary files /dev/null and b/Content/Blueprints/Items/RifleAmmoBox.uasset differ diff --git a/Content/Blueprints/Items/ShotGun.uasset b/Content/Blueprints/Items/ShotGun.uasset index 4dffcc1..fa6eb93 100644 Binary files a/Content/Blueprints/Items/ShotGun.uasset and b/Content/Blueprints/Items/ShotGun.uasset differ diff --git a/Content/Blueprints/Items/ShotgunAmmoBox.uasset b/Content/Blueprints/Items/ShotgunAmmoBox.uasset new file mode 100644 index 0000000..c24a8af Binary files /dev/null and b/Content/Blueprints/Items/ShotgunAmmoBox.uasset differ diff --git a/Content/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 2d56c03..317fd7c 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index d27b616..c406cfa 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -101,6 +101,26 @@ void UShootingComponent::Reload() UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentGun->CurrentAmmo, CurrentGun->MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo } +bool UShootingComponent::AddAmmo(EAmmoType CheckingAmmo, int AddValue) +{ + if (IsValid(CurrentGun)) + { + // Adding ammo only if type is compatible + if (CurrentGun->AmmoType == CheckingAmmo) + { + CurrentGun->AddAmmo(AddValue); + return true; + } + if (SecondaryGun->AmmoType == CheckingAmmo) + { + SecondaryGun->AddAmmo(AddValue); + return true; + } + } + + return false; +} + void UShootingComponent::PickUpGun(AGunBase* gunItem) { if (IsValid(CurrentGun) && IsValid(SecondaryGun)) @@ -113,6 +133,7 @@ void UShootingComponent::PickUpGun(AGunBase* gunItem) NewGun->FireRateCooldown = gunItem->FireRateCooldown; NewGun->RecoilForceMultiplier = gunItem->RecoilForceMultiplier; NewGun->ReloadTime = gunItem->ReloadTime; + NewGun->AmmoType = gunItem->AmmoType; NewGun->CurrentAmmo = gunItem->CurrentAmmo; NewGun->MaxAmmo = gunItem->MaxAmmo; NewGun->SceneItemClass = gunItem->GetClass(); @@ -177,6 +198,7 @@ void UShootingComponent::DropGun() DroppedGun->FireRateCooldown = CurrentGun->FireRateCooldown; DroppedGun->RecoilForceMultiplier = CurrentGun->RecoilForceMultiplier; DroppedGun->ReloadTime = CurrentGun->ReloadTime; + DroppedGun->AmmoType = CurrentGun->AmmoType; DroppedGun->CurrentAmmo = CurrentGun->CurrentAmmo; DroppedGun->MaxAmmo = CurrentGun->MaxAmmo; diff --git a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp index 007dd45..2137d56 100644 --- a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp +++ b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp @@ -4,6 +4,8 @@ #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() @@ -22,5 +24,46 @@ AExoPlayerCharacter::AExoPlayerCharacter() 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; +} \ No newline at end of file diff --git a/Source/Exo/Private/Items/AmmoBoxBase.cpp b/Source/Exo/Private/Items/AmmoBoxBase.cpp new file mode 100644 index 0000000..c1f459a --- /dev/null +++ b/Source/Exo/Private/Items/AmmoBoxBase.cpp @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Items/AmmoBoxBase.h" + +AAmmoBoxBase::AAmmoBoxBase() +{ + PrimaryActorTick.bCanEverTick = true; + +} + +void AAmmoBoxBase::BeginPlay() +{ + Super::BeginPlay(); + +} + +void AAmmoBoxBase::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/Exo/Private/Items/GunBase.cpp b/Source/Exo/Private/Items/GunBase.cpp index dfd456f..1b50918 100644 --- a/Source/Exo/Private/Items/GunBase.cpp +++ b/Source/Exo/Private/Items/GunBase.cpp @@ -32,4 +32,11 @@ void AGunBase::Interact_Implementation(AExoPlayerCharacter* playerCharacter) playerCharacter->ShootingComponent->PickUpGun(this); Destroy(); +} + +void AGunBase::AddAmmo(int AddValue) +{ + CurrentAmmo += AddValue; + if (CurrentAmmo > MaxAmmo) + CurrentAmmo = MaxAmmo; } \ No newline at end of file diff --git a/Source/Exo/Private/Items/HealthBoxBase.cpp b/Source/Exo/Private/Items/HealthBoxBase.cpp new file mode 100644 index 0000000..c82efa6 --- /dev/null +++ b/Source/Exo/Private/Items/HealthBoxBase.cpp @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Items/HealthBoxBase.h" + +// Sets default values +AHealthBoxBase::AHealthBoxBase() +{ + PrimaryActorTick.bCanEverTick = true; + +} + +void AHealthBoxBase::BeginPlay() +{ + Super::BeginPlay(); + +} + +void AHealthBoxBase::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index de7b490..09dc357 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -45,9 +45,12 @@ public: UFUNCTION(Category = "Mele Attack") void MeleAttack(); - UFUNCTION(Category = "Shooting") + UFUNCTION(Category = "Ammo") void Reload(); + UFUNCTION(Category = "Ammo") + bool AddAmmo(EAmmoType CheckingAmmo, int AddValue); + UFUNCTION(BlueprintCallable, Category = "Shooting") void PickUpGun(AGunBase* gunItem); diff --git a/Source/Exo/Public/Characters/ExoPlayerCharacter.h b/Source/Exo/Public/Characters/ExoPlayerCharacter.h index 349e9b5..9039780 100644 --- a/Source/Exo/Public/Characters/ExoPlayerCharacter.h +++ b/Source/Exo/Public/Characters/ExoPlayerCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "Characters/ExoCharacterBase.h" +#include "Components/CapsuleComponent.h" #include "ExoPlayerCharacter.generated.h" class UInteractionComponent; @@ -38,8 +39,19 @@ public: UPROPERTY(EditAnywhere, Category = "Aiming") float bIsAimingMode = false; + UPROPERTY(EditAnywhere, Category = "Health") + float CurrentHealth = 50.0f; + + UFUNCTION() + void OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult + ); + + UFUNCTION() + void AddHealthPoints(float addValue); + protected: virtual void BeginPlay() override; - + float MaxHealth = 100.0f; }; diff --git a/Source/Exo/Public/Items/AmmoBoxBase.h b/Source/Exo/Public/Items/AmmoBoxBase.h new file mode 100644 index 0000000..357b168 --- /dev/null +++ b/Source/Exo/Public/Items/AmmoBoxBase.h @@ -0,0 +1,37 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "AmmoBoxBase.generated.h" + +UENUM() +enum class EAmmoType : uint8 +{ + Revolver UMETA(DisplayName = "Revolver"), + Shotgun UMETA(DisplayName = "Shotgun"), + Rifle UMETA(DisplayName = "Rifle") +}; + +UCLASS() +class EXO_API AAmmoBoxBase : public AActor +{ + GENERATED_BODY() + +public: + AAmmoBoxBase(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + EAmmoType AmmoType = EAmmoType::Revolver; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int AmmoValue = 30; + +protected: + virtual void BeginPlay() override; + +public: + virtual void Tick(float DeltaTime) override; + +}; diff --git a/Source/Exo/Public/Items/GunBase.h b/Source/Exo/Public/Items/GunBase.h index f75af53..ec100ef 100644 --- a/Source/Exo/Public/Items/GunBase.h +++ b/Source/Exo/Public/Items/GunBase.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "AmmoBoxBase.h" #include "GameFramework/Actor.h" #include "Interfaces/Interactable.h" #include "GunBase.generated.h" @@ -40,8 +41,14 @@ public: UPROPERTY(EditAnywhere, Category = "Ammo") int32 MaxAmmo = 10; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo") + EAmmoType AmmoType = EAmmoType::Revolver; + TSubclassOf SceneItemClass; + UFUNCTION(Category = "Ammo") + void AddAmmo(int AddValue); + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; diff --git a/Source/Exo/Public/Items/HealthBoxBase.h b/Source/Exo/Public/Items/HealthBoxBase.h new file mode 100644 index 0000000..5488dea --- /dev/null +++ b/Source/Exo/Public/Items/HealthBoxBase.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "HealthBoxBase.generated.h" + +UCLASS() +class EXO_API AHealthBoxBase : public AActor +{ + GENERATED_BODY() + +public: + AHealthBoxBase(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float HealthValue = 75.0f; + +protected: + virtual void BeginPlay() override; + +public: + virtual void Tick(float DeltaTime) override; + +};