2022-08-06 03:01:59 +00:00
|
|
|
#include "ItemSet.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "InventoryComponent.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "MissionComponent.h"
|
2023-01-22 23:38:47 +00:00
|
|
|
#include "eMissionTaskType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include <algorithm>
|
2024-04-14 04:41:51 +00:00
|
|
|
#include <array>
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDSkillBehaviorTable.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
2024-04-14 04:41:51 +00:00
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_ID = id;
|
|
|
|
this->m_InventoryComponent = inventoryComponent;
|
|
|
|
|
|
|
|
this->m_PassiveAbilities = ItemSetPassiveAbility::FindAbilities(id, m_InventoryComponent->GetParent(), this);
|
|
|
|
|
2022-01-13 03:48:27 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
|
|
|
"SELECT skillSetWith2, skillSetWith3, skillSetWith4, skillSetWith5, skillSetWith6, itemIDs FROM ItemSets WHERE setID = ?;");
|
2023-12-28 04:18:20 +00:00
|
|
|
query.bind(1, static_cast<int>(id));
|
2022-01-13 03:48:27 +00:00
|
|
|
|
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (result.eof()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2024-04-14 04:41:51 +00:00
|
|
|
constexpr std::array rowNames = { "skillSetWith2"sv, "skillSetWith3"sv, "skillSetWith4"sv, "skillSetWith5"sv, "skillSetWith6"sv };
|
|
|
|
for (auto i = 0; i < rowNames.size(); ++i) {
|
|
|
|
const auto rowName = rowNames[i];
|
|
|
|
if (result.fieldIsNull(rowName.data())) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-13 03:48:27 +00:00
|
|
|
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
|
|
|
|
"SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = ?;");
|
2024-04-14 04:41:51 +00:00
|
|
|
skillQuery.bind(1, result.getIntField(rowName.data()));
|
2022-01-13 03:48:27 +00:00
|
|
|
|
|
|
|
auto skillResult = skillQuery.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (skillResult.eof()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
while (!skillResult.eof()) {
|
2024-04-14 04:41:51 +00:00
|
|
|
if (skillResult.fieldIsNull("SkillID")) {
|
2021-12-05 17:54:36 +00:00
|
|
|
skillResult.nextRow();
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2024-04-14 04:41:51 +00:00
|
|
|
const auto skillId = skillResult.getIntField("SkillID");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
switch (i) {
|
2021-12-05 17:54:36 +00:00
|
|
|
case 0:
|
|
|
|
m_SkillsWith2.push_back(skillId);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
m_SkillsWith3.push_back(skillId);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_SkillsWith4.push_back(skillId);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_SkillsWith5.push_back(skillId);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_SkillsWith6.push_back(skillId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
skillResult.nextRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 04:41:51 +00:00
|
|
|
std::string ids = result.getStringField("itemIDs");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
ids.erase(std::remove_if(ids.begin(), ids.end(), ::isspace), ids.end());
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::istringstream stream(ids);
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
result.finalize();
|
|
|
|
|
|
|
|
m_Items = {};
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
while (std::getline(stream, token, ',')) {
|
2024-02-10 11:05:25 +00:00
|
|
|
const auto validToken = GeneralUtils::TryParse<int32_t>(token);
|
|
|
|
if (validToken) m_Items.push_back(validToken.value());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Equipped = {};
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto item : m_Items) {
|
|
|
|
if (inventoryComponent->IsEquipped(item)) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Equipped.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool ItemSet::Contains(const LOT lot) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return std::find(m_Items.begin(), m_Items.end(), lot) != m_Items.end();
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ItemSet::OnEquip(const LOT lot) {
|
|
|
|
if (!Contains(lot)) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& index = std::find(m_Equipped.begin(), m_Equipped.end(), lot);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (index != m_Equipped.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Equipped.push_back(lot);
|
|
|
|
|
|
|
|
const auto& skillSet = GetSkillSet(m_Equipped.size());
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (skillSet.empty()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* skillComponent = m_InventoryComponent->GetParent()->GetComponent<SkillComponent>();
|
|
|
|
auto* missionComponent = m_InventoryComponent->GetParent()->GetComponent<MissionComponent>();
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto skill : skillSet) {
|
2024-02-09 05:40:43 +00:00
|
|
|
auto* skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
|
|
|
|
|
2023-01-22 23:38:47 +00:00
|
|
|
missionComponent->Progress(eMissionTaskType::USE_SKILL, skill);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
skillComponent->HandleUnmanaged(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ItemSet::OnUnEquip(const LOT lot) {
|
|
|
|
if (!Contains(lot)) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& index = std::find(m_Equipped.begin(), m_Equipped.end(), lot);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (index == m_Equipped.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& skillSet = GetSkillSet(m_Equipped.size());
|
|
|
|
|
|
|
|
m_Equipped.erase(index);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (skillSet.empty()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& skillComponent = m_InventoryComponent->GetParent()->GetComponent<SkillComponent>();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto skill : skillSet) {
|
2024-02-09 05:40:43 +00:00
|
|
|
auto* skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
|
|
|
|
|
|
|
|
skillComponent->HandleUnCast(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t ItemSet::GetEquippedCount() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Equipped.size();
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t ItemSet::GetID() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_ID;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ItemSet::Update(float deltaTime) {
|
|
|
|
for (auto& passiveAbility : m_PassiveAbilities) {
|
2021-12-05 17:54:36 +00:00
|
|
|
passiveAbility.Update(deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-24 02:05:30 +00:00
|
|
|
void ItemSet::TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target) {
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto& passiveAbility : m_PassiveAbilities) {
|
2022-12-24 02:05:30 +00:00
|
|
|
passiveAbility.Trigger(trigger, target);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<uint32_t> ItemSet::GetSkillSet(const uint32_t itemCount) const {
|
|
|
|
switch (itemCount) {
|
2021-12-05 17:54:36 +00:00
|
|
|
case 2:
|
|
|
|
return m_SkillsWith2;
|
|
|
|
case 3:
|
|
|
|
return m_SkillsWith3;
|
|
|
|
case 4:
|
|
|
|
return m_SkillsWith4;
|
|
|
|
case 5:
|
|
|
|
return m_SkillsWith5;
|
|
|
|
case 6:
|
|
|
|
return m_SkillsWith6;
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|