DarkflameServer/dGame/dMission/Mission.cpp

629 lines
17 KiB
C++
Raw Permalink Normal View History

#include "Mission.h"
#include <ctime>
#include "CDClientManager.h"
#include "Character.h"
#include "CharacterComponent.h"
#include "LevelProgressionComponent.h"
#include "DestroyableComponent.h"
#include "EntityManager.h"
#include "Game.h"
#include "GameMessages.h"
#include "Mail.h"
#include "MissionComponent.h"
#include "eRacingTaskParam.h"
#include "Logger.h"
#include "dServer.h"
#include "dZoneManager.h"
#include "InventoryComponent.h"
#include "User.h"
2022-03-30 06:46:56 +00:00
#include "Database.h"
#include "WorldConfig.h"
#include "eMissionState.h"
#include "eMissionTaskType.h"
#include "eMissionLockState.h"
#include "eReplicaComponentType.h"
#include "Character.h"
#include "CDMissionEmailTable.h"
Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
2022-07-28 13:39:57 +00:00
m_MissionComponent = missionComponent;
2022-07-28 13:39:57 +00:00
m_Completions = 0;
2022-07-28 13:39:57 +00:00
m_Timestamp = 0;
m_UniqueMissionID = Game::zoneManager->GetUniqueMissionIdStartingValue();
2022-07-28 13:39:57 +00:00
m_Reward = 0;
m_State = eMissionState::UNKNOWN;
auto* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
2023-08-12 09:11:25 +00:00
auto* mis = missionsTable->GetPtrByMissionID(missionId);
info = *mis;
2023-08-12 09:11:25 +00:00
if (mis == &CDMissionsTable::Default) {
LOG("Failed to find mission (%i)!", missionId);
2022-07-28 13:39:57 +00:00
return;
}
auto* tasksTable = CDClientManager::GetTable<CDMissionTasksTable>();
2022-07-28 13:39:57 +00:00
auto tasks = tasksTable->GetByMissionID(missionId);
2022-07-28 13:39:57 +00:00
for (auto i = 0U; i < tasks.size(); ++i) {
auto* info = tasks[i];
2022-07-28 13:39:57 +00:00
auto* task = new MissionTask(this, info, i);
2022-07-28 13:39:57 +00:00
m_Tasks.push_back(task);
}
}
void Mission::LoadFromXml(const tinyxml2::XMLElement& element) {
2022-07-28 13:39:57 +00:00
// Start custom XML
if (element.Attribute("state") != nullptr) {
m_State = static_cast<eMissionState>(std::stoul(element.Attribute("state")));
2022-07-28 13:39:57 +00:00
}
// End custom XML
if (element.Attribute("cct") != nullptr) {
m_Completions = std::stoul(element.Attribute("cct"));
m_Timestamp = std::stoul(element.Attribute("cts"));
2022-07-28 13:39:57 +00:00
if (IsComplete()) {
return;
}
}
auto* task = element.FirstChildElement();
2022-07-28 13:39:57 +00:00
auto index = 0U;
2022-07-28 13:39:57 +00:00
while (task != nullptr) {
if (index >= m_Tasks.size()) {
break;
}
2022-07-28 13:39:57 +00:00
const auto type = m_Tasks[index]->GetType();
if (type == eMissionTaskType::COLLECTION ||
type == eMissionTaskType::VISIT_PROPERTY) {
2022-07-28 13:39:57 +00:00
std::vector<uint32_t> uniques;
2022-07-28 13:39:57 +00:00
const auto value = std::stoul(task->Attribute("v"));
2022-07-28 13:39:57 +00:00
m_Tasks[index]->SetProgress(value, false);
2022-07-28 13:39:57 +00:00
task = task->NextSiblingElement();
2022-07-28 13:39:57 +00:00
while (task != nullptr) {
const auto unique = std::stoul(task->Attribute("v"));
2022-07-28 13:39:57 +00:00
uniques.push_back(unique);
if (m_MissionComponent != nullptr && type == eMissionTaskType::COLLECTION) {
2022-07-28 13:39:57 +00:00
m_MissionComponent->AddCollectible(unique);
}
2022-07-28 13:39:57 +00:00
task = task->NextSiblingElement();
}
2022-07-28 13:39:57 +00:00
m_Tasks[index]->SetUnique(uniques);
2022-07-28 13:39:57 +00:00
m_Tasks[index]->SetProgress(uniques.size(), false);
2022-07-28 13:39:57 +00:00
break;
} else {
const auto value = std::stoul(task->Attribute("v"));
2022-07-28 13:39:57 +00:00
m_Tasks[index]->SetProgress(value, false);
2022-07-28 13:39:57 +00:00
task = task->NextSiblingElement();
}
2022-07-28 13:39:57 +00:00
index++;
}
}
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));
2022-07-28 13:39:57 +00:00
// End custom XML
element.DeleteChildren();
element.SetAttribute("id", static_cast<unsigned int>(info.id));
2022-07-28 13:39:57 +00:00
if (m_Completions > 0) {
element.SetAttribute("cct", static_cast<unsigned int>(m_Completions));
element.SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
2022-07-28 13:39:57 +00:00
if (IsComplete()) {
return;
}
}
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
if (task->GetType() == eMissionTaskType::COLLECTION ||
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
auto* child = element.GetDocument()->NewElement("sv");
2022-07-28 13:39:57 +00:00
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child);
2022-07-28 13:39:57 +00:00
for (auto unique : task->GetUnique()) {
auto* uniqueElement = element.GetDocument()->NewElement("sv");
2022-07-28 13:39:57 +00:00
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
element.LinkEndChild(uniqueElement);
2022-07-28 13:39:57 +00:00
}
2022-07-28 13:39:57 +00:00
break;
}
auto* child = element.GetDocument()->NewElement("sv");
2022-07-28 13:39:57 +00:00
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child);
2022-07-28 13:39:57 +00:00
}
}
bool Mission::IsValidMission(const uint32_t missionId) {
auto* table = CDClientManager::GetTable<CDMissionsTable>();
2022-07-28 13:39:57 +00:00
const auto missions = table->Query([=](const CDMissions& entry) {
return entry.id == static_cast<int>(missionId);
});
2022-07-28 13:39:57 +00:00
return !missions.empty();
}
bool Mission::IsValidMission(const uint32_t missionId, CDMissions& info) {
auto* table = CDClientManager::GetTable<CDMissionsTable>();
2022-07-28 13:39:57 +00:00
const auto missions = table->Query([=](const CDMissions& entry) {
return entry.id == static_cast<int>(missionId);
});
2022-07-28 13:39:57 +00:00
if (missions.empty()) {
return false;
}
2022-07-28 13:39:57 +00:00
info = missions[0];
2022-07-28 13:39:57 +00:00
return true;
}
Entity* Mission::GetAssociate() const {
2022-07-28 13:39:57 +00:00
return m_MissionComponent->GetParent();
}
Character* Mission::GetCharacter() const {
return GetAssociate()->GetCharacter();
}
uint32_t Mission::GetMissionId() const {
2023-08-12 09:11:25 +00:00
return info.id;
}
const CDMissions& Mission::GetClientInfo() const {
2023-08-12 09:11:25 +00:00
return info;
}
uint32_t Mission::GetCompletions() const {
2022-07-28 13:39:57 +00:00
return m_Completions;
}
uint32_t Mission::GetTimestamp() const {
2022-07-28 13:39:57 +00:00
return m_Timestamp;
}
LOT Mission::GetReward() const {
2022-07-28 13:39:57 +00:00
return m_Reward;
}
std::vector<MissionTask*> Mission::GetTasks() const {
2022-07-28 13:39:57 +00:00
return m_Tasks;
}
eMissionState Mission::GetMissionState() const {
2022-07-28 13:39:57 +00:00
return m_State;
}
bool Mission::IsAchievement() const {
2023-08-12 09:11:25 +00:00
return !info.isMission;
}
bool Mission::IsMission() const {
2023-08-12 09:11:25 +00:00
return info.isMission;
}
bool Mission::IsRepeatable() const {
2023-08-12 09:11:25 +00:00
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_ACTIVE;
}
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() {
2023-08-12 09:11:25 +00:00
SetMissionTypeState(eMissionLockState::NEW, info.defined_type, info.defined_subtype);
SetMissionState(m_Completions > 0 ? eMissionState::COMPLETE_ACTIVE : eMissionState::ACTIVE);
2022-07-28 13:39:57 +00:00
Catchup();
}
void Mission::Complete(const bool yieldRewards) {
if (m_State != eMissionState::ACTIVE && m_State != eMissionState::COMPLETE_ACTIVE) {
// 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();
}
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
task->Complete();
}
SetMissionState(eMissionState::REWARDING, true);
2022-07-28 13:39:57 +00:00
if (yieldRewards) {
YieldRewards();
}
SetMissionState(eMissionState::COMPLETE);
2022-07-28 13:39:57 +00:00
m_Completions++;
2022-07-28 13:39:57 +00:00
m_Timestamp = std::time(nullptr);
2022-07-28 13:39:57 +00:00
auto* entity = GetAssociate();
2022-07-28 13:39:57 +00:00
if (entity == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
auto* characterComponent = entity->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
2023-08-12 09:11:25 +00:00
characterComponent->TrackMissionCompletion(!info.isMission);
2022-07-28 13:39:57 +00:00
}
2022-07-28 13:39:57 +00:00
auto* missionComponent = entity->GetComponent<MissionComponent>();
2023-08-12 09:11:25 +00:00
missionComponent->Progress(eMissionTaskType::META, info.id);
missionComponent->Progress(eMissionTaskType::RACING, info.id, static_cast<LWOOBJID>(eRacingTaskParam::COMPLETE_ANY_RACING_TASK));
Implementing and Fixing All Racing Achievements (#366) * Grammatical changes in comments * Grammatical fixes in comments Small grammatical fixes found in comments throughout the code. * Added descriptions to functions Added descriptions to functions that didn't have them to keep the code well documented * Created RacingTaskParam.h Created RacingTaskParam so eliminate magic numbers in the original implementation of completing racing missions. * Updated magic numbers in Mission.cpp Updated magic numbers in Mission.cpp to a meaningful name. * Implemented racing smashable task progression Previously, races did not progress tasks for smashing Entities. Now all achievements tracking smashables track them correctly. This has been implemented in the three Entities that can be smashed in a race (imagination boxes, track specific smashables, Forbidden Valley dragon eggs). * Updated race imagination task progression Race imagination now no longer uses a magic number when passed to missionComponent. Instead we use a number defined in an enum located in RacingTaskParam.h * Updated Race task checks Racing tasks for completing races without smashing now no longer auto complete the whole chain of missions. Tasks that track placing on tracks and races overall now properly complete. Tasks that count how many missions in a zone are completed now function. Tasks that track race completions in multiple areas now function. * Updated RacingControlComponent.cpp Fixed any tasks that required 3 players to now require 3 or more players in a race to progress. This restriction is ignored if the world config opted in for solo racing to allow progression in solo worlds. Updated magic numbers sent into missionComponent->Progress to an enum created in this PR. Fixed some indentation. * Fixed a grammatical error in variable name Fixed a grammatical error in the enum for task params
2022-02-05 11:28:17 +00:00
missionComponent->Progress(eMissionTaskType::RACING, info.id, static_cast<LWOOBJID>(eRacingTaskParam::COMPLETE_TRACK_TASKS));
Implementing and Fixing All Racing Achievements (#366) * Grammatical changes in comments * Grammatical fixes in comments Small grammatical fixes found in comments throughout the code. * Added descriptions to functions Added descriptions to functions that didn't have them to keep the code well documented * Created RacingTaskParam.h Created RacingTaskParam so eliminate magic numbers in the original implementation of completing racing missions. * Updated magic numbers in Mission.cpp Updated magic numbers in Mission.cpp to a meaningful name. * Implemented racing smashable task progression Previously, races did not progress tasks for smashing Entities. Now all achievements tracking smashables track them correctly. This has been implemented in the three Entities that can be smashed in a race (imagination boxes, track specific smashables, Forbidden Valley dragon eggs). * Updated race imagination task progression Race imagination now no longer uses a magic number when passed to missionComponent. Instead we use a number defined in an enum located in RacingTaskParam.h * Updated Race task checks Racing tasks for completing races without smashing now no longer auto complete the whole chain of missions. Tasks that track placing on tracks and races overall now properly complete. Tasks that count how many missions in a zone are completed now function. Tasks that track race completions in multiple areas now function. * Updated RacingControlComponent.cpp Fixed any tasks that required 3 players to now require 3 or more players in a race to progress. This restriction is ignored if the world config opted in for solo racing to allow progression in solo worlds. Updated magic numbers sent into missionComponent->Progress to an enum created in this PR. Fixed some indentation. * Fixed a grammatical error in variable name Fixed a grammatical error in the enum for task params
2022-02-05 11:28:17 +00:00
auto* missionEmailTable = CDClientManager::GetTable<CDMissionEmailTable>();
2022-07-28 13:39:57 +00:00
const auto missionId = GetMissionId();
2022-07-28 13:39:57 +00:00
const auto missionEmails = missionEmailTable->Query([missionId](const CDMissionEmail& entry) {
return entry.missionID == missionId;
});
2022-07-28 13:39:57 +00:00
for (const auto& email : missionEmails) {
const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_";
if (email.messageType == 1) {
const auto subject = "%[" + missionEmailBase + "subjectText]";
const auto body = "%[" + missionEmailBase + "bodyText]";
const auto sender = "%[" + missionEmailBase + "senderName]";
2022-07-28 13:39:57 +00:00
Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1);
}
}
}
void Mission::CheckCompletion() {
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
if (!task->IsComplete()) {
return;
}
}
2022-07-28 13:39:57 +00:00
if (IsAchievement()) {
Complete();
2022-07-28 13:39:57 +00:00
return;
}
2022-07-28 13:39:57 +00:00
MakeReadyToComplete();
}
void Mission::Catchup() {
2022-07-28 13:39:57 +00:00
auto* entity = GetAssociate();
auto* inventory = static_cast<InventoryComponent*>(entity->GetComponent(eReplicaComponentType::INVENTORY));
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
const auto type = task->GetType();
if (type == eMissionTaskType::GATHER) {
2022-07-28 13:39:57 +00:00
for (auto target : task->GetAllTargets()) {
const auto count = inventory->GetLotCountNonTransfer(target);
2022-07-28 13:39:57 +00:00
for (auto i = 0U; i < count; ++i) {
task->Progress(target);
}
}
}
if (type == eMissionTaskType::PLAYER_FLAG) {
for (int32_t target : task->GetAllTargets()) {
const auto flag = GetCharacter()->GetPlayerFlag(target);
2022-07-28 13:39:57 +00:00
if (!flag) {
continue;
}
2022-07-28 13:39:57 +00:00
task->Progress(target);
2022-07-28 13:39:57 +00:00
if (task->IsComplete()) {
break;
}
}
}
}
}
void Mission::YieldRewards() {
2022-07-28 13:39:57 +00:00
auto* entity = GetAssociate();
if (entity == nullptr) {
return;
}
auto* character = GetCharacter();
2022-07-28 13:39:57 +00:00
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() != eMissionTaskType::GATHER) {
2022-07-28 13:39:57 +00:00
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::QUEST);
2022-07-28 13:39:57 +00:00
missionComponent->Progress(eMissionTaskType::GATHER, target, LWOOBJID_EMPTY, "", -task->GetClientInfo().targetValue);
2022-07-28 13:39:57 +00:00
}
}
}
int32_t coinsToSend = 0;
2023-08-12 09:11:25 +00:00
if (info.LegoScore > 0) {
eLootSourceType lootSource = info.isMission ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT;
if (levelComponent->GetLevel() >= Game::zoneManager->GetWorldConfig()->levelCap) {
2022-07-28 13:39:57 +00:00
// Since the character is at the level cap we reward them with coins instead of UScore.
2023-08-12 09:11:25 +00:00
coinsToSend += info.LegoScore * Game::zoneManager->GetWorldConfig()->levelCapCurrencyConversion;
2022-07-28 13:39:57 +00:00
} else {
2023-08-12 09:11:25 +00:00
characterComponent->SetUScore(characterComponent->GetUScore() + info.LegoScore);
GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), info.LegoScore, lootSource);
2022-07-28 13:39:57 +00:00
}
}
// Even with no repeatable column, reputation is repeatable
if (info.reward_reputation > 0) {
missionComponent->Progress(eMissionTaskType::EARN_REPUTATION, 0, LWOOBJID_EMPTY, "", info.reward_reputation);
auto* const character = entity->GetComponent<CharacterComponent>();
if (character) {
character->SetReputation(character->GetReputation() + info.reward_reputation);
GameMessages::SendUpdateReputation(entity->GetObjectID(), character->GetReputation(), entity->GetSystemAddress());
}
}
2022-07-28 13:39:57 +00:00
if (m_Completions > 0) {
std::vector<std::pair<LOT, uint32_t>> items;
2023-08-12 09:11:25 +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
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::MISSION : eLootSourceType::ACHIEVEMENT);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_currency_repeatable > 0 || coinsToSend > 0) {
eLootSourceType lootSource = info.isMission ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT;
character->SetCoins(character->GetCoins() + info.reward_currency_repeatable + coinsToSend, lootSource);
2022-07-28 13:39:57 +00:00
}
return;
}
std::vector<std::pair<LOT, int32_t>> items;
2023-08-12 09:11:25 +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
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::MISSION : eLootSourceType::ACHIEVEMENT);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_currency > 0 || coinsToSend > 0) {
eLootSourceType lootSource = info.isMission ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT;
character->SetCoins(character->GetCoins() + info.reward_currency + coinsToSend, lootSource);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_maxinventory > 0) {
2022-07-28 13:39:57 +00:00
auto* inventory = inventoryComponent->GetInventory(ITEMS);
2023-08-12 09:11:25 +00:00
inventory->SetSize(inventory->GetSize() + info.reward_maxinventory);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_bankinventory > 0) {
2022-07-28 13:39:57 +00:00
auto* inventory = inventoryComponent->GetInventory(eInventoryType::VAULT_ITEMS);
auto modelInventory = inventoryComponent->GetInventory(eInventoryType::VAULT_MODELS);
2023-08-12 09:11:25 +00:00
inventory->SetSize(inventory->GetSize() + info.reward_bankinventory);
modelInventory->SetSize(modelInventory->GetSize() + info.reward_bankinventory);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_maxhealth > 0) {
destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast<float>(info.reward_maxhealth), true);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_maximagination > 0) {
destroyableComponent->SetMaxImagination(destroyableComponent->GetMaxImagination() + static_cast<float>(info.reward_maximagination), true);
2022-07-28 13:39:57 +00:00
}
Game::entityManager->SerializeEntity(entity);
2023-08-12 09:11:25 +00:00
if (info.reward_emote > 0) {
character->UnlockEmote(info.reward_emote);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_emote2 > 0) {
character->UnlockEmote(info.reward_emote2);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_emote3 > 0) {
character->UnlockEmote(info.reward_emote3);
2022-07-28 13:39:57 +00:00
}
2023-08-12 09:11:25 +00:00
if (info.reward_emote4 > 0) {
character->UnlockEmote(info.reward_emote4);
2022-07-28 13:39:57 +00:00
}
}
void Mission::Progress(eMissionTaskType 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;
2022-07-28 13:39:57 +00:00
if (isRemoval && (IsComplete() || IsAchievement())) {
return;
}
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
if (task->IsComplete() && !isRemoval) {
continue;
}
2022-07-28 13:39:57 +00:00
if (task->GetType() != type) {
continue;
}
2022-07-28 13:39:57 +00:00
if (isRemoval && !task->InAllTargets(value)) {
continue;
}
2022-07-28 13:39:57 +00:00
task->Progress(value, associate, targets, count);
}
}
void Mission::SetMissionState(const eMissionState state, const bool sendingRewards) {
2022-07-28 13:39:57 +00:00
this->m_State = state;
2022-07-28 13:39:57 +00:00
auto* entity = GetAssociate();
2022-07-28 13:39:57 +00:00
if (entity == nullptr) {
return;
}
auto* characterComponent = entity->GetComponent<CharacterComponent>();
if (!characterComponent) return;
GameMessages::SendNotifyMission(entity, characterComponent->GetSystemAddress(), info.id, static_cast<int>(state), sendingRewards);
}
void Mission::SetMissionTypeState(eMissionLockState state, const std::string& type, const std::string& subType) {
2022-07-28 13:39:57 +00:00
// TODO
}
void Mission::SetCompletions(const uint32_t value) {
2022-07-28 13:39:57 +00:00
m_Completions = value;
}
void Mission::SetReward(const LOT lot) {
2022-07-28 13:39:57 +00:00
m_Reward = lot;
}
Mission::~Mission() {
2022-07-28 13:39:57 +00:00
for (auto* task : m_Tasks) {
delete task;
}
2022-07-28 13:39:57 +00:00
m_Tasks.clear();
}