Add health warning message
This commit is contained in:
@@ -1243,6 +1243,8 @@ public partial class CECGameRun : ITickable
|
||||
// g_TickMemoryHistory();
|
||||
// #endif
|
||||
|
||||
TickHealthPlaytimeChatReminder(dwDeltaTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user