Added : virtual and override fire for weapons

This commit is contained in:
sSebster 2025-01-21 17:14:10 +01:00
parent 3c68d50ed1
commit e9e8ce49a2
19 changed files with 100 additions and 37 deletions

BIN
Content/Legumix/Player/BP_Player.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Legumix/Player/Input/IA_Scroll.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,8 @@
#include "Player/LMPlayer.h"
#include "Camera/CameraComponent.h"
#include "Weapon/LMAmmo.h"
#include "Weapon/LMWeaponManager.h"
@ -10,12 +12,13 @@ ALMPlayer::ALMPlayer()
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
WeaponManager = CreateDefaultSubobject<ULMWeaponManager>(TEXT("Weapon Manager"));
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(RootComponent);
Camera->bUsePawnControlRotation = true;
Camera->SetRelativeLocation(FVector(20, 0, 90));
WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon Mesh"));
WeaponSkeletalMeshComponent->SetupAttachment(GetMesh());
WeaponManager->SetWeaponMeshComponent(WeaponSkeletalMeshComponent);
WeaponSkeletalMeshComponent->SetupAttachment(Camera);
}
// Called when the game starts or when spawned
@ -34,6 +37,19 @@ void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo)
}
}
void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager)
{
UE_LOG(LogTemp, Warning, TEXT("Set weapon manager"))
if (!Manager)
{
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.f, FColor::Red, TEXT("No Weapon Manager was given to the player !"));
return;
}
WeaponManager = Manager;
WeaponManager->Initialize(WeaponSkeletalMeshComponent);
}
// Called every frame
void ALMPlayer::Tick(float DeltaTime)
{

View File

@ -26,6 +26,7 @@ void ALMPlayerController::SetupInputComponent()
Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look);
Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire);
Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload);
Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll);
}
}
@ -57,3 +58,9 @@ void ALMPlayerController::Reload(const FInputActionValue& InputValue)
{
LegumixPlayer->GetWeaponManager()->Reload();
}
void ALMPlayerController::Scroll(const FInputActionValue& InputValue)
{
const float ScrollAmount = InputValue.Get<float>();
LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount);
}

View File

@ -3,7 +3,7 @@
#include "Weapon\LMBazoucorn.h"
void ULMWeapon::Fire()
void UBazoucorn::Fire()
{
//Fire like a Bazoucorn
}

View File

@ -3,7 +3,7 @@
#include "Weapon/LMRadivolver.h"
void ULMWeapon::Fire()
void ULMRadivolver::Fire()
{
//Fire like a Radivolver
}

View File

@ -5,6 +5,8 @@
void ULMWeapon::Initialize()
{
WeaponDataStructure =* WeaponRow.GetRow<FLMWeaponDataStructure>(TEXT(""));
//Get FVector de la position de l'arme
}
bool ULMWeapon::HasAmmoInClip()

View File

