mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(scripts): L_ELEMENTAL_CHESTS_SERVER
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>
This commit is contained in:
@@ -3,6 +3,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
|
||||
"BaseInteractDropLootServer.cpp"
|
||||
"Binoculars.cpp"
|
||||
"DoorIndicatorServer.cpp"
|
||||
"ElementalChestsServer.cpp"
|
||||
"EnemyClearThreat.cpp"
|
||||
"ExplodingAsset.cpp"
|
||||
"FrictionVolumeServer.cpp"
|
||||
|
||||
41
dScripts/02_server/Map/General/ElementalChestsServer.cpp
Normal file
41
dScripts/02_server/Map/General/ElementalChestsServer.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#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));
|
||||
}
|
||||
13
dScripts/02_server/Map/General/ElementalChestsServer.h
Normal file
13
dScripts/02_server/Map/General/ElementalChestsServer.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
#include <optional>
|
||||
|
||||
// L_ELEMENTAL_CHESTS_SERVER.lua (Fire Temple chests, LOT 16837-16841): used (its CheckPrecondition is checked on use
|
||||
// as for any object), it drops its loot matrix and coins from currency table 132 at level 1 for the player, and sets
|
||||
// the flag its precondition targets.
|
||||
class ElementalChestsServer : public CppScripts::Script {
|
||||
public:
|
||||
void OnUse(Entity* self, Entity* user) override;
|
||||
// The flag a CheckPrecondition value targets (the precondition's targetLOT), or nothing
|
||||
static std::optional<uint32_t> PreconditionFlag(const std::string& checkPrecondition);
|
||||
};
|
||||
@@ -279,6 +279,7 @@
|
||||
#include "KillCounterUtil.h"
|
||||
#include "SpinnersVol.h"
|
||||
#include "DoorIndicatorServer.h"
|
||||
#include "ElementalChestsServer.h"
|
||||
#include "SimpleOnceOnlyMoverSpinnerEvent.h"
|
||||
#include "ImaginationShrineServer.h"
|
||||
#include "Lieutenant.h"
|
||||
@@ -697,6 +698,7 @@ namespace {
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_BSPINNERS_VOL.lua", []() {return new BSpinnersVol();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_DSPINNERS_VOL.lua", []() {return new DSpinnersVol();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_DOOR_INDICATOR_SERVER.lua", []() {return new DoorIndicatorServer();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_ELEMENTAL_CHESTS_SERVER.lua", []() {return new ElementalChestsServer();}},
|
||||
{"scripts\\02_server\\Map\\General\\L_KILL_COUNTER_UTIL.lua", []() {return new KillCounterUtil();}},
|
||||
{"scripts\\02_server\\Enemy\\General\\L_ENEMY_NJ_BUFF_STUN_IMMUNITY.lua", []() {return new EnemyNjBuff();}},
|
||||
{"scripts\\02_server\\Map\\njhub\\L_IMAGINATION_SHRINE_SERVER.lua", []() {return new ImaginationShrineServer();}},
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "02_server/Map/General/KillCounterUtil.h"
|
||||
#include "02_server/Map/General/SpinnersVol.h"
|
||||
#include "02_server/Map/General/DoorIndicatorServer.h"
|
||||
#include "02_server/Map/General/ElementalChestsServer.h"
|
||||
#include "CDClientDatabase.h"
|
||||
|
||||
namespace {
|
||||
// A kill counter extension that records its limit events
|
||||
@@ -94,3 +96,13 @@ TEST_F(FireTempleScriptsTest, DoorIndicatorLightsOnEitherEvent) {
|
||||
indicator.OnFireEventServerSide(&entity, &entity, "DoorClose", 0, 0, 0);
|
||||
EXPECT_TRUE(entity.GetNetworkVar<bool>(u"FlameOn"));
|
||||
}
|
||||
|
||||
// L_ELEMENTAL_CHESTS_SERVER: the flag set on use is the chest's precondition's target
|
||||
TEST_F(FireTempleScriptsTest, ElementalChestFlagIsItsPreconditionsTarget) {
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE Preconditions (id INTEGER, type INTEGER, targetLOT TEXT, targetCount INTEGER, validContexts INTEGER);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO Preconditions VALUES (321, 23, '2063', 1, 0);");
|
||||
EXPECT_EQ(ElementalChestsServer::PreconditionFlag("321"), 2063u);
|
||||
EXPECT_EQ(ElementalChestsServer::PreconditionFlag("322"), std::nullopt);
|
||||
EXPECT_EQ(ElementalChestsServer::PreconditionFlag(""), std::nullopt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user