Started working on new ammo system
This commit is contained in:
parent
fc50cd6317
commit
ac4176e2f7
@ -1,9 +1,8 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
#include "Weapon/LMAmmo.h"
|
#include "Ammo/LMAmmo.h"
|
||||||
|
|
||||||
#include "Components/BoxComponent.h"
|
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
#include "Player/LMPlayer.h"
|
#include "Player/LMPlayer.h"
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Weapon/LMAmmoType.h"
|
#include "Ammo/LMAmmoType.h"
|
||||||
#include "LMBulletInfo.generated.h"
|
#include "LMBulletInfo.generated.h"
|
||||||
|
|
||||||
USTRUCT(BlueprintType)
|
USTRUCT(BlueprintType)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "KismetTraceUtils.h"
|
#include "KismetTraceUtils.h"
|
||||||
#include "LMBulletInfo.h"
|
#include "LMBulletInfo.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Weapon/LMAmmo.h"
|
#include "Ammo/LMAmmo.h"
|
||||||
#include "Weapon/LMWeaponManager.h"
|
#include "Weapon/LMWeaponManager.h"
|
||||||
|
|
||||||
ALMPlayer::ALMPlayer()
|
ALMPlayer::ALMPlayer()
|
||||||
|
@ -14,6 +14,32 @@ ULMWeaponManager::ULMWeaponManager()
|
|||||||
void ULMWeaponManager::BeginPlay()
|
void ULMWeaponManager::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
if (AmmoData.IsEmpty())
|
||||||
|
SetupAmmoData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ULMWeaponManager::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
|
||||||
|
{
|
||||||
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||||
|
|
||||||
|
if (AmmoDataTable)
|
||||||
|
SetupAmmoData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ULMWeaponManager::SetupAmmoData()
|
||||||
|
{
|
||||||
|
TArray<FLMAmmoData*> Rows;
|
||||||
|
AmmoData.Empty();
|
||||||
|
|
||||||
|
AmmoDataTable->GetAllRows(TEXT(""), Rows);
|
||||||
|
for (const auto Data : Rows)
|
||||||
|
{
|
||||||
|
if (AmmoData.Contains(Data->AmmoType))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
AmmoData.Add(Data->AmmoType, *Data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
||||||
@ -48,8 +74,6 @@ void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount)
|
|||||||
void ULMWeaponManager::Fire()
|
void ULMWeaponManager::Fire()
|
||||||
{
|
{
|
||||||
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
||||||
|
|
||||||
GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire");
|
|
||||||
Weapon->PrimaryFire();
|
Weapon->PrimaryFire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
Source/LegumeMix/Public/Ammo/LMAmmoData.h
Normal file
26
Source/LegumeMix/Public/Ammo/LMAmmoData.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "LMAmmoType.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
|
#include "LMAmmoData.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FLMAmmoData : public FTableRowBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
EAmmoType AmmoType;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin=1, ClampMax=1000, Uimin=1, Uimax=1000))
|
||||||
|
int MaxAmmo;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin=0, Uimin=0))
|
||||||
|
int AmmoCount;
|
||||||
|
|
||||||
|
void AddAmmo(const int Quantity)
|
||||||
|
{
|
||||||
|
AmmoCount += UKismetMathLibrary::Clamp(Quantity, 0, MaxAmmo);
|
||||||
|
}
|
||||||
|
};
|
@ -3,7 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "LMAmmo.h"
|
#include "Ammo/LMAmmo.h"
|
||||||
#include "LMWeaponDataStructure.h"
|
#include "LMWeaponDataStructure.h"
|
||||||
#include "GameFramework/Actor.h"
|
#include "GameFramework/Actor.h"
|
||||||
#include "LMWeaponBase.generated.h"
|
#include "LMWeaponBase.generated.h"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "LMAmmo.h"
|
#include "Ammo/LMAmmoData.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include "LMWeaponManager.generated.h"
|
#include "LMWeaponManager.generated.h"
|
||||||
|
|
||||||
@ -43,12 +43,20 @@ public:
|
|||||||
|
|
||||||
void Initialize(USkeletalMeshComponent* Mesh);
|
void Initialize(USkeletalMeshComponent* Mesh);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
||||||
|
void SetupAmmoData();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta = (AllowPrivateAccess = "true"))
|
||||||
TObjectPtr<USkeletalMeshComponent> ArmsMesh;
|
TObjectPtr<USkeletalMeshComponent> ArmsMesh;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Ammo", meta=(AllowPrivateAccess=true))
|
||||||
|
TObjectPtr<UDataTable> AmmoDataTable;
|
||||||
|
|
||||||
/** The weapons the player starts with. */
|
/** The weapons the player starts with. */
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||||
@ -59,4 +67,9 @@ private:
|
|||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true))
|
||||||
int CurrentWeaponIndex = 0;
|
int CurrentWeaponIndex = 0;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Ammo", meta=(AllowPrivateAccess=true))
|
||||||
|
TMap<EAmmoType, FLMAmmoData> AmmoData;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user