@ -14,6 +14,11 @@ ULMWeaponManager::ULMWeaponManager()
void ULMWeaponManager::BeginPlay()
{
Super::BeginPlay();
}
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
{
SetWeaponMeshComponent(Mesh);
for (auto Weapon : StartingWeapons)
{
@ -22,8 +27,7 @@ void ULMWeaponManager::BeginPlay()
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
Weapons.Add(Instance);
// TODO
// Instance->Initialize();
// Instance->Initialize(Mesh->GetRelativeLocation());
}
}
@ -33,7 +37,7 @@ void ULMWeaponManager::BeginPlay()
}
}
void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount)
void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount)
{
FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType);
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug);
@ -41,33 +45,46 @@ void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount)
for (const auto Weapon : Weapons)
{
// TODO : match weapon ammo type
if (!Weapon)
if (Weapon->WeaponDataStructure.AmmoType == AmmoType)
continue;
// TODO
// Weapon.AddAmmo(AmmoCount);
Weapon->AddAmmo(AmmoCount);
}
}
void ULMWeaponManager::Fire()
{
// ULMWeapon* Weapon = GetCurrentWeapon();
ULMWeapon* Weapon = GetCurrentWeapon();
GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire");
// TODO
Weapon->Fire();
}
void ULMWeaponManager::Reload()
{
GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading");
// ULMWeapon* Weapon = GetCurrentWeapon();
// TODO
// Weapon->Reload();
ULMWeapon* Weapon = GetCurrentWeapon();
Weapon->Reload();
}
void ULMWeaponManager::SetWeapon(int Index)
void ULMWeaponManager::SwitchWeapon(const int Direction)
{
const int NewIndex = Direction + CurrentWeaponIndex;
if (NewIndex >= 0 && NewIndex < Weapons.Num())
{
SetWeapon(NewIndex);
}
else
{
if (NewIndex < 0)
SetWeapon(Weapons.Num() - 1);
else
SetWeapon(0);
}
}
void ULMWeaponManager::SetWeapon(const int Index)
{
if (Index < 0 || Index >= Weapons.Num())
{
@ -79,8 +96,9 @@ void ULMWeaponManager::SetWeapon(int Index)
if (WeaponMeshComponent)
{
// TODO
// WeaponMeshComponent->SetSkeletalMesh()
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Has Mesh");
WeaponMeshComponent->SetSkeletalMeshAsset(GetCurrentWeapon()->WeaponDataStructure.MeshWeapon);
}
}

View File

@ -6,6 +6,7 @@
#include "GameFramework/Character.h"
#include "LMPlayer.generated.h"
class UCameraComponent;
class ULMWeaponManager;
class ALMAmmo;
@ -32,10 +33,16 @@ public:
UFUNCTION(BlueprintCallable)
ULMWeaponManager* GetWeaponManager() { return WeaponManager; }
UFUNCTION(BlueprintCallable)
void SetWeaponManager(ULMWeaponManager* Manager);
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<ULMWeaponManager> WeaponManager;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<USkeletalMeshComponent> WeaponSkeletalMeshComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<UCameraComponent> Camera;
};

View File

@ -42,6 +42,9 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<UInputAction> ReloadAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<UInputAction> ScrollAction;
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<ALMPlayer> LegumixPlayer;
@ -51,4 +54,5 @@ private:
void Look(const FInputActionValue& InputValue);
void Fire(const FInputActionValue& InputValue);
void Reload(const FInputActionValue& InputValue);
void Scroll(const FInputActionValue& InputValue);
};

View File

@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable)
class LEGUMEMIX_API UBazoucorn : public ULMWeapon
{
GENERATED_BODY()
virtual void Fire() override;
};

View File

@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable)
class LEGUMEMIX_API ULMRadivolver : public ULMWeapon
{
GENERATED_BODY()
virtual void Fire() override;
};

View File

@ -26,7 +26,7 @@ public:
void Initialize();
void Fire();
virtual void Fire();
UFUNCTION(BlueprintCallable)
void Reload(); //Reload current clip to max ammo in clip

View File

@ -15,7 +15,7 @@ struct FLMWeaponDataStructure : public FTableRowBase
int MaxClipAmmo; // Max ammo in clip
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UStaticMesh> MeshWeapon; //Mesh of the weapon display in the scene
TObjectPtr<USkeletalMesh> MeshWeapon; //Mesh of the weapon display in the scene
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EAmmoType AmmoType; //Type of ammo, which ammo this weapon is using

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "LMAmmo.h"
#include "Components/ActorComponent.h"
#include "LMWeaponManager.generated.h"
@ -30,13 +31,16 @@ public:
void SetWeapon(int Index);
UFUNCTION(BlueprintCallable, Category="Legumix")
void AddAmmoType(uint8 AmmoType, int AmmoCount);
void AddAmmoType(EAmmoType AmmoType, int AmmoCount);
UFUNCTION(BlueprintCallable, Category="Legumix")
void Fire();
UFUNCTION(BlueprintCallable, Category="Legumix")
void Reload();
void SwitchWeapon(int Direction);
void Initialize(USkeletalMeshComponent* Mesh);
protected:
virtual void BeginPlay() override;