更新任务的存档功能
This commit is contained in:
parent
f07e298eb8
commit
1ccc1d8796
Binary file not shown.
@ -19,8 +19,10 @@ void UGameInfoManager::Initialize(FSubsystemCollectionBase& Collection)
|
|||||||
|
|
||||||
void UGameInfoManager::SaveGameInfo()
|
void UGameInfoManager::SaveGameInfo()
|
||||||
{
|
{
|
||||||
if (IsValid(PlayerInfo.Get()))
|
if (!IsValid(PlayerInfo.Get()))
|
||||||
{
|
{
|
||||||
|
PlayerInfo = NewObject<UPlayerInfoSaveGame>(this);
|
||||||
|
}
|
||||||
// 保存任务数据
|
// 保存任务数据
|
||||||
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
||||||
{
|
{
|
||||||
@ -36,11 +38,6 @@ void UGameInfoManager::SaveGameInfo()
|
|||||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败"));
|
UE_LOG(LogTemp, Warning, TEXT("存档保存失败"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("存档保存失败, PlayerInfo为空"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UGameInfoManager::LoadGameInfo()
|
bool UGameInfoManager::LoadGameInfo()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class PROJECTFISH_API UGameInfoManager : public UGameInstanceSubsystem
|
|||||||
public:
|
public:
|
||||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void SaveGameInfo();
|
void SaveGameInfo();
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "QuestManager.h"
|
#include "QuestManager.h"
|
||||||
|
|
||||||
|
#include "GameInfoManager.h"
|
||||||
#include "AssetRegistry/AssetRegistryModule.h"
|
#include "AssetRegistry/AssetRegistryModule.h"
|
||||||
#include "Engine/AssetManager.h"
|
#include "Engine/AssetManager.h"
|
||||||
#include "ProjectFish/DataAsset/QuestAsset.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)
|
for (auto QuestAsset : QuestAssets)
|
||||||
{
|
{
|
||||||
if (!ActiveQuestsMap.Find(QuestAsset->QuestID) && !CompletedQuestIDs.Contains(QuestAsset->QuestID))
|
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)
|
if (!QuestAsset)
|
||||||
{
|
{
|
||||||
@ -83,6 +84,13 @@ bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
|||||||
// 触发事件
|
// 触发事件
|
||||||
OnQuestStateChanged.Broadcast(QuestAsset->QuestID);
|
OnQuestStateChanged.Broadcast(QuestAsset->QuestID);
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Quest %s Accepted"), *QuestAsset->QuestName.ToString());
|
UE_LOG(LogTemp, Warning, TEXT("Quest %s Accepted"), *QuestAsset->QuestName.ToString());
|
||||||
|
|
||||||
|
if (bSaveGameInfo)
|
||||||
|
{
|
||||||
|
//更新存档数据
|
||||||
|
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +110,9 @@ bool UQuestManager::FollowQuest(int32 QuestID, bool Follow)
|
|||||||
{
|
{
|
||||||
FollowingQuestIDs.Remove(QuestID);
|
FollowingQuestIDs.Remove(QuestID);
|
||||||
}
|
}
|
||||||
|
//更新存档数据
|
||||||
|
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +142,12 @@ bool UQuestManager::CompleteQuest(int32 QuestID)
|
|||||||
UE_LOG(LogTemp, Warning, TEXT("Quest id = %d Complete"), QuestID);
|
UE_LOG(LogTemp, Warning, TEXT("Quest id = %d Complete"), QuestID);
|
||||||
// 从活动任务中移除
|
// 从活动任务中移除
|
||||||
ActiveQuestsMap.Remove(QuestID);
|
ActiveQuestsMap.Remove(QuestID);
|
||||||
|
//更新存档数据
|
||||||
|
GetGameInstance()->GetSubsystem<UGameInfoManager>()->SaveGameInfo();
|
||||||
|
|
||||||
//检测是否有其他可接受的任务
|
//检测是否有其他可接受的任务
|
||||||
CheckAcceptableQuests();
|
CheckAcceptableQuests();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +374,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckAcceptableQuests();
|
CheckAcceptableQuests(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UQuestManager::CheckQuestCompletion(int32 QuestID)
|
void UQuestManager::CheckQuestCompletion(int32 QuestID)
|
||||||
|
|||||||
@ -53,11 +53,11 @@ public:
|
|||||||
|
|
||||||
/** 检测所有可接收的任务 */
|
/** 检测所有可接收的任务 */
|
||||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||||
void CheckAcceptableQuests();
|
void CheckAcceptableQuests(bool bSaveGameInfo = false);
|
||||||
|
|
||||||
/** 接受任务 */
|
/** 接受任务 */
|
||||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||||
bool AcceptQuest(UQuestAsset* QuestAsset);
|
bool AcceptQuest(UQuestAsset* QuestAsset, bool bSaveGameInfo = false);
|
||||||
|
|
||||||
/** 接受任务 */
|
/** 接受任务 */
|
||||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user