From 17b414002e01e19603c998cc7d3c06da9ee35189 Mon Sep 17 00:00:00 2001 From: Robbe Bryssinck Date: Wed, 22 Jun 2022 17:47:06 +0200 Subject: [PATCH] fix: health percentage rounding --- Code/client/Services/Generic/OverlayService.cpp | 13 ++++++++----- Code/server_runner/DediRunner.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Code/client/Services/Generic/OverlayService.cpp b/Code/client/Services/Generic/OverlayService.cpp index bc8f9fadf..5a64d7132 100644 --- a/Code/client/Services/Generic/OverlayService.cpp +++ b/Code/client/Services/Generic/OverlayService.cpp @@ -95,7 +95,10 @@ float CalculateHealthPercentage(Actor* apActor) noexcept { const float health = apActor->GetActorValue(ActorValueInfo::kHealth); const float maxHealth = apActor->GetActorPermanentValue(ActorValueInfo::kHealth); - return health / maxHealth * 100.f; + float percentage = health / maxHealth * 100.f; + if (percentage < 0.f) + percentage = 0.f; + return percentage; } OverlayService::OverlayService(World& aWorld, TransportService& transport, entt::dispatcher& aDispatcher) @@ -260,8 +263,7 @@ void OverlayService::SetPlayerHealthPercentage(uint32_t aFormId) const noexcept auto pArguments = CefListValue::Create(); pArguments->SetInt(0, playerComponent.Id); - // TODO: SetDouble()? - pArguments->SetInt(1, static_cast(percentage)); + pArguments->SetDouble(1, static_cast(percentage)); m_pOverlay->ExecuteAsync("setHealth", pArguments); } @@ -417,10 +419,11 @@ void OverlayService::OnNotifyTeleport(const NotifyTeleport& acMessage) noexcept void OverlayService::OnNotifyPlayerHealthUpdate(const NotifyPlayerHealthUpdate& acMessage) noexcept { + const float percentage = acMessage.Percentage >= 0.f ? acMessage.Percentage : 0.f; + auto pArguments = CefListValue::Create(); pArguments->SetInt(0, acMessage.PlayerId); - // TODO: SetDouble()? - pArguments->SetInt(1, static_cast(acMessage.Percentage)); + pArguments->SetDouble(1, static_cast(percentage)); m_pOverlay->ExecuteAsync("setHealth", pArguments); } diff --git a/Code/server_runner/DediRunner.cpp b/Code/server_runner/DediRunner.cpp index 4cb524aef..4d092743d 100644 --- a/Code/server_runner/DediRunner.cpp +++ b/Code/server_runner/DediRunner.cpp @@ -131,7 +131,7 @@ void DediRunner::RunGSThread() void DediRunner::StartTerminalIO() { - spdlog::get("ConOut")->info("Server started, type /help for a list of commands.\n"); + spdlog::get("ConOut")->info("\nServer started, type /help for a list of commands.\n"); PrintExecutorArrowHack(); uv_tty_init(&m_loop, &m_tty, 0, 1);