mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-14 15:57:13 +00:00
The script (with L_BASE_SWITCH_ACTIVATED_SERVER) asks the switches in the platform's switchGroup to tell it when they are activated and deactivated, and sends the platform to waypoint 1 on the one and back to waypoint 0 on the other. The NJ monastery's ice and lightning attic platforms (LOTs 14539 and 14376) run it. A switch can now be asked for that (SwitchComponent:: AddActivationCallback). Where live's switch tells its group that it has loaded, the platform here looks for its switches again each second until it has found one. The script was on the list of scripts left out, with a note that its platform does not exist; it is taken off the list. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
38 lines
1.5 KiB
C++
38 lines
1.5 KiB
C++
#include "SimpleMoverSwitch.h"
|
|
|
|
#include "Entity.h"
|
|
#include "EntityManager.h"
|
|
#include "MovingPlatformComponent.h"
|
|
#include "SwitchComponent.h"
|
|
|
|
void SimpleMoverSwitch::OnStartup(Entity* self) {
|
|
RequestSwitches(self);
|
|
}
|
|
|
|
// switchStartup: every switch in the group is asked for its ObjectActivated (and from then on, in turn, its
|
|
// ObjectDeactivated and ObjectActivated). A switch loaded after the platform tells its group so in live
|
|
// (objectTypeLoaded) and is asked then; here the platform looks again until it has found one.
|
|
void SimpleMoverSwitch::RequestSwitches(Entity* self) {
|
|
const auto group = self->GetVarAsString(u"switchGroup");
|
|
if (group.empty()) return;
|
|
|
|
bool found = false;
|
|
for (auto* const object : Game::entityManager->GetEntitiesInGroup(group)) {
|
|
if (object == self) continue;
|
|
auto* const switchComponent = object->GetComponent<SwitchComponent>();
|
|
if (!switchComponent) continue;
|
|
found = true;
|
|
switchComponent->AddActivationCallback([platformID = self->GetObjectID()](const bool active) {
|
|
auto* const platformObject = Game::entityManager->GetEntity(platformID);
|
|
if (!platformObject) return;
|
|
// notifyObjectActivated: GoToWaypoint{ iPathIndex = 1 }; notifyObjectDeactivated: GoToWaypoint{ iPathIndex = 0 }
|
|
if (auto* const platform = platformObject->GetComponent<MovingPlatformComponent>()) platform->GotoWaypoint(active ? 1 : 0);
|
|
});
|
|
}
|
|
if (!found) self->AddTimer("FindSwitch", 1.0f);
|
|
}
|
|
|
|
void SimpleMoverSwitch::OnTimerDone(Entity* self, std::string timerName) {
|
|
if (timerName == "FindSwitch") RequestSwitches(self);
|
|
}
|