Started working on new drop system
Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
parent
3bfb6a125e
commit
0ee681cc61
10
Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp
Normal file
10
Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Ammo/LMAmmoPack.h"
|
||||
|
||||
|
||||
ALMAmmoPack::ALMAmmoPack()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
}
|
61
Source/LegumeMix/Private/Ammo/LMItemDropComponent.cpp
Normal file
61
Source/LegumeMix/Private/Ammo/LMItemDropComponent.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Ammo/LMItemDropComponent.h"
|
||||
|
||||
#include "LMHealthPack.h"
|
||||
#include "Ammo/LMAmmoPack.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Player/LMPlayer.h"
|
||||
#include "Weapon/LMWeaponManager.h"
|
||||
#include "Windows/WindowsApplication.h"
|
||||
|
||||
|
||||
ULMItemDropComponent::ULMItemDropComponent()
|
||||
{
|
||||
PrimaryComponentTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
void ULMItemDropComponent::TryDropItems()
|
||||
{
|
||||
float Result = FMath::RandRange(0.f, 100.f);
|
||||
|
||||
if (DropChanceHealthPack >= Result)
|
||||
{
|
||||
SpawnHealth();
|
||||
}
|
||||
|
||||
if (ALMPlayer* Player = Cast<ALMPlayer>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)))
|
||||
{
|
||||
Result = FMath::RandRange(0.f, 1.f);
|
||||
const FLMAmmoData Ammo = Player->GetWeaponManager()->GetAmmoData(AmmoType);
|
||||
const float Percentage = static_cast<float>(Ammo.AmmoCount) / static_cast<float>(Ammo.MaxAmmo);
|
||||
const float DropChance = DropChanceAtRemainingAmmo->GetFloatValue(Percentage);
|
||||
|
||||
FString Random = FString::Printf(TEXT("Drop Chance of %f for ammo (%i / %i) %f with random at %f"), DropChance, Ammo.AmmoCount, Ammo.MaxAmmo, Percentage, Result);
|
||||
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5.f, FColor::Green, Random);
|
||||
if (DropChance >= Result)
|
||||
{
|
||||
SpawnAmmo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ULMItemDropComponent::SpawnAmmo()
|
||||
{
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
||||
|
||||
ALMAmmoPack* Pack = GetWorld()->SpawnActor<ALMAmmoPack>(AmmoPack, GetOwner()->GetActorTransform(), SpawnParams);
|
||||
}
|
||||
|
||||
void ULMItemDropComponent::SpawnHealth()
|
||||
{
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
||||
|
||||
ALMHealthPack* Pack = GetWorld()->SpawnActor<ALMHealthPack>(HealthPack, GetOwner()->GetActorTransform(), SpawnParams);
|
||||
}
|
||||
|
||||
|
||||
|
11
Source/LegumeMix/Private/LMHealthPack.cpp
Normal file
11
Source/LegumeMix/Private/LMHealthPack.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "LMHealthPack.h"
|
||||
|
||||
|
||||
ALMHealthPack::ALMHealthPack()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
}
|
||||
|
25
Source/LegumeMix/Private/LMItemDrop.cpp
Normal file
25
Source/LegumeMix/Private/LMItemDrop.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "LMItemDrop.h"
|
||||
|
||||
|
||||
ALMItemDrop::ALMItemDrop()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("MeshComponent");
|
||||
RootComponent = StaticMeshComponent;
|
||||
}
|
||||
|
||||
void ALMItemDrop::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
GetWorldTimerManager().SetTimer(DespawnHandle, this, &ALMItemDrop::Despawn, TimeBeforeDespawn);
|
||||
}
|
||||
|
||||
void ALMItemDrop::Despawn()
|
||||
{
|
||||
GetWorldTimerManager().ClearTimer(DespawnHandle);
|
||||
Destroy();
|
||||
}
|
||||
|
@ -143,6 +143,11 @@ int ULMWeaponManager::GetAmmoCount(const EAmmoType AmmoType)
|
||||
return 0;
|
||||
}
|
||||
|
||||
FLMAmmoData& ULMWeaponManager::GetAmmoData(const EAmmoType AmmoType)
|
||||
{
|
||||
return AmmoData[AmmoType];
|
||||
}
|
||||
|
||||
void ULMWeaponManager::Fire()
|
||||
{
|
||||
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
||||
|
24
Source/LegumeMix/Public/Ammo/LMAmmoPack.h
Normal file
24
Source/LegumeMix/Public/Ammo/LMAmmoPack.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "LMAmmoType.h"
|
||||
#include "LMItemDrop.h"
|
||||
#include "LMAmmoPack.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class LEGUMEMIX_API ALMAmmoPack : public ALMItemDrop
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true, ClampMin=0))
|
||||
int AmmoCount = 6;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||
EAmmoType AmmoType = EAmmoType::EAT_CornAmmo;
|
||||
|
||||
public:
|
||||
ALMAmmoPack();
|
||||
};
|
42
Source/LegumeMix/Public/Ammo/LMItemDropComponent.h
Normal file
42
Source/LegumeMix/Public/Ammo/LMItemDropComponent.h
Normal file
@ -0,0 +1,42 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "LMAmmoType.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "LMItemDropComponent.generated.h"
|
||||
|
||||
class ALMAmmoPack;
|
||||
class ALMHealthPack;
|
||||
|
||||
UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class LEGUMEMIX_API ULMItemDropComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||
TObjectPtr<UCurveFloat> DropChanceAtRemainingAmmo;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true, ClampMin=0, ClampMax=100, UIMin=0, UIMax=100))
|
||||
float DropChanceHealthPack = 10.f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||
EAmmoType AmmoType = EAmmoType::EAT_CornAmmo;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||
TSubclassOf<ALMAmmoPack> AmmoPack;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||
TSubclassOf<ALMHealthPack> HealthPack;
|
||||
|
||||
public:
|
||||
ULMItemDropComponent();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void TryDropItems();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SpawnAmmo();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SpawnHealth();
|
||||
};
|
20
Source/LegumeMix/Public/LMHealthPack.h
Normal file
20
Source/LegumeMix/Public/LMHealthPack.h
Normal file
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "LMItemDrop.h"
|
||||
#include "LMHealthPack.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class LEGUMEMIX_API ALMHealthPack : public ALMItemDrop
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true, ClampMin=0))
|
||||
float HealthGain = 10.f;
|
||||
|
||||
public:
|
||||
ALMHealthPack();
|
||||
};
|
33
Source/LegumeMix/Public/LMItemDrop.h
Normal file
33
Source/LegumeMix/Public/LMItemDrop.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "LMItemDrop.generated.h"
|
||||
|
||||
class ULMDropData;
|
||||
|
||||
UCLASS()
|
||||
class LEGUMEMIX_API ALMItemDrop : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix)
|
||||
float TimeBeforeDespawn = 30.f;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<UStaticMeshComponent> StaticMeshComponent;
|
||||
|
||||
FTimerHandle DespawnHandle;
|
||||
|
||||
public:
|
||||
ALMItemDrop();
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
protected:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void Despawn();
|
||||
};
|
@ -38,6 +38,8 @@ public:
|
||||
bool AddAmmoType(EAmmoType AmmoType, int AmmoCount);
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
int GetAmmoCount(EAmmoType AmmoType);
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
FLMAmmoData& GetAmmoData(EAmmoType AmmoType);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
void Fire();
|
||||
|
Reference in New Issue
Block a user