mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
The server hardcoded each item set's passives by set ID. They now come from data: - On-kill bonuses (Paradox imagination, Sentinel armor repair, Bat Lord heal) are the set's DarkInspiration skills in ItemSetSkills. The client turns those into a status effect that casts the behavior's action when the wearer kills something of a faction in faction_list; the server now runs the same behavior on the smashed enemy, so the amounts, faction check and extra effects (e.g. rank 3 Sorcerer team imagination) follow the data. A behavior repeated in a higher tier does not stack. - Low imagination / low armor skills are what the live equipmenttriggers item scripts do. Items link to those scripts through their ScriptComponent; the script vars (skill, items required, set, cooldown) only exist in the scripts, so they are mirrored in a small table keyed by script name. The Sentinel scripts have no cooldown (was 11s). - Knockback immunity while quickbuilding comes from the Immunity behavior's immune_quickbuild_interrupts (the 5 item Assembly rank 2/3 set skill) instead of a set ID list; ImmunityBehavior now pops its immunities when an equip skill is uncast. Removes eItemSetPassiveAbilityID and InventoryComponent::HasAnyPassive (unused now). Refs #691 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
211 lines
4.9 KiB
C++
211 lines
4.9 KiB
C++
#include "ItemSet.h"
|
|
|
|
#include "InventoryComponent.h"
|
|
#include "Entity.h"
|
|
#include "SkillComponent.h"
|
|
#include "CDClientDatabase.h"
|
|
#include "Game.h"
|
|
#include "MissionComponent.h"
|
|
#include "eMissionTaskType.h"
|
|
#include <algorithm>
|
|
#include <array>
|
|
|
|
#include "CDSkillBehaviorTable.h"
|
|
|
|
ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
|
using namespace std::string_view_literals;
|
|
|
|
this->m_ID = id;
|
|
this->m_InventoryComponent = inventoryComponent;
|
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
|
"SELECT skillSetWith2, skillSetWith3, skillSetWith4, skillSetWith5, skillSetWith6, itemIDs FROM ItemSets WHERE setID = ?;");
|
|
query.bind(1, static_cast<int>(id));
|
|
|
|
auto result = query.execQuery();
|
|
|
|
if (result.eof()) {
|
|
return;
|
|
}
|
|
|
|
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())) {
|
|
continue;
|
|
}
|
|
|
|
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
|
|
"SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = ?;");
|
|
skillQuery.bind(1, result.getIntField(rowName.data()));
|
|
|
|
auto skillResult = skillQuery.execQuery();
|
|
|
|
if (skillResult.eof()) {
|
|
continue;
|
|
}
|
|
|
|
while (!skillResult.eof()) {
|
|
if (skillResult.fieldIsNull("SkillID")) {
|
|
skillResult.nextRow();
|
|
|
|
continue;
|
|
}
|
|
|
|
const auto skillId = skillResult.getIntField("SkillID");
|
|
|
|
switch (i) {
|
|
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;
|
|
}
|
|
|
|
skillResult.nextRow();
|
|
}
|
|
}
|
|
|
|
std::string ids = result.getStringField("itemIDs");
|
|
|
|
ids.erase(std::remove_if(ids.begin(), ids.end(), ::isspace), ids.end());
|
|
|
|
std::istringstream stream(ids);
|
|
std::string token;
|
|
|
|
result.finalize();
|
|
|
|
m_Items = {};
|
|
|
|
while (std::getline(stream, token, ',')) {
|
|
const auto validToken = GeneralUtils::TryParse<int32_t>(token);
|
|
if (validToken) m_Items.push_back(validToken.value());
|
|
}
|
|
|
|
m_PassiveAbilities = ItemSetPassiveAbility::FindAbilities(id, m_Items, { m_SkillsWith2, m_SkillsWith3, m_SkillsWith4, m_SkillsWith5, m_SkillsWith6 }, m_InventoryComponent->GetParent(), this);
|
|
|
|
m_Equipped = {};
|
|
|
|
for (const auto item : m_Items) {
|
|
if (inventoryComponent->IsEquipped(item)) {
|
|
m_Equipped.push_back(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool ItemSet::Contains(const LOT lot) {
|
|
return std::find(m_Items.begin(), m_Items.end(), lot) != m_Items.end();
|
|
}
|
|
|
|
void ItemSet::OnEquip(const LOT lot) {
|
|
if (!Contains(lot)) {
|
|
return;
|
|
}
|
|
|
|
const auto& index = std::find(m_Equipped.begin(), m_Equipped.end(), lot);
|
|
|
|
if (index != m_Equipped.end()) {
|
|
return;
|
|
}
|
|
|
|
m_Equipped.push_back(lot);
|
|
|
|
const auto& skillSet = GetSkillSet(m_Equipped.size());
|
|
|
|
if (skillSet.empty()) {
|
|
return;
|
|
}
|
|
|
|
auto [skillComponent, missionComponent] = m_InventoryComponent->GetParent()->GetComponentsMut<SkillComponent, MissionComponent>();
|
|
if (!skillComponent || !missionComponent) return; // Nothing to do here if these are null
|
|
|
|
for (const auto skill : skillSet) {
|
|
auto* skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
|
|
|
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
|
|
|
|
missionComponent->Progress(eMissionTaskType::USE_SKILL, skill);
|
|
|
|
skillComponent->HandleUnmanaged(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
|
|
}
|
|
}
|
|
|
|
void ItemSet::OnUnEquip(const LOT lot) {
|
|
if (!Contains(lot)) {
|
|
return;
|
|
}
|
|
|
|
const auto& index = std::find(m_Equipped.begin(), m_Equipped.end(), lot);
|
|
|
|
if (index == m_Equipped.end()) {
|
|
return;
|
|
}
|
|
|
|
const auto& skillSet = GetSkillSet(m_Equipped.size());
|
|
|
|
m_Equipped.erase(index);
|
|
|
|
if (skillSet.empty()) {
|
|
return;
|
|
}
|
|
|
|
const auto& skillComponent = m_InventoryComponent->GetParent()->GetComponent<SkillComponent>();
|
|
|
|
for (const auto skill : skillSet) {
|
|
auto* skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
|
|
|
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
|
|
|
|
skillComponent->HandleUnCast(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
|
|
}
|
|
}
|
|
|
|
uint32_t ItemSet::GetEquippedCount() const {
|
|
return m_Equipped.size();
|
|
}
|
|
|
|
uint32_t ItemSet::GetID() const {
|
|
return m_ID;
|
|
}
|
|
|
|
void ItemSet::Update(float deltaTime) {
|
|
for (auto& passiveAbility : m_PassiveAbilities) {
|
|
passiveAbility.Update(deltaTime);
|
|
}
|
|
}
|
|
|
|
void ItemSet::TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target) {
|
|
for (auto& passiveAbility : m_PassiveAbilities) {
|
|
passiveAbility.Trigger(trigger, target);
|
|
}
|
|
}
|
|
|
|
std::vector<uint32_t> ItemSet::GetSkillSet(const uint32_t itemCount) const {
|
|
switch (itemCount) {
|
|
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 {};
|
|
}
|
|
}
|