Narrowing
This commit is contained in:
@@ -254,11 +254,12 @@ FVector UEBBarrel::CalculateRecoilImpulse(UEBBulletPropertiesAsset* BulletType)
|
||||
float LengthFactor = FMath::Clamp(20.0f / BarrelLength, 0.8f, 1.5f);
|
||||
RecoilForce *= LengthFactor;
|
||||
|
||||
// Direction from weapon config (if parent gun has config)
|
||||
// Get recoil direction from the parent gun
|
||||
FVector RecoilDirection = FVector(0, 0, 1); // Default upward
|
||||
if (ParentGun && ParentGun->WeaponConfig)
|
||||
if (ParentGun)
|
||||
{
|
||||
RecoilDirection = ParentGun->WeaponConfig->BarrelConfig.RecoilDirection;
|
||||
// Use the gun's calculation for direction
|
||||
RecoilDirection = ParentGun->CalculateRecoilImpulse().GetSafeNormal();
|
||||
}
|
||||
|
||||
return RecoilDirection * RecoilForce;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "EBGun.h"
|
||||
#include "EBMagazine.h"
|
||||
#include "EBWeaponConfiguration.h"
|
||||
#include "EBWeaponData.h"
|
||||
#include "EBBullet.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
#include "Engine/Engine.h"
|
||||
@@ -92,9 +92,9 @@ void AEBGun::BeginPlay()
|
||||
SetMeshType(bUseSkeletal);
|
||||
|
||||
// Apply weapon configuration if available
|
||||
if (WeaponConfig)
|
||||
if (WeaponData)
|
||||
{
|
||||
ApplyWeaponConfiguration(WeaponConfig);
|
||||
ApplyWeaponData(WeaponData);
|
||||
}
|
||||
|
||||
// Initialize magazine
|
||||
@@ -249,7 +249,7 @@ void AEBGun::SetSafety(bool bNewSafetyState)
|
||||
|
||||
void AEBGun::ServerSetSafety_Implementation(bool bNewSafetyState)
|
||||
{
|
||||
if (!WeaponConfig || !WeaponConfig->FireControlConfig.bHasSafety)
|
||||
if (!WeaponData || !WeaponData->bHasSafety)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -463,67 +463,56 @@ UEBBulletPropertiesAsset* AEBGun::GetChamberedBulletType() const
|
||||
return ChamberedBulletType;
|
||||
}
|
||||
|
||||
void AEBGun::ApplyWeaponConfiguration(UEBWeaponConfiguration* NewConfig)
|
||||
void AEBGun::ApplyWeaponData(UEBWeaponData* NewData)
|
||||
{
|
||||
if (!NewConfig)
|
||||
{
|
||||
return;
|
||||
if (!NewData) return;
|
||||
WeaponData = NewData;
|
||||
|
||||
// Apply basic properties
|
||||
|
||||
// Barrel & Ballistics (defaults for unmapped)
|
||||
BarrelLength = 16.0f; // Default, no direct map
|
||||
RiflingTwist = 7.0f; // Default
|
||||
BoreRadius = 0.112f; // Default
|
||||
MuzzleVelocityMin = NewData->MuzzleVelocity;
|
||||
MuzzleVelocityMax = NewData->MuzzleVelocity;
|
||||
Spread = 1.0f - NewData->Accuracy;
|
||||
SpreadBias = 0.0f; // Default
|
||||
MuzzleVelocityMultiplierMin = 1.0f;
|
||||
MuzzleVelocityMultiplierMax = 1.0f;
|
||||
|
||||
// Fire Control
|
||||
FireMode = NewData->DefaultFireMode;
|
||||
FireRateMin = NewData->FireRate / 60.0f;
|
||||
FireRateMax = NewData->FireRate / 60.0f;
|
||||
BurstCount = NewData->BurstCount;
|
||||
BurstCooldown = 0.0f; // Default
|
||||
|
||||
// Gatling (defaults)
|
||||
bGatlingAutoSpool = true;
|
||||
GatlingSpoolUpTime = 1.0f;
|
||||
GatlingSpoolDownTime = 1.0f;
|
||||
|
||||
// Magazine
|
||||
if (Magazine) {
|
||||
Magazine->MagazineConfig.MaxCapacity = NewData->MagazineSize;
|
||||
// Add other magazine configs if needed
|
||||
}
|
||||
|
||||
WeaponConfig = NewConfig;
|
||||
|
||||
// Apply gun configuration from barrel config
|
||||
BarrelLength = NewConfig->BarrelConfig.BarrelLength;
|
||||
RiflingTwist = NewConfig->BarrelConfig.RiflingTwist;
|
||||
BoreRadius = NewConfig->BarrelConfig.BoreRadius;
|
||||
MuzzleVelocityMin = NewConfig->BarrelConfig.MuzzleVelocityMin;
|
||||
MuzzleVelocityMax = NewConfig->BarrelConfig.MuzzleVelocityMax;
|
||||
|
||||
// Apply fire control configuration to gun
|
||||
FireMode = NewConfig->FireControlConfig.DefaultFireMode;
|
||||
FireRateMin = NewConfig->FireControlConfig.FireRateMin / 60.0f; // Convert RPM to RPS
|
||||
FireRateMax = NewConfig->FireControlConfig.FireRateMax / 60.0f;
|
||||
BurstCount = NewConfig->FireControlConfig.BurstCount;
|
||||
BurstCooldown = NewConfig->FireControlConfig.BurstCooldown;
|
||||
GatlingSpoolUpTime = NewConfig->FireControlConfig.GatlingSpoolUpTime;
|
||||
GatlingSpoolDownTime = NewConfig->FireControlConfig.GatlingSpoolDownTime;
|
||||
bGatlingAutoSpool = NewConfig->FireControlConfig.bGatlingAutoSpool;
|
||||
|
||||
// Apply configuration to barrel for backward compatibility
|
||||
if (Barrel)
|
||||
{
|
||||
// Set parent gun reference
|
||||
Barrel->SetParentGun(this);
|
||||
|
||||
// Apply barrel-specific configuration
|
||||
Barrel->ApplyBarrelConfiguration(NewConfig->BarrelConfig);
|
||||
|
||||
// Apply networking configuration from gun to barrel
|
||||
Barrel->ReplicateShotFiredEvents = NewConfig->bReplicateShotEvents;
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("Barrel '%s' configured by Gun '%s'"), *Barrel->GetName(), *NewConfig->GetWeaponDisplayName());
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("Gun '%s' applied configuration"), *NewConfig->GetWeaponDisplayName());
|
||||
|
||||
// Apply configuration to magazine
|
||||
if (Magazine)
|
||||
{
|
||||
Magazine->MagazineConfig.MaxCapacity = NewConfig->DefaultMagazineCapacity;
|
||||
Magazine->MagazineConfig.MagazineType = NewConfig->DefaultMagazineType;
|
||||
Magazine->MagazineConfig.bAllowMixedBulletTypes = NewConfig->bAllowMixedAmmo;
|
||||
Magazine->MagazineConfig.MalfunctionChance = NewConfig->ReliabilityConfig.MalfunctionRate;
|
||||
}
|
||||
|
||||
// Set default safety state
|
||||
if (NewConfig->FireControlConfig.bHasSafety)
|
||||
{
|
||||
bSafetyOn = NewConfig->FireControlConfig.bDefaultSafetyOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Safety
|
||||
if (NewData->bHasSafety) {
|
||||
// bSafetyOn is managed by the gun state, not set from data by default.
|
||||
// Default is 'false' (off). Use SetSafety() to change.
|
||||
} else {
|
||||
bSafetyOn = false;
|
||||
}
|
||||
|
||||
// Apply to barrel for compatibility
|
||||
if (Barrel) {
|
||||
// Map relevant fields to barrel
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("Gun '%s' applied data configuration"), *NewData->WeaponName.ToString());
|
||||
}
|
||||
|
||||
void AEBGun::SetFireMode(EFireMode NewFireMode)
|
||||
@@ -540,8 +529,16 @@ void AEBGun::SetFireMode(EFireMode NewFireMode)
|
||||
|
||||
void AEBGun::ServerSetFireMode_Implementation(EFireMode NewFireMode)
|
||||
{
|
||||
if (!WeaponConfig || !WeaponConfig->IsFireModeAvailable(NewFireMode))
|
||||
if (!WeaponData || !WeaponData->IsFireModeSupported(NewFireMode))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] SetFireMode() FAILED - Invalid fire mode: %s"), *UEnum::GetValueAsString(NewFireMode));
|
||||
//Is weapon config null?
|
||||
if (!WeaponData)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] Weapon config is null"));
|
||||
}
|
||||
//Is the fire mode available?
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] Fire mode available: %s"), WeaponData->IsFireModeSupported(NewFireMode) ? TEXT("True") : TEXT("False"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -942,12 +939,8 @@ void AEBGun::SwitchFireMode(EFireMode NewFireMode)
|
||||
|
||||
void AEBGun::ServerSwitchFireMode_Implementation(EFireMode NewFireMode)
|
||||
{
|
||||
if (WeaponConfig && WeaponConfig->IsFireModeAvailable(NewFireMode))
|
||||
{
|
||||
if (WeaponData && WeaponData->IsFireModeSupported(NewFireMode)) {
|
||||
FireMode = NewFireMode;
|
||||
|
||||
// Update barrel for backward compatibility
|
||||
// Barrel no longer keeps FireMode state.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -456,7 +456,12 @@ void UEBPlayerWeaponController::ApplyWeaponData(UEBWeaponData* WeaponData)
|
||||
{
|
||||
UEBWeaponData* PreviousWeapon = CurrentWeaponData;
|
||||
CurrentWeaponData = WeaponData;
|
||||
|
||||
|
||||
// Set WeaponData on the WeaponActor as well
|
||||
if (WeaponActor)
|
||||
{
|
||||
WeaponActor->WeaponData = WeaponData;
|
||||
}
|
||||
// Debug logging if enabled
|
||||
if (CurrentWeaponData && CurrentWeaponData->bEnableFireDebug)
|
||||
{
|
||||
@@ -464,16 +469,16 @@ void UEBPlayerWeaponController::ApplyWeaponData(UEBWeaponData* WeaponData)
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] - Previous Weapon: %s"), PreviousWeapon ? *PreviousWeapon->WeaponName.ToString() : TEXT("None"));
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] - New Weapon: %s"), WeaponData ? *WeaponData->WeaponName.ToString() : TEXT("None"));
|
||||
}
|
||||
|
||||
|
||||
// Apply to weapon actor
|
||||
InternalApplyWeaponData(WeaponData);
|
||||
|
||||
|
||||
// Update ammo
|
||||
UpdateAmmoFromWeaponData();
|
||||
|
||||
|
||||
// Broadcast event
|
||||
OnWeaponChanged.Broadcast(WeaponData);
|
||||
|
||||
|
||||
if (CurrentWeaponData && CurrentWeaponData->bEnableFireDebug)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[WEAPON DEBUG] ApplyWeaponData() completed - weapon data applied and events broadcast"));
|
||||
|
||||
@@ -77,6 +77,6 @@ void UEBWeaponConfiguration::ApplyConfigurationToGun(AEBGun* Gun) const
|
||||
{
|
||||
if (Gun)
|
||||
{
|
||||
Gun->ApplyWeaponConfiguration(const_cast<UEBWeaponConfiguration*>(this));
|
||||
// Gun->ApplyWeaponConfiguration(const_cast<UEBWeaponConfiguration*>(this));
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "EBBarrel.h"
|
||||
#include "EBMagazine.h"
|
||||
#include "EBWeaponConfiguration.h"
|
||||
#include "EBWeaponData.h"
|
||||
#include "EBBulletProperties.h"
|
||||
|
||||
#include "EBGun.generated.h"
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
// CONFIGURATION
|
||||
// ========================================
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "1. Configuration")
|
||||
UEBWeaponConfiguration* WeaponConfig;
|
||||
UEBWeaponData* WeaponData;
|
||||
|
||||
// ========================================
|
||||
// BARREL & BALLISTICS (Most Common Settings)
|
||||
@@ -292,7 +292,7 @@ public:
|
||||
|
||||
// Configuration
|
||||
UFUNCTION(BlueprintCallable, Category = "Ballistics|Configuration|Setup")
|
||||
void ApplyWeaponConfiguration(UEBWeaponConfiguration* NewConfig);
|
||||
void ApplyWeaponData(UEBWeaponData* NewData);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Ballistics|Configuration|Fire Control")
|
||||
void SetFireMode(EFireMode NewFireMode);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "EBGunActorFactory.h"
|
||||
#include "EBGun.h"
|
||||
#include "EBWeaponData.h"
|
||||
#include "Engine/Selection.h"
|
||||
#include "Editor.h"
|
||||
|
||||
@@ -17,7 +18,7 @@ bool UEBGunActorFactory::CanCreateActorFrom(const FAssetData& AssetData, FText&
|
||||
if (AssetData.IsValid())
|
||||
{
|
||||
UClass* AssetClass = AssetData.GetClass();
|
||||
if (AssetClass && AssetClass->IsChildOf(UEBWeaponConfiguration::StaticClass()))
|
||||
if (AssetClass && AssetClass->IsChildOf(UEBWeaponData::StaticClass()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -33,10 +34,10 @@ AActor* UEBGunActorFactory::SpawnActor(UObject* InAsset, ULevel* InLevel, const
|
||||
if (NewGun)
|
||||
{
|
||||
// If spawned from a weapon configuration asset, apply it
|
||||
if (UEBWeaponConfiguration* WeaponConfig = Cast<UEBWeaponConfiguration>(InAsset))
|
||||
if (UEBWeaponData* WeaponData = Cast<UEBWeaponData>(InAsset))
|
||||
{
|
||||
NewGun->WeaponConfig = WeaponConfig;
|
||||
NewGun->ApplyWeaponConfiguration(WeaponConfig);
|
||||
NewGun->WeaponData = WeaponData;
|
||||
NewGun->ApplyWeaponData(WeaponData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user