-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equipment spawner with support to spawn kevlar vest, helmet and…
… medkit (#191) * #170 Added model for armor and helmet * #170 Added Kevlar vest and Helmet spawners
- Loading branch information
Showing
41 changed files
with
444 additions
and
38 deletions.
There are no files selected for viewing
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 not shown.
Binary file not shown.
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.
Binary file added
BIN
+974 KB
Importing/textures/materials_models_player_ct_swat_ct_swat_head_normal.png
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
BIN
+709 KB
Importing/textures/materials_models_props_survival_upgrades_dz_armor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
Source/Cloud9/Character/Components/Cloud9CharacterHealthComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
112
Source/Cloud9/Character/Components/Cloud9CharacterHealthComponent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.