diff --git a/Content/Blueprints/Player/BP_ExoPlayerController.uasset b/Content/Blueprints/Player/BP_ExoPlayerController.uasset index 2913100..d792f12 100644 Binary files a/Content/Blueprints/Player/BP_ExoPlayerController.uasset and b/Content/Blueprints/Player/BP_ExoPlayerController.uasset differ diff --git a/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset b/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset index a0f74ec..7947f64 100644 Binary files a/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset and b/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset differ diff --git a/Content/Blueprints/Player/Inputs/Inputs/AI_ChangeWeapon.uasset b/Content/Blueprints/Player/Inputs/Inputs/AI_ChangeWeapon.uasset new file mode 100644 index 0000000..cea36d8 Binary files /dev/null and b/Content/Blueprints/Player/Inputs/Inputs/AI_ChangeWeapon.uasset differ diff --git a/Content/Blueprints/Player/Inputs/Inputs/AI_SelectFirstWeapon.uasset b/Content/Blueprints/Player/Inputs/Inputs/AI_SelectFirstWeapon.uasset new file mode 100644 index 0000000..3877cb1 Binary files /dev/null and b/Content/Blueprints/Player/Inputs/Inputs/AI_SelectFirstWeapon.uasset differ diff --git a/Content/Blueprints/Player/Inputs/Inputs/AI_SelectSecondWeapon.uasset b/Content/Blueprints/Player/Inputs/Inputs/AI_SelectSecondWeapon.uasset new file mode 100644 index 0000000..7e18fb9 Binary files /dev/null and b/Content/Blueprints/Player/Inputs/Inputs/AI_SelectSecondWeapon.uasset differ diff --git a/Content/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 609f87a..27dd436 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 948c86f..b5e96da 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -3,8 +3,6 @@ #include "Characters/Components/ShootingComponent.h" -#include "KismetTraceUtils.h" - // Sets default values for this component's properties UShootingComponent::UShootingComponent() { @@ -27,13 +25,13 @@ void UShootingComponent::BeginPlay() void UShootingComponent::Shoot() { - if (!bIsHoldingGun || CurrentAmmo == 0 || bIsReloading || !bCanShoot) return; + if (!IsValid(CurrentGun) || CurrentGun->CurrentAmmo == 0 || bIsReloading || !bCanShoot) return; APawn* PawnOwner = Cast(PlayerCharacter); if (!PawnOwner || !PawnOwner->GetController()) return; bCanShoot = false; - CurrentAmmo--; + CurrentGun->CurrentAmmo--; FVector ViewLocation; FRotator ViewRotation; @@ -41,7 +39,7 @@ void UShootingComponent::Shoot() FVector ForwardVector = ViewRotation.Vector(); FVector LineStart = ViewLocation; //PlayerCharacter->GetActorLocation(); - FVector LineEnd = LineStart + (ForwardVector * MaxRange); + FVector LineEnd = LineStart + (ForwardVector * CurrentGun->MaxRange); FHitResult HitResult; FCollisionQueryParams QueryParams; @@ -52,19 +50,19 @@ void UShootingComponent::Shoot() if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements()) { - IDamageable::Execute_TakeDamage(HitResult.GetActor(), FireDamageValue); + IDamageable::Execute_TakeDamage(HitResult.GetActor(), CurrentGun->DamageValue); - UE_LOG(LogTemp, Display, TEXT("Shoot. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo + UE_LOG(LogTemp, Display, TEXT("Shoot. Ammo: %d/%d"), CurrentGun->CurrentAmmo, CurrentGun->MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo } - PlayerCharacter->GetWorldTimerManager().SetTimer(ShootCooldownTimer, this, &UShootingComponent::ResetFireCooldown, FireRateCooldown, false); + PlayerCharacter->GetWorldTimerManager().SetTimer(ShootCooldownTimer, this, &UShootingComponent::ResetFireCooldown, CurrentGun->FireRateCooldown, false); // Odrzut float RecoilPitch = FMath::RandRange(-1.0f, -0.5f); float RecoilYaw = FMath::RandRange(-0.5f, 0.5f); - PlayerCharacter->AddControllerPitchInput(RecoilPitch * RecoilForceMultiplier); - PlayerCharacter->AddControllerYawInput(RecoilYaw * RecoilForceMultiplier); + PlayerCharacter->AddControllerPitchInput(RecoilPitch * CurrentGun->RecoilForceMultiplier); + PlayerCharacter->AddControllerYawInput(RecoilYaw * CurrentGun->RecoilForceMultiplier); // DEBUG if (bShowDebugLine) @@ -73,7 +71,6 @@ void UShootingComponent::Shoot() void UShootingComponent::MeleAttack() { - FVector ForwardVector = PlayerCharacter->GetActorForwardVector(); FVector ViewLocation; FRotator ViewRotation; @@ -85,7 +82,8 @@ void UShootingComponent::MeleAttack() FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(PlayerCharacter); - //DrawDebugLine(GetWorld(), ViewLocation, EndVector, FColor::Red, false, 1.0f, 0, 1.0f); + if (bShowDebugLine) + DrawDebugLine(GetWorld(), ViewLocation, EndVector, FColor::Red, false, 1.0f, 0, 1.0f); if (GetWorld()->LineTraceSingleByChannel(Hit, ViewLocation, EndVector, ECC_Visibility, QueryParams)) { @@ -94,43 +92,45 @@ void UShootingComponent::MeleAttack() IDamageable::Execute_TakeDamage(Hit.GetActor(), MeleDamageValue); } } - - } void UShootingComponent::Reload() { - if (!bIsHoldingGun || bIsReloading) return; + if (!IsValid(CurrentGun) || bIsReloading) return; bIsReloading = true; - CurrentAmmo = MaxAmmo; - PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, ReloadTime, false); + CurrentGun->CurrentAmmo = CurrentGun->MaxAmmo; + PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, CurrentGun->ReloadTime, false); - UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo + UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentGun->CurrentAmmo, CurrentGun->MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo } void UShootingComponent::PickUpGun(AGunBase* gunItem) { - if (bIsHoldingGun) + if (IsValid(CurrentGun) && IsValid(SecondaryGun)) DropGun(); - bIsHoldingGun = true; - - HoldingGunClass = gunItem->GetClass(); + AGunBase* NewGun = NewObject(); - MaxRange = gunItem->MaxRange; - FireDamageValue = gunItem->DamageValue; - FireRateCooldown = gunItem->FireRateCooldown; - RecoilForceMultiplier = gunItem->RecoilForceMultiplier; - ReloadTime = gunItem->ReloadTime; - CurrentAmmo = gunItem->CurrentAmmo; - MaxAmmo = gunItem->MaxAmmo; + NewGun->MaxRange = gunItem->MaxRange; + NewGun->DamageValue = gunItem->DamageValue; + NewGun->FireRateCooldown = gunItem->FireRateCooldown; + NewGun->RecoilForceMultiplier = gunItem->RecoilForceMultiplier; + NewGun->ReloadTime = gunItem->ReloadTime; + NewGun->CurrentAmmo = gunItem->CurrentAmmo; + NewGun->MaxAmmo = gunItem->MaxAmmo; + NewGun->SceneItemClass = gunItem->GetClass(); + + if (IsValid(CurrentGun)) + SecondaryGun = NewGun; + else + CurrentGun = NewGun; } void UShootingComponent::DropGun() { - if (!bIsHoldingGun) return; + if (!IsValid(CurrentGun)) return; FVector ForwardVector = PlayerCharacter->GetActorForwardVector(); FVector PlayerPos = PlayerCharacter->GetActorLocation(); @@ -139,19 +139,20 @@ void UShootingComponent::DropGun() FTransform DroppedGunTransform = PlayerCharacter->GetActorTransform(); DroppedGunTransform.SetLocation(DroppedGunPos); - AGunBase* DroppedGun = GetWorld()->SpawnActor(HoldingGunClass, DroppedGunTransform); + AGunBase* DroppedGun = GetWorld()->SpawnActor(CurrentGun->SceneItemClass, DroppedGunTransform); if (DroppedGun) { - DroppedGun->MaxRange = MaxRange; - DroppedGun->DamageValue = FireDamageValue; - DroppedGun->FireRateCooldown = FireRateCooldown; - DroppedGun->RecoilForceMultiplier = RecoilForceMultiplier; - DroppedGun->ReloadTime = ReloadTime; - DroppedGun->CurrentAmmo = CurrentAmmo; - DroppedGun->MaxAmmo = MaxAmmo; - - bIsHoldingGun = false; + DroppedGun->MaxRange = CurrentGun->MaxRange; + DroppedGun->DamageValue = CurrentGun->DamageValue; + DroppedGun->FireRateCooldown = CurrentGun->FireRateCooldown; + DroppedGun->RecoilForceMultiplier = CurrentGun->RecoilForceMultiplier; + DroppedGun->ReloadTime = CurrentGun->ReloadTime; + DroppedGun->CurrentAmmo = CurrentGun->CurrentAmmo; + DroppedGun->MaxAmmo = CurrentGun->MaxAmmo; + + CurrentGun->Destroy(); + CurrentGun = nullptr; } } @@ -165,6 +166,31 @@ void UShootingComponent::ReloadCompleted() bIsReloading = false; } +void UShootingComponent::SelectGun(bool bSelectFirstSlot) +{ + if (bSelectFirstSlot != bIsFirstGunSelected) + SwitchGun(); +} + +void UShootingComponent::SwitchGun() +{ + AGunBase* temp = CurrentGun; + CurrentGun = SecondaryGun; + SecondaryGun = temp; + + bIsFirstGunSelected = !bIsFirstGunSelected; + + // Debug info + if (bIsFirstGunSelected) + { + UE_LOG(LogTemp, Display, TEXT("Zmiana broni na broń 1")); + } + else + { + UE_LOG(LogTemp, Display, TEXT("Zmiana broni na broń 2")); + } +} + // Called every frame void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 61e52a1..d2cffe6 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -60,6 +60,8 @@ void AExoPlayerController::SetupInputComponent() EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim); EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack); EnhancedInputComponent->BindAction(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon); + EnhancedInputComponent->BindAction(SelectFirstWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSelectFirstWeapon); + EnhancedInputComponent->BindAction(SelectSecondWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSelectSecondWeapon); EnhancedInputComponent->BindAction(DropWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDropWeapon); EnhancedInputComponent->BindAction(ReloadAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerReload); } @@ -169,7 +171,17 @@ void AExoPlayerController::PlayerMeleAttack() void AExoPlayerController::PlayerChangeWeapon() { - + ShootingComponent->SwitchGun(); +} + +void AExoPlayerController::PlayerSelectFirstWeapon() +{ + ShootingComponent->SelectGun(true); +} + +void AExoPlayerController::PlayerSelectSecondWeapon() +{ + ShootingComponent->SelectGun(false); } void AExoPlayerController::PlayerDropWeapon() diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index 9db67e8..94730eb 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -48,33 +48,32 @@ public: UFUNCTION(Category = "Shooting") void DropGun(); + UFUNCTION(Category = "Shooting") + void SwitchGun(); + + UFUNCTION(Category = "Shooting") + void SelectGun(bool bSelectFirstSlot); + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting") float DropGunRange = 20.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mele Attack") float MeleRange = 75.f; + AGunBase* CurrentGun = nullptr; + AGunBase* SecondaryGun = nullptr; + private: void ResetFireCooldown(); - void ReloadCompleted(); FTimerHandle ShootCooldownTimer; - FTimerHandle ReloadTimer; - - bool bIsHoldingGun = false; - TSubclassOf HoldingGunClass; bool bCanShoot = true; bool bIsReloading = false; + + bool bIsFirstGunSelected = true; - float MaxRange = 2000.0f; - float FireDamageValue = 100.0f; float MeleDamageValue = 50.f; - float FireRateCooldown = 1.0f; - float RecoilForceMultiplier = 1.0f; - float ReloadTime = 3.0f; - int32 CurrentAmmo = 10; - int32 MaxAmmo = 10; }; diff --git a/Source/Exo/Public/Items/GunBase.h b/Source/Exo/Public/Items/GunBase.h index 8bea1ba..f5ed743 100644 --- a/Source/Exo/Public/Items/GunBase.h +++ b/Source/Exo/Public/Items/GunBase.h @@ -37,6 +37,8 @@ public: UPROPERTY(EditAnywhere, Category = "Ammo") int32 MaxAmmo = 10; + TSubclassOf SceneItemClass; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; diff --git a/Source/Exo/Public/Player/ExoPlayerController.h b/Source/Exo/Public/Player/ExoPlayerController.h index befa154..38f1d9e 100644 --- a/Source/Exo/Public/Player/ExoPlayerController.h +++ b/Source/Exo/Public/Player/ExoPlayerController.h @@ -69,8 +69,14 @@ protected: void PlayerMeleAttack(); // V - nieprzypisane UFUNCTION(BlueprintCallable, Category = "Input") - void PlayerChangeWeapon(); // 1\2\MouseScroll - nieprzypisane + void PlayerChangeWeapon(); // MouseScroll + UFUNCTION(BlueprintCallable, Category = "Input") + void PlayerSelectFirstWeapon(); // 1 + + UFUNCTION(BlueprintCallable, Category = "Input") + void PlayerSelectSecondWeapon(); // 2 + UFUNCTION(BlueprintCallable, Category = "Input") void PlayerDropWeapon(); // F @@ -124,6 +130,12 @@ protected: UPROPERTY(EditAnywhere, Category = "Input") TObjectPtr ChangeWeaponAction; + UPROPERTY(EditAnywhere, Category = "Input") + TObjectPtr SelectFirstWeaponAction; + + UPROPERTY(EditAnywhere, Category = "Input") + TObjectPtr SelectSecondWeaponAction; + UPROPERTY(EditAnywhere, Category = "Input") TObjectPtr DropWeaponAction;