角色属性配置化
This commit is contained in:
		| @ -1,52 +0,0 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
|  | ||||
| #include "BusyActorManagerSubSystem.h" | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "Subsystems/SubsystemBlueprintLibrary.h" | ||||
|  | ||||
| void UBusyActorManagerSubSystem::Initialize(FSubsystemCollectionBase& Collection){ | ||||
| 	Super::Initialize(Collection); | ||||
| 	ReceiveSubSystemInitialize(); | ||||
| } | ||||
|  | ||||
| void UBusyActorManagerSubSystem::OnWorldBeginPlay(UWorld& InWorld) { | ||||
| 	Super::OnWorldBeginPlay(InWorld); | ||||
| 	ReceiveWorldBeginPlay(); | ||||
| } | ||||
|  | ||||
| void UBusyActorManagerSubSystem::Deinitialize(){ | ||||
| 	Super::Deinitialize(); | ||||
| } | ||||
|  | ||||
| FString UBusyActorManagerSubSystem::GetLuaFilePath_Implementation() const{ | ||||
| 	return TEXT("GamePlay/Level/BusyActorManagerSubSystem"); | ||||
| } | ||||
|  | ||||
| bool UBusyActorManagerSubSystem::GetLevelBaseConfig(FBusyLevelBaseConfig& config){ | ||||
| 	FBusyLevelBaseConfig* Config; | ||||
| 	UDataTable *DataTable = UBusyGameplayLibrary::GetGameDataTable("LevelBaseConfig"); | ||||
| 	if (!DataTable) return false; | ||||
|  | ||||
| 	Config = DataTable->FindRow<FBusyLevelBaseConfig>( | ||||
| 		TEXT("Default"), | ||||
| 		TEXT("UBusyActorManagerSubSystem::GetLevelBaseConfig"), | ||||
| 		true | ||||
| 	); | ||||
|  | ||||
| 	if (!Config) return false; | ||||
| 	config = *Config; | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| UWorld* UBusyActorManagerSubSystem::K2_GetWorld(){ | ||||
| 	return this->GetWorld(); | ||||
| } | ||||
|  | ||||
| UBusyActorManagerSubSystem* UBusyActorManagerSubSystem::Get(UObject* WorldContextObject){ | ||||
| 	UWorldSubsystem *SubSystem = USubsystemBlueprintLibrary::GetWorldSubsystem( | ||||
| 		WorldContextObject, | ||||
| 		UBusyActorManagerSubSystem::StaticClass() | ||||
| 	); | ||||
| 	return Cast<UBusyActorManagerSubSystem>(SubSystem); | ||||
| } | ||||
| @ -1,7 +1,7 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings.
 | ||||
| 
 | ||||
| 
 | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
| #include "BusyDataAsset.h" | ||||
| 
 | ||||
| static inline const UBusyDataAsset* GetGameAsset() { | ||||
| @ -51,10 +51,6 @@ UWorld* UBusyGameplayLibrary::K2_GetWorld(const UObject* UObj){ | ||||
| 	return UObj->GetWorld(); | ||||
| } | ||||
| 
 | ||||
| bool UBusyGameplayLibrary::GetLevelBaseConfig(const FName& RowName, FBusyLevelBaseConfig& RowData){ | ||||
| 	return GetTableConfig<FBusyLevelBaseConfig>(TEXT("LevelBaseConfig"), RowName, RowData); | ||||
| } | ||||
| 
 | ||||
| bool UBusyGameplayLibrary::GetLevelItemConfig(const FName& RowName, FBusyLevelItemConfig& RowData){ | ||||
| 	return GetTableConfig<FBusyLevelItemConfig>(TEXT("LevelItems"), RowName, RowData); | ||||
| } | ||||
| @ -4,6 +4,8 @@ | ||||
| #include "SpineSkeletonAnimationComponent.h" | ||||
| #include "Level/Actor/Components/BusyPawnMovement.h" | ||||
|  | ||||
| DEFINE_LOG_CATEGORY(LogBusyPawn) | ||||
|  | ||||
|  | ||||
| ABusyPawnBase::ABusyPawnBase() | ||||
| { | ||||
| @ -42,7 +44,7 @@ float ABusyPawnBase::GetSpeed_Implementation()const | ||||
| 	{ | ||||
| 		return Attribute->GetMoveSpeed(); | ||||
| 	} | ||||
| 	return 200; | ||||
| 	return 0.f; | ||||
| } | ||||
|  | ||||
| void ABusyPawnBase::InitMoveSpeed(const float MoveSpeed)const | ||||
|  | ||||
| @ -1,7 +1,11 @@ | ||||
| #include "Level/Actor/BusyPlayerRole.h" | ||||
| #include "Camera/CameraComponent.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
| #include "Animation/AnimAttributes.h" | ||||
| #include "Tables/BusyPawnConfig.h" | ||||
| #include "GameFramework/SpringArmComponent.h" | ||||
|  | ||||
|  | ||||
| ABusyPlayerRole::ABusyPlayerRole() | ||||
| { | ||||
| 	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent")); | ||||
| @ -27,7 +31,34 @@ void ABusyPlayerRole::BeginPlay() | ||||
| 	InitRoleAttributes(); | ||||
| } | ||||
|  | ||||
| void ABusyPlayerRole::InitRoleAttributes() | ||||
| bool ABusyPlayerRole::InitRoleAttributes() | ||||
| { | ||||
| 	if (!PawnName.IsValid()) return false; | ||||
| 	const UDataTable* ConfigTable = UBusyGameplayLibrary::GetGameDataTable(TEXT("LevelRoleBaseConfig")); | ||||
| 	if (!ConfigTable) | ||||
| 	{ | ||||
| 		UE_LOG(LogBusyPawn, Log, TEXT("ABusyPlayerRole::InitRoleAttributes Can't find config table: LevelRoleBaseConfig")) | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	const FBusyRoleBaseConfig* Result = ConfigTable->FindRow<FBusyRoleBaseConfig>( | ||||
| 		PawnName, | ||||
| 		*FString::Printf(TEXT("ABusyPlayerRole::InitRoleAttributes, PawnName: %ls"), *PawnName.ToString()) | ||||
| 	); | ||||
| 	if (Result) | ||||
| 	{ | ||||
| 		UBusyPlayerRoleAttributeSet* RoleAttributes = Cast<UBusyPlayerRoleAttributeSet>(Attribute); | ||||
| 		RoleAttributes->InitHealth(Result->Health); | ||||
| 		RoleAttributes->InitMaxHealth(Result->Health); | ||||
| 		RoleAttributes->InitMoveSpeed(Result->MoveSpeed); | ||||
| 		 | ||||
| 		RoleAttributes->InitHunger(Result->Hunger); | ||||
| 		RoleAttributes->InitMaxHunger(Result->Hunger); | ||||
| 		RoleAttributes->InitHungerConsume(Result->HungerConsume); | ||||
|  | ||||
| 		RoleAttributes->InitDamage(Result->Damage); | ||||
| 		RoleAttributes->InitDefense(Result->Defense); | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| @ -4,7 +4,7 @@ | ||||
| #include "Level/BusyLevelItem.h" | ||||
| #include "Components/CapsuleComponent.h" | ||||
| #include "Components/WidgetComponent.h" | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
|  | ||||
| ABusyLevelItem::ABusyLevelItem(): CurrentItemID("100001") { | ||||
| 	LuaFilePath = TEXT("GamePlay.LevelItem.LevelItem"); | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| #include "Components/SceneComponent.h" | ||||
| #include "PaperFlipbook.h" | ||||
| #include "PaperFlipbookComponent.h" | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
|  | ||||
|  | ||||
| ALevelItemReward::ALevelItemReward(){ | ||||
|  | ||||
| @ -9,7 +9,7 @@ | ||||
| #include "PaperFlipbookComponent.h" | ||||
| #include "Role/BusyRoleMovement.h" | ||||
| #include "Role/RoleAnimation.h" | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
| #include "Components/InventoryComponent.h" | ||||
| #include "Core/PW_AbilitySystemComponent.h" | ||||
| #include "EnhancedInputComponent.h" | ||||
|  | ||||
| @ -3,7 +3,7 @@ | ||||
|  | ||||
| #include "Role/RoleAnimation.h" | ||||
| #include "Role/BusyRole.h" | ||||
| #include "BusyGamePlayLibrary.h" | ||||
| #include "BusyGameplayLibrary.h" | ||||
|  | ||||
| DEFINE_LOG_CATEGORY(LogRoleAnimation); | ||||
|  | ||||
|  | ||||
| @ -1,67 +0,0 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Engine/Datatable.h" | ||||
| #include "LuaOverriderInterface.h" | ||||
| #include "Subsystems/WorldSubsystem.h" | ||||
| #include "Level/BusyLevelItem.h" | ||||
| #include "BusyActorManagerSubSystem.generated.h" | ||||
|  | ||||
|  | ||||
| USTRUCT(BlueprintType) | ||||
| struct FBusyLevelBaseConfig : public FTableRowBase { | ||||
| 	GENERATED_BODY() | ||||
| 	/* 第一个篝火的位置 */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "初始篝火位置") | ||||
| 	FVector2D FirstBonfirePosition; | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "每次Tick的时间(MS)") | ||||
| 	int TickInterval; | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "一个物品生成周期包含的Tick次数") | ||||
| 	int Period; | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName ="关卡中存在的物品配置") | ||||
| 	TMap<int32, FBusyLevelItemGenerateConfig> LevelItemIds; | ||||
| }; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  */ | ||||
| UCLASS() | ||||
| class BUSYRABBIT_API UBusyActorManagerSubSystem : public UWorldSubsystem, public ILuaOverriderInterface | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
| 	// 初始化(关卡加载时调用) | ||||
| 	virtual void Initialize(FSubsystemCollectionBase& Collection) override; | ||||
|  | ||||
| 	virtual void OnWorldBeginPlay(UWorld& InWorld)override; | ||||
|  | ||||
| 	// 销毁(关卡卸载时调用) | ||||
| 	virtual void Deinitialize() override; | ||||
|  | ||||
| 	virtual FString GetLuaFilePath_Implementation() const override; | ||||
|  | ||||
|  | ||||
| public:  // 需要蓝图实现接口 | ||||
| 	UFUNCTION(BlueprintImplementableEvent) | ||||
| 	void ReceiveSubSystemInitialize(); | ||||
| 	 | ||||
| 	UFUNCTION(BlueprintImplementableEvent) | ||||
| 	void ReceiveWorldBeginPlay(); | ||||
|  | ||||
| public: | ||||
| 	UFUNCTION(BlueprintPure) | ||||
| 	bool GetLevelBaseConfig(FBusyLevelBaseConfig& config); | ||||
|  | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	UWorld* K2_GetWorld(); | ||||
|  | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	static UBusyActorManagerSubSystem* Get(UObject* WorldContextObject); | ||||
| }; | ||||
| @ -3,16 +3,13 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| #include "slua.h" | ||||
| #include "Role/BusyRole.h" | ||||
| #include "Engine/World.h" | ||||
| #include "Level/BusyLevelItem.h" | ||||
| #include "Engine/DataTable.h" | ||||
| #include "BusyActorManagerSubSystem.h" | ||||
| #include "Kismet/BlueprintFunctionLibrary.h" | ||||
| #include "GameAsset/BusyItem.h" | ||||
| #include "LuaBlueprintLibrary.h" | ||||
| #include "BusyGamePlayLibrary.generated.h" | ||||
| #include "BusyGameplayLibrary.generated.h" | ||||
| 
 | ||||
| /**
 | ||||
|  *  | ||||
| @ -34,10 +31,7 @@ public: | ||||
| 
 | ||||
| 	UFUNCTION(BlueprintPure) | ||||
| 	static UWorld* K2_GetWorld(const UObject* UObj); | ||||
| 
 | ||||
| 	UFUNCTION(BlueprintPure) | ||||
| 	static bool GetLevelBaseConfig(const FName& RowName, FBusyLevelBaseConfig& RowData); | ||||
| 
 | ||||
| 	 | ||||
| 	UFUNCTION(BlueprintPure) | ||||
| 	static bool GetLevelItemConfig(const FName& RowName, FBusyLevelItemConfig& RowData); | ||||
| 
 | ||||
| @ -18,6 +18,8 @@ GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \ | ||||
| GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \ | ||||
| GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName) | ||||
|  | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogBusyPawn, Log, All); | ||||
|  | ||||
|  | ||||
| UCLASS(Blueprintable, BlueprintType) | ||||
| class UBusyPawnAttributeSet : public UAttributeSet | ||||
| @ -32,12 +34,18 @@ public: | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData MaxHealth; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPawnAttributeSet, MaxHealth); | ||||
| 	 | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData MoveSpeed; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPawnAttributeSet, MoveSpeed); | ||||
| 	 | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData Damage; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPawnAttributeSet, Damage); | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData Defense; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPawnAttributeSet, Defense); | ||||
| }; | ||||
|  | ||||
| #undef MY_ATTRIBUTE_ACCESSORS | ||||
| @ -54,6 +62,9 @@ public: | ||||
|  | ||||
| 	virtual float GetSpeed_Implementation()const override; | ||||
|  | ||||
| public: | ||||
| 	virtual bool InitRoleAttributes() { return false; } | ||||
|  | ||||
| protected: | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	void InitMoveSpeed(const float MoveSpeed)const; | ||||
| @ -94,6 +105,9 @@ public: | ||||
| 	TObjectPtr<UBusyPawnMovement> MovementComponent; | ||||
| 	/*-------------------------------------------------------------------*/ | ||||
|  | ||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, DisplayName="角色名称") | ||||
| 	FName PawnName; | ||||
|  | ||||
|  | ||||
| protected: | ||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) | ||||
|  | ||||
| @ -18,12 +18,18 @@ class UBusyPlayerRoleAttributeSet: public UBusyPawnAttributeSet | ||||
| public: | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="饱食度") | ||||
| 	FGameplayAttributeData Hunger; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPlayerRoleAttributeSet, Hunger); | ||||
| 	 | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="最大饱食度") | ||||
| 	FGameplayAttributeData MaxHunger; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPlayerRoleAttributeSet, MaxHunger); | ||||
| 	 | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="饱食度消耗速度") | ||||
| 	FGameplayAttributeData HungerConsume; | ||||
| 	MY_ATTRIBUTE_ACCESSORS(UBusyPlayerRoleAttributeSet, HungerConsume); | ||||
| 	 | ||||
| }; | ||||
|  | ||||
| #undef MY_ATTRIBUTE_ACCESSORS | ||||
| @ -39,9 +45,9 @@ public: | ||||
|  | ||||
| 	virtual void BeginPlay() override; | ||||
|  | ||||
| protected: | ||||
| 	void InitRoleAttributes(); | ||||
| 	 | ||||
|  | ||||
| 	virtual bool InitRoleAttributes()override; | ||||
|  | ||||
|  | ||||
| protected: | ||||
| 	/*--------------------相机相关--------------------------*/ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user