diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index a41080a..df8fa0f 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -131,7 +131,7 @@ ManualIPAddress= +Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Bullet",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.") +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap),(Channel="Bullet",Response=ECR_Ignore)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") -+Profiles=(Name="Drop",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="Drop",CustomResponses=,HelpMessage="Needs description") ++Profiles=(Name="Drop",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="Drop",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="Bullet",Response=ECR_Ignore),(Channel="Enemy",Response=ECR_Ignore),(Channel="Drop",Response=ECR_Ignore)),HelpMessage="Needs description") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Block,bTraceType=True,bStaticObject=False,Name="Bullet") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel2,DefaultResponse=ECR_Block,bTraceType=True,bStaticObject=False,Name="Enemy") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel3,DefaultResponse=ECR_Ignore,bTraceType=False,bStaticObject=False,Name="Projectile") diff --git a/Content/Legumix/Drops/BP_DropRevolver.uasset b/Content/Legumix/Drops/BP_DropRevolver.uasset index a4728c9..085476f 100644 --- a/Content/Legumix/Drops/BP_DropRevolver.uasset +++ b/Content/Legumix/Drops/BP_DropRevolver.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cfee965cd84a5caa4fd913f387ae7c13cd4f541d04c4288a709d64703652b721 -size 35231 +oid sha256:c81ae7940fd0d9bfbbd9ab2659f2a0aca7b56c094a00dc57f52ecfa43e8c82aa +size 38220 diff --git a/Content/Legumix/Drops/BP_DropShotgun.uasset b/Content/Legumix/Drops/BP_DropShotgun.uasset index 8da0127..8307c21 100644 --- a/Content/Legumix/Drops/BP_DropShotgun.uasset +++ b/Content/Legumix/Drops/BP_DropShotgun.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a8ef945ed99c81f382c62241939f189a0f5ea6284817a7e98ef5250533e8a1fd -size 35768 +oid sha256:58d5e1577f8d3fe8d6e31fa53b2f7f9e6141138dad56b8a7b38dd44cc08ba89f +size 38044 diff --git a/Content/Legumix/Drops/BP_HealthPack.uasset b/Content/Legumix/Drops/BP_HealthPack.uasset index 103847f..2cbe4f6 100644 --- a/Content/Legumix/Drops/BP_HealthPack.uasset +++ b/Content/Legumix/Drops/BP_HealthPack.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bd25a277922168a5f19ae9d29e8d606180d5fab78f2a2b089500fe65aa6ba76e -size 36931 +oid sha256:237e35c4b2e5a378032198bb9da95c9f9e43fbe93b3309e593ad0ce151e724d0 +size 38978 diff --git a/Content/Legumix/Player/BP_GrabComponent.uasset b/Content/Legumix/Player/BP_GrabComponent.uasset index 3f28caf..6546214 100644 --- a/Content/Legumix/Player/BP_GrabComponent.uasset +++ b/Content/Legumix/Player/BP_GrabComponent.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94d44c354900a897e9d28ac01a7718cc6287fdbab0adc3c8916a0285692a56d9 -size 79004 +oid sha256:fc4a6166579c377d3c8a2ac96634a5e37d05c2aa325abac959e5ea39f3558d4d +size 9696 diff --git a/Content/Legumix/Player/BP_Play.uasset b/Content/Legumix/Player/BP_Play.uasset index 14f01a0..e0b165c 100644 --- a/Content/Legumix/Player/BP_Play.uasset +++ b/Content/Legumix/Player/BP_Play.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4571d7448aa5ff7b727a5d3df7a1c2cfc9e86a63bfbe20e8caaa38fbf74cf464 -size 649059 +oid sha256:df786d770dc0106b0d0ba66b32f9fde2483ed489db125481e847c87523c7b467 +size 642697 diff --git a/Content/Legumix/Player/C_GrabMovement.uasset b/Content/Legumix/Player/C_GrabMovement.uasset index 31268a5..9e6ef1d 100644 --- a/Content/Legumix/Player/C_GrabMovement.uasset +++ b/Content/Legumix/Player/C_GrabMovement.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8496ddd779404f4331461e71ede1cf9a4cd96bee35fe3d437fc8d8fb388f37a0 -size 5060 +oid sha256:5683d4d38474f956c5e35a3597c4f1d18766f2d312303cfe8173aacf1557f4be +size 5054 diff --git a/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp b/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp index 5986eed..366a839 100644 --- a/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp +++ b/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp @@ -16,7 +16,7 @@ void ALMAmmoPack::ConsumePack(ALMPlayer* Player) { Super::ConsumePack(Player); - Player->GetWeaponManager()->AddAmmoType(AmmoType, AmmoCount); + Player->AddAmmo(AmmoType, AmmoCount); OnPackConsumed(); Despawn(); } diff --git a/Source/LegumeMix/Private/LMHealthPack.cpp b/Source/LegumeMix/Private/LMHealthPack.cpp index 7adcdaa..833ee14 100644 --- a/Source/LegumeMix/Private/LMHealthPack.cpp +++ b/Source/LegumeMix/Private/LMHealthPack.cpp @@ -14,6 +14,8 @@ ALMHealthPack::ALMHealthPack() void ALMHealthPack::ConsumePack(ALMPlayer* Player) { + Super::ConsumePack(Player); + Player->GetHealthComponent()->AddHealth(HealthGain); OnPackConsumed(); Despawn(); diff --git a/Source/LegumeMix/Private/LMItemDrop.cpp b/Source/LegumeMix/Private/LMItemDrop.cpp index af6ac13..e6ad47e 100644 --- a/Source/LegumeMix/Private/LMItemDrop.cpp +++ b/Source/LegumeMix/Private/LMItemDrop.cpp @@ -3,12 +3,17 @@ #include "LMItemDrop.h" +#include "Kismet/KismetMathLibrary.h" + ALMItemDrop::ALMItemDrop() { PrimaryActorTick.bCanEverTick = true; + Root = CreateDefaultSubobject("Root"); + RootComponent = Root; + StaticMeshComponent = CreateDefaultSubobject("MeshComponent"); - RootComponent = StaticMeshComponent; + StaticMeshComponent->SetupAttachment(RootComponent); } void ALMItemDrop::BeginPlay() @@ -18,8 +23,41 @@ void ALMItemDrop::BeginPlay() GetWorldTimerManager().SetTimer(DespawnHandle, this, &ALMItemDrop::Despawn, TimeBeforeDespawn); } +void ALMItemDrop::SetAttractor(AActor* Target) +{ + Attractor = Target; + GetWorldTimerManager().SetTimer(MoveHandle, this, &ALMItemDrop::DoMovingTowardsTarget, MoveRate, true); + GetWorldTimerManager().ClearTimer(DespawnHandle); +} + +void ALMItemDrop::DoMovingTowardsTarget() +{ + if (MoveTime >= MoveDuration) + { + GetWorldTimerManager().ClearTimer(MoveHandle); + SetActorLocation(Attractor->GetActorLocation()); + return; + } + + const FVector Position = Attractor->GetActorLocation(); + + const float Duration = MoveTime / MoveDuration; + + FString text = FString::Printf(TEXT("Time : %f / %f = %f"), MoveTime, MoveDuration, Duration); + GEngine->AddOnScreenDebugMessage(-15, 1.f, FColor::Red, text); + const float CurvePosition = PositionAtTime->GetFloatValue(Duration); + const FVector NewPosition = UKismetMathLibrary::VLerp(SpawnLocation, Position, CurvePosition); + + MoveTime += MoveRate; + SetActorLocation(NewPosition); +} + void ALMItemDrop::ConsumePack(ALMPlayer* Player) { + if (MoveHandle.IsValid()) + { + GetWorldTimerManager().ClearTimer(MoveHandle); + } } void ALMItemDrop::Despawn() diff --git a/Source/LegumeMix/Private/Player/LMGrabRange.cpp b/Source/LegumeMix/Private/Player/LMGrabRange.cpp index 8dcea6c..0a67c9b 100644 --- a/Source/LegumeMix/Private/Player/LMGrabRange.cpp +++ b/Source/LegumeMix/Private/Player/LMGrabRange.cpp @@ -17,19 +17,32 @@ void ULMGrabRange::TickComponent(float DeltaTime, enum ELevelTick TickType, FAct { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - + if (!bIsEnabled) + return; + + for (int i = Drops.Num() - 1; i >= 0; i--) + { + ALMItemDrop* Item = Drops[i]; + + const FVector ItemPosition = Item->GetActorLocation(); + const FVector Position = GetComponentLocation(); + + const float DistanceLeft = FVector::Dist(ItemPosition, Position); + FString text = FString::Printf(TEXT("Item %s at distance %f"), *Item->GetName(), DistanceLeft); + GEngine->AddOnScreenDebugMessage(i, 1.f, FColor::Cyan, text); + + if (DistanceLeft <= RangeToGrab) + { + Item->ConsumePack(Player); + Drops.Remove(Item); + } + } } -void ULMGrabRange::OnDropOverlapped_Implementation(ALMItemDrop* ItemDrop) +void ULMGrabRange::OnDropOverlapped(ALMItemDrop* ItemDrop) { Drops.AddUnique(ItemDrop); -} - - -void ULMGrabRange::ConsumeDrop(ALMItemDrop* ItemDrop) -{ - ItemDrop->ConsumePack(Player); - + ItemDrop->SetAttractor(Player); } void ULMGrabRange::BeginPlay() diff --git a/Source/LegumeMix/Private/Player/LMGrabRange.h b/Source/LegumeMix/Private/Player/LMGrabRange.h index a8237aa..eeb97e7 100644 --- a/Source/LegumeMix/Private/Player/LMGrabRange.h +++ b/Source/LegumeMix/Private/Player/LMGrabRange.h @@ -26,21 +26,14 @@ private: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true, ClampMin=0.1f)) float RangeToGrab = 10.f; - /** Distance curve from 0-1 to the player. */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true)) - TObjectPtr SpeedAtPosition; - TObjectPtr Player; public: ULMGrabRange(); - UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Legumix) + UFUNCTION(BlueprintCallable, Category=Legumix) void OnDropOverlapped(ALMItemDrop* ItemDrop); - UFUNCTION(BlueprintCallable, Category=Legumix) - void ConsumeDrop(ALMItemDrop* ItemDrop); - - void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; protected: virtual void BeginPlay() override; diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index 10d4bb7..f5b5f86 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -116,6 +116,14 @@ bool ALMPlayer::CanJumpInternal_Implementation() const return JumpIsAllowedInternal(); } +void ALMPlayer::AddAmmo(const EAmmoType Ammo, const int AmmoCount) +{ + if (GetWeaponManager()->AddAmmoType(Ammo, AmmoCount)) + { + OnAmmoPickup(); + } +} + void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager) { UE_LOG(LogTemp, Warning, TEXT("Set weapon manager")) diff --git a/Source/LegumeMix/Public/LMItemDrop.h b/Source/LegumeMix/Public/LMItemDrop.h index 808a1ae..1ccb8b7 100644 --- a/Source/LegumeMix/Public/LMItemDrop.h +++ b/Source/LegumeMix/Public/LMItemDrop.h @@ -17,19 +17,41 @@ class LEGUMEMIX_API ALMItemDrop : public AActor protected: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix) float TimeBeforeDespawn = 30.f; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix) + float MoveRate = 0.1f; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix) + float MoveDuration = 1.f; + + /** Distance curve from 0-1 to the player. */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true)) + TObjectPtr PositionAtTime; FTimerHandle DespawnHandle; + FTimerHandle MoveHandle; private: + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) + TObjectPtr Root; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) TObjectPtr StaticMeshComponent; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) FVector SpawnLocation; + UPROPERTY() + TObjectPtr Attractor; + + float MoveTime = 0.f; + public: ALMItemDrop(); virtual void BeginPlay() override; + + void SetAttractor(AActor* Target); + UFUNCTION() + void DoMovingTowardsTarget(); UFUNCTION(BlueprintCallable) virtual void ConsumePack(ALMPlayer* Player); @@ -37,7 +59,7 @@ public: UFUNCTION(BlueprintImplementableEvent) void OnPackConsumed(); - FVector GetSpawnLocation() { return SpawnLocation; } + FVector GetSpawnLocation() const { return SpawnLocation; } protected: UFUNCTION(BlueprintCallable) diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index 02e4b55..2183e22 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "LMBulletInfo.h" #include "LMTeam.h" +#include "Ammo/LMAmmoPack.h" #include "Camera/CameraComponent.h" #include "GameFramework/Character.h" #include "LMPlayer.generated.h" @@ -56,6 +57,9 @@ public: virtual bool CanJumpInternal_Implementation() const override; + UFUNCTION(BlueprintCallable) + void AddAmmo(EAmmoType Ammo, int AmmoCount); + protected: // Called when the game starts or when spawned virtual void BeginPlay() override;