Compare commits
2 Commits
f07e298eb8
...
111f68fa10
| Author | SHA1 | Date | |
|---|---|---|---|
| 111f68fa10 | |||
| 1ccc1d8796 |
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,26 +19,23 @@ void UGameInfoManager::Initialize(FSubsystemCollectionBase& Collection)
|
||||
|
||||
void UGameInfoManager::SaveGameInfo()
|
||||
{
|
||||
if (IsValid(PlayerInfo.Get()))
|
||||
if (!IsValid(PlayerInfo.Get()))
|
||||
{
|
||||
// 保存任务数据
|
||||
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
||||
{
|
||||
PlayerInfo->QuestSaveData = QuestManager->GetQuestSaveData();
|
||||
}
|
||||
PlayerInfo = NewObject<UPlayerInfoSaveGame>(this);
|
||||
}
|
||||
// 保存任务数据
|
||||
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
||||
{
|
||||
PlayerInfo->QuestSaveData = QuestManager->GetQuestSaveData();
|
||||
}
|
||||
|
||||
if (UGameplayStatics::SaveGameToSlot(PlayerInfo.Get(), SaveGameSlotName, 0))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存成功"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败"));
|
||||
}
|
||||
if (UGameplayStatics::SaveGameToSlot(PlayerInfo.Get(), SaveGameSlotName, 0))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存成功"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败, PlayerInfo为空"));
|
||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class PROJECTFISH_API UGameInfoManager : public UGameInstanceSubsystem
|
||||
public:
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
|
||||
protected:
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SaveGameInfo();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include "QuestManager.h"
|
||||
|
||||
#include "GameInfoManager.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "Engine/AssetManager.h"
|
||||
#include "ProjectFish/DataAsset/QuestAsset.h"
|
||||
@ -44,19 +45,19 @@ void UQuestManager::LoadAllQuests()
|
||||
|
||||
}
|
||||
|
||||
void UQuestManager::CheckAcceptableQuests()
|
||||
void UQuestManager::CheckAcceptableQuests(bool bSaveGameInfo)
|
||||
{
|
||||
for (auto QuestAsset : QuestAssets)
|
||||
{
|
||||
if (!ActiveQuestsMap.Find(QuestAsset->QuestID) && !CompletedQuestIDs.Contains(QuestAsset->QuestID))
|
||||
{
|
||||
//任务不在当前已激活的任务 和 已完成的任务列表中
|
||||
AcceptQuest(QuestAsset);
|
||||
AcceptQuest(QuestAsset, bSaveGameInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
||||
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo )
|
||||
{
|
||||
if (!QuestAsset)
|
||||
{
|
||||
@ -83,6 +84,13 @@ bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
||||
// 触发事件
|
||||
OnQuestStateChanged.Broadcast(QuestAsset->QuestID);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Quest %s Accepted"), *QuestAsset->QuestName.ToString());
|
||||
|
||||
if (bSaveGameInfo)
|
||||
{
|
||||
//更新存档数据
|
||||
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -102,6 +110,9 @@ bool UQuestManager::FollowQuest(int32 QuestID, bool Follow)
|
||||
{
|
||||
FollowingQuestIDs.Remove(QuestID);
|
||||
}
|
||||
//更新存档数据
|
||||
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -131,9 +142,12 @@ 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;
|
||||
}
|
||||
|
||||
@ -243,6 +257,19 @@ 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;
|
||||
@ -267,6 +294,17 @@ 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)
|
||||
@ -339,7 +377,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
||||
if (questAsset->QuestID == Data.QuestID)
|
||||
{
|
||||
FQuestRuntimeData RuntimeData = CreateRuntimeData(questAsset);
|
||||
for (int i =0; i < RuntimeData.ObjectiveProgress.Num(); i++)
|
||||
for (int i =0; i < Data.ObjectiveProgress.Num(); i++)
|
||||
{
|
||||
RuntimeData.ObjectiveProgress[i].CurrentProgress = Data.ObjectiveProgress[i];
|
||||
RuntimeData.ObjectiveProgress[i].bCompleted = Data.ObjectiveCompleted[i];
|
||||
@ -360,7 +398,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
||||
|
||||
}
|
||||
|
||||
CheckAcceptableQuests();
|
||||
CheckAcceptableQuests(true);
|
||||
}
|
||||
|
||||
void UQuestManager::CheckQuestCompletion(int32 QuestID)
|
||||
|
||||
@ -53,11 +53,11 @@ public:
|
||||
|
||||
/** 检测所有可接收的任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
void CheckAcceptableQuests();
|
||||
void CheckAcceptableQuests(bool bSaveGameInfo = false);
|
||||
|
||||
/** 接受任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
bool AcceptQuest(UQuestAsset* QuestAsset);
|
||||
bool AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo = false);
|
||||
|
||||
/** 接受任务 */
|
||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||
@ -95,6 +95,10 @@ 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;
|
||||
@ -103,6 +107,10 @@ 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;
|
||||
@ -140,7 +148,7 @@ private:
|
||||
TMap<int32, FQuestRuntimeData> ActiveQuestsMap;
|
||||
|
||||
/** 正在追踪的任务列表 */
|
||||
UPROPERTY()
|
||||
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||
TSet<int32> FollowingQuestIDs;
|
||||
|
||||
/** 已完成的任务ID列表 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user