diff --git a/Content/Enemy/BP_RandomWeapon.uasset b/Content/Enemy/BP_RandomWeapon.uasset new file mode 100644 index 0000000..2d6d36b --- /dev/null +++ b/Content/Enemy/BP_RandomWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:239f0d3da917db9f742cf66c1e503f733b71cb9c55dc3c80dfae461703d93fea +size 46793 diff --git a/Content/Enemy/BP_WeaponPickupTemplate.uasset b/Content/Enemy/BP_WeaponPickupTemplate.uasset index 511b346..f6ac3f3 100644 --- a/Content/Enemy/BP_WeaponPickupTemplate.uasset +++ b/Content/Enemy/BP_WeaponPickupTemplate.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f13af74119d9904b9142d37bf62c5e662727c3ac4facae428d12608c792a1c4b -size 22694 +oid sha256:cf2d74421ab77b6b5e8ce4d015ac61780b35f31624e845379f5694d76c508562 +size 24582 diff --git a/Content/Enemy/BP_WeaponPickupWidget.uasset b/Content/Enemy/BP_WeaponPickupWidget.uasset index f988d95..3aba481 100644 --- a/Content/Enemy/BP_WeaponPickupWidget.uasset +++ b/Content/Enemy/BP_WeaponPickupWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6096fa0cb6acef41fba1492b33d8c40fa8cf82403ac176473d6918f69dd01013 -size 23122 +oid sha256:c85f152efd8b30547c135c14ed2f09d5db2bb8fc036452dcc8cf5c87fdbdd723 +size 44152 diff --git a/Content/Enemy/BP_WeaponThrowableTemplate.uasset b/Content/Enemy/BP_WeaponThrowableTemplate.uasset new file mode 100644 index 0000000..d1fc57e --- /dev/null +++ b/Content/Enemy/BP_WeaponThrowableTemplate.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05cded140c4237b4fe0c1a9e67b3b7dea4243b1ecf3711d6b1ed22cce10b77de +size 23394 diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index 259e413..a47a6a1 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -123,9 +123,16 @@ void AEnemyAIController::OnDeath(FDamageInfo info) if (enemy->DefaultWeaponInventory.Num() > 0) { // TODO: This can sometimes crash, need to investigate - if (auto weaponPickup = GetWorld()->SpawnActor()) + if (auto weaponPickup = GetWorld()->SpawnActor(enemy->GetCurrentWeapon()->GetPickupTemplate())) { - weaponPickup->SetActorLocation(enemy->GetActorLocation()); + float radius; + float halfHeight; + enemy->GetCapsuleComponent()->GetScaledCapsuleSize(radius, halfHeight); + + auto location = enemy->GetActorLocation(); + location.Z -= halfHeight; + weaponPickup->SetActorLocation(location); + weaponPickup->SetWeapon(enemy->DefaultWeaponInventory[enemy->GetCurrentInventorySlot()]); weaponPickup->SetWeaponProperties(*enemy->CurrentWeapon->GetWeaponProperties()); } diff --git a/Source/Nakatomi/Weapon.cpp b/Source/Nakatomi/Weapon.cpp index c5a0309..eeda6db 100644 --- a/Source/Nakatomi/Weapon.cpp +++ b/Source/Nakatomi/Weapon.cpp @@ -137,6 +137,11 @@ UNiagaraSystem* AWeapon::GetImpactParticleSystem() return ImpactParticleSystem; } +TSubclassOf AWeapon::GetPickupTemplate() +{ + return PickupTemplate; +} + TSubclassOf AWeapon::GetFieldSystemActor() { return FieldSystemActor; diff --git a/Source/Nakatomi/Weapon.h b/Source/Nakatomi/Weapon.h index 9301f15..befb69b 100644 --- a/Source/Nakatomi/Weapon.h +++ b/Source/Nakatomi/Weapon.h @@ -59,6 +59,9 @@ protected: UPROPERTY(EditDefaultsOnly) UNiagaraSystem* ImpactParticleSystem; + UPROPERTY(EditDefaultsOnly) + TSubclassOf PickupTemplate; + public: // Sets default values for this actor's properties AWeapon(); @@ -108,4 +111,6 @@ public: TSubclassOf GetDecalActor(); UNiagaraSystem* GetImpactParticleSystem(); + + TSubclassOf GetPickupTemplate(); }; diff --git a/Source/Nakatomi/WeaponPickup.cpp b/Source/Nakatomi/WeaponPickup.cpp index 33e11cd..9db4d12 100644 --- a/Source/Nakatomi/WeaponPickup.cpp +++ b/Source/Nakatomi/WeaponPickup.cpp @@ -2,10 +2,18 @@ #include "WeaponPickup.h" #include "PlayerCharacter.h" +#include "Kismet/GameplayStatics.h" +#include "Kismet/KismetMathLibrary.h" +#include "UI/WeaponPickupUserWidget.h" // Sets default values AWeaponPickup::AWeaponPickup() { + WeaponPropertiesWidgetComponent = CreateDefaultSubobject(TEXT("Healthbar")); + WeaponPropertiesWidgetComponent->SetupAttachment(RootComponent); + WeaponPropertiesWidgetComponent->SetRelativeLocation(FVector(0,0,90)); + WeaponPropertiesWidgetComponent->SetTwoSided(true); + WeaponPropertiesWidgetComponent->SetBackgroundColor(FLinearColor(1,1,1,0)); } // Called when the game starts or when spawned @@ -34,6 +42,18 @@ void AWeaponPickup::Tick(const float DeltaTime) const float Sine = FMath::Abs(FMath::Sin(Time * MovementSpeed)); WeaponComponent->SetActorLocation(WeaponStartingLocation + ((MovementDirection * Sine) * MovementDistance)); } + + APlayerCharacter* PlayerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); + if (PlayerCharacter && WeaponPropertiesWidgetComponent->GetWidget()) + { + FVector ActorLocation = GetActorLocation(); + + UCameraComponent* PlayerCamera = PlayerCharacter->GetCameraComponent(); + FVector PlayerLocation = PlayerCamera->GetComponentTransform().GetLocation(); + + FRotator rotation = UKismetMathLibrary::FindLookAtRotation(ActorLocation, PlayerLocation); + WeaponPropertiesWidgetComponent->SetWorldRotation(rotation); + } } void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, @@ -74,6 +94,23 @@ FWeaponProperties* AWeaponPickup::GetWeaponProperties() void AWeaponPickup::SetWeaponProperties(const FWeaponProperties& FWeaponProperties) const { WeaponComponent->SetWeaponProperties(FWeaponProperties); + + UWeaponPickupUserWidget* userWidget = Cast(WeaponPropertiesWidgetComponent->GetWidget()); + + userWidget->AmmoText->SetText(FText::AsNumber(FWeaponProperties.DefaultAmmo)); + + FString ProjectilesString = FString::FromInt(FWeaponProperties.ProjectilesPerShot); + ProjectilesString += "x"; + userWidget->ProjectilesText->SetText(FText::FromString(ProjectilesString)); + + FString CooldownString = FString::SanitizeFloat(FWeaponProperties.WeaponCooldown); + CooldownString.LeftInline(3); + CooldownString += "s"; + userWidget->CooldownText->SetText(FText::FromString(CooldownString)); + + FString SpreadString = FString::SanitizeFloat(FWeaponProperties.WeaponSpread); + SpreadString.LeftInline(4); + userWidget->SpreadText->SetText(FText::FromString(SpreadString)); } void AWeaponPickup::SpawnWeapon() diff --git a/Source/Nakatomi/WeaponPickup.h b/Source/Nakatomi/WeaponPickup.h index 61617ce..b0fb0f4 100644 --- a/Source/Nakatomi/WeaponPickup.h +++ b/Source/Nakatomi/WeaponPickup.h @@ -4,6 +4,7 @@ #include "Pickup.h" #include "Weapon.h" +#include "Components/WidgetComponent.h" #include "WeaponPickup.generated.h" UCLASS() @@ -30,6 +31,9 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float RotationSpeed = 50.0f; + UPROPERTY(EditAnywhere) + UWidgetComponent* WeaponPropertiesWidgetComponent; + private: UPROPERTY() AWeapon* WeaponComponent;