fix: multiple collection tasks in one mission and remove sanity check on mission rewards (#1843)

This commit is contained in:
David Markowitz
2025-07-12 19:04:41 -07:00
committed by GitHub
parent 5e9fe40bec
commit 5ec4142ca1

View File

@@ -96,20 +96,18 @@ void Mission::LoadFromXmlCur(const tinyxml2::XMLElement& element) {
if (index >= m_Tasks.size()) { if (index >= m_Tasks.size()) {
break; break;
} }
auto* const curTask = m_Tasks[index];
const auto type = m_Tasks[index]->GetType(); const auto type = curTask->GetType();
if (type == eMissionTaskType::COLLECTION ||
type == eMissionTaskType::VISIT_PROPERTY) {
std::vector<uint32_t> uniques;
const auto value = std::stoul(task->Attribute("v"));
m_Tasks[index]->SetProgress(value, false);
auto value = std::stoul(task->Attribute("v"));
curTask->SetProgress(value, false);
task = task->NextSiblingElement(); task = task->NextSiblingElement();
while (task != nullptr) { // Collection tasks and visit property tasks store each of the collected/visited targets after the progress value
if (type == eMissionTaskType::COLLECTION || type == eMissionTaskType::VISIT_PROPERTY) {
std::vector<uint32_t> uniques;
while (task != nullptr && value > 0) {
const auto unique = std::stoul(task->Attribute("v")); const auto unique = std::stoul(task->Attribute("v"));
uniques.push_back(unique); uniques.push_back(unique);
@@ -119,19 +117,10 @@ void Mission::LoadFromXmlCur(const tinyxml2::XMLElement& element) {
} }
task = task->NextSiblingElement(); task = task->NextSiblingElement();
value--;
} }
m_Tasks[index]->SetUnique(uniques); curTask->SetUnique(uniques);
m_Tasks[index]->SetProgress(uniques.size(), false);
break;
} else {
const auto value = std::stoul(task->Attribute("v"));
m_Tasks[index]->SetProgress(value, false);
task = task->NextSiblingElement();
} }
index++; index++;
@@ -163,31 +152,19 @@ void Mission::UpdateXmlCur(tinyxml2::XMLElement& element) {
if (IsComplete()) return; if (IsComplete()) return;
for (auto* task : m_Tasks) { for (const auto* const task : m_Tasks) {
if (task->GetType() == eMissionTaskType::COLLECTION || auto* const child = element.InsertNewChildElement("sv");
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
auto* child = element.GetDocument()->NewElement("sv");
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress())); child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child); // Collection and visit property tasks then need to store the collected/visited items after the progress
const auto taskType = task->GetType();
for (auto unique : task->GetUnique()) { if (taskType == eMissionTaskType::COLLECTION || taskType == eMissionTaskType::VISIT_PROPERTY) {
auto* uniqueElement = element.GetDocument()->NewElement("sv"); for (const auto unique : task->GetUnique()) {
auto* uniqueElement = element.InsertNewChildElement("sv");
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique)); uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
element.LinkEndChild(uniqueElement);
} }
break;
} }
auto* child = element.GetDocument()->NewElement("sv");
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child);
} }
} }
@@ -507,11 +484,6 @@ void Mission::YieldRewards() {
// If a mission rewards zero of an item, make it reward 1. // If a mission rewards zero of an item, make it reward 1.
auto count = pair.second > 0 ? pair.second : 1; auto count = pair.second > 0 ? pair.second : 1;
// Sanity check, 6 is the max any mission yields
if (count > 6) {
count = 0;
}
inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT); inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT);
} }
@@ -540,11 +512,6 @@ void Mission::YieldRewards() {
// If a mission rewards zero of an item, make it reward 1. // If a mission rewards zero of an item, make it reward 1.
auto count = pair.second > 0 ? pair.second : 1; auto count = pair.second > 0 ? pair.second : 1;
// Sanity check, 6 is the max any mission yields
if (count > 6) {
count = 0;
}
inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT); inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT);
} }