Files
BladeSmith/Source/BladeSmith/BladeSmithWeaponComponent.h
T
2025-08-06 23:47:59 +08:00

76 lines
2.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/SkeletalMeshComponent.h"
#include "BladeSmithWeaponComponent.generated.h"
class ABladeSmithCharacter;
class AIronBlock;
UCLASS(Blueprintable, BlueprintType, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BLADESMITH_API UBladeSmithWeaponComponent : public USkeletalMeshComponent
{
GENERATED_BODY()
public:
/** 锤击音效 */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)
USoundBase* HammerHitSound;
/** 锤击动画 */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
UAnimMontage* HammerSwingAnimation;
/** 锤子头部偏移 */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)
FVector HammerHeadOffset;
/** 锤击力度 */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)
float HammerForce = 1000.0f;
/** 锤击范围 */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)
float HammerRange = 200.0f;
/** 输入映射上下文 */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputMappingContext* HammerMappingContext;
/** 锤击输入动作 */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputAction* HammerAction;
/** 设置默认值 */
UBladeSmithWeaponComponent();
/** 将锤子附加到角色 */
UFUNCTION(BlueprintCallable, Category="Hammer")
bool AttachHammer(ABladeSmithCharacter* TargetCharacter);
/** 执行锤击 */
UFUNCTION(BlueprintCallable, Category="Hammer")
void SwingHammer();
/** 获取锤子头部位置 */
UFUNCTION(BlueprintCallable, Category="Hammer")
FVector GetHammerHeadLocation() const;
protected:
/** 组件结束游戏时的处理 */
UFUNCTION()
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
private:
/** 持有此锤子的角色 */
ABladeSmithCharacter* Character;
/** 执行锤击检测 */
void PerformHammerHit();
/** 处理与铁块的碰撞 */
void HandleIronBlockHit(AIronBlock* IronBlock, const FHitResult& HitResult);
};