Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shoot effect on armored character #245

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Config/DefaultGame.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ bIsPrintHitScanInfo=0
CameraVerticalSpeedLag=0.000000
NetGraph=1
bIsAutoSelectWeapon=0
bIsInfiniteAmmo=0
bIsCheatsEnabled=0
bIsSelfAimEnabled=0
Volume=0.200000
UnUsedEnum=Everything
UnUsedStruct=(IntField0=3,FloatField1=0.000000)
Expand Down
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
Binary file modified Content/Physicals/PM_Character.uasset
Binary file not shown.
9 changes: 4 additions & 5 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ float ACloud9Character::InternalTakePointDamage(
let BoneName = PointDamageEvent.HitInfo.BoneName;
Damage = Super::InternalTakePointDamage(Damage, PointDamageEvent, EventInstigator, DamageCauser);

let Armor = HealthComponent->GetArmor();

if (let Weapon = Cast<ACloud9WeaponFirearm>(DamageCauser))
{
let WeaponInfo = Weapon->GetWeaponInfo();
Expand All @@ -334,12 +332,12 @@ float ACloud9Character::InternalTakePointDamage(
if (HeadBoneNames.Contains(BoneName))
{
Damage *= WeaponInfo->HeadshotMultiplier;
HitInArmor = true;
HitInArmor = HealthComponent->HasHelmet();
}
else if (UpperBodyBoneNames.Contains(BoneName))
{
Damage *= WeaponInfo->UpperBodyMultiplier;
HitInArmor = true;
HitInArmor = HealthComponent->IsArmored();
}
else if (LowerBodyBoneNames.Contains(BoneName))
{
Expand All @@ -350,9 +348,10 @@ float ACloud9Character::InternalTakePointDamage(
Damage *= WeaponInfo->LegMultiplier;
}

if (Armor != 0.0f and HitInArmor)
if (HitInArmor)
{
Damage *= WeaponInfo->ArmorPenetration * ArmorCoefficient;
HealthComponent->TakeArmorDamage(Damage / 2);
}

let Distance = FVector::DistSquared(DamageCauser->GetActorLocation(), GetActorLocation());
Expand Down
2 changes: 0 additions & 2 deletions Source/Cloud9/Character/Components/Cloud9HealthComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ void UCloud9HealthComponent::OnTakePointDamage(
AActor* DamageCauser)
{
TakeHealthDamage(Damage);
TakeArmorDamage(0.0f); // TODO: Add armor damage calc
AddAttackerScore(InstigatedBy);
}

Expand All @@ -181,6 +180,5 @@ void UCloud9HealthComponent::OnTakeRadialDamage(
AActor* DamageCauser)
{
TakeHealthDamage(Damage);
TakeArmorDamage(0.0f); // TODO: Add armor damage calc
AddAttackerScore(InstigatedBy);
}
1 change: 1 addition & 0 deletions Source/Cloud9/Character/Components/Cloud9HealthComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CLOUD9_API UCloud9HealthComponent : public UActorComponent

float GetHealth() const { return Health; }
float GetArmor() const { return Armor; }
bool IsArmored() const { return Armor > 0.0f; }
bool HasHelmet() const { return bHasHelmet; }
bool IsAlive() const { return bIsAlive; }

Expand Down
5 changes: 4 additions & 1 deletion Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ bool UCloud9PhysicalMaterial::TestBackgroundDecalProbability() const
return FMath::RandRange(0.0f, 1.0f) < FirearmBackgroundDecalProbability;
}

UNiagaraSystem* UCloud9PhysicalMaterial::GetRandomFirearmSquib() const { return GetRandomItem(FirearmEffects); }
UNiagaraSystem* UCloud9PhysicalMaterial::GetRandomFirearmSquib(bool IsAlternative) const
{
return IsAlternative ? GetRandomItem(FirearmAltEffects) : GetRandomItem(FirearmEffects);
}
4 changes: 3 additions & 1 deletion Source/Cloud9/Physicals/Cloud9PhysicalMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CLOUD9_API UCloud9PhysicalMaterial : public UPhysicalMaterial
UCloud9PhysicalMaterial();

UMaterialInterface* GetRandomFirearmDecal() const;
UNiagaraSystem* GetRandomFirearmSquib() const;
UNiagaraSystem* GetRandomFirearmSquib(bool IsAlternative) const;

UMaterialInterface* GetRandomBackgroundDecal() const;
FVector GetBackgroundDecalSize() const;
Expand Down Expand Up @@ -48,6 +48,8 @@ class CLOUD9_API UCloud9PhysicalMaterial : public UPhysicalMaterial
UPROPERTY(EditDefaultsOnly, Category="Firearm Hit Effect")
TSet<UNiagaraSystem*> FirearmEffects;

UPROPERTY(EditDefaultsOnly, Category="Firearm Hit Effect")
TSet<UNiagaraSystem*> FirearmAltEffects;

UPROPERTY(EditDefaultsOnly, Category="Firearm Background Decal")
TSet<UMaterialInterface*> FirearmBackgroundDecals;
Expand Down
18 changes: 17 additions & 1 deletion Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "Cloud9/Contollers/Cloud9PlayerController.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Character/Components/Cloud9AnimationComponent.h"
#include "Cloud9/Character/Components/Cloud9HealthComponent.h"
#include "Cloud9/Character/Components/Cloud9InventoryComponent.h"
#include "Cloud9/Character/Damages/FirearmDamageType.h"
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
Expand Down Expand Up @@ -470,7 +471,22 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire(

if (let PhysicalMaterial = Cast<UCloud9PhysicalMaterial>(LineHit.PhysMaterial); IsValid(PhysicalMaterial))
{
if (let FirearmSquib = PhysicalMaterial->GetRandomFirearmSquib(); IsValid(FirearmSquib))
if (let HealthComponent = DamagedActor->FindComponentByClass<UCloud9HealthComponent>();
IsValid(HealthComponent) and HealthComponent->IsArmored())
{
if (let FirearmSquib = PhysicalMaterial->GetRandomFirearmSquib(true); IsValid(FirearmSquib))
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
GetWorld(),
FirearmSquib,
LineHit.Location,
LineHit.Normal.Rotation(),
FVector::OneVector,
true);
}
}

if (let FirearmSquib = PhysicalMaterial->GetRandomFirearmSquib(false); IsValid(FirearmSquib))
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
GetWorld(),
Expand Down