DarkflameServer/dScripts/BaseConsoleTeleportServer.cpp

105 lines
3.6 KiB
C++
Raw Normal View History

#include "BaseConsoleTeleportServer.h"
#include "GameMessages.h"
#include "Player.h"
#include "RenderComponent.h"
#include "EntityManager.h"
#include "eTerminateType.h"
#include "eStateChangeType.h"
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::BaseOnUse(Entity* self, Entity* user) {
auto* player = user;
2022-07-28 13:39:57 +00:00
const auto& teleportLocString = self->GetVar<std::u16string>(u"teleportString");
2022-07-28 13:39:57 +00:00
GameMessages::SendDisplayMessageBox(player->GetObjectID(), true, self->GetObjectID(), u"TransferBox", 0, teleportLocString, u"", player->GetSystemAddress());
}
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::BaseOnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
auto* player = sender;
2022-07-28 13:39:57 +00:00
if (button == 1) {
GameMessages::SendSetStunned(
player->GetObjectID(), eStateChangeType::PUSH, player->GetSystemAddress(), player->GetObjectID(),
2022-07-28 13:39:57 +00:00
true, true, true, true, true, true, true
);
2022-07-28 13:39:57 +00:00
const auto teleportFXID = self->GetVar<int32_t>(u"teleportEffectID");
2022-07-28 13:39:57 +00:00
if (teleportFXID != 0) {
const auto& teleportFXs = self->GetVar<std::vector<std::u16string>>(u"teleportEffectTypes");
2022-07-28 13:39:57 +00:00
for (const auto& type : teleportFXs) {
GameMessages::SendPlayFXEffect(player->GetObjectID(), teleportFXID, type, "FX" + GeneralUtils::UTF16ToWTF8(type));
}
}
2022-07-28 13:39:57 +00:00
const auto& teleIntroAnim = self->GetVar<std::u16string>(u"teleportAnim");
auto animTime = 3.32999992370605f;
2022-07-28 13:39:57 +00:00
if (!teleIntroAnim.empty()) {
animTime = RenderComponent::PlayAnimation(player, teleIntroAnim);
2022-07-28 13:39:57 +00:00
}
2022-07-28 13:39:57 +00:00
UpdatePlayerTable(self, player, true);
2022-07-28 13:39:57 +00:00
const auto playerID = player->GetObjectID();
2022-07-28 13:39:57 +00:00
self->AddCallbackTimer(animTime, [playerID, self]() {
auto* player = Game::entityManager->GetEntity(playerID);
2022-07-28 13:39:57 +00:00
if (player == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
GameMessages::SendDisplayZoneSummary(playerID, player->GetSystemAddress(), false, false, self->GetObjectID());
});
} else if (button == -1 || button == 0) {
GameMessages::SendTerminateInteraction(player->GetObjectID(), eTerminateType::FROM_INTERACTION, player->GetObjectID());
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::UpdatePlayerTable(Entity* self, Entity* player, bool bAdd) {
const auto iter = std::find(m_Players.begin(), m_Players.end(), player->GetObjectID());
if (iter == m_Players.end() && bAdd) {
m_Players.push_back(player->GetObjectID());
} else if (iter != m_Players.end() && !bAdd) {
m_Players.erase(iter);
}
}
2022-07-28 13:39:57 +00:00
bool BaseConsoleTeleportServer::CheckPlayerTable(Entity* self, Entity* player) {
const auto iter = std::find(m_Players.begin(), m_Players.end(), player->GetObjectID());
2022-07-28 13:39:57 +00:00
return iter != m_Players.end();
}
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::BaseOnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
if (args == "summaryComplete") {
TransferPlayer(self, sender, 0);
}
}
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::TransferPlayer(Entity* self, Entity* player, int32_t altMapID) {
if (player == nullptr || !CheckPlayerTable(self, player)) {
return;
}
GameMessages::SendSetStunned(
player->GetObjectID(), eStateChangeType::POP, player->GetSystemAddress(), player->GetObjectID(),
2022-07-28 13:39:57 +00:00
true, true, true, true, true, true, true
);
GameMessages::SendTerminateInteraction(player->GetObjectID(), eTerminateType::FROM_INTERACTION, player->GetObjectID());
2022-07-28 13:39:57 +00:00
const auto& teleportZone = self->GetVar<std::u16string>(u"transferZoneID");
2022-07-28 13:39:57 +00:00
static_cast<Player*>(player)->SendToZone(std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone)));
2022-07-28 13:39:57 +00:00
UpdatePlayerTable(self, player, false);
}
2022-07-28 13:39:57 +00:00
void BaseConsoleTeleportServer::BaseOnTimerDone(Entity* self, const std::string& timerName) {
}