-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e1826c
Showing
8 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
/Intermediate/ | ||
/Binaries/ |
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,24 @@ | ||
{ | ||
"FileVersion": 3, | ||
"Version": 1, | ||
"VersionName": "1.0", | ||
"FriendlyName": "HealthSystem", | ||
"Description": "", | ||
"Category": "Other", | ||
"CreatedBy": "Space_Mex", | ||
"CreatedByURL": "", | ||
"DocsURL": "", | ||
"MarketplaceURL": "", | ||
"SupportURL": "", | ||
"CanContainContent": true, | ||
"IsBetaVersion": false, | ||
"IsExperimentalVersion": false, | ||
"Installed": false, | ||
"Modules": [ | ||
{ | ||
"Name": "HealthSystem", | ||
"Type": "Runtime", | ||
"LoadingPhase": "Default" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,53 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
using UnrealBuildTool; | ||
|
||
public class HealthSystem : ModuleRules | ||
{ | ||
public HealthSystem(ReadOnlyTargetRules Target) : base(Target) | ||
{ | ||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; | ||
|
||
PublicIncludePaths.AddRange( | ||
new string[] { | ||
// ... add public include paths required here ... | ||
} | ||
); | ||
|
||
|
||
PrivateIncludePaths.AddRange( | ||
new string[] { | ||
// ... add other private include paths required here ... | ||
} | ||
); | ||
|
||
|
||
PublicDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"Core", | ||
// ... add other public dependencies that you statically link with here ... | ||
} | ||
); | ||
|
||
|
||
PrivateDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"CoreUObject", | ||
"Engine", | ||
"Slate", | ||
"SlateCore", | ||
// ... add private dependencies that you statically link with here ... | ||
} | ||
); | ||
|
||
|
||
DynamicallyLoadedModuleNames.AddRange( | ||
new string[] | ||
{ | ||
// ... add any modules that your module loads dynamically here ... | ||
} | ||
); | ||
} | ||
} |
165 changes: 165 additions & 0 deletions
165
Source/HealthSystem/Private/Components/HealthComponent.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,165 @@ | ||
/* | ||
* Copyright (c) 2023 Space_Mex | ||
* | ||
* All rights reserved. | ||
* | ||
* This file is part of the HealthSystem Plugin. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
* Proprietary and confidential. | ||
*/ | ||
|
||
|
||
#include "Components/HealthComponent.h" | ||
|
||
// Sets default values for this component's properties | ||
UHealthComponent::UHealthComponent() | ||
{ | ||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features | ||
// off to improve performance if you don't need them. | ||
PrimaryComponentTick.bCanEverTick = true; | ||
|
||
// ... | ||
} | ||
|
||
|
||
// Called when the game starts | ||
void UHealthComponent::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
|
||
// ... | ||
|
||
} | ||
|
||
|
||
// Called every frame | ||
void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) | ||
{ | ||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); | ||
|
||
// ... | ||
} | ||
|
||
void UHealthComponent::SetHealth(float NewHealth) | ||
{ | ||
Health = NewHealth; | ||
} | ||
|
||
void UHealthComponent::SetMaxHealth(float NewMaxHealth) | ||
{ | ||
MaxHealth = NewMaxHealth; | ||
} | ||
|
||
void UHealthComponent::SetRegenHealth(bool NewRegenHealth) | ||
{ | ||
RegenHealth = NewRegenHealth; | ||
} | ||
|
||
void UHealthComponent::SetHealthRegen(float NewRegenSpeed) | ||
{ | ||
HealthRegenSpeed = NewRegenSpeed; | ||
} | ||
|
||
void UHealthComponent::SetArmor(float NewArmor) | ||
{ | ||
Armor = NewArmor; | ||
} | ||
|
||
void UHealthComponent::SetMaxArmor(float NewMaxArmor) | ||
{ | ||
MaxArmor = NewMaxArmor; | ||
} | ||
|
||
void UHealthComponent::SetRegenArmor(bool NewRegenArmor) | ||
{ | ||
RegenArmor = NewRegenArmor; | ||
} | ||
|
||
void UHealthComponent::SetArmorRegen(float NewRegenSpeed) | ||
{ | ||
ArmorRegenSpeed = NewRegenSpeed; | ||
} | ||
|
||
void UHealthComponent::Damage(float AfflictedDamage) | ||
{ | ||
if (Armor > AfflictedDamage) | ||
{ | ||
Armor -= AfflictedDamage; | ||
|
||
GetWorld()->GetTimerManager().ClearTimer(ArmorRegenTimerHandle); | ||
|
||
GetWorld()->GetTimerManager().SetTimer(ArmorRegenTimerHandle,this, | ||
&UHealthComponent::RegenArmorTimer,RegenAfterDamagedDelay, false); | ||
|
||
} | ||
else | ||
{ | ||
float DamageAfterArmor = AfflictedDamage - Armor; | ||
Armor = 0.0; | ||
|
||
Health = FMath::Clamp(Health - DamageAfterArmor, 0.0, MaxHealth); | ||
|
||
GetWorld()->GetTimerManager().ClearTimer(HealthRegenTimerHandle); | ||
GetWorld()->GetTimerManager().ClearTimer(ArmorRegenTimerHandle); | ||
|
||
|
||
if (RegenHealth && RegenArmor) | ||
{ | ||
GetWorld()->GetTimerManager().SetTimer(HealthRegenTimerHandle,this, | ||
&UHealthComponent::RegenHealthTimer,RegenAfterDamagedDelay, false); | ||
|
||
GetWorld()->GetTimerManager().SetTimer(ArmorRegenTimerHandle,this, | ||
&UHealthComponent::RegenArmorTimer,RegenAfterDamagedDelay, false); | ||
} else if (RegenArmor) | ||
{ | ||
GetWorld()->GetTimerManager().SetTimer(ArmorRegenTimerHandle,this, | ||
&UHealthComponent::RegenArmorTimer,RegenAfterDamagedDelay, false); | ||
} else if (RegenHealth) | ||
{ | ||
GetWorld()->GetTimerManager().SetTimer(HealthRegenTimerHandle,this, | ||
&UHealthComponent::RegenHealthTimer,RegenAfterDamagedDelay, false); | ||
} | ||
} | ||
} | ||
|
||
void UHealthComponent::AddHealthAndArmor(float HealthAmount, float ArmorAmount) | ||
{ | ||
Health = FMath::Clamp(Health + HealthAmount,0,MaxHealth); | ||
Armor = FMath::Clamp(Armor + ArmorAmount,0,MaxArmor); | ||
} | ||
|
||
void UHealthComponent::RegenArmorTimer() | ||
{ | ||
if (RegenArmor) | ||
{ | ||
GetWorld()->GetTimerManager().SetTimer(ArmorRegenTimerHandle, this, | ||
&UHealthComponent::RegenerateArmor, ArmorRegenSpeed,true); | ||
} | ||
|
||
} | ||
|
||
void UHealthComponent::RegenHealthTimer() | ||
{ | ||
if (RegenHealth) | ||
{ | ||
GetWorld()->GetTimerManager().SetTimer(HealthRegenTimerHandle,this, | ||
&UHealthComponent::RegenerateHealth, HealthRegenSpeed,true); | ||
} | ||
|
||
} | ||
|
||
void UHealthComponent::RegenerateArmor() | ||
{ | ||
if (RegenArmor && Armor < MaxArmor) | ||
{ | ||
Armor = FMath::Clamp(Armor + 1.0f, 0.0f,MaxArmor); | ||
} | ||
} | ||
|
||
void UHealthComponent::RegenerateHealth() | ||
{ | ||
if (RegenHealth && Health < MaxHealth) | ||
{ | ||
Health = FMath::Clamp(Health + 1.0f,0.0f,MaxHealth); | ||
} | ||
} |
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,20 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "HealthSystem.h" | ||
|
||
#define LOCTEXT_NAMESPACE "FHealthSystemModule" | ||
|
||
void FHealthSystemModule::StartupModule() | ||
{ | ||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module | ||
} | ||
|
||
void FHealthSystemModule::ShutdownModule() | ||
{ | ||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, | ||
// we call this function before unloading the module. | ||
} | ||
|
||
#undef LOCTEXT_NAMESPACE | ||
|
||
IMPLEMENT_MODULE(FHealthSystemModule, HealthSystem) |
Oops, something went wrong.