更新任务的存档功能
This commit is contained in:
parent
f07e298eb8
commit
1ccc1d8796
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;
|
||||
}
|
||||
|
||||
@ -360,7 +374,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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user