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 "eRacingTaskParam.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "dLogger.h"
|
|
|
|
#include "dServer.h"
|
2022-02-03 06:50:02 +00:00
|
|
|
#include "dZoneManager.h"
|
2022-12-18 15:46:04 +00:00
|
|
|
#include "InventoryComponent.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "User.h"
|
2022-03-30 06:46:56 +00:00
|
|
|
#include "Database.h"
|
2023-01-01 12:51:22 +00:00
|
|
|
#include "WorldConfig.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "eMissionState.h"
|
|
|
|
#include "eMissionTaskType.h"
|
|
|
|
#include "eMissionLockState.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
|
|
|
|
m_MissionComponent = missionComponent;
|
|
|
|
|
|
|
|
m_Completions = 0;
|
|
|
|
|
|
|
|
m_Timestamp = 0;
|
|
|
|
|
2022-07-31 03:56:21 +00:00
|
|
|
m_UniqueMissionID = dZoneManager::Instance()->GetUniqueMissionIdStartingValue();
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Reward = 0;
|
|
|
|
|
|
|
|
m_State = eMissionState::UNKNOWN;
|
|
|
|
|
|
|
|
auto* missionsTable = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
|
|
|
|
|
|
|
info = missionsTable->GetPtrByMissionID(missionId);
|
|
|
|
|
|
|
|
if (info == &CDMissionsTable::Default) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("Missions", "Failed to find mission (%i)!", missionId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* tasksTable = CDClientManager::Instance()->GetTable<CDMissionTasksTable>("MissionTasks");
|
|
|
|
|
|
|
|
auto tasks = tasksTable->GetByMissionID(missionId);
|
|
|
|
|
|
|
|
for (auto i = 0U; i < tasks.size(); ++i) {
|
|
|
|
auto* info = tasks[i];
|
|
|
|
|
|
|
|
auto* task = new MissionTask(this, info, i);
|
|
|
|
|
|
|
|
m_Tasks.push_back(task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
|
|
|
// Start custom XML
|
|
|
|
if (element->Attribute("state") != nullptr) {
|
|
|
|
m_State = static_cast<eMissionState>(std::stoul(element->Attribute("state")));
|
|
|
|
}
|
|
|
|
// End custom XML
|
|
|
|
|
|
|
|
if (element->Attribute("cct") != nullptr) {
|
|
|
|
m_Completions = std::stoul(element->Attribute("cct"));
|
|
|
|
|
|
|
|
m_Timestamp = std::stoul(element->Attribute("cts"));
|
|
|
|
|
|
|
|
if (IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* task = element->FirstChildElement();
|
|
|
|
|
|
|
|
auto index = 0U;
|
|
|
|
|
|
|
|
while (task != nullptr) {
|
|
|
|
if (index >= m_Tasks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto type = m_Tasks[index]->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);
|
|
|
|
|
|
|
|
task = task->NextSiblingElement();
|
|
|
|
|
|
|
|
while (task != nullptr) {
|
|
|
|
const auto unique = std::stoul(task->Attribute("v"));
|
|
|
|
|
|
|
|
uniques.push_back(unique);
|
|
|
|
|
|
|
|
if (m_MissionComponent != nullptr && type == eMissionTaskType::COLLECTION) {
|
|
|
|
m_MissionComponent->AddCollectible(unique);
|
|
|
|
}
|
|
|
|
|
|
|
|
task = task->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Tasks[index]->SetUnique(uniques);
|
|
|
|
|
|
|
|
m_Tasks[index]->SetProgress(uniques.size(), false);
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
const auto value = std::stoul(task->Attribute("v"));
|
|
|
|
|
2022-02-10 11:08:47 +00:00
|
|
|
m_Tasks[index]->SetProgress(value, false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
task = task->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
|
|
|
// Start custom XML
|
|
|
|
element->SetAttribute("state", static_cast<unsigned int>(m_State));
|
|
|
|
// End custom XML
|
|
|
|
|
|
|
|
element->DeleteChildren();
|
|
|
|
|
|
|
|
element->SetAttribute("id", static_cast<unsigned int>(info->id));
|
|
|
|
|
|
|
|
if (m_Completions > 0) {
|
|
|
|
element->SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
|
|
|
|
|
|
|
element->SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
|
|
|
|
|
|
|
if (IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->GetType() == eMissionTaskType::COLLECTION ||
|
|
|
|
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
|
|
|
|
|
|
|
|
auto* child = element->GetDocument()->NewElement("sv");
|
|
|
|
|
|
|
|
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
|
|
|
|
|
|
|
element->LinkEndChild(child);
|
|
|
|
|
|
|
|
for (auto unique : task->GetUnique()) {
|
|
|
|
auto* uniqueElement = element->GetDocument()->NewElement("sv");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsValidMission(const uint32_t missionId) {
|
|
|
|
auto* table = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
|
|
|
|
|
|
|
const auto missions = table->Query([=](const CDMissions& entry) {
|
|
|
|
return entry.id == static_cast<int>(missionId);
|
|
|
|
});
|
|
|
|
|
|
|
|
return !missions.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsValidMission(const uint32_t missionId, CDMissions& info) {
|
|
|
|
auto* table = CDClientManager::Instance()->GetTable<CDMissionsTable>("Missions");
|
|
|
|
|
|
|
|
const auto missions = table->Query([=](const CDMissions& entry) {
|
|
|
|
return entry.id == static_cast<int>(missionId);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missions.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = missions[0];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity* Mission::GetAssociate() const {
|
|
|
|
return m_MissionComponent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
User* Mission::GetUser() const {
|
|
|
|
return GetAssociate()->GetParentUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetMissionId() const {
|
|
|
|
return info->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CDMissions& Mission::GetClientInfo() const {
|
|
|
|
return *info;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetCompletions() const {
|
|
|
|
return m_Completions;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Mission::GetTimestamp() const {
|
|
|
|
return m_Timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOT Mission::GetReward() const {
|
|
|
|
return m_Reward;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MissionTask*> Mission::GetTasks() const {
|
|
|
|
return m_Tasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
eMissionState Mission::GetMissionState() const {
|
|
|
|
return m_State;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsAchievement() const {
|
|
|
|
return !info->isMission;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsMission() const {
|
|
|
|
return info->isMission;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsRepeatable() const {
|
|
|
|
return info->repeatable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsComplete() const {
|
|
|
|
return m_State == eMissionState::COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsActive() const {
|
|
|
|
return m_State == eMissionState::ACTIVE || m_State == eMissionState::COMPLETE_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeActive() {
|
|
|
|
SetMissionState(m_Completions == 0 ? eMissionState::ACTIVE : eMissionState::COMPLETE_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsReadyToComplete() const {
|
|
|
|
return m_State == eMissionState::READY_TO_COMPLETE || m_State == eMissionState::COMPLETE_READY_TO_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeReadyToComplete() {
|
|
|
|
SetMissionState(m_Completions == 0 ? eMissionState::READY_TO_COMPLETE : eMissionState::COMPLETE_READY_TO_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsAvalible() const {
|
|
|
|
return m_State == eMissionState::AVAILABLE || m_State == eMissionState::COMPLETE_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mission::IsFetchMission() const {
|
|
|
|
return m_Tasks.size() == 1 && m_Tasks[0]->GetType() == eMissionTaskType::TALK_TO_NPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::MakeAvalible() {
|
|
|
|
SetMissionState(m_Completions == 0 ? eMissionState::AVAILABLE : eMissionState::COMPLETE_AVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Accept() {
|
|
|
|
SetMissionTypeState(eMissionLockState::NEW, info->defined_type, info->defined_subtype);
|
|
|
|
|
|
|
|
SetMissionState(m_Completions > 0 ? eMissionState::COMPLETE_ACTIVE : eMissionState::ACTIVE);
|
|
|
|
|
|
|
|
Catchup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Complete(const bool yieldRewards) {
|
|
|
|
if (m_State != eMissionState::ACTIVE && m_State != eMissionState::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.
|
2021-12-05 17:54:36 +00:00
|
|
|
Accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
task->Complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetMissionState(eMissionState::REWARDING, true);
|
|
|
|
|
|
|
|
if (yieldRewards) {
|
|
|
|
YieldRewards();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetMissionState(eMissionState::COMPLETE);
|
|
|
|
|
|
|
|
m_Completions++;
|
|
|
|
|
|
|
|
m_Timestamp = std::time(nullptr);
|
|
|
|
|
|
|
|
auto* entity = GetAssociate();
|
|
|
|
|
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent != nullptr) {
|
|
|
|
characterComponent->TrackMissionCompletion(!info->isMission);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
|
|
|
|
|
|
|
missionComponent->Progress(eMissionTaskType::META, info->id);
|
|
|
|
|
2022-02-05 11:28:17 +00:00
|
|
|
missionComponent->Progress(eMissionTaskType::RACING, info->id, (LWOOBJID)eRacingTaskParam::COMPLETE_ANY_RACING_TASK);
|
|
|
|
|
|
|
|
missionComponent->Progress(eMissionTaskType::RACING, info->id, (LWOOBJID)eRacingTaskParam::COMPLETE_TRACK_TASKS);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* missionEmailTable = CDClientManager::Instance()->GetTable<CDMissionEmailTable>("MissionEmail");
|
|
|
|
|
|
|
|
const auto missionId = GetMissionId();
|
|
|
|
|
|
|
|
const auto missionEmails = missionEmailTable->Query([missionId](const CDMissionEmail& entry) {
|
|
|
|
return entry.missionID == missionId;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto& email : missionEmails) {
|
|
|
|
const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_";
|
|
|
|
|
2022-11-28 00:56:55 +00:00
|
|
|
if (email.messageType == 1) {
|
|
|
|
const auto subject = "%[" + missionEmailBase + "subjectText]";
|
|
|
|
const auto body = "%[" + missionEmailBase + "bodyText]";
|
|
|
|
const auto sender = "%[" + missionEmailBase + "senderName]";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::CheckCompletion() {
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (!task->IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsAchievement()) {
|
|
|
|
Complete();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-10 00:42:03 +00:00
|
|
|
MakeReadyToComplete();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Catchup() {
|
|
|
|
auto* entity = GetAssociate();
|
|
|
|
|
2023-03-04 07:16:37 +00:00
|
|
|
auto* inventory = static_cast<InventoryComponent*>(entity->GetComponent(eReplicaComponentType::INVENTORY));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
const auto type = task->GetType();
|
|
|
|
|
|
|
|
if (type == eMissionTaskType::GATHER) {
|
|
|
|
for (auto target : task->GetAllTargets()) {
|
|
|
|
const auto count = inventory->GetLotCountNonTransfer(target);
|
|
|
|
|
|
|
|
for (auto i = 0U; i < count; ++i) {
|
|
|
|
task->Progress(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == eMissionTaskType::PLAYER_FLAG) {
|
|
|
|
for (auto target : task->GetAllTargets()) {
|
|
|
|
const auto flag = GetUser()->GetLastUsedChar()->GetPlayerFlag(target);
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
task->Progress(target);
|
|
|
|
|
|
|
|
if (task->IsComplete()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::YieldRewards() {
|
|
|
|
auto* entity = GetAssociate();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* character = GetUser()->GetLastUsedChar();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
2022-07-24 18:04:02 +00:00
|
|
|
auto* levelComponent = entity->GetComponent<LevelProgressionComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
|
|
|
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Remove mission items
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->GetType() != eMissionTaskType::GATHER) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& param = task->GetParameters();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (param.empty() || (param[0] & 1) == 0) // Should items be removed?
|
|
|
|
{
|
|
|
|
for (const auto target : task->GetAllTargets()) {
|
2022-07-06 15:54:41 +00:00
|
|
|
// 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);
|
2022-12-18 15:46:04 +00:00
|
|
|
inventoryComponent->RemoveItem(target, task->GetClientInfo().targetValue, eInventoryType::QUEST);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
missionComponent->Progress(eMissionTaskType::GATHER, target, LWOOBJID_EMPTY, "", -task->GetClientInfo().targetValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-02-03 06:50:02 +00:00
|
|
|
int32_t coinsToSend = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->LegoScore > 0) {
|
2022-04-24 03:32:31 +00:00
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
2023-01-01 12:51:22 +00:00
|
|
|
if (levelComponent->GetLevel() >= dZoneManager::Instance()->GetWorldConfig()->levelCap) {
|
2022-02-03 06:50:02 +00:00
|
|
|
// Since the character is at the level cap we reward them with coins instead of UScore.
|
2023-01-01 12:51:22 +00:00
|
|
|
coinsToSend += info->LegoScore * dZoneManager::Instance()->GetWorldConfig()->levelCapCurrencyConversion;
|
2022-02-03 06:50:02 +00:00
|
|
|
} else {
|
|
|
|
characterComponent->SetUScore(characterComponent->GetUScore() + info->LegoScore);
|
|
|
|
GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), info->LegoScore, lootSource);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (m_Completions > 0) {
|
|
|
|
std::vector<std::pair<LOT, uint32_t>> items;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
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);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (const auto& pair : items) {
|
2022-01-14 13:00:09 +00:00
|
|
|
// 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)) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-01-14 13:00:09 +00:00
|
|
|
// If a mission rewards zero of an item, make it reward 1.
|
2021-12-05 17:54:36 +00:00
|
|
|
auto count = pair.second > 0 ? pair.second : 1;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-22 07:26:54 +00:00
|
|
|
// Sanity check, 6 is the max any mission yields
|
2021-12-05 17:54:36 +00:00
|
|
|
if (count > 6) {
|
|
|
|
count = 0;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-02-03 06:50:02 +00:00
|
|
|
if (info->reward_currency_repeatable > 0 || coinsToSend > 0) {
|
2022-04-24 03:32:31 +00:00
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
2022-02-03 06:50:02 +00:00
|
|
|
character->SetCoins(character->GetCoins() + info->reward_currency_repeatable + coinsToSend, lootSource);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<std::pair<LOT, int32_t>> items;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
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);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (const auto& pair : items) {
|
2022-01-14 13:00:09 +00:00
|
|
|
// 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.
|
2021-12-05 17:54:36 +00:00
|
|
|
if (pair.second < 0 || (m_Reward > 0 && pair.first != m_Reward)) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-01-14 13:00:09 +00:00
|
|
|
// If a mission rewards zero of an item, make it reward 1.
|
2021-12-05 17:54:36 +00:00
|
|
|
auto count = pair.second > 0 ? pair.second : 1;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-24 03:50:17 +00:00
|
|
|
// Sanity check, 6 is the max any mission yields
|
2021-12-05 17:54:36 +00:00
|
|
|
if (count > 6) {
|
|
|
|
count = 0;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-02-03 06:50:02 +00:00
|
|
|
if (info->reward_currency > 0 || coinsToSend > 0) {
|
2022-04-24 03:32:31 +00:00
|
|
|
eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT;
|
2022-02-03 06:50:02 +00:00
|
|
|
character->SetCoins(character->GetCoins() + info->reward_currency + coinsToSend, lootSource);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->reward_maxinventory > 0) {
|
|
|
|
auto* inventory = inventoryComponent->GetInventory(ITEMS);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
inventory->SetSize(inventory->GetSize() + info->reward_maxinventory);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->reward_bankinventory > 0) {
|
2022-04-13 08:49:55 +00:00
|
|
|
auto* inventory = inventoryComponent->GetInventory(eInventoryType::VAULT_ITEMS);
|
|
|
|
auto modelInventory = inventoryComponent->GetInventory(eInventoryType::VAULT_MODELS);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
inventory->SetSize(inventory->GetSize() + info->reward_bankinventory);
|
2022-04-13 08:49:55 +00:00
|
|
|
modelInventory->SetSize(modelInventory->GetSize() + info->reward_bankinventory);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->reward_reputation > 0) {
|
2022-02-05 12:08:40 +00:00
|
|
|
missionComponent->Progress(eMissionTaskType::EARN_REPUTATION, 0, 0L, "", info->reward_reputation);
|
2022-04-01 01:17:58 +00:00
|
|
|
auto character = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (character) {
|
|
|
|
character->SetReputation(character->GetReputation() + info->reward_reputation);
|
|
|
|
GameMessages::SendUpdateReputation(entity->GetObjectID(), character->GetReputation(), entity->GetSystemAddress());
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->reward_maxhealth > 0) {
|
2022-04-25 00:25:45 +00:00
|
|
|
destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast<float>(info->reward_maxhealth), true);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (info->reward_maximagination > 0) {
|
2022-04-25 00:25:45 +00:00
|
|
|
destroyableComponent->SetMaxImagination(destroyableComponent->GetMaxImagination() + static_cast<float>(info->reward_maximagination), true);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(entity);
|
|
|
|
|
|
|
|
if (info->reward_emote > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_emote2 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_emote3 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->reward_emote4 > 0) {
|
|
|
|
character->UnlockEmote(info->reward_emote4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::Progress(eMissionTaskType type, int32_t value, LWOOBJID associate, const std::string& targets, int32_t count) {
|
|
|
|
const auto isRemoval = count < 0;
|
|
|
|
|
|
|
|
if (isRemoval && (IsComplete() || IsAchievement())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
if (task->IsComplete() && !isRemoval) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (task->GetType() != type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRemoval && !task->InAllTargets(value)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
task->Progress(value, associate, targets, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetMissionState(const eMissionState state, const bool sendingRewards) {
|
|
|
|
this->m_State = state;
|
|
|
|
|
|
|
|
auto* entity = GetAssociate();
|
|
|
|
|
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameMessages::SendNotifyMission(entity, entity->GetParentUser()->GetSystemAddress(), info->id, static_cast<int>(state), sendingRewards);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetMissionTypeState(eMissionLockState state, const std::string& type, const std::string& subType) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetCompletions(const uint32_t value) {
|
|
|
|
m_Completions = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mission::SetReward(const LOT lot) {
|
|
|
|
m_Reward = lot;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mission::~Mission() {
|
|
|
|
for (auto* task : m_Tasks) {
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Tasks.clear();
|
|
|
|
}
|