104 lines
2.0 KiB
C++
104 lines
2.0 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Weapon/LMWeaponManager.h"
|
|
|
|
#include "Weapon/LMWeapon.h"
|
|
|
|
|
|
ULMWeaponManager::ULMWeaponManager()
|
|
{
|
|
PrimaryComponentTick.bCanEverTick = false;
|
|
}
|
|
|
|
void ULMWeaponManager::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
|
|
{
|
|
SetWeaponMeshComponent(Mesh);
|
|
|
|
for (auto Weapon : StartingWeapons)
|
|
{
|
|
if (Weapon)
|
|
{
|
|
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
|
|
Weapons.Add(Instance);
|
|
|
|
Instance->Initialize(Mesh->GetRelativeLocation());
|
|
}
|
|
}
|
|
|
|
if (!Weapons.IsEmpty())
|
|
{
|
|
SetWeapon(CurrentWeaponIndex);
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
for (const auto Weapon : Weapons)
|
|
{
|
|
if (Weapon->WeaponDataStructure.AmmoType != AmmoType)
|
|
continue;
|
|
|
|
Weapon->AddAmmo(AmmoCount);
|
|
}
|
|
}
|
|
|
|
void ULMWeaponManager::Fire()
|
|
{
|
|
ULMWeapon* Weapon = GetCurrentWeapon();
|
|
|
|
GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire");
|
|
Weapon->Fire();
|
|
}
|
|
|
|
void ULMWeaponManager::Reload()
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading");
|
|
|
|
ULMWeapon* Weapon = GetCurrentWeapon();
|
|
Weapon->Reload();
|
|
}
|
|
|
|
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())
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index");
|
|
return;
|
|
}
|
|
|
|
CurrentWeaponIndex = Index;
|
|
|
|
if (WeaponMeshComponent)
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Has Mesh");
|
|
|
|
WeaponMeshComponent->SetSkeletalMeshAsset(GetCurrentWeapon()->WeaponDataStructure.MeshWeapon);
|
|
}
|
|
}
|
|
|