Added revolver and basic reloading
This commit is contained in:
parent
bc9c73df78
commit
6a82183c66
BIN
Content/Legumix/Player/Input/IA_Shoot.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/Input/IA_Shoot.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Weapon/Revolver/BP_Revolver.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Legumix/Weapon/Revolver/BP_Revolver.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Legumix/Weapon/Shotgun/BP_Revolver.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Weapon/Shotgun/BP_Revolver.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset
(Stored with Git LFS)
Binary file not shown.
@ -42,6 +42,16 @@ void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo)
|
|||||||
WeaponManager->AddAmmoType(Ammo->GetAmmoType(), Ammo->GetAmmoAmount());
|
WeaponManager->AddAmmoType(Ammo->GetAmmoType(), Ammo->GetAmmoAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ALMPlayer::GetAmmoCount(const EAmmoType AmmoType) const
|
||||||
|
{
|
||||||
|
return WeaponManager->GetAmmoCount(AmmoType);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ALMPlayer::RemoveAmmo(const EAmmoType AmmoType, const int Count) const
|
||||||
|
{
|
||||||
|
return WeaponManager->RemoveAmmo(AmmoType, Count);
|
||||||
|
}
|
||||||
|
|
||||||
void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager)
|
void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager)
|
||||||
{
|
{
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Set weapon manager"))
|
UE_LOG(LogTemp, Warning, TEXT("Set weapon manager"))
|
||||||
|
32
Source/LegumeMix/Private/Weapon/LMRevolver.cpp
Normal file
32
Source/LegumeMix/Private/Weapon/LMRevolver.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Weapon/LMRevolver.h"
|
||||||
|
|
||||||
|
#include "Player/LMBulletInfo.h"
|
||||||
|
#include "Player/LMPlayer.h"
|
||||||
|
|
||||||
|
|
||||||
|
ALMRevolver::ALMRevolver()
|
||||||
|
{
|
||||||
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ALMRevolver::PrimaryFire()
|
||||||
|
{
|
||||||
|
if (!Player)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlaySound(FireSound);
|
||||||
|
PlayAnimation(PrimaryFireAnimation);
|
||||||
|
|
||||||
|
const FVector Origin = Player->GetWeaponFiringOrigin();
|
||||||
|
const FVector Direction = Player->GetAimVector();
|
||||||
|
|
||||||
|
ClipAmmo--;
|
||||||
|
|
||||||
|
FLMBulletInfo ShotInfo = FLMBulletInfo(1, Origin, Direction, WeaponSpread, MaxDistance, DamageFalloff, AmmoType, Damage);
|
||||||
|
|
||||||
|
Player->FireBullets(ShotInfo);
|
||||||
|
}
|
||||||
|
|
@ -31,8 +31,3 @@ void ALMShotgun::PrimaryFire()
|
|||||||
Player->FireBullets(ShotInfo);
|
Player->FireBullets(ShotInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALMShotgun::Tick(float DeltaTime)
|
|
||||||
{
|
|
||||||
Super::Tick(DeltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ void ALMWeaponBase::Setup(USkeletalMeshComponent* Mesh, AActor* CharOwner)
|
|||||||
|
|
||||||
void ALMWeaponBase::Reload()
|
void ALMWeaponBase::Reload()
|
||||||
{
|
{
|
||||||
|
DefaultReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALMWeaponBase::PrimaryFire()
|
void ALMWeaponBase::PrimaryFire()
|
||||||
@ -52,7 +53,7 @@ void ALMWeaponBase::PlaySound(USoundWave* Sound, const bool Replacing)
|
|||||||
{
|
{
|
||||||
if (AudioComponent->IsPlaying() && !Replacing)
|
if (AudioComponent->IsPlaying() && !Replacing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AudioComponent->Stop();
|
AudioComponent->Stop();
|
||||||
AudioComponent->SetSound(Sound);
|
AudioComponent->SetSound(Sound);
|
||||||
AudioComponent->Play();
|
AudioComponent->Play();
|
||||||
@ -66,4 +67,25 @@ void ALMWeaponBase::PlayAnimation(UAnimMontage* Animation)
|
|||||||
{
|
{
|
||||||
AnimInstance->Montage_Play(Animation);
|
AnimInstance->Montage_Play(Animation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ALMWeaponBase::DefaultReload()
|
||||||
|
{
|
||||||
|
if (State != EWeaponState::EWS_Idle)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int AmmoCount = Player->GetAmmoCount(AmmoType);
|
||||||
|
if (AmmoCount <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ClipAmmo >= MaxClip)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlaySound(ReloadSound, true);
|
||||||
|
PlayAnimation(ReloadAnimation);
|
||||||
|
|
||||||
|
State = EWeaponState::EWS_Reloading;
|
||||||
|
|
||||||
|
// TODO: Use Animations
|
||||||
|
OnDefaultReload();
|
||||||
|
}
|
||||||
|
@ -42,6 +42,30 @@ void ULMWeaponManager::SetupAmmoData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ULMWeaponManager::RemoveAmmo(const EAmmoType Ammo, const int Count)
|
||||||
|
{
|
||||||
|
if (AmmoData.Contains(Ammo))
|
||||||
|
{
|
||||||
|
FLMAmmoData &Data = AmmoData[Ammo];
|
||||||
|
|
||||||
|
int Difference = Data.AmmoCount - Count;
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Difference: %i | Removing: %i | Storage: %i"), Difference, Count, Data.AmmoCount)
|
||||||
|
if (Difference < 0)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("%i - %i = %i"), Data.AmmoCount, Count, Data.AmmoCount - Count);
|
||||||
|
Data.AmmoCount = FMath::Clamp(Data.AmmoCount - Count, 0, Data.MaxAmmo);
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Difference < 0 | Munition to add: %i | Removed: %i | New Munition: %i"), Count + Difference, Count, Data.AmmoCount)
|
||||||
|
return Count + Difference;
|
||||||
|
}
|
||||||
|
|
||||||
|
Data.AmmoCount -= Count;
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("New munition: %i | Removed: %i"), Data.AmmoCount, Count)
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
||||||
{
|
{
|
||||||
ArmsMesh = Mesh;
|
ArmsMesh = Mesh;
|
||||||
@ -84,6 +108,14 @@ void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ULMWeaponManager::GetAmmoCount(const EAmmoType AmmoType)
|
||||||
|
{
|
||||||
|
if (AmmoData.Contains(AmmoType))
|
||||||
|
return AmmoData[AmmoType].AmmoCount;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Fire()
|
void ULMWeaponManager::Fire()
|
||||||
{
|
{
|
||||||
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
||||||
|
@ -24,9 +24,26 @@ public:
|
|||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION(BlueprintCallable)
|
||||||
void PickUpAmmo(ALMAmmo* Ammo);
|
void PickUpAmmo(ALMAmmo* Ammo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of ammo from the given type.
|
||||||
|
* @param AmmoType The ammo type to get.
|
||||||
|
* @return The amount of ammo from the given type.
|
||||||
|
*/
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
int GetAmmoCount(EAmmoType AmmoType) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a given amount of ammo from the type.
|
||||||
|
* @param AmmoType The type of ammo to remove.
|
||||||
|
* @param Count The amount of ammo to remove.
|
||||||
|
* @return The amount that was removed.
|
||||||
|
*/
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
int RemoveAmmo(EAmmoType AmmoType, int Count) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
17
Source/LegumeMix/Public/Weapon/LMRevolver.h
Normal file
17
Source/LegumeMix/Public/Weapon/LMRevolver.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "LMWeaponBase.h"
|
||||||
|
#include "LMRevolver.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class LEGUMEMIX_API ALMRevolver : public ALMWeaponBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
ALMRevolver();
|
||||||
|
virtual void PrimaryFire() override;
|
||||||
|
};
|
@ -13,7 +13,6 @@ class LEGUMEMIX_API ALMShotgun : public ALMWeaponBase
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ALMShotgun();
|
ALMShotgun();
|
||||||
virtual void Tick(float DeltaTime) override;
|
|
||||||
virtual void PrimaryFire() override;
|
virtual void PrimaryFire() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -39,12 +39,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
FName GetAttachmentSocketName() const { return WeaponSocket; }
|
FName GetAttachmentSocketName() const { return WeaponSocket; }
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
|
||||||
|
void OnDefaultReload();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void DefaultReload();
|
||||||
|
|
||||||
protected: /* Weapon Data */
|
protected: /* Weapon Data */
|
||||||
/** The sound to play when firing. */
|
/** The sound to play when firing. */
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
|
||||||
TObjectPtr<USoundWave> FireSound;
|
TObjectPtr<USoundWave> FireSound;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
|
||||||
|
TObjectPtr<USoundWave> ReloadSound;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Animations", meta=(AllowPrivateAccess=true))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Animations", meta=(AllowPrivateAccess=true))
|
||||||
TObjectPtr<UAnimMontage> PrimaryFireAnimation;
|
TObjectPtr<UAnimMontage> PrimaryFireAnimation;
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ public:
|
|||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||||
void AddAmmoType(EAmmoType AmmoType, int AmmoCount);
|
void AddAmmoType(EAmmoType AmmoType, int AmmoCount);
|
||||||
|
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||||
|
int GetAmmoCount(EAmmoType AmmoType);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||||
void Fire();
|
void Fire();
|
||||||
@ -45,6 +47,8 @@ public:
|
|||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
||||||
void SetupAmmoData();
|
void SetupAmmoData();
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
||||||
|
int RemoveAmmo(EAmmoType Ammo, int Count);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
Reference in New Issue
Block a user