diff --git a/Assets/Scripts/EC_GameRunChat.cs b/Assets/Scripts/EC_GameRunChat.cs index eec1fa7fe5..477047a261 100644 --- a/Assets/Scripts/EC_GameRunChat.cs +++ b/Assets/Scripts/EC_GameRunChat.cs @@ -100,18 +100,33 @@ partial class CECGameRun public float healthPlaytimeChatReminderIntervalSeconds = 600f; private uint _healthPlaytimeChatReminderAccumMs; + private bool _healthPlaytimeChatReminderDidImmediateThisSession; private const string HealthPlaytimeChatReminderText = "Chơi game quá 180 phút có hại cho sức khoẻ"; + private static void PublishHealthPlaytimeChatReminder() + { + string redMsg = "" + HealthPlaytimeChatReminderText + ""; + EventBus.Publish(new GameSession.ChatMessageEvent(redMsg, (byte)ChatChannel.GP_CHAT_SYSTEM)); + } + private void TickHealthPlaytimeChatReminder(uint dwDeltaMs) { if (GetGameState() != (int)GameState.GS_GAME) { _healthPlaytimeChatReminderAccumMs = 0; + _healthPlaytimeChatReminderDidImmediateThisSession = false; return; } + if (!_healthPlaytimeChatReminderDidImmediateThisSession) + { + _healthPlaytimeChatReminderDidImmediateThisSession = true; + _healthPlaytimeChatReminderAccumMs = 0; + PublishHealthPlaytimeChatReminder(); + } + float intervalSec = Mathf.Max(0.1f, healthPlaytimeChatReminderIntervalSeconds); uint intervalMs = (uint)(intervalSec * 1000f); if (intervalMs < 1) @@ -121,8 +136,7 @@ partial class CECGameRun while (_healthPlaytimeChatReminderAccumMs >= intervalMs) { _healthPlaytimeChatReminderAccumMs -= intervalMs; - string redMsg = "" + HealthPlaytimeChatReminderText + ""; - EventBus.Publish(new GameSession.ChatMessageEvent(redMsg, (byte)ChatChannel.GP_CHAT_SYSTEM)); + PublishHealthPlaytimeChatReminder(); } } }