Added : virtual and override fire for weapons
This commit is contained in:
parent
3c68d50ed1
commit
e9e8ce49a2
BIN
Content/Legumix/Player/BP_Player.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/BP_Player.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Player/BP_PlayerController.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/BP_PlayerController.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Player/Input/IA_Scroll.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Legumix/Player/Input/IA_Scroll.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Legumix/Player/Input/IMC_Default.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/Input/IMC_Default.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset
(Stored with Git LFS)
Binary file not shown.
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Player/LMPlayer.h"
|
#include "Player/LMPlayer.h"
|
||||||
|
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Weapon/LMAmmo.h"
|
#include "Weapon/LMAmmo.h"
|
||||||
#include "Weapon/LMWeaponManager.h"
|
#include "Weapon/LMWeaponManager.h"
|
||||||
|
|
||||||
@ -9,13 +11,14 @@ ALMPlayer::ALMPlayer()
|
|||||||
{
|
{
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// 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;
|
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 = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon Mesh"));
|
||||||
WeaponSkeletalMeshComponent->SetupAttachment(GetMesh());
|
WeaponSkeletalMeshComponent->SetupAttachment(Camera);
|
||||||
|
|
||||||
WeaponManager->SetWeaponMeshComponent(WeaponSkeletalMeshComponent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// 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
|
// Called every frame
|
||||||
void ALMPlayer::Tick(float DeltaTime)
|
void ALMPlayer::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,7 @@ void ALMPlayerController::SetupInputComponent()
|
|||||||
Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look);
|
Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look);
|
||||||
Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire);
|
Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire);
|
||||||
Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload);
|
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();
|
LegumixPlayer->GetWeaponManager()->Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ALMPlayerController::Scroll(const FInputActionValue& InputValue)
|
||||||
|
{
|
||||||
|
const float ScrollAmount = InputValue.Get<float>();
|
||||||
|
LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount);
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "Weapon\LMBazoucorn.h"
|
#include "Weapon\LMBazoucorn.h"
|
||||||
|
|
||||||
void ULMWeapon::Fire()
|
void UBazoucorn::Fire()
|
||||||
{
|
{
|
||||||
//Fire like a Bazoucorn
|
//Fire like a Bazoucorn
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "Weapon/LMRadivolver.h"
|
#include "Weapon/LMRadivolver.h"
|
||||||
|
|
||||||
void ULMWeapon::Fire()
|
void ULMRadivolver::Fire()
|
||||||
{
|
{
|
||||||
//Fire like a Radivolver
|
//Fire like a Radivolver
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
void ULMWeapon::Initialize()
|
void ULMWeapon::Initialize()
|
||||||
{
|
{
|
||||||
WeaponDataStructure =* WeaponRow.GetRow<FLMWeaponDataStructure>(TEXT(""));
|
WeaponDataStructure =* WeaponRow.GetRow<FLMWeaponDataStructure>(TEXT(""));
|
||||||
|
|
||||||
|
//Get FVector de la position de l'arme
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ULMWeapon::HasAmmoInClip()
|
bool ULMWeapon::HasAmmoInClip()
|
||||||
|
@ -14,6 +14,11 @@ ULMWeaponManager::ULMWeaponManager()
|
|||||||
void ULMWeaponManager::BeginPlay()
|
void ULMWeaponManager::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
||||||
|
{
|
||||||
|
SetWeaponMeshComponent(Mesh);
|
||||||
|
|
||||||
for (auto Weapon : StartingWeapons)
|
for (auto Weapon : StartingWeapons)
|
||||||
{
|
{
|
||||||
@ -21,19 +26,18 @@ void ULMWeaponManager::BeginPlay()
|
|||||||
{
|
{
|
||||||
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
|
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
|
||||||
Weapons.Add(Instance);
|
Weapons.Add(Instance);
|
||||||
|
|
||||||
// TODO
|
// Instance->Initialize(Mesh->GetRelativeLocation());
|
||||||
// Instance->Initialize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Weapons.IsEmpty())
|
if (!Weapons.IsEmpty())
|
||||||
{
|
{
|
||||||
SetWeapon(CurrentWeaponIndex);
|
SetWeapon(CurrentWeaponIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType);
|
||||||
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug);
|
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug);
|
||||||
@ -41,33 +45,46 @@ void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount)
|
|||||||
for (const auto Weapon : Weapons)
|
for (const auto Weapon : Weapons)
|
||||||
{
|
{
|
||||||
// TODO : match weapon ammo type
|
// TODO : match weapon ammo type
|
||||||
if (!Weapon)
|
if (Weapon->WeaponDataStructure.AmmoType == AmmoType)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO
|
Weapon->AddAmmo(AmmoCount);
|
||||||
// Weapon.AddAmmo(AmmoCount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Fire()
|
void ULMWeaponManager::Fire()
|
||||||
{
|
{
|
||||||
// ULMWeapon* Weapon = GetCurrentWeapon();
|
ULMWeapon* Weapon = GetCurrentWeapon();
|
||||||
|
|
||||||
GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire");
|
GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire");
|
||||||
// TODO
|
Weapon->Fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Reload()
|
void ULMWeaponManager::Reload()
|
||||||
{
|
{
|
||||||
GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading");
|
GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading");
|
||||||
|
|
||||||
|
|
||||||
// ULMWeapon* Weapon = GetCurrentWeapon();
|
ULMWeapon* Weapon = GetCurrentWeapon();
|
||||||
// TODO
|
Weapon->Reload();
|
||||||
// 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())
|
if (Index < 0 || Index >= Weapons.Num())
|
||||||
{
|
{
|
||||||
@ -79,8 +96,9 @@ void ULMWeaponManager::SetWeapon(int Index)
|
|||||||
|
|
||||||
if (WeaponMeshComponent)
|
if (WeaponMeshComponent)
|
||||||
{
|
{
|
||||||
// TODO
|
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Has Mesh");
|
||||||
// WeaponMeshComponent->SetSkeletalMesh()
|
|
||||||
|
WeaponMeshComponent->SetSkeletalMeshAsset(GetCurrentWeapon()->WeaponDataStructure.MeshWeapon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "LMPlayer.generated.h"
|
#include "LMPlayer.generated.h"
|
||||||
|
|
||||||
|
class UCameraComponent;
|
||||||
class ULMWeaponManager;
|
class ULMWeaponManager;
|
||||||
|
|
||||||
class ALMAmmo;
|
class ALMAmmo;
|
||||||
@ -32,10 +33,16 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
ULMWeaponManager* GetWeaponManager() { return WeaponManager; }
|
ULMWeaponManager* GetWeaponManager() { return WeaponManager; }
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void SetWeaponManager(ULMWeaponManager* Manager);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
||||||
TObjectPtr<ULMWeaponManager> WeaponManager;
|
TObjectPtr<ULMWeaponManager> WeaponManager;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
||||||
TObjectPtr<USkeletalMeshComponent> WeaponSkeletalMeshComponent;
|
TObjectPtr<USkeletalMeshComponent> WeaponSkeletalMeshComponent;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
||||||
|
TObjectPtr<UCameraComponent> Camera;
|
||||||
};
|
};
|
||||||
|
@ -41,6 +41,9 @@ private:
|
|||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||||
TObjectPtr<UInputAction> ReloadAction;
|
TObjectPtr<UInputAction> ReloadAction;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||||
|
TObjectPtr<UInputAction> ScrollAction;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||||
TObjectPtr<ALMPlayer> LegumixPlayer;
|
TObjectPtr<ALMPlayer> LegumixPlayer;
|
||||||
@ -51,4 +54,5 @@ private:
|
|||||||
void Look(const FInputActionValue& InputValue);
|
void Look(const FInputActionValue& InputValue);
|
||||||
void Fire(const FInputActionValue& InputValue);
|
void Fire(const FInputActionValue& InputValue);
|
||||||
void Reload(const FInputActionValue& InputValue);
|
void Reload(const FInputActionValue& InputValue);
|
||||||
|
void Scroll(const FInputActionValue& InputValue);
|
||||||
};
|
};
|
||||||
|
@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable)
|
|||||||
class LEGUMEMIX_API UBazoucorn : public ULMWeapon
|
class LEGUMEMIX_API UBazoucorn : public ULMWeapon
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
virtual void Fire() override;
|
||||||
};
|
};
|
||||||
|
@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable)
|
|||||||
class LEGUMEMIX_API ULMRadivolver : public ULMWeapon
|
class LEGUMEMIX_API ULMRadivolver : public ULMWeapon
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
virtual void Fire() override;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void Fire();
|
virtual void Fire();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void Reload(); //Reload current clip to max ammo in clip
|
void Reload(); //Reload current clip to max ammo in clip
|
||||||
|
@ -15,7 +15,7 @@ struct FLMWeaponDataStructure : public FTableRowBase
|
|||||||
int MaxClipAmmo; // Max ammo in clip
|
int MaxClipAmmo; // Max ammo in clip
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
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)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
EAmmoType AmmoType; //Type of ammo, which ammo this weapon is using
|
EAmmoType AmmoType; //Type of ammo, which ammo this weapon is using
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "LMAmmo.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include "LMWeaponManager.generated.h"
|
#include "LMWeaponManager.generated.h"
|
||||||
|
|
||||||
@ -30,13 +31,16 @@ public:
|
|||||||
void SetWeapon(int Index);
|
void SetWeapon(int Index);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="Legumix")
|
UFUNCTION(BlueprintCallable, Category="Legumix")
|
||||||
void AddAmmoType(uint8 AmmoType, int AmmoCount);
|
void AddAmmoType(EAmmoType AmmoType, int AmmoCount);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="Legumix")
|
UFUNCTION(BlueprintCallable, Category="Legumix")
|
||||||
void Fire();
|
void Fire();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="Legumix")
|
UFUNCTION(BlueprintCallable, Category="Legumix")
|
||||||
void Reload();
|
void Reload();
|
||||||
|
void SwitchWeapon(int Direction);
|
||||||
|
|
||||||
|
void Initialize(USkeletalMeshComponent* Mesh);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
Reference in New Issue
Block a user