154 - Ammo Pickups

This commit is contained in:
Kingsmedia 2022-05-22 22:56:28 +02:00
parent 3fae6c46d7
commit 9e357cb57b
20 changed files with 93 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -31,6 +31,19 @@ void UCombatComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Out
DOREPLIFETIME(UCombatComponent, Grenades);
}
void UCombatComponent::PickupAmmo(EWeaponType WeaponType, int32 AmmoAmount)
{
if (CarriedAmmoMap.Contains(WeaponType))
{
CarriedAmmoMap[WeaponType] = FMath::Clamp(CarriedAmmoMap[WeaponType] + AmmoAmount, 0, MaxCarriedAmmo);
UpdateCarriedAmmo();
}
if (EquippedWeapon && EquippedWeapon->IsEmpty() && EquippedWeapon->GetWeaponType() == WeaponType)
{
Reload();
}
}
void UCombatComponent::BeginPlay()
{
Super::BeginPlay();

View File

@ -45,6 +45,8 @@ public:
FORCEINLINE int32 GetGrenades() const { return Grenades; }
void PickupAmmo(EWeaponType WeaponType, int32 AmmoAmount);
protected:
virtual void BeginPlay() override;
void SetAiming(bool bIsAiming);
@ -151,6 +153,9 @@ private:
TMap<EWeaponType, int32> CarriedAmmoMap;
UPROPERTY(EditAnywhere)
int32 MaxCarriedAmmo = 500;
UPROPERTY(EditAnywhere)
int32 StartingARAmmo = 30;

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AmmoPickup.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/CombatComponent.h"
void AAmmoPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("AmmoPickup Overlap"));
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor);
if (BlasterCharacter)
{
UCombatComponent* Combat = BlasterCharacter->GetCombat();
if (Combat)
{
Combat->PickupAmmo(WeaponType, AmmoAmount);
}
}
Destroy();
}

View File

@ -0,0 +1,35 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Pickup.h"
#include "Blaster/Weapon/WeaponTypes.h"
#include "AmmoPickup.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API AAmmoPickup : public APickup
{
GENERATED_BODY()
protected:
virtual void OnSphereOverlap(
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
);
private:
UPROPERTY(EditAnywhere)
int32 AmmoAmount = 30;
UPROPERTY(EditAnywhere)
EWeaponType WeaponType;
};

View File

@ -3,6 +3,7 @@
#include "Pickup.h"
#include "Blaster/Weapon/WeaponTypes.h"
#include "Components/SphereComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Sound/SoundCue.h"
@ -20,10 +21,14 @@ APickup::APickup()
OverlapSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
OverlapSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
OverlapSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
OverlapSphere->AddLocalOffset(FVector(0.f, 0.f, 85.f));
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
PickupMesh->SetupAttachment(OverlapSphere);
PickupMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
PickupMesh->SetRelativeScale3D(FVector(5.f, 5.f, 5.f));
PickupMesh->SetRenderCustomDepth(true);
PickupMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_PURPLE);
}
void APickup::BeginPlay()
@ -39,13 +44,17 @@ void APickup::BeginPlay()
void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("Pickup Overlap"));
}
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (PickupMesh)
{
PickupMesh->AddWorldRotation(FRotator(0.f, BaseTurnRate * DeltaTime, 0.f));
}
}
void APickup::Destroyed()

View File

@ -29,6 +29,9 @@ protected:
const FHitResult& SweepResult
);
UPROPERTY(EditAnywhere)
float BaseTurnRate = 45.f;
private:
UPROPERTY(EditAnywhere)
class USphereComponent* OverlapSphere;