Finished implementing item drops
Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
parent
82c0257e14
commit
cb59ea1628
@ -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")
|
||||
|
BIN
Content/Legumix/Drops/BP_DropRevolver.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Drops/BP_DropRevolver.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Drops/BP_DropShotgun.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Drops/BP_DropShotgun.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Drops/BP_HealthPack.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Drops/BP_HealthPack.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Player/BP_GrabComponent.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/BP_GrabComponent.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Player/BP_Play.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/BP_Play.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Player/C_GrabMovement.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/C_GrabMovement.uasset
(Stored with Git LFS)
Binary file not shown.
@ -16,7 +16,7 @@ void ALMAmmoPack::ConsumePack(ALMPlayer* Player)
|
||||
{
|
||||
Super::ConsumePack(Player);
|
||||
|
||||
Player->GetWeaponManager()->AddAmmoType(AmmoType, AmmoCount);
|
||||
Player->AddAmmo(AmmoType, AmmoCount);
|
||||
OnPackConsumed();
|
||||
Despawn();
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ ALMHealthPack::ALMHealthPack()
|
||||
|
||||
void ALMHealthPack::ConsumePack(ALMPlayer* Player)
|
||||
{
|
||||
Super::ConsumePack(Player);
|
||||
|
||||
Player->GetHealthComponent()->AddHealth(HealthGain);
|
||||
OnPackConsumed();
|
||||
Despawn();
|
||||
|
@ -3,12 +3,17 @@
|
||||
|
||||
#include "LMItemDrop.h"
|
||||
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
|
||||
ALMItemDrop::ALMItemDrop()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
Root = CreateDefaultSubobject<USceneComponent>("Root");
|
||||
RootComponent = Root;
|
||||
|
||||
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("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()
|
||||
|
@ -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()
|
||||
|
@ -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<UCurveFloat> SpeedAtPosition;
|
||||
|
||||
TObjectPtr<ALMPlayer> 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;
|
||||
|
@ -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"))
|
||||
|
@ -18,26 +18,48 @@ 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<UCurveFloat> PositionAtTime;
|
||||
|
||||
FTimerHandle DespawnHandle;
|
||||
FTimerHandle MoveHandle;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<USceneComponent> Root;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<UStaticMeshComponent> StaticMeshComponent;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
|
||||
FVector SpawnLocation;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<AActor> 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);
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void OnPackConsumed();
|
||||
|
||||
FVector GetSpawnLocation() { return SpawnLocation; }
|
||||
FVector GetSpawnLocation() const { return SpawnLocation; }
|
||||
|
||||
protected:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user