diff --git a/Content/Legumix/Player/Input/IA_Shoot.uasset b/Content/Legumix/Player/Input/IA_Shoot.uasset index 4e8c799..27c446c 100644 --- a/Content/Legumix/Player/Input/IA_Shoot.uasset +++ b/Content/Legumix/Player/Input/IA_Shoot.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:08c6295c098e9397372285219b1b5d37bc166e40d82eeeb81766dd85d10e91b9 -size 1387 +oid sha256:2d635494781c3c33aa1c50811caaa2351f6a6d4a0b9c8d469a37920cf4cb06c6 +size 1691 diff --git a/Content/Legumix/Weapon/BP_WeaponManager.uasset b/Content/Legumix/Weapon/BP_WeaponManager.uasset index ce38a6a..04a7c7f 100644 --- a/Content/Legumix/Weapon/BP_WeaponManager.uasset +++ b/Content/Legumix/Weapon/BP_WeaponManager.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cedb028e7e61821b30692bc77c901339b7ad8e14b2bfc4de63f2cb34dc7dff70 -size 7486 +oid sha256:1bf2c3d9729731e0e3308fc288e2bf8ba8fd42ec700c615bf431e2a6639c30f2 +size 7487 diff --git a/Content/Legumix/Weapon/Revolver/BP_Revolver.uasset b/Content/Legumix/Weapon/Revolver/BP_Revolver.uasset new file mode 100644 index 0000000..a856f7d --- /dev/null +++ b/Content/Legumix/Weapon/Revolver/BP_Revolver.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69747eb332341171ff918ae22f4ee76665b726d27b5bfb2526f8d85f4a5483dc +size 49460 diff --git a/Content/Legumix/Weapon/Shotgun/BP_Revolver.uasset b/Content/Legumix/Weapon/Shotgun/BP_Revolver.uasset deleted file mode 100644 index b9b9428..0000000 --- a/Content/Legumix/Weapon/Shotgun/BP_Revolver.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3cf116185fa5ffa77f1c1b0bcd58ced74d48270ec611a0bdf2bbb9afc6c00f4c -size 32168 diff --git a/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset b/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset index 27db14c..f1cfe7d 100644 --- a/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset +++ b/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:df121a93495b25dedf1d472eb4ee1289ecccff9d1513776960ee6c6ba701bc5e -size 33696 +oid sha256:ba83cc1f0f293cb4f791e1beab4d509e65a0c141fd8fc799b3336202d1f35765 +size 55015 diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index 0526e8e..df6129a 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -42,6 +42,16 @@ void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo) WeaponManager->AddAmmoType(Ammo->GetAmmoType(), Ammo->GetAmmoAmount()); } +int ALMPlayer::GetAmmoCount(const EAmmoType AmmoType) const +{ + return WeaponManager->GetAmmoCount(AmmoType); +} + +int ALMPlayer::RemoveAmmo(const EAmmoType AmmoType, const int Count) const +{ + return WeaponManager->RemoveAmmo(AmmoType, Count); +} + void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager) { UE_LOG(LogTemp, Warning, TEXT("Set weapon manager")) diff --git a/Source/LegumeMix/Private/Weapon/LMRevolver.cpp b/Source/LegumeMix/Private/Weapon/LMRevolver.cpp new file mode 100644 index 0000000..d5e9930 --- /dev/null +++ b/Source/LegumeMix/Private/Weapon/LMRevolver.cpp @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Weapon/LMRevolver.h" + +#include "Player/LMBulletInfo.h" +#include "Player/LMPlayer.h" + + +ALMRevolver::ALMRevolver() +{ + PrimaryActorTick.bCanEverTick = true; +} + +void ALMRevolver::PrimaryFire() +{ + if (!Player) + return; + + PlaySound(FireSound); + PlayAnimation(PrimaryFireAnimation); + + const FVector Origin = Player->GetWeaponFiringOrigin(); + const FVector Direction = Player->GetAimVector(); + + ClipAmmo--; + + FLMBulletInfo ShotInfo = FLMBulletInfo(1, Origin, Direction, WeaponSpread, MaxDistance, DamageFalloff, AmmoType, Damage); + + Player->FireBullets(ShotInfo); +} + diff --git a/Source/LegumeMix/Private/Weapon/LMShotgun.cpp b/Source/LegumeMix/Private/Weapon/LMShotgun.cpp index 539b657..d2023ab 100644 --- a/Source/LegumeMix/Private/Weapon/LMShotgun.cpp +++ b/Source/LegumeMix/Private/Weapon/LMShotgun.cpp @@ -31,8 +31,3 @@ void ALMShotgun::PrimaryFire() Player->FireBullets(ShotInfo); } -void ALMShotgun::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); -} - diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp index c0e78dd..7229ad0 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp @@ -42,6 +42,7 @@ void ALMWeaponBase::Setup(USkeletalMeshComponent* Mesh, AActor* CharOwner) void ALMWeaponBase::Reload() { + DefaultReload(); } void ALMWeaponBase::PrimaryFire() @@ -52,7 +53,7 @@ void ALMWeaponBase::PlaySound(USoundWave* Sound, const bool Replacing) { if (AudioComponent->IsPlaying() && !Replacing) return; - + AudioComponent->Stop(); AudioComponent->SetSound(Sound); AudioComponent->Play(); @@ -66,4 +67,25 @@ void ALMWeaponBase::PlayAnimation(UAnimMontage* Animation) { AnimInstance->Montage_Play(Animation); } -} \ No newline at end of file +} + +void ALMWeaponBase::DefaultReload() +{ + if (State != EWeaponState::EWS_Idle) + return; + + const int AmmoCount = Player->GetAmmoCount(AmmoType); + if (AmmoCount <= 0) + return; + + if (ClipAmmo >= MaxClip) + return; + + PlaySound(ReloadSound, true); + PlayAnimation(ReloadAnimation); + + State = EWeaponState::EWS_Reloading; + + // TODO: Use Animations + OnDefaultReload(); +} diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index a01d32b..bc972f8 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -42,6 +42,30 @@ void ULMWeaponManager::SetupAmmoData() } } +int ULMWeaponManager::RemoveAmmo(const EAmmoType Ammo, const int Count) +{ + if (AmmoData.Contains(Ammo)) + { + FLMAmmoData &Data = AmmoData[Ammo]; + + int Difference = Data.AmmoCount - Count; + UE_LOG(LogTemp, Display, TEXT("Difference: %i | Removing: %i | Storage: %i"), Difference, Count, Data.AmmoCount) + if (Difference < 0) + { + UE_LOG(LogTemp, Error, TEXT("%i - %i = %i"), Data.AmmoCount, Count, Data.AmmoCount - Count); + Data.AmmoCount = FMath::Clamp(Data.AmmoCount - Count, 0, Data.MaxAmmo); + UE_LOG(LogTemp, Warning, TEXT("Difference < 0 | Munition to add: %i | Removed: %i | New Munition: %i"), Count + Difference, Count, Data.AmmoCount) + return Count + Difference; + } + + Data.AmmoCount -= Count; + UE_LOG(LogTemp, Warning, TEXT("New munition: %i | Removed: %i"), Data.AmmoCount, Count) + return Count; + } + + return 0; +} + void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) { ArmsMesh = Mesh; @@ -84,6 +108,14 @@ void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount) } } +int ULMWeaponManager::GetAmmoCount(const EAmmoType AmmoType) +{ + if (AmmoData.Contains(AmmoType)) + return AmmoData[AmmoType].AmmoCount; + + return 0; +} + void ULMWeaponManager::Fire() { ALMWeaponBase* Weapon = GetCurrentWeapon(); diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index 0b15b06..2c66c4a 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -24,9 +24,26 @@ public: virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; - UFUNCTION() + UFUNCTION(BlueprintCallable) void PickUpAmmo(ALMAmmo* Ammo); + /** + * Gets the number of ammo from the given type. + * @param AmmoType The ammo type to get. + * @return The amount of ammo from the given type. + */ + UFUNCTION(BlueprintCallable) + int GetAmmoCount(EAmmoType AmmoType) const; + + /** + * Removes a given amount of ammo from the type. + * @param AmmoType The type of ammo to remove. + * @param Count The amount of ammo to remove. + * @return The amount that was removed. + */ + UFUNCTION(BlueprintCallable) + int RemoveAmmo(EAmmoType AmmoType, int Count) const; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; diff --git a/Source/LegumeMix/Public/Weapon/LMRevolver.h b/Source/LegumeMix/Public/Weapon/LMRevolver.h new file mode 100644 index 0000000..17c1c87 --- /dev/null +++ b/Source/LegumeMix/Public/Weapon/LMRevolver.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "LMWeaponBase.h" +#include "LMRevolver.generated.h" + +UCLASS() +class LEGUMEMIX_API ALMRevolver : public ALMWeaponBase +{ + GENERATED_BODY() + +public: + ALMRevolver(); + virtual void PrimaryFire() override; +}; diff --git a/Source/LegumeMix/Public/Weapon/LMShotgun.h b/Source/LegumeMix/Public/Weapon/LMShotgun.h index b067ff1..7fca267 100644 --- a/Source/LegumeMix/Public/Weapon/LMShotgun.h +++ b/Source/LegumeMix/Public/Weapon/LMShotgun.h @@ -13,7 +13,6 @@ class LEGUMEMIX_API ALMShotgun : public ALMWeaponBase public: ALMShotgun(); - virtual void Tick(float DeltaTime) override; virtual void PrimaryFire() override; private: diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponBase.h b/Source/LegumeMix/Public/Weapon/LMWeaponBase.h index 6b4839c..4d1b0ca 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponBase.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponBase.h @@ -39,12 +39,21 @@ public: */ UFUNCTION(BlueprintCallable) FName GetAttachmentSocketName() const { return WeaponSocket; } + + UFUNCTION(BlueprintCallable, BlueprintImplementableEvent) + void OnDefaultReload(); + +private: + void DefaultReload(); protected: /* Weapon Data */ /** The sound to play when firing. */ UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds") TObjectPtr FireSound; + UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds") + TObjectPtr ReloadSound; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Animations", meta=(AllowPrivateAccess=true)) TObjectPtr PrimaryFireAnimation; diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h index 411e287..57a0803 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -33,6 +33,8 @@ public: UFUNCTION(BlueprintCallable, Category=Legumix) void AddAmmoType(EAmmoType AmmoType, int AmmoCount); + UFUNCTION(BlueprintCallable, Category=Legumix) + int GetAmmoCount(EAmmoType AmmoType); UFUNCTION(BlueprintCallable, Category=Legumix) void Fire(); @@ -45,6 +47,8 @@ public: UFUNCTION(BlueprintCallable, Category="Legumix|Ammo") void SetupAmmoData(); + UFUNCTION(BlueprintCallable, Category="Legumix|Ammo") + int RemoveAmmo(EAmmoType Ammo, int Count); protected: virtual void BeginPlay() override;