Skip to content

Commit

Permalink
Added equipment spawner with support to spawn kevlar vest, helmet and…
Browse files Browse the repository at this point in the history
… medkit (#191)

* #170 Added model for armor and helmet
* #170 Added Kevlar vest and Helmet spawners
  • Loading branch information
xthebat authored Feb 15, 2024
1 parent bb62fe6 commit 6b05a97
Show file tree
Hide file tree
Showing 41 changed files with 444 additions and 38 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Blueprints/Modes/BP_Cloud9Default.uasset
Binary file not shown.
Binary file modified Content/Blueprints/Widgets/HudWidget.uasset
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Importing/upgrade_dz_armor.blend
Binary file not shown.
Binary file added Importing/upgrade_dz_armor.fbx
Binary file not shown.
Binary file added Importing/upgrade_dz_armor_helmet.blend
Binary file not shown.
Binary file added Importing/upgrade_dz_armor_helmet.fbx
Binary file not shown.
Binary file added Importing/upgrade_dz_helmet.blend
Binary file not shown.
Binary file added Importing/upgrade_dz_helmet.fbx
Binary file not shown.
26 changes: 10 additions & 16 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@
#include "Components/DecalComponent.h"
#include "Components/CapsuleComponent.h"

#include "Cloud9/Game/Cloud9GameInstance.h"
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Contollers//Cloud9PlayerController.h"
#include "Cloud9/Character/Components/Cloud9CharacterMovement.h"
#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h"
#include "Cloud9/Character/Components/Cloud9Inventory.h"
#include "Cloud9/Character/Components/Cloud9CharacterMovement.h"
#include "Cloud9/Character/Components/Cloud9SpringArmComponent.h"
#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h"
#include "Cloud9/Character/Components/Cloud9CharacterHealthComponent.h"

const FName ACloud9Character::SpringArmComponentName = TEXT("CameraBoom");
const FName ACloud9Character::CameraComponentName = TEXT("TopDownCamera");
const FName ACloud9Character::DecalComponentName = TEXT("CursorToWorld");
const FName ACloud9Character::InventoryComponentName = TEXT("Inventory");
const FName ACloud9Character::HealthComponentName = TEXT("HealthComponent");

ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer) : Super(
ObjectInitializer.SetDefaultSubobjectClass<UCloud9CharacterMovement>(CharacterMovementComponentName))
Expand Down Expand Up @@ -77,11 +78,13 @@ ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer)
CursorToWorld->SetupAttachment(RootComponent);

Inventory = CreateDefaultSubobject<UCloud9Inventory>(InventoryComponentName);
HealthComponent = CreateDefaultSubobject<UCloud9CharacterHealthComponent>(HealthComponentName);

Health = 100.0f;
Armor = 25.0f; // TODO: Set armor to 0 after health shot and armor pack added
Score = 1; // TODO: Set score to 0 after implementation

OnTakePointDamage.AddDynamic(HealthComponent, &UCloud9CharacterHealthComponent::OnTakePointDamage);
OnTakeRadialDamage.AddDynamic(HealthComponent, &UCloud9CharacterHealthComponent::OnTakeRadialDamage);

// Activate ticking in order to update the cursor every frame.
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
Expand Down Expand Up @@ -226,6 +229,8 @@ void ACloud9Character::SetCameraZoomHeight(float Value) const

UCloud9Inventory* ACloud9Character::GetInventory() const { return Inventory; }

UCloud9CharacterHealthComponent* ACloud9Character::GetHealthComponent() const { return HealthComponent; }

void ACloud9Character::UseObject()
{
// TODO: Implement UseObject
Expand Down Expand Up @@ -271,15 +276,4 @@ void ACloud9Character::Tick(float DeltaSeconds)
{
Inventory->SelectOtherAvailableWeapon(false);
}

// // TODO: Remove auto grenade add after debug
// if (not Inventory->GetWeaponAt(EWeaponSlot::Grenade) and Inventory->GetSelectedWeapon() != nullptr)
// {
// if (let GameInstance = GetGameInstance<UCloud9GameInstance>(); IsValid(GameInstance))
// {
// GameInstance->GetDefaultWeaponsConfig()
// | ETContainer::Filter{[this](let& Config) { return IsValid(Config) and Config.IsGrenadeWeapon(); }}
// | ETContainer::ForEach{[this](let& Config) { Inventory->AddWeapon(Config); }};
// }
// }
}
14 changes: 8 additions & 6 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "Cloud9Character.generated.h"


