2022-07-24 18:04:02 +00:00
|
|
|
#include "Mission.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include "CDClientManager.h"
|
|
|
|
#include "Character.h"
|
|
|
|
#include "CharacterComponent.h"
|
2022-07-24 18:04:02 +00:00
|
|
|
#include "LevelProgressionComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "Mail.h"
|
|
|
|
#include "MissionComponent.h"
|
2022-02-05 11:28:17 +00:00
|
|
|
#include "RacingTaskParam.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "dLocale.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "dServer.h"
|
2022-02-03 06:50:02 +00:00
|
|
|
#include "dZoneManager.h"
|
2022-03-30 06:46:56 +00:00
|
|
|
#include "Database.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_MissionComponent = missionComponent;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Completions = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Timestamp = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-31 03:56:21 +00:00
|
|
|
m_UniqueMissionID = dZoneManager::Instance()->GetUniqueMissionIdStartingValue();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Reward = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_State = MissionState::MISSION_STATE_UNKNOWN;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* missionsTable = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
info = missionsTable->GetPtrByMissionID(missionId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (info == &CDMissionsTable::Default) {
|
|
|
|
Game::logger->Log("Missions", "Failed to find mission (%i)!", missionId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* tasksTable = CDClientManager::Instance()->GetTable<CDMissionTasksTable>("MissionTasks");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto tasks = tasksTable->GetByMissionID(missionId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto i = 0U; i < tasks.size(); ++i) {
|
|
|
|
auto* info = tasks[i];
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* task = new MissionTask(this, info, i);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks.push_back(task);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
2022-07-28 13:39:57 +00:00
|
|
|
// Start custom XML
|
|
|
|
if (element->Attribute("state") != nullptr) {
|
|
|
|
m_State = static_cast<MissionState>(std::stoul(element->Attribute("state")));
|
|
|
|
}
|
|
|
|
// End custom XML
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (element->Attribute("cct") != nullptr) {
|
|
|
|
m_Completions = std::stoul(element->Attribute("cct"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Timestamp = std::stoul(element->Attribute("cts"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* task = element->FirstChildElement();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto index = 0U;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
while (task != nullptr) {
|
|
|
|
if (index >= m_Tasks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto type = m_Tasks[index]->GetType();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (type == MissionTaskType::MISSION_TASK_TYPE_ENVIRONMENT ||
|
|
|
|
type == MissionTaskType::MISSION_TASK_TYPE_VISIT_PROPERTY) {
|
|
|
|
std::vector<uint32_t> uniques;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto value = std::stoul(task->Attribute("v"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks[index]->SetProgress(value, false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
task = task->NextSiblingElement();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
while (task != nullptr) {
|
|
|
|
const auto unique = std::stoul(task->Attribute("v"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uniques.push_back(unique);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_MissionComponent != nullptr && type == MissionTaskType::MISSION_TASK_TYPE_ENVIRONMENT) {
|
|
|
|
m_MissionComponent->AddCollectible(unique);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
task = task->NextSiblingElement();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks[index]->SetUnique(uniques);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks[index]->SetProgress(uniques.size(), false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
const auto value = std::stoul(task->Attribute("v"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks[index]->SetProgress(value, false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
task = task->NextSiblingElement();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
index++;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
2022-07-28 13:39:57 +00:00
|
|
|
// Start custom XML
|
|
|
|
element->SetAttribute("state", static_cast<unsigned int>(m_State));
|
|
|
|
// End custom XML
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->DeleteChildren();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->SetAttribute("id", static_cast<unsigned int>(info->id));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_Completions > 0) {
|
|
|
|
element->SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->GetType() == MissionTaskType::MISSION_TASK_TYPE_ENVIRONMENT ||
|
|
|
|
task->GetType() == MissionTaskType::MISSION_TASK_TYPE_VISIT_PROPERTY) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* child = element->GetDocument()->NewElement("sv");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->LinkEndChild(child);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto unique : task->GetUnique()) {
|
|
|
|
auto* uniqueElement = element->GetDocument()->NewElement("sv");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->LinkEndChild(uniqueElement);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
auto* child = element->GetDocument()->NewElement("sv");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
element->LinkEndChild(child);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsValidMission(const uint32_t missionId) {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* table = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto missions = table->Query([=](const CDMissions& entry) {
|
|
|
|
return entry.id == static_cast<int>(missionId);
|
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return !missions.empty();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsValidMission(const uint32_t missionId, CDMissions& info) {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* table = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto missions = table->Query([=](const CDMissions& entry) {
|
|
|
|
return entry.id == static_cast<int>(missionId);
|
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (missions.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
info = missions[0];
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return true;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Entity* Mission::GetAssociate() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_MissionComponent->GetParent();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
User* Mission::GetUser() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return GetAssociate()->GetParentUser();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetMissionId() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return info->id;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CDMissions& Mission::GetClientInfo() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return *info;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetCompletions() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_Completions;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetTimestamp() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_Timestamp;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LOT Mission::GetReward() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_Reward;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MissionTask*> Mission::GetTasks() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_Tasks;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MissionState Mission::GetMissionState() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_State;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsAchievement() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return !info->isMission;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsMission() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return info->isMission;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsRepeatable() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return info->repeatable;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsComplete() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_State == MissionState::MISSION_STATE_COMPLETE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsActive() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_State == MissionState::MISSION_STATE_ACTIVE || m_State == MissionState::MISSION_STATE_COMPLETE_AVAILABLE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeActive() {
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(m_Completions == 0 ? MissionState::MISSION_STATE_ACTIVE : MissionState::MISSION_STATE_COMPLETE_ACTIVE);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsReadyToComplete() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_State == MissionState::MISSION_STATE_READY_TO_COMPLETE || m_State == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeReadyToComplete() {
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(m_Completions == 0 ? MissionState::MISSION_STATE_READY_TO_COMPLETE : MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsAvalible() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_State == MissionState::MISSION_STATE_AVAILABLE || m_State == MissionState::MISSION_STATE_COMPLETE_AVAILABLE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsFetchMission() const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return m_Tasks.size() == 1 && m_Tasks[0]->GetType() == MissionTaskType::MISSION_TASK_TYPE_MISSION_INTERACTION;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeAvalible() {
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(m_Completions == 0 ? MissionState::MISSION_STATE_AVAILABLE : MissionState::MISSION_STATE_COMPLETE_AVAILABLE);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Accept() {
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionTypeState(MissionLockState::MISSION_LOCK_NEW, info->defined_type, info->defined_subtype);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(m_Completions > 0 ? MissionState::MISSION_STATE_COMPLETE_ACTIVE : MissionState::MISSION_STATE_ACTIVE);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Catchup();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Complete(const bool yieldRewards) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_State != MissionState::MISSION_STATE_ACTIVE && m_State != MissionState::MISSION_STATE_COMPLETE_ACTIVE) {
|
2022-07-31 03:56:21 +00:00
|
|
|
// If we are accepting a mission here there is no point to giving it a unique ID since we just complete it immediately.
|
2022-07-28 13:39:57 +00:00
|
|
|
Accept();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
task->Complete();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(MissionState::MISSION_STATE_REWARDING, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (yieldRewards) {
|
|
|
|
YieldRewards();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
SetMissionState(MissionState::MISSION_STATE_COMPLETE);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Completions++;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Timestamp = std::time(nullptr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = GetAssociate();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent != nullptr) {
|
|
|
|
characterComponent->TrackMissionCompletion(!info->isMission);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_MISSION_COMPLETE, info->id);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, info->id, (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_COMPLETE_ANY_RACING_TASK);
|
2022-02-05 11:28:17 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, info->id, (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_COMPLETE_TRACK_TASKS);
|
2022-02-05 11:28:17 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* missionEmailTable = CDClientManager::Instance()->GetTable<CDMissionEmailTable>("MissionEmail");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto missionId = GetMissionId();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto missionEmails = missionEmailTable->Query([missionId](const CDMissionEmail& entry) {
|
|
|
|
return entry.missionID == missionId;
|
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& email : missionEmails) {
|
|
|
|
const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto senderLocale = missionEmailBase + "senderName";
|
|
|
|
const auto announceLocale = missionEmailBase + "announceText";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (email.messageType == 1 && Game::locale->HasPhrase(senderLocale)) {
|
|
|
|
const auto subject = dLocale::GetTemplate(missionEmailBase + "subjectText");
|
|
|
|
const auto body = dLocale::GetTemplate(missionEmailBase + "bodyText");
|
|
|
|
const auto sender = dLocale::GetTemplate(senderLocale);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1);
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::CheckCompletion() {
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (!task->IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (IsAchievement()) {
|
|
|
|
Complete();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
MakeReadyToComplete();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Catchup() {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = GetAssociate();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* inventory = static_cast<InventoryComponent*>(entity->GetComponent(COMPONENT_TYPE_INVENTORY));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
const auto type = task->GetType();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (type == MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION) {
|
|
|
|
for (auto target : task->GetAllTargets()) {
|
|
|
|
const auto count = inventory->GetLotCountNonTransfer(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto i = 0U; i < count; ++i) {
|
|
|
|
task->Progress(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (type == MissionTaskType::MISSION_TASK_TYPE_PLAYER_FLAG) {
|
|
|
|
for (auto target : task->GetAllTargets()) {
|
|
|
|
const auto flag = GetUser()->GetLastUsedChar()->GetPlayerFlag(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!flag) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
task->Progress(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (task->IsComplete()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::YieldRewards() {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = GetAssociate();
|
|
|
|
|
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* character = GetUser()->GetLastUsedChar();
|
|
|
|
|
|
|
|
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
|
|
|
auto* levelComponent = entity->GetComponent<LevelProgressionComponent>();
|
|
|
|
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
|
|
|
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
|
|
|
|
|
|
|
// Remove mission items
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->GetType() != MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& param = task->GetParameters();
|
|
|
|
|
|
|
|
if (param.empty() || (param[0] & 1) == 0) // Should items be removed?
|
|
|
|
{
|
|
|
|
for (const auto target : task->GetAllTargets()) {
|
|
|
|
// This is how live did it. ONLY remove item collection items from the items and hidden inventories and none of the others.
|
|
|
|
inventoryComponent->RemoveItem(target, task->GetClientInfo().targetValue, eInventoryType::ITEMS);
|
|
|
|
inventoryComponent->RemoveItem(target, task->GetClientInfo().targetValue, eInventoryType::HIDDEN);
|
|
|
|
|
|
|
|
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, target, LWOOBJID_EMPTY, "", -task->GetClientInfo().targetValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t coinsToSend = 0;
|
|
|
|
if (info->LegoScore > 0) {
|
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
|
|
|
if (levelComponent->GetLevel() >= dZoneManager::Instance()->GetMaxLevel()) {
|
|
|
|
// Since the character is at the level cap we reward them with coins instead of UScore.
|
|
|
|
coinsToSend += info->LegoScore * dZoneManager::Instance()->GetLevelCapCurrencyConversion();
|
|
|
|
} else {
|
|
|
|
characterComponent->SetUScore(characterComponent->GetUScore() + info->LegoScore);
|
|
|
|
GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), info->LegoScore, lootSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Completions > 0) {
|
|
|
|
std::vector<std::pair<LOT, uint32_t>> items;
|
|
|
|
|
|
|
|
items.emplace_back(info->reward_item1_repeatable, info->reward_item1_repeat_count);
|
|
|
|
items.emplace_back(info->reward_item2_repeatable, info->reward_item2_repeat_count);
|
|
|
|
items.emplace_back(info->reward_item3_repeatable, info->reward_item3_repeat_count);
|
|
|
|
items.emplace_back(info->reward_item4_repeatable, info->reward_item4_repeat_count);
|
|
|
|
|
|
|
|
for (const auto& pair : items) {
|
|
|
|
// Some missions reward zero of an item and so they must be allowed through this clause,
|
|
|
|
// hence pair.second < 0 instead of pair.second <= 0.
|
|
|
|
if (pair.second < 0 || (m_Reward > 0 && pair.first != m_Reward)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a mission rewards zero of an item, make it reward 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::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_currency_repeatable > 0 || coinsToSend > 0) {
|
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
|
|
|
character->SetCoins(character->GetCoins() + info->reward_currency_repeatable + coinsToSend, lootSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<LOT, int32_t>> items;
|
|
|
|
|
|
|
|
items.emplace_back(info->reward_item1, info->reward_item1_count);
|
|
|
|
items.emplace_back(info->reward_item2, info->reward_item2_count);
|
|
|
|
items.emplace_back(info->reward_item3, info->reward_item3_count);
|
|
|
|
items.emplace_back(info->reward_item4, info->reward_item4_count);
|
|
|
|
|
|
|
|
for (const auto& pair : items) {
|
|
|
|
// Some missions reward zero of an item and so they must be allowed through this clause,
|
|
|
|
// hence pair.second < 0 instead of pair.second <= 0.
|
|
|
|
if (pair.second < 0 || (m_Reward > 0 && pair.first != m_Reward)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a mission rewards zero of an item, make it reward 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::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_currency > 0 || coinsToSend > 0) {
|
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
|
|
|
character->SetCoins(character->GetCoins() + info->reward_currency + coinsToSend, lootSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_maxinventory > 0) {
|
|
|
|
auto* inventory = inventoryComponent->GetInventory(ITEMS);
|
|
|
|
|
|
|
|
inventory->SetSize(inventory->GetSize() + info->reward_maxinventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_bankinventory > 0) {
|
|
|
|
auto* inventory = inventoryComponent->GetInventory(eInventoryType::VAULT_ITEMS);
|
|
|
|
auto modelInventory = inventoryComponent->GetInventory(eInventoryType::VAULT_MODELS);
|
|
|
|
|
|
|
|
inventory->SetSize(inventory->GetSize() + info->reward_bankinventory);
|
|
|
|
modelInventory->SetSize(modelInventory->GetSize() + info->reward_bankinventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_reputation > 0) {
|
|
|
|
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_EARN_REPUTATION, 0, 0L, "", info->reward_reputation);
|
|
|
|
auto character = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (character) {
|
|
|
|
character->SetReputation(character->GetReputation() + info->reward_reputation);
|
|
|
|
GameMessages::SendUpdateReputation(entity->GetObjectID(), character->GetReputation(), entity->GetSystemAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_maxhealth > 0) {
|
|
|
|
destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast<float>(info->reward_maxhealth), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_maximagination > 0) {
|
|
|
|
destroyableComponent->SetMaxImagination(destroyableComponent->GetMaxImagination() + static_cast<float>(info->reward_maximagination), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(entity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (info->reward_emote > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (info->reward_emote2 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote2);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (info->reward_emote3 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote3);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (info->reward_emote4 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote4);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Progress(MissionTaskType type, int32_t value, LWOOBJID associate, const std::string& targets, int32_t count) {
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto isRemoval = count < 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (isRemoval && (IsComplete() || IsAchievement())) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->IsComplete() && !isRemoval) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (task->GetType() != type) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (isRemoval && !task->InAllTargets(value)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
task->Progress(value, associate, targets, count);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetMissionState(const MissionState state, const bool sendingRewards) {
|
2022-07-28 13:39:57 +00:00
|
|
|
this->m_State = state;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = GetAssociate();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
GameMessages::SendNotifyMission(entity, entity->GetParentUser()->GetSystemAddress(), info->id, static_cast<int>(state), sendingRewards);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetMissionTypeState(MissionLockState state, const std::string& type, const std::string& subType) {
|
2022-07-28 13:39:57 +00:00
|
|
|
// TODO
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetCompletions(const uint32_t value) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Completions = value;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetReward(const LOT lot) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Reward = lot;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Mission::~Mission() {
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
delete task;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Tasks.clear();
|
|
|
|
}
|