Implemented infinite ammo / clip commands
This commit is contained in:
parent
1e3baeb391
commit
44d6d7f36a
BIN
Content/Legumix/Weapon/Revolver/BP_Revolver.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Weapon/Revolver/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.
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Weapon/LMRevolver.h"
|
||||
|
||||
#include "LMUtils.h"
|
||||
#include "Player/LMBulletInfo.h"
|
||||
#include "Player/LMPlayer.h"
|
||||
|
||||
@ -36,6 +37,10 @@ void ALMRevolver::PrimaryFire()
|
||||
const FVector Origin = Player->GetWeaponFiringOrigin();
|
||||
const FVector Direction = Player->GetAimVector();
|
||||
|
||||
const int InfiniteClip = LMCheats::CVarInfiniteClip.GetValueOnGameThread();
|
||||
if (InfiniteClip == 0)
|
||||
ClipAmmo--;
|
||||
else if (InfiniteClip == 1 and ClipAmmo > 1)
|
||||
ClipAmmo--;
|
||||
|
||||
FLMBulletInfo ShotInfo = FLMBulletInfo(1, Origin, Direction, WeaponSpread, MaxDistance, DamageFalloff, AmmoType, Damage);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Weapon/LMShotgun.h"
|
||||
|
||||
#include "LMUtils.h"
|
||||
#include "Player/LMBulletInfo.h"
|
||||
#include "Player/LMPlayer.h"
|
||||
|
||||
@ -35,6 +36,10 @@ void ALMShotgun::PrimaryFire()
|
||||
const FVector Origin = Player->GetWeaponFiringOrigin();
|
||||
const FVector Direction = Player->GetAimVector();
|
||||
|
||||
const int InfiniteClip = LMCheats::CVarInfiniteClip.GetValueOnGameThread();
|
||||
if (InfiniteClip == 0)
|
||||
ClipAmmo--;
|
||||
else if (InfiniteClip == 1 and ClipAmmo > 1)
|
||||
ClipAmmo--;
|
||||
|
||||
FLMBulletInfo ShotInfo = FLMBulletInfo(PelletCount, Origin, Direction, WeaponSpread, MaxDistance, DamageFalloff, AmmoType, Damage);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Weapon/LMWeaponBase.h"
|
||||
|
||||
#include "LMUtils.h"
|
||||
#include "Components/AudioComponent.h"
|
||||
#include "Player/LMPlayer.h"
|
||||
|
||||
@ -82,9 +83,13 @@ bool ALMWeaponBase::DefaultReload()
|
||||
if (State != EWeaponState::EWS_Idle)
|
||||
return false;
|
||||
|
||||
int InfiniteAmmo = LMCheats::CVarInfiniteAmmo.GetValueOnGameThread();
|
||||
if (InfiniteAmmo <= 0)
|
||||
{
|
||||
const int AmmoCount = Player->GetAmmoCount(AmmoType);
|
||||
if (AmmoCount <= 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ClipAmmo >= MaxClip)
|
||||
return false;
|
||||
@ -102,6 +107,13 @@ bool ALMWeaponBase::DefaultReload()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ALMWeaponBase::OnDefaultReload_Implementation()
|
||||
{
|
||||
const int RequestedAmmo = MaxClip - ClipAmmo;
|
||||
const int ReceivedAmmo = Player->RemoveAmmo(AmmoType, RequestedAmmo);
|
||||
ClipAmmo += ReceivedAmmo;
|
||||
}
|
||||
|
||||
void ALMWeaponBase::AllowRefire()
|
||||
{
|
||||
// TODO : improve this
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Weapon/LMWeaponManager.h"
|
||||
|
||||
#include "LMUtils.h"
|
||||
#include "Weapon/LMWeaponBase.h"
|
||||
|
||||
|
||||
@ -48,6 +49,10 @@ int ULMWeaponManager::RemoveAmmo(const EAmmoType Ammo, const int Count)
|
||||
{
|
||||
if (AmmoData.Contains(Ammo))
|
||||
{
|
||||
const int InfiniteAmmo = LMCheats::CVarInfiniteAmmo.GetValueOnGameThread();
|
||||
if (InfiniteAmmo == 2)
|
||||
return Count;
|
||||
|
||||
FLMAmmoData &Data = AmmoData[Ammo];
|
||||
|
||||
int Difference = Data.AmmoCount - Count;
|
||||
@ -55,7 +60,7 @@ int ULMWeaponManager::RemoveAmmo(const EAmmoType Ammo, const int Count)
|
||||
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);
|
||||
Data.AmmoCount = FMath::Clamp(Data.AmmoCount - Count, InfiniteAmmo == 1 ? 1 : 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;
|
||||
}
|
||||
|
@ -2,3 +2,23 @@
|
||||
|
||||
/** The Trace Channel for Bullets. */
|
||||
#define TRACE_BULLET ECC_GameTraceChannel1
|
||||
|
||||
namespace LMCheats
|
||||
{
|
||||
static TAutoConsoleVariable<int> CVarInfiniteAmmo(
|
||||
TEXT("l.InfiniteAmmo"),
|
||||
0,
|
||||
TEXT("Defines if an ammo type stockage is infinite or not.\n")
|
||||
TEXT("0 = off\n")
|
||||
TEXT("1 = decrease until 1 ammo\n")
|
||||
TEXT("2 = infinite ammo"));
|
||||
|
||||
|
||||
static TAutoConsoleVariable<int> CVarInfiniteClip(
|
||||
TEXT("l.InfiniteClip"),
|
||||
0,
|
||||
TEXT("Defines if a clip is infinite or not.\n")
|
||||
TEXT("0 = off\n")
|
||||
TEXT("1 = decrease until 1 bullet left in clip\n")
|
||||
TEXT("2 = infinite clip"));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FName GetAttachmentSocketName() const { return WeaponSocket; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
|
||||
void OnDefaultReload();
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user