diff --git a/Content/Assets/MilitaryWeapSilver/Weapons/Materials/M_Pistol_Ammo.uasset b/Content/Assets/MilitaryWeapSilver/Weapons/Materials/M_Pistol_Ammo.uasset new file mode 100644 index 0000000..f24d17e Binary files /dev/null and b/Content/Assets/MilitaryWeapSilver/Weapons/Materials/M_Pistol_Ammo.uasset differ diff --git a/Content/Assets/MilitaryWeapSilver/Weapons/Pistols_A.uasset b/Content/Assets/MilitaryWeapSilver/Weapons/Pistols_A.uasset index d98792d..9790514 100644 Binary files a/Content/Assets/MilitaryWeapSilver/Weapons/Pistols_A.uasset and b/Content/Assets/MilitaryWeapSilver/Weapons/Pistols_A.uasset differ diff --git a/Content/Blueprints/Weapon/BP_Pistol.uasset b/Content/Blueprints/Weapon/BP_Pistol.uasset new file mode 100644 index 0000000..d53008d Binary files /dev/null and b/Content/Blueprints/Weapon/BP_Pistol.uasset differ diff --git a/Content/Blueprints/Weapon/Casings/BP_PistolCasing.uasset b/Content/Blueprints/Weapon/Casings/BP_PistolCasing.uasset new file mode 100644 index 0000000..2502fa4 Binary files /dev/null and b/Content/Blueprints/Weapon/Casings/BP_PistolCasing.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 9db2870..c9d053e 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 05c4f8f..9b5ab20 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -270,6 +270,12 @@ void ABlasterCharacter::PlayReloadMontage() case EWeaponType::EWT_RocketLauncher: SectionName = FName("Rifle"); // Todo: create rocket reload montage section break; + case EWeaponType::EWT_Pistol: + SectionName = FName("Rifle"); // Todo: create pistol reload montage section + break; + default: + SectionName = FName("Rifle"); + break; } AnimInstance->Montage_JumpToSection(SectionName); diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index a0803fc..2ad70ac 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -456,4 +456,5 @@ void UCombatComponent::InitializeCarriedAmmo() { CarriedAmmoMap.Emplace(EWeaponType::EWT_AssaultRifle, StartingARAmmo); CarriedAmmoMap.Emplace(EWeaponType::EWT_RocketLauncher, StartingRocketAmmo); + CarriedAmmoMap.Emplace(EWeaponType::EWT_Pistol, StartingPistolAmmo); } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index f5b6471..807b834 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -126,6 +126,9 @@ private: UPROPERTY(EditAnywhere) int32 StartingRocketAmmo = 8; + UPROPERTY(EditAnywhere) + int32 StartingPistolAmmo = 15; + void InitializeCarriedAmmo(); UPROPERTY(ReplicatedUsing=OnRep_CombatState) diff --git a/Source/Blaster/Weapon/HitScanWeapon.cpp b/Source/Blaster/Weapon/HitScanWeapon.cpp new file mode 100644 index 0000000..853eb27 --- /dev/null +++ b/Source/Blaster/Weapon/HitScanWeapon.cpp @@ -0,0 +1,64 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "HitScanWeapon.h" + +#include "Blaster/Character/BlasterCharacter.h" +#include "Engine/SkeletalMeshSocket.h" +#include "Kismet/GameplayStatics.h" + +void AHitScanWeapon::Fire(const FVector& HitTarget) +{ + Super::Fire(HitTarget); + + APawn* OwnerPawn = Cast(GetOwner()); + if (OwnerPawn == nullptr) return; + AController* InstigatorController = OwnerPawn->GetController(); + + const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash"); + if (MuzzleFlashSocket && InstigatorController) + { + FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh()); + FVector Start = SocketTransform.GetLocation(); + FVector End = Start + (HitTarget - Start) * 1.25f; + + FHitResult FireHit; + UWorld* World = GetWorld(); + if (World) + { + World->LineTraceSingleByChannel( + FireHit, + Start, + End, + ECC_Visibility + ); + if (FireHit.bBlockingHit) + { + ABlasterCharacter* BlasterCharacter = Cast(FireHit.GetActor()); + if (BlasterCharacter) + { + if (HasAuthority()) + { + UGameplayStatics::ApplyDamage( + BlasterCharacter, + Damage, + InstigatorController, + this, + UDamageType::StaticClass() + ); + } + } + + if (ImpactParticles) + { + UGameplayStatics::SpawnEmitterAtLocation( + World, + ImpactParticles, + FireHit.ImpactPoint, + FireHit.ImpactNormal.Rotation() + ); + } + } + } + } +} diff --git a/Source/Blaster/Weapon/HitScanWeapon.h b/Source/Blaster/Weapon/HitScanWeapon.h new file mode 100644 index 0000000..1ba2439 --- /dev/null +++ b/Source/Blaster/Weapon/HitScanWeapon.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Weapon.h" +#include "HitScanWeapon.generated.h" + +/** + * + */ +UCLASS() +class BLASTER_API AHitScanWeapon : public AWeapon +{ + GENERATED_BODY() + +public: + + virtual void Fire(const FVector& HitTarget) override; + +private: + + UPROPERTY(EditAnywhere) + float Damage = 20.f; + + UPROPERTY(EditAnywhere) + class UParticleSystem* ImpactParticles; +}; diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index 9472ed8..c136ddc 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -89,25 +89,25 @@ protected: ); private: - UPROPERTY(VisibleAnywhere, Category="Weapon Properties") + UPROPERTY(VisibleAnywhere, Category = "Weapon Properties") USkeletalMeshComponent* WeaponMesh; - UPROPERTY(VisibleAnywhere, Category="Weapon Properties") + UPROPERTY(VisibleAnywhere, Category = "Weapon Properties") class USphereComponent* AreaSphere; - UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category="Weapon Properties") + UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category = "Weapon Properties") EWeaponState WeaponState; UFUNCTION() void OnRep_WeaponState(); - UPROPERTY(VisibleAnywhere, Category="Weapon Properties") + UPROPERTY(VisibleAnywhere, Category = "Weapon Properties") class UWidgetComponent* PickupWidget; - UPROPERTY(EditAnywhere, Category= "Weapon Properties") + UPROPERTY(EditAnywhere, Category = "Weapon Properties") class UAnimationAsset* FireAnimation; - UPROPERTY(EditAnywhere, Category= "Weapon Properties") + UPROPERTY(EditAnywhere, Category = "Weapon Properties") TSubclassOf CasingClass; UPROPERTY(EditAnywhere, ReplicatedUsing=OnRep_Ammo) diff --git a/Source/Blaster/Weapon/WeaponTypes.h b/Source/Blaster/Weapon/WeaponTypes.h index 4dd0a4a..07885d8 100644 --- a/Source/Blaster/Weapon/WeaponTypes.h +++ b/Source/Blaster/Weapon/WeaponTypes.h @@ -5,6 +5,7 @@ enum class EWeaponType: uint8 { EWT_AssaultRifle UMETA(DisplayName="Assault Rifle"), EWT_RocketLauncher UMETA(DisplayName="Rocket Launcher"), + EWT_Pistol UMETA(DisplayName="Pistol"), EWT_MAX UMETA(DisplayName="DefaultMAX") }; \ No newline at end of file