How do you limit the time of the bonus when there's no game?
-
I have a code that counts how much money a man earns in the absence of a game. How do you limit the time of receipt to 30 minutes? To keep the bonus out of 30 minutes.
DateTime dt = new DateTime(sv.date[0], sv.date[1], sv.date[2], sv.date[3], sv.date[4], sv.date[5]); TimeSpan ts = DateTime.Now - dt; float offlineBonus = (int)ts.TotalSeconds * totalBonusPS; score += offlineBonus; SecondMoney += offlineBonus; print("Вы отсутствовали: " + ts.Days + "Д. " + ts.Hours + "Ч. " + ts.Minutes + "М. " + ts.Seconds + "S."); print("Ваши рабочие заработали: " + offlineBonus + "$");
sv.date[0] = DateTime.Now.Year;
sv.date[1] = DateTime.Now.Month;
sv.date[2] = DateTime.Now.Day;
sv.date[3] = DateTime.Now.Hour;
sv.date[4] = DateTime.Now.Minute;
sv.date[5] = DateTime.Now.Second;
-
To that end, it is understandable that if a person is absent from the game for more than 30 minutes, the bonus will be the same as in 30 minutes. Then the bonus counting code will be:
TimeSpan ts = DateTime.Now - dt; var secondsOffline = (int)ts.TotalSeconds; const int maxTimeForBonusInSeconds = 1800; float offlineBonus = secondsOffline < maxTimeForBonusInSeconds ? secondsOffline * totalBonusPS : maxTimeForBonusInSeconds * totalBonusPS;
score += offlineBonus;
SecondMoney += offlineBonus;