From 85de65c0414ea81c78eee76f85b166821b2ba2bf Mon Sep 17 00:00:00 2001 From: Lucca Faria Ferri Date: Tue, 31 Jan 2023 14:51:49 -0800 Subject: [PATCH] #115 Always save quests progress if config.ini has AutoSaveQuests = true - unless in open world. In tests. --- src/DiIiS-NA/D3-GameServer/Config.cs | 9 +++++++++ .../GSSystem/GameSystem/QuestManager.cs | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/DiIiS-NA/D3-GameServer/Config.cs b/src/DiIiS-NA/D3-GameServer/Config.cs index dba074a..5c197dd 100644 --- a/src/DiIiS-NA/D3-GameServer/Config.cs +++ b/src/DiIiS-NA/D3-GameServer/Config.cs @@ -152,6 +152,15 @@ namespace DiIiS_NA.GameServer set => Set(nameof(BossDamageMultiplier), value); } + /// + /// Whether to bypass the quest's settings of "Saveable" to TRUE (unless in OpenWorld) + /// + public bool AutoSaveQuests + { + get => GetBoolean(nameof(AutoSaveQuests), false); + set => Set(nameof(AutoSaveQuests), value); + } + public static Config Instance { get; } = new(); private Config() : base("Game-Server") diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/GameSystem/QuestManager.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/GameSystem/QuestManager.cs index e7b3af9..189686e 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/GameSystem/QuestManager.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/GameSystem/QuestManager.cs @@ -11,6 +11,7 @@ using DiIiS_NA.Core.Logging; using DiIiS_NA.Core.MPQ.FileFormats; using DiIiS_NA.Core.Storage.AccountDataBase.Entities; using DiIiS_NA.D3_GameServer.Core.Types.SNO; +using DiIiS_NA.GameServer; using DiIiS_NA.GameServer.GSSystem.ActorSystem; using DiIiS_NA.GameServer.GSSystem.GameSystem; using DiIiS_NA.GameServer.GSSystem.ItemsSystem; @@ -261,7 +262,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem if (!Game.Empty) { RevealQuestProgress(); - if (Quests[Game.CurrentQuest].Steps[Game.CurrentStep].Saveable) + if ((Game.CurrentActEnum != ActEnum.OpenWorld && Config.Instance.AutoSaveQuests) || Quests[Game.CurrentQuest].Steps[Game.CurrentStep].Saveable) SaveQuestProgress(false); } OnQuestProgress(); @@ -803,7 +804,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem public void SaveQuestProgress(bool questCompleted) { - foreach (var player in Game.Players.Values) + Game.BroadcastPlayers((client, player) => { player.Toon.CurrentAct = CurrentAct; player.Toon.CurrentQuestId = Game.CurrentQuest; @@ -813,10 +814,12 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem dbi => dbi.DBToon.Id == player.Toon.PersistentID && dbi.QuestId == Game.CurrentQuest); if (query.Count == 0) { - var questHistory = new DBQuestHistory(); - questHistory.DBToon = player.Toon.DBToon; - questHistory.QuestId = Game.CurrentQuest; - questHistory.QuestStep = Game.CurrentStep; + var questHistory = new DBQuestHistory + { + DBToon = player.Toon.DBToon, + QuestId = Game.CurrentQuest, + QuestStep = Game.CurrentStep + }; Game.GameDbSession.SessionSave(questHistory); } else @@ -829,7 +832,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem Game.GameDbSession.SessionUpdate(questHistory); } } - } + }); } }