mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
The Fire Temple chests drop their loot matrix and coins from currency table 132 at level 1 for the player, and set the flag their precondition targets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.7 KiB
C++
42 lines
1.7 KiB
C++
#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<DestroyableComponent>();
|
|
const uint32_t lootMatrix = destroyable ? destroyable->GetLootMatrixID() : 0;
|
|
const auto currencyRows = CDClientManager::GetTable<CDCurrencyTableTable>()->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<uint32_t> ElementalChestsServer::PreconditionFlag(const std::string& checkPrecondition) {
|
|
const auto precondition = GeneralUtils::TryParse<uint32_t>(checkPrecondition);
|
|
if (!precondition) return std::nullopt;
|
|
auto query = CDClientDatabase::CreatePreppedStmt("SELECT targetLOT FROM Preconditions WHERE id = ?;");
|
|
query.bind(1, static_cast<int32_t>(*precondition));
|
|
auto result = query.execQuery();
|
|
if (result.eof()) return std::nullopt;
|
|
return GeneralUtils::TryParse<uint32_t>(result.getStringField(0));
|
|
}
|