diff --git a/SwordNGun/Content/Weapons/Revolver/BP_Revolver.uasset b/SwordNGun/Content/Weapons/Revolver/BP_Revolver.uasset index 892600d..c67f117 100644 --- a/SwordNGun/Content/Weapons/Revolver/BP_Revolver.uasset +++ b/SwordNGun/Content/Weapons/Revolver/BP_Revolver.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6dfcee3d24acafb18277540acd2b8a85e668403e4d238393d3845848a818fdfb -size 188658 +oid sha256:5a8e3b66702dc90c2bfe27e76562f50bb8541a23661dea30e3f7ce4bda004ed5 +size 184081 diff --git a/SwordNGun/Content/Weapons/Revolver/BP_RevolverImpact.uasset b/SwordNGun/Content/Weapons/Revolver/BP_RevolverImpact.uasset new file mode 100644 index 0000000..060cb25 --- /dev/null +++ b/SwordNGun/Content/Weapons/Revolver/BP_RevolverImpact.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c60a08e7d63b6e74a8d29bb3161f74219990329d9bc3fcd71b6bcb5ddaff8bd9 +size 23220 diff --git a/SwordNGun/Content/Weapons/Revolver/RevolverDamageFalloffCurve.uasset b/SwordNGun/Content/Weapons/Revolver/RevolverDamageFalloffCurve.uasset deleted file mode 100644 index d7c491f..0000000 --- a/SwordNGun/Content/Weapons/Revolver/RevolverDamageFalloffCurve.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c2e09f762e1ac647e0a421b26b67b913f29c7afdf1f666185957878df201687e -size 1463 diff --git a/SwordNGun/Content/Weapons/Shotgun/BP_Shotgun.uasset b/SwordNGun/Content/Weapons/Shotgun/BP_Shotgun.uasset index 9d36639..d2e2ca5 100644 --- a/SwordNGun/Content/Weapons/Shotgun/BP_Shotgun.uasset +++ b/SwordNGun/Content/Weapons/Shotgun/BP_Shotgun.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fdf6abb96a3f1dc59d8a8696b9c7dc5d9d4141d9f76d617242059de45ff89a30 -size 221915 +oid sha256:b0c64f5a4835ea13aac3b323dfc46b79931a190a9b63020db1994a9a0b691d6b +size 222700 diff --git a/SwordNGun/Content/Weapons/Shotgun/BP_ShotgunImpact.uasset b/SwordNGun/Content/Weapons/Shotgun/BP_ShotgunImpact.uasset new file mode 100644 index 0000000..1767ee7 --- /dev/null +++ b/SwordNGun/Content/Weapons/Shotgun/BP_ShotgunImpact.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ebbefc7896855fe458db3e986da9df1095546f1b55936f87fbcdd5b9d495e66d +size 22382 diff --git a/SwordNGun/Source/SwordNGun/Private/Effects/SNGImpactEffect.cpp b/SwordNGun/Source/SwordNGun/Private/Effects/SNGImpactEffect.cpp new file mode 100644 index 0000000..717013e Binary files /dev/null and b/SwordNGun/Source/SwordNGun/Private/Effects/SNGImpactEffect.cpp differ diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGHitscanWeapon.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGHitscanWeapon.cpp deleted file mode 100644 index 8ac71e2..0000000 Binary files a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGHitscanWeapon.cpp and /dev/null differ diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGInstantRangedWeapon.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGInstantRangedWeapon.cpp new file mode 100644 index 0000000..d313c68 --- /dev/null +++ b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGInstantRangedWeapon.cpp @@ -0,0 +1,128 @@ +// Project Sword & Gun Copyright © 2021 Kevin Poretti + + +#include "Weapons/SNGInstantRangedWeapon.h" + +#include "DrawDebugHelpers.h" +#include "Characters/SNGCharacterBase.h" +#include "Kismet/GameplayStatics.h" +#include "Particles/ParticleSystemComponent.h" +#include "PhysicalMaterials/PhysicalMaterial.h" +#include "SwordNGun/SNGTypes.h" +#include "SwordNGun/SwordNGun.h" + +static int32 DebugInstantWeaponDrawing = 0; +FAutoConsoleVariableRef CVARDebugInstantWeaponDrawing(TEXT("SNG.DebugInstantWeapons"), + DebugInstantWeaponDrawing, + TEXT("Draw debug line traces and impact points for instant type ranged weapons"), + ECVF_Cheat); + +ASNGInstantRangedWeapon::ASNGInstantRangedWeapon() +{ + Range = 10000.0f; +} + +void ASNGInstantRangedWeapon::PlayTracerEffect(FVector TraceEnd) +{ + // perform tracer effect from muzzle to trace end + if(TracerEffect) + { + FVector MuzzleLocation = WeaponMesh->GetSocketLocation(MuzzleSocketName); + UParticleSystemComponent* TracerComp = + UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), TracerEffect, MuzzleLocation); + if(TracerComp) + { + TracerComp->SetVectorParameter(TracerTargetName, TraceEnd); + } + } +} + +void ASNGInstantRangedWeapon::DoFire_Implementation() +{ + Super::DoFire_Implementation(); + + DoLineTrace(); +} + +void ASNGInstantRangedWeapon::DoLineTrace(FRotator SpreadOffset) +{ + // Get weapon owner and check if valid + AActor* WeaponOwner = GetOwner(); + if(!WeaponOwner) + { + UE_LOG(LogTemp, Error, TEXT("SNGHitscanWeapon :: Weapon does not have owner")); + return; + } + + // Get actor eyes viewpoint + FVector EyesLocation; + FRotator EyesRotation; + WeaponOwner->GetActorEyesViewPoint(EyesLocation, EyesRotation); + + // Calculate final raycast direction based on actor eyes and spread offset + // find trace end using range value or final falloff curve keyframe + FRotator ShotRotation = EyesRotation + SpreadOffset; + FVector ShotDirection = ShotRotation.Vector(); + FVector TraceEnd = EyesLocation + (ShotDirection * Range); + + // set up collision query params (ignore weapon and owner, trace complex, return phys material) + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(this); + QueryParams.AddIgnoredActor(WeaponOwner); + QueryParams.bTraceComplex = true; + QueryParams.bReturnPhysicalMaterial = true; + + // do line trace + EPhysicalSurface SurfaceType = SurfaceType_Default; + FHitResult HitResult; + bool IsHitSuccessful = GetWorld()->LineTraceSingleByChannel(HitResult, EyesLocation, TraceEnd, COLLISION_RANGED_WEAPON, QueryParams); + if(IsHitSuccessful) + { + AActor* HitActor = HitResult.GetActor(); + + SurfaceType = UPhysicalMaterial::DetermineSurfaceType(HitResult.PhysMaterial.Get()); + //int ActualDamage = CalculateWeaponDamage(); + // NOTE(kevin): This won't work once we have weapon falloff curves. Might want to separate damage from HitData + // eventually + if(SurfaceType == SNG_SURFACE_Flesh || SurfaceType == SNG_SURFACE_FleshVulnerable) + { + OnHit.Broadcast(); + if(HitMarkerSound) + UGameplayStatics::PlaySound2D(GetWorld(), HitMarkerSound); + } + + int ActualDamage = HitData.BaseDamage; + if(SurfaceType == SNG_SURFACE_FleshVulnerable) + { + ActualDamage *= VulnerableDamageMultiplier; + } + + FSNGDamageEvent DamageEvent; + DamageEvent.DamageTypeClass = UDamageType::StaticClass(); + DamageEvent.HitData = HitData; + DamageEvent.SurfaceType = SurfaceType; + DamageEvent.ImpactPoint = HitResult.ImpactPoint; + HitActor->TakeDamage(ActualDamage, DamageEvent, WeaponOwner->GetInstigatorController(), this); + + if(HitData.HitstopApplicationType == ESNGHitstopApplicationType::Both || + HitData.HitstopApplicationType == ESNGHitstopApplicationType::CauserOnly) + { + ASNGCharacterBase* OwnerAsChar = Cast(GetOwner()); + OwnerAsChar->ApplyHitStop(HitData.StopTime, HitData.SlowTime); + } + + FTransform SpawnTransform(HitResult.ImpactNormal.Rotation(), HitResult.ImpactPoint); + PlayImpactEffects(SurfaceType, SpawnTransform); + } + + PlayFireEffect(); + PlayTracerEffect(IsHitSuccessful ? HitResult.ImpactPoint : TraceEnd); + + if(DebugInstantWeaponDrawing) + { + DrawDebugLine(GetWorld(), EyesLocation, TraceEnd, FColor::Red, false, 1.0f, 0, 1.0f); + DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 5.0f, 32, FColor::Green, false, 1.0f, 0, 1.0f); + } +} + + diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGMeleeWeaponBase.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGMeleeWeaponBase.cpp index d1bed1f..25e41e1 100644 Binary files a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGMeleeWeaponBase.cpp and b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGMeleeWeaponBase.cpp differ diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileWeapon.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileRangedWeapon.cpp similarity index 55% rename from SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileWeapon.cpp rename to SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileRangedWeapon.cpp index 4d1e1e9..a992b40 100644 Binary files a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileWeapon.cpp and b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGProjectileRangedWeapon.cpp differ diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGRangedWeaponBase.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGRangedWeaponBase.cpp index 5b1236c..ea61d84 100644 Binary files a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGRangedWeaponBase.cpp and b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGRangedWeaponBase.cpp differ diff --git a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGWeaponBase.cpp b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGWeaponBase.cpp index 129c37e..57d4c24 100644 Binary files a/SwordNGun/Source/SwordNGun/Private/Weapons/SNGWeaponBase.cpp and b/SwordNGun/Source/SwordNGun/Private/Weapons/SNGWeaponBase.cpp differ diff --git a/SwordNGun/Source/SwordNGun/Public/Components/SNGHealthComponent.h b/SwordNGun/Source/SwordNGun/Public/Components/SNGHealthComponent.h index 08190ae..e5453d5 100644 Binary files a/SwordNGun/Source/SwordNGun/Public/Components/SNGHealthComponent.h and b/SwordNGun/Source/SwordNGun/Public/Components/SNGHealthComponent.h differ diff --git a/SwordNGun/Source/SwordNGun/Public/Effects/SNGImpactEffect.h b/SwordNGun/Source/SwordNGun/Public/Effects/SNGImpactEffect.h new file mode 100644 index 0000000..505c6ec Binary files /dev/null and b/SwordNGun/Source/SwordNGun/Public/Effects/SNGImpactEffect.h differ diff --git a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGHitscanWeapon.h b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGHitscanWeapon.h deleted file mode 100644 index 8c5f244..0000000 Binary files a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGHitscanWeapon.h and /dev/null differ diff --git a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGInstantRangedWeapon.h b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGInstantRangedWeapon.h new file mode 100644 index 0000000..804fc9a --- /dev/null +++ b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGInstantRangedWeapon.h @@ -0,0 +1,57 @@ +// Project Sword & Gun Copyright © 2021 Kevin Poretti + +#pragma once + +#include "CoreMinimal.h" +#include "Weapons/SNGRangedWeaponBase.h" +#include "SNGInstantRangedWeapon.generated.h" + +/** + * Base class for instant type ranged weapons. + * + * An instant weapon is one where a line trace is performed in the same tick when the weapon is fired. If the line + * trace hits something damage is also applied immediately. + */ +UCLASS() +class SWORDNGUN_API ASNGInstantRangedWeapon : public ASNGRangedWeaponBase +{ + GENERATED_BODY() + +public: + /** Sets default values for this actor's properties. */ + ASNGInstantRangedWeapon(); + +protected: + /** The length/distance of the line trace */ + UPROPERTY(EditDefaultsOnly, Category="Properties") + float Range; + + /** + * Spawns and plays the tracer/smoke trailer effect. + * + * The tracer will be spawned from this weapon's muzzle socket location and will stretch to the location provided + * by the TraceEnd parameter. + * + * @param TraceEnd where the tracer effect should end + */ + void PlayTracerEffect(FVector TraceEnd); + + /** + * C++ implementation of the DoFire function, which is called in Fire if this weapon is actually able to be fired. + * + * This function is overriden to do a single line trace. + */ + virtual void DoFire_Implementation() override; + + /** + * Performs the actual line trace from the weapon owner's "eyes." For example, if the weapon owner is a player it + * will perform a line trace from the center of the camera. + * + * If something is hit this will apply damage if applicable and play appropriate effects. + * + * @param SpreadOffset modifies the direction of the line trace by this rotation + */ + UFUNCTION(BlueprintCallable) + void DoLineTrace(FRotator SpreadOffset = FRotator::ZeroRotator); +}; + diff --git a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileWeapon.h b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileRangedWeapon.h similarity index 70% rename from SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileWeapon.h rename to SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileRangedWeapon.h index 5d90441..c9852b8 100644 Binary files a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileWeapon.h and b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGProjectileRangedWeapon.h differ diff --git a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGRangedWeaponBase.h b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGRangedWeaponBase.h index 16bd610..053a64b 100644 Binary files a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGRangedWeaponBase.h and b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGRangedWeaponBase.h differ diff --git a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGWeaponBase.h b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGWeaponBase.h index ce0b302..4eb2ed7 100644 Binary files a/SwordNGun/Source/SwordNGun/Public/Weapons/SNGWeaponBase.h and b/SwordNGun/Source/SwordNGun/Public/Weapons/SNGWeaponBase.h differ diff --git a/SwordNGun/Source/SwordNGun/SNGTypes.h b/SwordNGun/Source/SwordNGun/SNGTypes.h index 42a5d09..489f0f4 100644 Binary files a/SwordNGun/Source/SwordNGun/SNGTypes.h and b/SwordNGun/Source/SwordNGun/SNGTypes.h differ