Add health warning message

This commit is contained in:
HungDK
2026-03-25 11:36:29 +07:00
parent 6fe87fe3cf
commit 05adae4f21
2 changed files with 34 additions and 0 deletions
+2
View File
@@ -1243,6 +1243,8 @@ public partial class CECGameRun : ITickable
// g_TickMemoryHistory();
// #endif
TickHealthPlaytimeChatReminder(dwDeltaTime);
return true;
}
+32
View File
@@ -93,4 +93,36 @@ partial class CECGameRun
}
}
}
/// <summary>
/// Seconds between chat reminders (default 10). Change at runtime or in code as needed.
/// </summary>
public float healthPlaytimeChatReminderIntervalSeconds = 600f;
private uint _healthPlaytimeChatReminderAccumMs;
private const string HealthPlaytimeChatReminderText =
"Chơi game quá 180 phút có hại cho sức khoẻ";
private void TickHealthPlaytimeChatReminder(uint dwDeltaMs)
{
if (GetGameState() != (int)GameState.GS_GAME)
{
_healthPlaytimeChatReminderAccumMs = 0;
return;
}
float intervalSec = Mathf.Max(0.1f, healthPlaytimeChatReminderIntervalSeconds);
uint intervalMs = (uint)(intervalSec * 1000f);
if (intervalMs < 1)
intervalMs = 1;
_healthPlaytimeChatReminderAccumMs += dwDeltaMs;
while (_healthPlaytimeChatReminderAccumMs >= intervalMs)
{
_healthPlaytimeChatReminderAccumMs -= intervalMs;
string redMsg = "<color=#FF0000>" + HealthPlaytimeChatReminderText + "</color>";
EventBus.Publish(new GameSession.ChatMessageEvent(redMsg, (byte)ChatChannel.GP_CHAT_SYSTEM));
}
}
}