#include #include #include #include #include #include #include #include #include #include #include "Messages/SetTimeCommandRequest.h" #include CommandService::CommandService(World& aWorld, TransportService& aTransport, entt::dispatcher& aDispatcher) : m_world(aWorld) , m_transport(aTransport) { m_setTimeConnection = aDispatcher.sink().connect<&CommandService::OnSetTimeCommand>(this); m_teleportConnection = aDispatcher.sink().connect<&CommandService::OnTeleportCommandResponse>(this); } void CommandService::OnSetTimeCommand(const SetTimeCommandEvent& acEvent) const noexcept { SetTimeCommandRequest request{}; request.Hours = acEvent.Hours; request.Minutes = acEvent.Minutes; request.PlayerId = acEvent.PlayerId; m_transport.Send(request); } void CommandService::OnTeleportCommandResponse(const TeleportCommandResponse& acMessage) noexcept { spdlog::info("TeleportCommandResponse: {:X}:{:X} at position {}, {}, {}", acMessage.CellId.ModId, acMessage.CellId.BaseId, acMessage.Position.x, acMessage.Position.y, acMessage.Position.z); auto& modSystem = m_world.GetModSystem(); const uint32_t cellId = modSystem.GetGameId(acMessage.CellId); TESObjectCELL* pCell = Cast(TESForm::GetById(cellId)); if (!pCell) { const uint32_t worldSpaceId = modSystem.GetGameId(acMessage.WorldSpaceId); TESWorldSpace* pWorldSpace = Cast(TESForm::GetById(worldSpaceId)); if (pWorldSpace) { GridCellCoords coordinates = GridCellCoords::CalculateGridCellCoords(acMessage.Position); pCell = pWorldSpace->LoadCell(coordinates.X, coordinates.Y); } if (!pCell) { spdlog::error("Failed to fetch cell to teleport to."); m_world.GetOverlayService().SendSystemMessage("Teleporting to player failed."); return; } } PlayerCharacter::Get()->MoveTo(pCell, acMessage.Position); }