diff --git a/.gitattributes b/.gitattributes index 3e8f1d6..288a003 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ Content/** filter=lfs diff=lfs merge=lfs -text +Binaries/** filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/.gitignore b/.gitignore index 34d9a49..a7cf50f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -Binaries +# Binaries DerivedDataCache Intermediate Saved @@ -9,9 +9,11 @@ Saved *.opendb *.sdf *.sln +*.sln.DotSettings.user *.suo *.xcodeproj *.xcworkspace .idea .vsconfig +*.pdb \ No newline at end of file diff --git a/Binaries/Win64/FirstPersonDemoEditor.target b/Binaries/Win64/FirstPersonDemoEditor.target new file mode 100644 index 0000000..2fd86cb --- /dev/null +++ b/Binaries/Win64/FirstPersonDemoEditor.target @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bd92c0fe4eb6f811d53b1d70c09e8972906f6c038755c4c566b1d3f759e826e +size 917812 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.dll b/Binaries/Win64/UnrealEditor-FirstPersonDemo.dll new file mode 100644 index 0000000..728dcd5 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33a48f294e712f45baaa582184875ac3b8e08ebcf03034e7ed98e63d68fa6cae +size 647680 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exe new file mode 100644 index 0000000..dd50ec9 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c49ee102c8824239d6247a8af26cdd6efb6db3762b0269b803f38ccff2f343e3 +size 433664 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exp new file mode 100644 index 0000000..455502a --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b34f49d84e7d0eced1fb2fc3189d703e159b3477faa1a816769077c00dd9b54 +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.lib new file mode 100644 index 0000000..bdedbe0 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65d05c8ff78251c0e558ace42a490a8739ffda078670ab9791e6624ecbcd083b +size 2198 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exe new file mode 100644 index 0000000..c253e57 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d2dae251f58090320bac5e533858b7deafd1940ff9de22406f026f2d654f312 +size 407040 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exp new file mode 100644 index 0000000..34221be --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5f214fb77a893edf06863bd5e1d673f3501202867f61683235340c206222429 +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.lib new file mode 100644 index 0000000..6ac663f --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e8fcc62f519252af226853c0d6e1415c70d03d5205da29487f8d6e9c6f8ee81 +size 2198 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exe new file mode 100644 index 0000000..b7268d6 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4cc189f171bcbf5231fc205847bd05084fde8eb21884cbe8e0938dd87651f3d +size 415744 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exp new file mode 100644 index 0000000..ff96c83 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1ae119320ee6a2e71f5cdb573023850d93c7476d57bffadeb28baad5f2f5089 +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.lib new file mode 100644 index 0000000..3edd59e --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a119db2011e3ff75411436af176c08dfe4edf52f532fdc45748565a0c16e78d1 +size 2198 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exe new file mode 100644 index 0000000..c807e12 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6a78e85e4ab8df4a6547e3b1b6f8962380a27d55493575ea5eddc5dd3f64a0a +size 431616 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exp new file mode 100644 index 0000000..1ce6364 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eabd8b99e94f2b92c7622b03a7925a664c19a033c4356ba30a05d9d03942c7ca +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.lib new file mode 100644 index 0000000..7172da0 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:364cb2595bb8f05c4e3196979c04b081995ba4939d4ae29428f566392770fc11 +size 2198 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exe new file mode 100644 index 0000000..a9d673a --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52b6268f93a8c0c65531c211fddd9b1c412f579d5ba7a531494fb416adfa0644 +size 431616 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exp new file mode 100644 index 0000000..06ec415 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:476dbdd2eddd8b0fbf06e0dd907f59258aa36ff049138d71325915a8c885b1f6 +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.lib new file mode 100644 index 0000000..f62206b --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f5c84f0793492b0a0bf34287ab1c62c79ab20da378da7200dc7328805afd903 +size 2198 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exe b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exe new file mode 100644 index 0000000..7a1f952 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8199b82f4f207bd78e441599a2a625d04941dc6cac1c1e5d76f93a6e05b8d084 +size 441344 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exp b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exp new file mode 100644 index 0000000..0b46cd0 --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75a301963b2f706500676bfa68f1b9dfc7612d02730cfd9f6eb2d165988b13e8 +size 798 diff --git a/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.lib b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.lib new file mode 100644 index 0000000..e1024fc --- /dev/null +++ b/Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52ee888e1d98787c93e73a35ce80ef96dfe09e0ff5efe522e37c18db68a49af6 +size 2198 diff --git a/Binaries/Win64/UnrealEditor.modules b/Binaries/Win64/UnrealEditor.modules new file mode 100644 index 0000000..85ba684 --- /dev/null +++ b/Binaries/Win64/UnrealEditor.modules @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea434399f34d0e7b06035638de1ecc90f9ed534751805e46b437572f547925f1 +size 108 diff --git a/README.md b/README.md index 497c754..3291d16 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # FirstPersonDemo Developed with Unreal Engine 5 + +asdfasdf + +sdfsdfdsf + +dsfsdfd +sdds +Ciallo diff --git a/Source/FirstPersonDemo/Surviver_FPS/.gitignore b/Source/FirstPersonDemo/Surviver_FPS/.gitignore new file mode 100644 index 0000000..b543368 --- /dev/null +++ b/Source/FirstPersonDemo/Surviver_FPS/.gitignore @@ -0,0 +1 @@ +html/* \ No newline at end of file diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/DamageableInterface.h b/Source/FirstPersonDemo/Surviver_FPS/Battle/DamageableInterface.h index 20da634..e08585c 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/DamageableInterface.h +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/DamageableInterface.h @@ -14,7 +14,7 @@ class UDamageableInterface : public UInterface { /** * @class IDamageableInterface - * @brief 伤害组件 + * @brief 伤害接口 * @ingroup Battle */ class FIRSTPERSONDEMO_API IDamageableInterface { diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp b/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp index 8436cd3..736f063 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp @@ -2,28 +2,41 @@ #include "Surviver_FPS/Battle/EnemyBase.h" +#include "HealthComponent.h" +#include "GameFramework/Actor.h" -// Sets default values +/** + * @brief AEnemyBase的构造函数。 + */ AEnemyBase::AEnemyBase() { - // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // 允许该Pawn每帧调用Tick() PrimaryActorTick.bCanEverTick = true; + + // 创建并附加生命组件 + HealthComponent = CreateDefaultSubobject(TEXT("HealthComponent")); } -// Called when the game starts or when spawned void AEnemyBase::BeginPlay() { Super::BeginPlay(); } -// Called every frame void AEnemyBase::Tick(float DeltaTime) { Super::Tick(DeltaTime); } -// Called to bind functionality to input void AEnemyBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); } +/** + * @brief 接收伤害的实现。 + * @param DamageAmount 伤害量。 + * @param InstigatorActor 造成伤害的Actor。 + */ void AEnemyBase::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) { - return; + if (HealthComponent) + { + // 通过生命组件处理伤害 + HealthComponent->HandleDamage(DamageAmount); + } } diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h b/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h index 0c39dfc..f366fdd 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h @@ -7,36 +7,41 @@ #include "GameFramework/Pawn.h" #include "EnemyBase.generated.h" +class UHealthComponent; /** * @class AEnemyBase - * @brief 敌人基类 + * @brief 敌人基类,实现了可受伤害接口。 * @ingroup Battle - * @todo 实现TakeDamage接口,挂HealthComponent组件 */ - UCLASS() class FIRSTPERSONDEMO_API AEnemyBase : public APawn, public IDamageableInterface { GENERATED_BODY() public: - // Sets default values for this pawn's properties + /** + * @brief 构造函数,设置Pawn的默认属性。 + */ AEnemyBase(); protected: - // Called when the game starts or when spawned + /** + * @brief 管理敌人生命值的组件。 + */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components") + UHealthComponent* HealthComponent; + virtual void BeginPlay() override; public: - // Called every frame virtual void Tick(float DeltaTime) override; - - // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; /** - * @brief 敌人受伤函数 - * @param DamageAmount 伤害量 + * @brief 接收伤害的接口实现。 + * @param DamageAmount 伤害量。 + * @param InstigatorActor 造成伤害的Actor。 */ virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override; }; diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.cpp b/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.cpp index edff659..a84916a 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.cpp +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.cpp @@ -2,36 +2,66 @@ #include "HealthComponent.h" - +#include "GameFramework/Actor.h" +#include "Net/UnrealNetwork.h" #include "Kismet/GameplayStatics.h" +/** + * @brief 定义需要网络同步的属性。 + * @param OutLifetimeProps 存储同步属性的数组。 + */ +void UHealthComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { + Super::GetLifetimeReplicatedProps(OutLifetimeProps); -// 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; - - // ... + DOREPLIFETIME(UHealthComponent, CurrentHealth); } +/** + * @brief UHealthComponent的构造函数。 + */ +UHealthComponent::UHealthComponent() { + // 关闭每帧Tick以提高性能 + PrimaryComponentTick.bCanEverTick = false; + // 默认启用网络复制 + SetIsReplicatedByDefault(true); +} -// Called when the game starts +/** + * @brief 组件开始运行时调用。 + */ void UHealthComponent::BeginPlay() { Super::BeginPlay(); + // 初始化当前生命值为最大生命值 + CurrentHealth = MaxHealth; +} - // ... +/** + * @brief 当CurrentHealth属性被复制时在客户端上调用。 + */ +void UHealthComponent::OnRep_CurrentHealth() { + // 在客户端上,当CurrentHealth被复制时调用 } -// Called every frame void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // ... } - +/** + * @brief 供外部调用的伤害处理函数。 + * @param DamageAmount 伤害量。 + */ void UHealthComponent::HandleDamage(float DamageAmount) { - + if (DamageAmount <= 0.0f) { + return; + } + // 仅在服务器上处理伤害逻辑 + if (GetOwner()->HasAuthority()) { + CurrentHealth = FMath::Clamp(CurrentHealth - DamageAmount, 0.0f, MaxHealth); + if (CurrentHealth <= 0.0f) { + OnDeath.Broadcast(); + } + } } diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h b/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h index f7b8357..cb60d0c 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h @@ -4,8 +4,14 @@ #include "CoreMinimal.h" #include "Components/ActorComponent.h" +#include "Net/UnrealNetwork.h" #include "HealthComponent.generated.h" +/** + * @brief 当生命值降为0时调用的多播委托。 + */ +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnDeath); + /** * @class UHealthComponent * @brief 生命组件 @@ -17,30 +23,46 @@ class FIRSTPERSONDEMO_API UHealthComponent : public UActorComponent { GENERATED_BODY() public: - // Sets default values for this component's properties UHealthComponent(); + /** + * @brief 死亡时广播的多播委托。可以在蓝图中绑定事件。 + */ + UPROPERTY(BlueprintAssignable, Category = "Health") + FOnDeath OnDeath; + protected: - // 最大生命值 + /** + * @brief 角色的最大生命值。 + */ UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health") float MaxHealth = 100.0f; - // 当前生命值 - UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health") + /** + * @brief 角色的当前生命值。此属性会从服务器复制到客户端。 + */ + UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_CurrentHealth, Category="Health") float CurrentHealth; - // Called when the game starts - virtual void BeginPlay() override; + /** + * @brief 当CurrentHealth属性被复制时在客户端上调用的函数。 + * @todo 处理客户端上的血条UI更新等逻辑。 + */ + UFUNCTION() + void OnRep_CurrentHealth(); + /** + * @brief 游戏开始时调用,用于初始化组件。 + */ + virtual void BeginPlay() override; + public: - // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; /** - * @brief 处理伤害 - * @param DamageAmount 伤害量 - * @todo 实现血量计算,处理死亡逻辑 + * @brief 外部调用以处理伤害的函数。 + * @param DamageAmount 伤害量。 */ UFUNCTION(BlueprintCallable, Category="Health") void HandleDamage(float DamageAmount); diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp b/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp index 9730a63..6119796 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp @@ -2,30 +2,62 @@ #include "SuriverPlayer.h" +#include "HealthComponent.h" +#include "GameFramework/Actor.h" - -// Sets default values +/** + * @brief ASuriverPlayer的构造函数。 + */ ASuriverPlayer::ASuriverPlayer() { - // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // 允许该角色每帧调用Tick() PrimaryActorTick.bCanEverTick = true; + + // 创建并附加生命组件 + HealthComponent = CreateDefaultSubobject(TEXT("HealthComponent")); } -// Called when the game starts or when spawned +/** + * @brief 游戏开始或角色生成时调用。 + */ void ASuriverPlayer::BeginPlay() { Super::BeginPlay(); - + if (HealthComponent) { + HealthComponent->OnDeath.AddDynamic(this, &ASuriverPlayer::OnPlayerDied); + } } -// Called every frame +/** + * @brief 每帧调用。 + * @param DeltaTime 帧间隔时间。 + */ void ASuriverPlayer::Tick(float DeltaTime) { Super::Tick(DeltaTime); } -// Called to bind functionality to input +/** + * @brief 绑定输入功能。 + * @param PlayerInputComponent 用于绑定输入的组件。 + */ void ASuriverPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); } +/** + * @brief 接收伤害的实现。 + * @param DamageAmount 伤害量。 + * @param InstigatorActor 造成伤害的Actor。 + */ void ASuriverPlayer::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) { - + if (HealthComponent) { + // 通过生命组件处理伤害 + HealthComponent->HandleDamage(DamageAmount); + } +} + +/** + * @brief 当玩家死亡时调用,打印日志。 + * @todo 通知 GameMode 玩家已死亡,处理结算逻辑 + */ +void ASuriverPlayer::OnPlayerDied() { + UE_LOG(LogTemp, Warning, TEXT("你死了")); } diff --git a/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h b/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h index c1cd6db..28be90f 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h +++ b/Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h @@ -7,31 +7,48 @@ #include "GameFramework/Character.h" #include "SuriverPlayer.generated.h" +class UHealthComponent; + /** * @class ASuriverPlayer - * @brief 玩家基类 + * @brief 玩家角色基类,实现了可受伤害接口。 * @ingroup Battle - * @todo 实现TakeDamage接口,挂HealthComponent组件 */ - UCLASS() class FIRSTPERSONDEMO_API ASuriverPlayer : public ACharacter, public IDamageableInterface { GENERATED_BODY() public: - // Sets default values for this character's properties + /** + * @brief 构造函数,设置角色的默认属性。 + */ ASuriverPlayer(); protected: - // Called when the game starts or when spawned + /** + * @brief 管理角色生命值的组件。 + */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components") + UHealthComponent* HealthComponent; + virtual void BeginPlay() override; -public: - // Called every frame - virtual void Tick(float DeltaTime) override; + /** + * @brief 当玩家死亡时调用。 + * @todo 添加死亡处理逻辑,如UI弹窗等 + */ + UFUNCTION() + void OnPlayerDied(); - // Called to bind functionality to input +public: + virtual void Tick(float DeltaTime) override; + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + /** + * @brief 接收伤害的接口实现。 + * @param DamageAmount 伤害量。 + * @param InstigatorActor 造成伤害的Actor。 + */ virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override; }; diff --git a/Source/FirstPersonDemo/Surviver_FPS/Documentation.h b/Source/FirstPersonDemo/Surviver_FPS/Documentation.h index 52cf56f..0cf01b0 100644 --- a/Source/FirstPersonDemo/Surviver_FPS/Documentation.h +++ b/Source/FirstPersonDemo/Surviver_FPS/Documentation.h @@ -2,12 +2,12 @@ /** * @defgroup GameCore 核心玩法系统 - * 包含游戏模式、角色和控制器等基础类。 + * 包含游戏模式、控制器等基础类。 */ /** * @defgroup Battle 战斗系统 - * 包含所有枪械、投射物和拾取物。 + * 包含玩家角色、敌人、枪械、投射物和拾取物。 */ /**