class UCloud9CharacterHealthComponent;

UCLASS(config=Game, Blueprintable)
class ACloud9Character : public ACharacter
{
Expand All @@ -42,6 +44,7 @@ class ACloud9Character : public ACharacter
static const FName CameraComponentName;
static const FName DecalComponentName;
static const FName InventoryComponentName;
static const FName HealthComponentName;

ACloud9Character(const FObjectInitializer& ObjectInitializer);

Expand Down Expand Up @@ -79,6 +82,9 @@ class ACloud9Character : public ACharacter
void SetCameraZoomHeight(float Value) const;

UCloud9Inventory* GetInventory() const;

UCloud9CharacterHealthComponent* GetHealthComponent() const;

void UseObject();

// Set by character movement to specify that this Character is currently sneaking.
Expand Down Expand Up @@ -115,13 +121,9 @@ class ACloud9Character : public ACharacter
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Inventory, meta=(AllowPrivateAccess))
UCloud9Inventory* Inventory;

/** Current percentage health of character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
float Health;

/** Current percentage armor of character */
/** A state of the character health and armor. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
float Armor;
UCloud9CharacterHealthComponent* HealthComponent;

/** Current number of frags made by character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
Expand Down
112 changes: 112 additions & 0 deletions Source/Cloud9/Character/Components/Cloud9CharacterHealthComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2024 Alexei Gladkikh

#include "Cloud9CharacterHealthComponent.h"

#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"

UCloud9CharacterHealthComponent::UCloud9CharacterHealthComponent()
{
Health = 100.0f;
Armor = 0.0f;
bHasHelmet = false;
}

void UCloud9CharacterHealthComponent::Initialize(FHealthConfig Config)
{
ChangeHealth(Config.Health);
ChangeArmor(Config.Armor);
ChangeHasHelmet(Config.bHasHelmet);
}

bool UCloud9CharacterHealthComponent::TakeHealthDamage(float Change)
{
return ChangeHealth(Health - Change);
}

bool UCloud9CharacterHealthComponent::TakeArmorDamage(float Change)
{
return ChangeArmor(Armor - Change);
}

bool UCloud9CharacterHealthComponent::ChangeHealth(float NewHealth)
{
if (let Value = FMath::Max(NewHealth, 0.0f); Value != Health)
{
Health = Value;
OnHealthChange.Broadcast(Health);

if (Health == 0.0f)
{
let Owner = GetOwner();

if (not IsValid(Owner))
{
log(Fatal, "[Component = %s] Owner isn't valid", *GetName());
return false;
}

Owner->MarkPendingKill();
}

return true;
}

return false;
}

bool UCloud9CharacterHealthComponent::ChangeArmor(float NewArmor)
{
if (let Value = FMath::Clamp(NewArmor, 0.0f, 100.0f); Value != Armor)
{
Armor = Value;
OnArmorChange.Broadcast(Armor);
if (Armor == 0.0f)
{
ChangeHasHelmet(false);
}
return true;
}

return false;
}

bool UCloud9CharacterHealthComponent::ChangeHasHelmet(bool NewState)
{
if (bHasHelmet != NewState)
{
bHasHelmet = NewState;
OnHelmetChange.Broadcast(NewState);
return true;
}

return false;
}

void UCloud9CharacterHealthComponent::OnTakePointDamage(
AActor* DamagedActor,
float Damage,
AController* InstigatedBy,
FVector HitLocation,
UPrimitiveComponent* FHitComponent,
FName BoneName,
FVector ShotFromDirection,
const UDamageType* DamageType,
AActor* DamageCauser)
{
TakeHealthDamage(Damage); // TODO: Add factor by armor
TakeArmorDamage(0.0f); // TODO: Add armor damage calc
}

void UCloud9CharacterHealthComponent::OnTakeRadialDamage(
AActor* DamagedActor,
float Damage,
const UDamageType* DamageType,
FVector Origin,
FHitResult HitInfo,
AController* InstigatedBy,
AActor* DamageCauser)
{
TakeHealthDamage(Damage); // TODO: Add factor by armor
TakeArmorDamage(0.0f); // TODO: Add armor damage calc
}
112 changes: 112 additions & 0 deletions Source/Cloud9/Character/Components/Cloud9CharacterHealthComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2023 Alexei Gladkikh
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#include "CoreMinimal.h"

#include "Cloud9/Character/Components/Cloud9CharacterComponent.h"
#include "Cloud9/Character/Structures/HealthConfig.h"

#include "Cloud9CharacterHealthComponent.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHealthChange, float, Health);

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnArmorChange, float, Armor);

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHelmetChange, bool, State);


class ACloud9Character;

UCLASS(Blueprintable)
class CLOUD9_API UCloud9CharacterHealthComponent
: public UActorComponent
, public ICloud9CharacterComponent
{
GENERATED_BODY()

public:
UCloud9CharacterHealthComponent();

void Initialize(FHealthConfig Config);

bool TakeHealthDamage(float Change);
bool TakeArmorDamage(float Change);

// Helmet is permanent(?)
bool ChangeHasHelmet(bool NewState);

UFUNCTION()
void OnTakePointDamage(
AActor* DamagedActor,
float Damage,
AController* InstigatedBy,
FVector HitLocation,
UPrimitiveComponent* FHitComponent,
FName BoneName,
FVector ShotFromDirection,
const UDamageType* DamageType,
AActor* DamageCauser);

UFUNCTION()
void OnTakeRadialDamage(
AActor* DamagedActor,
float Damage,
const UDamageType* DamageType,
FVector Origin,
FHitResult HitInfo,
AController* InstigatedBy,
AActor* DamageCauser
);

float GetHealth() const { return Health; }
float GetArmor() const { return Armor; }
bool HasHelmet() const { return bHasHelmet; }

protected:
bool ChangeHealth(float NewHealth);
bool ChangeArmor(float NewArmor);

protected:
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnHealthChange OnHealthChange;

UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnArmorChange OnArmorChange;

UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnHelmetChange OnHelmetChange;

/** Current percentage health of character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
float Health;

/** Current percentage armor of character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
float Armor;

/** Current percentage armor of character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
bool bHasHelmet;
};
22 changes: 22 additions & 0 deletions Source/Cloud9/Character/Structures/HealthConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2024 Alexei Gladkikh

#pragma once

#include "HealthConfig.generated.h"

USTRUCT(BlueprintType)
struct FHealthConfig
{
GENERATED_BODY()

UPROPERTY(Category=Config, EditDefaultsOnly, BlueprintReadOnly,
meta=(UIMin="0", UIMax="20000.0", ClampMin="0", ClampMax="20000.0"))
float Health = 100.0f;

UPROPERTY(Category=Config, EditDefaultsOnly, BlueprintReadOnly,
meta=(UIMin="0", UIMax="100.0", ClampMin="0", ClampMax="100.0"))
float Armor = 0.0f;

UPROPERTY(Category=Config, EditDefaultsOnly, BlueprintReadOnly)
bool bHasHelmet = false;
};
8 changes: 6 additions & 2 deletions Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

#include "Cloud9DefaultGameMode.h"

#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Game/Cloud9GameInstance.h"
#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"
#include "Cloud9/Game/Cloud9GameInstance.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Character/Components/Cloud9CharacterHealthComponent.h"

FName ACloud9DefaultGameMode::CtSidePlayer = TEXT("CT");
FName ACloud9DefaultGameMode::TSidePlayer = TEXT("T");
Expand Down Expand Up @@ -76,7 +77,10 @@ bool ACloud9DefaultGameMode::OnWorldStart(FSavedInfo& SavedInfo)
{
let Character = GetPlayerCharacter(LocalPlayer);
let Inventory = Character->GetInventory();
let Health = Character->GetHealthComponent();

Inventory->Initialize(PlayerConfig.WeaponConfigs, PlayerConfig.WeaponSlot);
Health->Initialize(PlayerConfig.HealthConfig);
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions Source/Cloud9/Structures/PlayerSavedInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include "Cloud9/Character/Structures/HealthConfig.h"
#include "Cloud9/Weapon/Structures/WeaponConfig.h"

#include "PlayerSavedInfo.generated.h"
Expand All @@ -11,6 +12,9 @@ struct FPlayerSavedInfo
{
GENERATED_BODY()

UPROPERTY(Category=Health, EditDefaultsOnly, BlueprintReadOnly)
FHealthConfig HealthConfig;

UPROPERTY(Category=Weapon, EditDefaultsOnly, BlueprintReadOnly)
EWeaponSlot WeaponSlot = EWeaponSlot::NotSelected;

Expand Down
Loading

0 comments on commit 6b05a97

Please sign in to comment.