diff --git a/Content/Blueprints/Weapons/WeaponTableDefinitions.uasset b/Content/Blueprints/Weapons/WeaponTableDefinitions.uasset index aae9294fd..27467c63a 100644 Binary files a/Content/Blueprints/Weapons/WeaponTableDefinitions.uasset and b/Content/Blueprints/Weapons/WeaponTableDefinitions.uasset differ diff --git a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp index 11527d202..443af4ddd 100644 --- a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp +++ b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp @@ -23,12 +23,15 @@ #include "WeaponDefinitionsAsset.h" +#include "Cloud9/Tools/Macro/Common.h" +#include "Cloud9/Tools/Macro/Logging.h" + #include "Cloud9/Weapon/Extensions/EWeaponId.h" const FPrimaryAssetId UWeaponDefinitionsAsset::PrimaryAssetId = FPrimaryAssetId("Weapon:Definitions"); template -TOptional UWeaponDefinitionsAsset::GetWeaponDefinition( +FWeaponDefinition UWeaponDefinitionsAsset::GetWeaponDefinition( UDataTable* WeaponsInfoTable, ValidatorType Validator, WeaponIdType WeaponId) const @@ -73,28 +76,26 @@ TOptional UWeaponDefinitionsAsset::GetWeaponDefinition( return {}; } - return FWeaponDefinition(*WeaponInfo, *Montages); + return FWeaponDefinition(*WeaponInfo, *Montages, WeaponCommonData); } bool UWeaponDefinitionsAsset::GetWeaponDefinition(const FWeaponId& WeaponId, FWeaponDefinition& WeaponDefinition) const { - var Found = Visit( + WeaponDefinition = Visit( ETVariant::Overloaded{ [&](EFirearm Id) { return GetWeaponDefinition(FirearmsWeaponsInfoTable, UWeaponType::IsFirearm, Id); }, [&](EMelee Id) { return GetWeaponDefinition(MeleeWeaponsInfoTable, UWeaponType::IsMelee, Id); }, [&](EGrenade Id) { return GetWeaponDefinition(GrenadeWeaponInfoTable, UWeaponType::IsGrenade, Id); }, - [](auto) { return TOptional(); } + [](auto) { return FWeaponDefinition{}; } }, WeaponId ); - if (not Found.IsSet()) + if (not IsValid(WeaponDefinition)) { log(Error, "Can't get weapon definition for WeaponId='%s'", WeaponId | EFWeaponId::ToName() | EFName::ToCStr()); return false; } - WeaponDefinition = MoveTemp(*Found); - return true; } diff --git a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.h b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.h index 49c3ab158..966311f30 100644 --- a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.h +++ b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.h @@ -25,11 +25,10 @@ #include "Engine/DataTable.h" -#include "Cloud9/Tools/Macro/Common.h" -#include "Cloud9/Tools/Macro/Logging.h" #include "Cloud9/Weapon/Enums/WeaponId.h" #include "Cloud9/Weapon/Enums/WeaponType.h" #include "Cloud9/Weapon/Structures/WeaponDefinition.h" +#include "Cloud9/Weapon/Tables/WeaponCommonData.h" #include "Cloud9/Weapon/Tables/WeaponMontages.h" #include "WeaponDefinitionsAsset.generated.h" @@ -74,14 +73,14 @@ class CLOUD9_API UWeaponDefinitionsAsset : public UPrimaryDataAsset TMap WeaponActionMontages; /** - * Weapon tracer + * Weapon common data */ UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Weapon) - UParticleSystem* FirearmTracer; + FWeaponCommonData WeaponCommonData; private: // functions template - TOptional GetWeaponDefinition( + FWeaponDefinition GetWeaponDefinition( UDataTable* WeaponsInfoTable, ValidatorType Validator, WeaponIdType WeaponId) const; diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index 1589426c2..bf46d2b6d 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -23,12 +23,15 @@ #include "Cloud9WeaponFirearm.h" +#include "Cloud9/Tools/Macro/Common.h" +#include "Cloud9/Tools/Macro/Logging.h" #include "Cloud9/Tools/Extensions/AActor.h" #include "Cloud9/Tools/Extensions/TVariant.h" #include "Cloud9/Tools/Extensions/USoundBase.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" #include "Cloud9/Game/Cloud9PlayerController.h" #include "Cloud9/Character/Cloud9Character.h" +#include "Cloud9/Tools/Extensions/FVector.h" #include "Cloud9/Weapon/Tables/WeaponTableFirearm.h" @@ -146,6 +149,7 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) let Character = GetOwner(); let WeaponInfo = WeaponDefinition.GetWeaponInfo(); let PoseMontages = WeaponDefinition.GetPoseMontages(Character->bIsCrouched); + let CommonData = WeaponDefinition.GetCommonData(); if (bIsDeploying) { @@ -171,7 +175,7 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) PlayRandomSound(WeaponInfo->Sounds.FireSounds, Settings->Volume)) { MuzzleFlash->Activate(true); - return Fire(); + return Fire(WeaponInfo, CommonData->ImpulseMultiplier); } return false; @@ -187,7 +191,7 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) else {} } -bool ACloud9WeaponFirearm::Fire() const +bool ACloud9WeaponFirearm::Fire(const FFirearmWeaponInfo* WeaponInfo, float ImpulseMultiplier) const { let Character = GetOwner(); @@ -228,10 +232,8 @@ bool ACloud9WeaponFirearm::Fire() const if (Target->IsSimulatingPhysics() and Target->Mobility == EComponentMobility::Movable) { - var Direction = LineHit.Location - StartLocation; - Direction.Normalize(); - // TODO: Add impulse based on weapon type (weapon power) - Target->AddImpulse(1000.0 * Direction, NAME_None, true); + let Direction = (LineHit.Location - StartLocation) | EFVector::Normalize{}; + Target->AddImpulse(WeaponInfo->Damage * ImpulseMultiplier * Direction, NAME_None, true); } return true; diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.h b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.h index 6c2aa4e89..cd00588da 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.h +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.h @@ -26,8 +26,6 @@ #include "CoreMinimal.h" #include "NiagaraComponent.h" -#include "Cloud9/Tools/Macro/Common.h" -#include "Cloud9/Tools/Macro/Logging.h" #include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h" #include "Cloud9/Weapon/Enums/FirearmNames.h" @@ -69,7 +67,7 @@ class CLOUD9_API ACloud9WeaponFirearm : public ACloud9WeaponBase virtual void Tick(float DeltaSeconds) override; - bool Fire() const; + bool Fire(const FFirearmWeaponInfo* WeaponInfo, float ImpulseMultiplier) const; protected: // properties /** diff --git a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h index b00b79729..fab632c60 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h +++ b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h @@ -24,6 +24,7 @@ #pragma once #include "Cloud9/Weapon/Enums/WeaponClass.h" +#include "Cloud9/Weapon/Tables/WeaponCommonData.h" #include "Cloud9/Weapon/Tables/WeaponTableBase.h" #include "Cloud9/Weapon/Tables/WeaponMontages.h" #include "Cloud9/Weapon/Tables/WeaponTableFirearm.h" @@ -44,23 +45,23 @@ struct FWeaponDefinition FWeaponDefinition() = default; - FWeaponDefinition(FMeleeWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, UParticleSystem* Tracer = nullptr) + FWeaponDefinition(FMeleeWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, FWeaponCommonData WeaponCommonData) : WeaponClass(EWeaponClass::Melee) , MeleeWeaponInfo(MoveTemp(WeaponInfo)) , Montages(MoveTemp(Montages)) - , Tracer(Tracer) {} + , WeaponCommonData(MoveTemp(WeaponCommonData)) {} - FWeaponDefinition(FFirearmWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, UParticleSystem* Tracer = nullptr) + FWeaponDefinition(FFirearmWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, FWeaponCommonData WeaponCommonData) : WeaponClass(EWeaponClass::Firearm) , FirearmWeaponInfo(MoveTemp(WeaponInfo)) , Montages(MoveTemp(Montages)) - , Tracer(Tracer) {} + , WeaponCommonData(MoveTemp(WeaponCommonData)) {} - FWeaponDefinition(FGrenadeWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, UParticleSystem* Tracer = nullptr) + FWeaponDefinition(FGrenadeWeaponInfo WeaponInfo, FWeaponPosesMontages Montages, FWeaponCommonData WeaponCommonData) : WeaponClass(EWeaponClass::Grenade) , GrenadeWeaponInfo(MoveTemp(WeaponInfo)) , Montages(MoveTemp(Montages)) - , Tracer(Tracer) {} + , WeaponCommonData(MoveTemp(WeaponCommonData)) {} // TODO: Refactor FWeaponDefinition somehow... template @@ -117,6 +118,8 @@ struct FWeaponDefinition return not bIsCrouch ? &Montages.OnStand : &Montages.OnCrouch; } + FORCEINLINE const FWeaponCommonData* GetCommonData() const { return &WeaponCommonData; } + void Reset() { if (WeaponClass == EWeaponClass::Melee) @@ -135,7 +138,7 @@ struct FWeaponDefinition } WeaponClass = EWeaponClass::NoClass; - Tracer = nullptr; + WeaponCommonData = {}; } protected: @@ -155,5 +158,5 @@ struct FWeaponDefinition FWeaponPosesMontages Montages{}; UPROPERTY() - UParticleSystem* Tracer = nullptr; + FWeaponCommonData WeaponCommonData{}; }; diff --git a/Source/Cloud9/Weapon/Tables/WeaponCommonData.h b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h new file mode 100644 index 000000000..b26953a0a --- /dev/null +++ b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h @@ -0,0 +1,38 @@ +// Copyright (c) 2023 Alexei Gladkikh +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#pragma once + +#include "WeaponCommonData.generated.h" + +USTRUCT(BlueprintType) +struct FWeaponCommonData +{ + GENERATED_BODY() + + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Damage) + float ImpulseMultiplier = 50.0f; + + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Visual) + UParticleSystem* FirearmTracer; +};