Compare commits
No commits in common. "111f68fa10366222b08ff517096445e2fc33b172" and "f07e298eb8858f779a7bd46a73da2e3058f441fc" have entirely different histories.
111f68fa10
...
f07e298eb8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -19,10 +19,8 @@ void UGameInfoManager::Initialize(FSubsystemCollectionBase& Collection)
|
||||
|
||||
void UGameInfoManager::SaveGameInfo()
|
||||
{
|
||||
if (!IsValid(PlayerInfo.Get()))
|
||||
if (IsValid(PlayerInfo.Get()))
|
||||
{
|
||||
PlayerInfo = NewObject<UPlayerInfoSaveGame>(this);
|
||||
}
|
||||
// 保存任务数据
|
||||
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
||||
{
|
||||
@ -37,6 +35,11 @@ void UGameInfoManager::SaveGameInfo()
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败, PlayerInfo为空"));
|
||||
}
|
||||
}
|
||||
|
||||
bool UGameInfoManager::LoadGameInfo()
|
||||
|
||||
@ -17,7 +17,7 @@ class PROJECTFISH_API UGameInfoManager : public UGameInstanceSubsystem
|
||||
public:
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SaveGameInfo();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
#include "QuestManager.h"
|
||||
|
||||
#include "GameInfoManager.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "Engine/AssetManager.h"
|
||||
#include "ProjectFish/DataAsset/QuestAsset.h"
|
||||
@ -45,19 +44,19 @@ void UQuestManager::LoadAllQuests()
|
||||
|
||||
}
|
||||
|
||||
void UQuestManager::CheckAcceptableQuests(bool bSaveGameInfo)
|
||||
void UQuestManager::CheckAcceptableQuests()
|
||||
{
|
||||
for (auto QuestAsset : QuestAssets)
|
||||
{
|
||||
if (!ActiveQuestsMap.Find(QuestAsset->QuestID) && !CompletedQuestIDs.Contains(QuestAsset->QuestID))
|
||||
{
|
||||
//任务不在当前已激活的任务 和 已完成的任务列表中
|
||||
AcceptQuest(QuestAsset, bSaveGameInfo);
|
||||
AcceptQuest(QuestAsset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo )
|
||||
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
||||
{
|
||||
if (!QuestAsset)
|
||||
{
|
||||
@ -84,13 +83,6 @@ bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo )
|
||||
// 触发事件
|
||||
OnQuestStateChanged.Broadcast(QuestAsset->QuestID);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Quest %s Accepted"), *QuestAsset->QuestName.ToString());
|
||||
|
||||
if (bSaveGameInfo)
|
||||
{
|
||||
//更新存档数据
|
||||
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -110,9 +102,6 @@ bool UQuestManager::FollowQuest(int32 QuestID, bool Follow)
|
||||
{
|
||||
FollowingQuestIDs.Remove(QuestID);
|
||||
}
|
||||
//更新存档数据
|
||||
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -142,12 +131,9 @@ bool UQuestManager::CompleteQuest(int32 QuestID)
|
||||
UE_LOG(LogTemp, Warning, TEXT("Quest id = %d Complete"), QuestID);
|
||||
// 从活动任务中移除
|
||||
ActiveQuestsMap.Remove(QuestID);
|
||||
//更新存档数据
|
||||
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||
|
||||
//检测是否有其他可接受的任务
|
||||
CheckAcceptableQuests();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -257,19 +243,6 @@ TArray<UQuestAsset*> UQuestManager::GetActiveQuests() const
|
||||
return Result;
|
||||
}
|
||||
|
||||
TArray<UQuestAsset*> UQuestManager::GetFollowingQuests() const
|
||||
{
|
||||
TArray<UQuestAsset*> Result;
|
||||
for (const TPair<int32, FQuestRuntimeData>& Pair : ActiveQuestsMap)
|
||||
{
|
||||
if (FollowingQuestIDs.Contains(Pair.Key))
|
||||
{
|
||||
Result.Add(Pair.Value.QuestAsset);
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
TArray<UQuestAsset*> UQuestManager::GetCompletedQuests() const
|
||||
{
|
||||
TArray<UQuestAsset*> Result;
|
||||
@ -294,17 +267,6 @@ bool UQuestManager::GetQuestProgress(int32 QuestID, TArray<FQuestProgress>& OutP
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UQuestManager::GetQuestRuntimeData(int32 QuestID, FQuestRuntimeData& OutData) const
|
||||
{
|
||||
const FQuestRuntimeData* RuntimeData = ActiveQuestsMap.Find(QuestID);
|
||||
if (RuntimeData)
|
||||
{
|
||||
OutData = *RuntimeData;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UQuestManager::CanAcceptQuest(UQuestAsset* QuestAsset) const
|
||||
{
|
||||
if (!QuestAsset)
|
||||
@ -377,7 +339,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
||||
if (questAsset->QuestID == Data.QuestID)
|
||||
{
|
||||
FQuestRuntimeData RuntimeData = CreateRuntimeData(questAsset);
|
||||
for (int i =0; i < Data.ObjectiveProgress.Num(); i++)
|
||||
for (int i =0; i < RuntimeData.ObjectiveProgress.Num(); i++)
|
||||
{
|
||||
RuntimeData.ObjectiveProgress[i].CurrentProgress = Data.ObjectiveProgress[i];
|
||||
RuntimeData.ObjectiveProgress[i].bCompleted = Data.ObjectiveCompleted[i];
|
||||
@ -398,7 +360,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
||||
|
||||
}
|
||||
|
||||
CheckAcceptableQuests(true);
|
||||
CheckAcceptableQuests();
|
||||
}
|
||||
|
||||
void UQuestManager::CheckQuestCompletion(int32 QuestID)
|
||||
|
||||
@ -53,11 +53,11 @@ public:
|
||||
|
||||
/** 检测所有可接收的任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
void CheckAcceptableQuests(bool bSaveGameInfo = false);
|
||||
void CheckAcceptableQuests();
|
||||
|
||||
/** 接受任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
bool AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo = false);
|
||||
bool AcceptQuest(UQuestAsset* QuestAsset);
|
||||
|
||||
/** 接受任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
@ -95,10 +95,6 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
TArray<UQuestAsset*> GetActiveQuests() const;
|
||||
|
||||
/** 获取所有追踪的任务 */
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
TArray<UQuestAsset*> GetFollowingQuests() const;
|
||||
|
||||
/** 获取所有已完成的任务 */
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
TArray<UQuestAsset*> GetCompletedQuests() const;
|
||||
@ -107,10 +103,6 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
bool GetQuestProgress(int32 QuestID, TArray<FQuestProgress>& OutProgress) const;
|
||||
|
||||
/** 获取任务进度 */
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
bool GetQuestRuntimeData(int32 QuestID, FQuestRuntimeData& OutData) const;
|
||||
|
||||
/** 检查是否可以接受任务(前置任务检查) */
|
||||
UFUNCTION(BlueprintPure, Category = "Quest")
|
||||
bool CanAcceptQuest(UQuestAsset* QuestAsset) const;
|
||||
@ -148,7 +140,7 @@ private:
|
||||
TMap<int32, FQuestRuntimeData> ActiveQuestsMap;
|
||||
|
||||
/** 正在追踪的任务列表 */
|
||||
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||
UPROPERTY()
|
||||
TSet<int32> FollowingQuestIDs;
|
||||
|
||||
/** 已完成的任务ID列表 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user