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());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void ALMShotgun::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ void ALMWeaponBase::Setup(USkeletalMeshComponent* Mesh, AActor* CharOwner)
|
||||
|
||||
void ALMWeaponBase::Reload()
|
||||
{
|
||||
DefaultReload();
|
||||
}
|
||||
|
||||
void ALMWeaponBase::PrimaryFire()
|
||||
@ -67,3 +68,24 @@ void ALMWeaponBase::PlayAnimation(UAnimMontage* 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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
ALMWeaponBase* Weapon = GetCurrentWeapon();
|
||||
|
@ -24,9 +24,26 @@ public:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
UFUNCTION()
|
||||
UFUNCTION(BlueprintCallable)
|
||||
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:
|
||||
// Called when the game starts or when spawned
|
||||
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:
|
||||
ALMShotgun();
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void PrimaryFire() override;
|
||||
|
||||
private:
|
||||
|
@ -40,11 +40,20 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FName GetAttachmentSocketName() const { return WeaponSocket; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
|
||||
void OnDefaultReload();
|
||||
|
||||
private:
|
||||
void DefaultReload();
|
||||
|
||||
protected: /* Weapon Data */
|
||||
/** The sound to play when firing. */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
|
||||
TObjectPtr<USoundWave> FireSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
|
||||
TObjectPtr<USoundWave> ReloadSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Animations", meta=(AllowPrivateAccess=true))
|
||||
TObjectPtr<UAnimMontage> PrimaryFireAnimation;
|
||||
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
void AddAmmoType(EAmmoType AmmoType, int AmmoCount);
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
int GetAmmoCount(EAmmoType AmmoType);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category=Legumix)
|
||||
void Fire();
|
||||
@ -45,6 +47,8 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
||||
void SetupAmmoData();
|
||||
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
|
||||
int RemoveAmmo(EAmmoType Ammo, int Count);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
Reference in New Issue
Block a user