mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
A spawner with spawnsGroupOnSmash and spawnNetNameForSpawnGroupOnSmash naming a zone spawner network only logged when an object of that network died, so quick builds behind crates (Fire Temple rooms and waves, Aura Mar bouncers) never appeared. A spawner with no_auto_spawn now spawns when an object of the named network dies, as the group paths already did. A spawner without no_auto_spawn is not linked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
3.8 KiB
C++
116 lines
3.8 KiB
C++
#include "GameDependencies.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
#include "CDClientManager.h"
|
|
#include "CDComponentsRegistryTable.h"
|
|
#include "Entity.h"
|
|
#include "EntityManager.h"
|
|
#include "Spawner.h"
|
|
#include "dZoneManager.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
// A spawner with spawnsGroupOnSmash and spawnNetNameForSpawnGroupOnSmash spawns when an object of the zone spawner
|
|
// network it names (a crate) dies.
|
|
class SpawnOnSmashTests : public GameDependenciesTest {
|
|
protected:
|
|
static constexpr LOT CrateLot = 16830;
|
|
static constexpr LOT QuickBuildLot = 16834;
|
|
static constexpr const char* CrateNetwork = "Room02Smash01";
|
|
|
|
void SetUp() override {
|
|
SetUpDependencies();
|
|
// Creating an entity looks its LOT up in the CDClient
|
|
CDClientDatabase::Connect(":memory:");
|
|
for (const auto* const table : {
|
|
"ComponentsRegistry (id INTEGER, component_type INTEGER, component_id INTEGER)",
|
|
"Objects (id INTEGER, name TEXT, type TEXT, interactionDistance REAL)",
|
|
}) {
|
|
CDClientDatabase::ExecuteDML(std::string("CREATE TABLE IF NOT EXISTS ") + table + ";");
|
|
}
|
|
// None of these LOTs has components, so nothing is looked up in a database
|
|
auto& registry = CDClientManager::GetEntriesMutable<CDComponentsRegistryTable>();
|
|
for (const LOT lot : { 176, CrateLot, QuickBuildLot }) registry.insert_or_assign(static_cast<uint64_t>(lot), 0);
|
|
}
|
|
|
|
void TearDown() override { TearDownDependencies(); }
|
|
|
|
SpawnerInfo WithOneNode(const LOT lot) {
|
|
SpawnerInfo spawnerInfo{};
|
|
spawnerInfo.templateID = lot;
|
|
spawnerInfo.nodes.push_back(m_Nodes.emplace_back(std::make_unique<SpawnerNode>()).get());
|
|
return spawnerInfo;
|
|
}
|
|
|
|
// The zone spawner network, made first as the zone file is loaded before the levels
|
|
Spawner* MakeCrateNetwork() {
|
|
auto spawnerInfo = WithOneNode(CrateLot);
|
|
spawnerInfo.name = CrateNetwork;
|
|
spawnerInfo.isNetwork = true;
|
|
return Game::zoneManager->GetSpawner(Game::zoneManager->MakeSpawner(spawnerInfo));
|
|
}
|
|
|
|
Spawner* MakeQuickBuild(const bool noAutoSpawn) {
|
|
auto spawnerInfo = WithOneNode(QuickBuildLot);
|
|
spawnerInfo.spawnsOnSmash = true;
|
|
spawnerInfo.spawnOnSmashGroupName = CrateNetwork;
|
|
spawnerInfo.noAutoSpawn = noAutoSpawn;
|
|
spawnerInfo.respawnTime = 20.0f;
|
|
return Game::zoneManager->GetSpawner(Game::zoneManager->MakeSpawner(spawnerInfo));
|
|
}
|
|
|
|
static void SmashCrate(Spawner& crates) {
|
|
auto* const crate = crates.Spawn();
|
|
ASSERT_NE(crate, nullptr);
|
|
crates.NotifyOfEntityDeath(crate->GetObjectID());
|
|
}
|
|
|
|
std::vector<std::unique_ptr<SpawnerNode>> m_Nodes;
|
|
};
|
|
|
|
TEST_F(SpawnOnSmashTests, TheQuickBuildWaitsForTheSmash) {
|
|
MakeCrateNetwork();
|
|
auto* const quickBuild = MakeQuickBuild(true);
|
|
ASSERT_NE(quickBuild, nullptr);
|
|
EXPECT_TRUE(quickBuild->GetIsSpawnSmashGroup());
|
|
|
|
// No timed spawn before the crate is smashed
|
|
quickBuild->Update(30.0f);
|
|
quickBuild->Update(30.0f);
|
|
EXPECT_TRUE(quickBuild->GetSpawnedObjectIDs().empty());
|
|
}
|
|
|
|
TEST_F(SpawnOnSmashTests, SmashingTheCrateSpawnsTheQuickBuild) {
|
|
auto* const crates = MakeCrateNetwork();
|
|
auto* const quickBuild = MakeQuickBuild(true);
|
|
ASSERT_NE(crates, nullptr);
|
|
ASSERT_NE(quickBuild, nullptr);
|
|
|
|
SmashCrate(*crates);
|
|
|
|
const auto spawned = quickBuild->GetSpawnedObjectIDs();
|
|
ASSERT_EQ(spawned.size(), 1);
|
|
auto* const entity = Game::entityManager->GetEntity(spawned[0]);
|
|
ASSERT_NE(entity, nullptr);
|
|
EXPECT_EQ(entity->GetLOT(), QuickBuildLot);
|
|
}
|
|
|
|
TEST_F(SpawnOnSmashTests, AnotherSmashKeepsOneQuickBuild) {
|
|
auto* const crates = MakeCrateNetwork();
|
|
auto* const quickBuild = MakeQuickBuild(true);
|
|
|
|
SmashCrate(*crates);
|
|
SmashCrate(*crates);
|
|
|
|
EXPECT_EQ(quickBuild->GetSpawnedObjectIDs().size(), 1);
|
|
}
|
|
|
|
TEST_F(SpawnOnSmashTests, WithoutNoAutoSpawnTheSmashSpawnsNothing) {
|
|
auto* const crates = MakeCrateNetwork();
|
|
auto* const quickBuild = MakeQuickBuild(false);
|
|
|
|
SmashCrate(*crates);
|
|
|
|
EXPECT_TRUE(quickBuild->GetSpawnedObjectIDs().empty());
|
|
}
|