Skip to content

Commit

Permalink
#235 Added shoot effect on armored character (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat authored Mar 10, 2024
1 parent c7361d0 commit 4811637
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
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

0 comments on commit 4811637

Please sign in to comment.