Core/Quests: Reset seasonal quests based on saved completion time and intended holiday start time

Port From (https://github.com/TrinityCore/TrinityCore/commit/49ad0d2d495a9f817ad2820f8e616f3a6564b480)
This commit is contained in:
hondacrx
2022-07-04 01:15:52 -04:00
parent 3a402854aa
commit c7123ad860
8 changed files with 69 additions and 27 deletions
+16 -7
View File
@@ -931,11 +931,16 @@ namespace Game.Entities
{
uint quest_id = result.Read<uint>(0);
uint event_id = result.Read<uint>(1);
long completedTime = result.Read<long>(2);
Quest quest = Global.ObjectMgr.GetQuestTemplate(quest_id);
if (quest == null)
continue;
m_seasonalquests.Add(event_id, quest_id);
if (!m_seasonalquests.ContainsKey(event_id))
m_seasonalquests[event_id] = new();
m_seasonalquests[event_id][quest_id] = completedTime;
uint questBit = Global.DB2Mgr.GetQuestUniqueBitFlag(quest_id);
if (questBit != 0)
SetQuestCompletedBit(questBit, true);
@@ -2128,13 +2133,17 @@ namespace Game.Entities
if (m_seasonalquests.Empty())
return;
foreach (var iter in m_seasonalquests)
foreach (var (eventId, dictionary) in m_seasonalquests)
{
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHARACTER_QUESTSTATUS_SEASONAL);
stmt.AddValue(0, GetGUID().GetCounter());
stmt.AddValue(1, iter.Value);
stmt.AddValue(2, iter.Key);
trans.Append(stmt);
foreach (var (questId, completedTime) in dictionary)
{
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHARACTER_QUESTSTATUS_SEASONAL);
stmt.AddValue(0, GetGUID().GetCounter());
stmt.AddValue(1, questId);
stmt.AddValue(2, eventId);
stmt.AddValue(3, completedTime);
trans.Append(stmt);
}
}
}
void _SaveMonthlyQuestStatus(SQLTransaction trans)
+1 -1
View File
@@ -164,7 +164,7 @@ namespace Game.Entities
List<uint> m_timedquests = new();
List<uint> m_weeklyquests = new();
List<uint> m_monthlyquests = new();
MultiMap<uint, uint> m_seasonalquests = new();
Dictionary<uint, Dictionary<uint, long>> m_seasonalquests = new();
Dictionary<uint, QuestStatusData> m_QuestStatus = new();
MultiMap<(QuestObjectiveType Type, int ObjectID), QuestObjectiveStatusData> m_questObjectiveStatus = new();
Dictionary<uint, QuestSaveType> m_QuestStatusSave = new();
+22 -11
View File
@@ -28,6 +28,7 @@ using Game.Networking.Packets;
using Game.Spells;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Game.Entities
{
@@ -200,22 +201,29 @@ namespace Game.Entities
}
public void ResetSeasonalQuestStatus(ushort event_id)
public void ResetSeasonalQuestStatus(ushort event_id, long eventStartTime)
{
// DB data deleted in caller
m_SeasonalQuestChanged = false;
var eventList = m_seasonalquests.LookupByKey(event_id);
if (eventList.Empty())
return;
foreach (uint questId in eventList)
foreach (var (questId, completedTime) in eventList.ToList())
{
uint questBit = Global.DB2Mgr.GetQuestUniqueBitFlag(questId);
if (questBit != 0)
SetQuestCompletedBit(questBit, false);
if (completedTime < eventStartTime)
{
uint questBit = Global.DB2Mgr.GetQuestUniqueBitFlag(questId);
if (questBit != 0)
SetQuestCompletedBit(questBit, false);
eventList.Remove(questId);
}
}
m_seasonalquests.Remove(event_id);
// DB data deleted in caller
m_SeasonalQuestChanged = false;
if (eventList.Empty())
m_seasonalquests.Remove(event_id);
}
public void ResetMonthlyQuestStatus()
@@ -1673,7 +1681,7 @@ namespace Game.Entities
return true;
// if not found in cooldown list
return !list.Contains(qInfo.Id);
return !list.ContainsKey(qInfo.Id);
}
public bool SatisfyQuestExpansion(Quest qInfo, bool msg)
@@ -1864,7 +1872,7 @@ namespace Game.Entities
ushort eventId = qInfo.GetEventIdForQuest();
if (m_seasonalquests.ContainsKey(eventId))
{
m_seasonalquests.Remove(eventId, questId);
m_seasonalquests[eventId].Remove(questId);
m_SeasonalQuestChanged = true;
}
}
@@ -3041,7 +3049,10 @@ namespace Game.Entities
if (quest == null)
return;
m_seasonalquests.Add(quest.GetEventIdForQuest(), quest_id);
if (!m_seasonalquests.ContainsKey(quest.GetEventIdForQuest()))
m_seasonalquests[quest.GetEventIdForQuest()] = new();
m_seasonalquests[quest.GetEventIdForQuest()][quest_id] = GameTime.GetGameTime();
m_SeasonalQuestChanged = true;
}