#include "ElementalChestsServer.h" #include "Entity.h" #include "Character.h" #include "CDClientDatabase.h" #include "CDClientManager.h" #include "CDCurrencyTableTable.h" #include "DestroyableComponent.h" #include "GeneralUtils.h" #include "Loot.h" namespace { // RollCurrency{ iTable = 132, iLevel = 1 } constexpr uint32_t CurrencyTable = 132; constexpr uint32_t CurrencyLevel = 1; } void ElementalChestsServer::OnUse(Entity* self, Entity* user) { if (!user) return; auto* const destroyable = self->GetComponent(); const uint32_t lootMatrix = destroyable ? destroyable->GetLootMatrixID() : 0; const auto currencyRows = CDClientManager::GetTable()->Query([](const CDCurrencyTable& row) { return row.currencyIndex == CurrencyTable; }); const auto [minCoins, maxCoins] = Loot::GetActivityCoinRange(currencyRows, CurrencyLevel); Loot::DropLoot(user, self->GetObjectID(), lootMatrix, minCoins, maxCoins); if (!self->HasVar(u"CheckPrecondition")) return; const auto flag = PreconditionFlag(self->GetVarAsString(u"CheckPrecondition")); auto* const character = user->GetCharacter(); if (flag && character) character->SetPlayerFlag(*flag, true); } std::optional ElementalChestsServer::PreconditionFlag(const std::string& checkPrecondition) { const auto precondition = GeneralUtils::TryParse(checkPrecondition); if (!precondition) return std::nullopt; auto query = CDClientDatabase::CreatePreppedStmt("SELECT targetLOT FROM Preconditions WHERE id = ?;"); query.bind(1, static_cast(*precondition)); auto result = query.execQuery(); if (result.eof()) return std::nullopt; return GeneralUtils::TryParse(result.getStringField(0)); }