Skip to content

Commit

Permalink
fix: health percentage rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Jun 22, 2022
1 parent e8c2d55 commit 17b4140
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Code/client/Services/Generic/OverlayService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<int>(percentage));
pArguments->SetDouble(1, static_cast<double>(percentage));
m_pOverlay->ExecuteAsync("setHealth", pArguments);
}

Expand Down Expand Up @@ -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<int>(acMessage.Percentage));
pArguments->SetDouble(1, static_cast<double>(percentage));
m_pOverlay->ExecuteAsync("setHealth", pArguments);
}

Expand Down
2 changes: 1 addition & 1 deletion Code/server_runner/DediRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17b4140

Please sign in to comment.