Files
DarkflameServer/dScripts/02_server/Map/njhub/FallingTile.cpp
Aaron Kimbrell 908d1954bd fix(njhub): falling tiles play their sounds as live did
Shaking once stepped on, landing at waypoint 1 (the shaking stops), rising when sent back, stopped at waypoint 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 11:14:40 -06:00

70 lines
2.2 KiB
C++

#include "FallingTile.h"
#include "MovingPlatformComponent.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
namespace {
// The sounds live played on the tile: shaking once stepped on, landing, and rising back
constexpr const char* ShakeSound = "{b7b848ad-7db0-4d51-a664-e38b386607dc}";
constexpr const char* LandSound = "{7665b557-a611-4718-8bb1-9bb1fb0f8f0f}";
constexpr const char* RiseSound = "{6f07abbd-1710-4047-8d54-e772c22a970f}";
}
void FallingTile::OnStartup(Entity* self) {
auto* movingPlatfromComponent = self->GetComponent<MovingPlatformComponent>();
if (movingPlatfromComponent == nullptr) {
return;
}
movingPlatfromComponent->SetSerialized(true);
}
void FallingTile::OnCollisionPhantom(Entity* self, Entity* target) {
if (self->GetVar<bool>(u"AboutToFall")) {
return;
}
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), ShakeSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
self->AddTimer("flipTime", 0.75f);
self->SetVar<bool>(u"AboutToFall", true);
self->SetNetworkVar<float>(u"startEffect", 2);
}
void FallingTile::OnWaypointReached(Entity* self, uint32_t waypointIndex) {
if (waypointIndex == 1) {
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), LandSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::StopNDAudioEmitter(self->GetObjectID(), ShakeSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
} else if (waypointIndex == 0) {
GameMessages::StopNDAudioEmitter(self->GetObjectID(), RiseSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}
void FallingTile::OnTimerDone(Entity* self, std::string timerName) {
auto* movingPlatfromComponent = self->GetComponent<MovingPlatformComponent>();
if (movingPlatfromComponent == nullptr) {
return;
}
if (timerName == "flipTime") {
self->AddTimer("flipBack", 2.0f);
self->SetNetworkVar<float>(u"stopEffect", 3);
movingPlatfromComponent->GotoWaypoint(1);
GameMessages::PlayFXEffect(self->GetObjectID(), -1, u"down", "down").Send(UNASSIGNED_SYSTEM_ADDRESS);
} else if (timerName == "flipBack") {
self->SetVar<bool>(u"AboutToFall", false);
movingPlatfromComponent->GotoWaypoint(0);
GameMessages::PlayFXEffect(self->GetObjectID(), -1, u"up", "up").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), RiseSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}