diff --git a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.dll b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.dll index d7dd8e9..2cf5bdb 100644 Binary files a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.dll and b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.dll differ diff --git a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFishEditor.dll b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFishEditor.dll index 1ac9c1e..262cee0 100644 Binary files a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFishEditor.dll and b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFishEditor.dll differ diff --git a/ProjectFish/Config/DefaultGame.ini b/ProjectFish/Config/DefaultGame.ini index d51ea61..cb20751 100644 --- a/ProjectFish/Config/DefaultGame.ini +++ b/ProjectFish/Config/DefaultGame.ini @@ -13,6 +13,7 @@ FixedCameraDistance=1500.0 +PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass="/Script/Engine.PrimaryAssetLabel",bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown)) +PrimaryAssetTypesToScan=(PrimaryAssetType="FishingRewardDataAsset",AssetBaseClass="/Script/ProjectFish.FishingRewardDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/FishReward")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook)) +PrimaryAssetTypesToScan=(PrimaryAssetType="ShapeAsset",AssetBaseClass="/Script/ProjectFish.ShapeAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook)) ++PrimaryAssetTypesToScan=(PrimaryAssetType="QuestAsset",AssetBaseClass="/Script/ProjectFish.QuestAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/Quest")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook)) bOnlyCookProductionAssets=False bShouldManagerDetermineTypeAndName=False bShouldGuessTypeAndNameInEditor=True diff --git a/ProjectFish/Content/DataAssets/Quest/Quest1_AutoAccept_CompleteByReward.uasset b/ProjectFish/Content/DataAssets/Quest/Quest1_AutoAccept_CompleteByReward.uasset new file mode 100644 index 0000000..d0b9974 Binary files /dev/null and b/ProjectFish/Content/DataAssets/Quest/Quest1_AutoAccept_CompleteByReward.uasset differ diff --git a/ProjectFish/Content/DataAssets/Quest/Quest2_TriggerByQuest1.uasset b/ProjectFish/Content/DataAssets/Quest/Quest2_TriggerByQuest1.uasset new file mode 100644 index 0000000..00f5d72 Binary files /dev/null and b/ProjectFish/Content/DataAssets/Quest/Quest2_TriggerByQuest1.uasset differ diff --git a/ProjectFish/Content/DataAssets/Quest/Quest3_CompleteByTargetPos.uasset b/ProjectFish/Content/DataAssets/Quest/Quest3_CompleteByTargetPos.uasset new file mode 100644 index 0000000..63d2dc9 Binary files /dev/null and b/ProjectFish/Content/DataAssets/Quest/Quest3_CompleteByTargetPos.uasset differ diff --git a/ProjectFish/Content/DataAssets/Quest/Quest4_CompleteByEnemy.uasset b/ProjectFish/Content/DataAssets/Quest/Quest4_CompleteByEnemy.uasset new file mode 100644 index 0000000..79da99c Binary files /dev/null and b/ProjectFish/Content/DataAssets/Quest/Quest4_CompleteByEnemy.uasset differ diff --git a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/GameInfoManager.cpp b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/GameInfoManager.cpp index c3f3b34..8f33a9e 100644 --- a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/GameInfoManager.cpp +++ b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/GameInfoManager.cpp @@ -48,13 +48,19 @@ bool UGameInfoManager::LoadGameInfo() PlayerInfo = Cast(UGameplayStatics::LoadGameFromSlot(SaveGameSlotName, 0)); // 加载任务数据 - if (PlayerInfo && GetGameInstance()) + if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem()) { - if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem()) + if (PlayerInfo && GetGameInstance()) { QuestManager->LoadFromSaveData(PlayerInfo->QuestSaveData); } + else + { + TArray SaveData; + QuestManager->LoadFromSaveData(SaveData); + } } + return true; } diff --git a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.cpp b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.cpp index 3c6e4d0..897ccc7 100644 --- a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.cpp +++ b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.cpp @@ -2,6 +2,8 @@ #include "QuestManager.h" +#include "AssetRegistry/AssetRegistryModule.h" +#include "Engine/AssetManager.h" #include "ProjectFish/DataAsset/QuestAsset.h" #include "ProjectFish/Quest/QuestTypes.h" @@ -18,6 +20,30 @@ void UQuestManager::Deinitialize() CompletedQuestIDs.Empty(); } +void UQuestManager::LoadAllQuests() +{ + if (QuestAssets.Num() == 0) + { + // 获得所有任务资源id + TArray QuestAssetIds; + UAssetManager::Get().GetPrimaryAssetIdList(TEXT("QuestAsset"), QuestAssetIds); + + // 异步加载所有任务资产 + TSharedPtr LoadHandle = UAssetManager::Get().LoadPrimaryAssets(QuestAssetIds); + if (LoadHandle.IsValid()) + { + LoadHandle->WaitUntilComplete(); + TArray Assets; + LoadHandle->GetLoadedAssets(Assets); // 获取所有加载成功的资源 + for (auto questAsset : Assets) + { + QuestAssets.Add(Cast(questAsset)); + } + } + } + +} + bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset) { if (!QuestAsset) @@ -250,10 +276,7 @@ void UQuestManager::LoadFromSaveData(const TArray& SaveData) // 清空现有数据 ActiveQuestsMap.Empty(); CompletedQuestIDs.Empty(); - - // 注意:这里需要从资产管理器或配置中加载QuestAsset - // 暂时留空,需要根据项目的资产加载方式实现 - // 建议在GameInstance或ProjectSettings中维护一个QuestAsset列表 + LoadAllQuests(); for (const FQuestSaveData& Data : SaveData) { @@ -261,9 +284,28 @@ void UQuestManager::LoadFromSaveData(const TArray& SaveData) { CompletedQuestIDs.Add(Data.QuestID); } - - // TODO: 从资产ID加载QuestAsset并恢复进度 - // 需要实现资产查找逻辑 + else if (Data.QuestState == EQuestState::InProgress) + { + for (auto questAsset: QuestAssets) + { + if (questAsset->QuestID == Data.QuestID) + { + FQuestRuntimeData RuntimeData = CreateRuntimeData(questAsset); + for (int i =0; i < RuntimeData.ObjectiveProgress.Num(); i++) + { + RuntimeData.ObjectiveProgress[i].CurrentProgress = Data.ObjectiveProgress[i]; + RuntimeData.ObjectiveProgress[i].bCompleted = Data.ObjectiveCompleted[i]; + } + + RuntimeData.State = EQuestState::InProgress; + ActiveQuestsMap.Add(questAsset->QuestID, RuntimeData); + + return; + } + } + + } + } } diff --git a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.h b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.h index ecdb17d..5e98b78 100644 --- a/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.h +++ b/ProjectFish/Source/ProjectFish/Gameplay/Subsystem/QuestManager.h @@ -48,6 +48,8 @@ public: virtual void Deinitialize() override; // ========== 任务操作 ========== + /** 加载本地所有任务 */ + void LoadAllQuests(); /** 接受任务 */ UFUNCTION(BlueprintCallable, Category = "Quest") @@ -128,4 +130,7 @@ private: /** 已完成的任务ID列表 */ UPROPERTY() TSet CompletedQuestIDs; + + UPROPERTY() + TArray QuestAssets; };