AntiAddictionController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using ET;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class AntiAddictionController
  7. {
  8. public static bool CheckAntiAddiction(int onlineTimeSecs, int onlineDurationSecs, int onlineDurationSecsDay) {
  9. if(!GameGlobal.antiAddiction) {
  10. return false;
  11. }
  12. Debug.LogFormat("init onlineTimeSecs {0} onlineDurationSecs {1} onlineDurationSecsDay{2}", onlineTimeSecs, onlineDurationSecs, onlineDurationSecsDay);
  13. int age = GameGlobal.userAge;
  14. if (age < 18)
  15. {
  16. int remainMinutes = GetRemainGameMinutes();
  17. if (remainMinutes <= 0)
  18. {
  19. string promptStr = "您属于未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏,目前已超出健康游戏体验时间,将强制游戏下线。";
  20. Alert.Show(promptStr)
  21. .SetRightButton(true, "知道啦", (object data) => {
  22. GameController.QuitToLoginView(false);
  23. });
  24. return true;
  25. }
  26. else
  27. {
  28. string ageRangeStr = null;
  29. int maxRechargeSingle = 0;
  30. int maxRechargeTotal = 0;
  31. GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
  32. string promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏,目前游戏剩余{1}分钟。";
  33. promptStr = String.Format(promptStr, ageRangeStr, remainMinutes);
  34. if (age < 8)
  35. {
  36. promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
  37. }
  38. else
  39. {
  40. promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
  41. promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
  42. }
  43. Alert.Show(promptStr)
  44. .SetRightButton(true, "知道啦");
  45. }
  46. }
  47. return false;
  48. }
  49. public static bool CheckOnlineTime(int onlineTimeSecs, int onlineDurationSecs, int onlineDurationSecsDay) {
  50. if(!GameGlobal.antiAddiction)
  51. {
  52. return false;
  53. }
  54. Debug.LogFormat("update onlineTimeSecs {0} onlineDurationSecs {1} onlineDurationSecsDay{2}", onlineTimeSecs, onlineDurationSecs, onlineDurationSecsDay);
  55. int age = GameGlobal.userAge;
  56. if (age < 18)
  57. {
  58. int remainMinutes = GetRemainGameMinutes();
  59. if (remainMinutes <= 0)
  60. {
  61. string promptStr = "您属于未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏。目前已超出健康游戏体验时间,将强制游戏下线。";
  62. Alert.Show(promptStr)
  63. .SetRightButton(true, "知道啦", (object data) => {
  64. GameController.QuitToLoginView(false);
  65. });
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. public static bool CheckAntiAddictionRecharge(int value) {
  72. if(!GameGlobal.antiAddiction)
  73. {
  74. return false;
  75. }
  76. string promptStr = "";
  77. if (GameGlobal.isVisitor)
  78. {
  79. promptStr += "您当前为游客模式,已被纳入防沉迷系统,在此模式下不能充值和付费消费。";
  80. Alert.Show(promptStr)
  81. .SetRightButton(true, "知道啦");
  82. return true;
  83. }
  84. string ageRangeStr = null;
  85. int maxRechargeSingle = 0;
  86. int maxRechargeTotal = 0;
  87. GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
  88. promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。";
  89. promptStr = String.Format(promptStr, ageRangeStr);
  90. int age = GameGlobal.userAge;
  91. if (age < 8)
  92. {
  93. promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
  94. Alert.Show(promptStr)
  95. .SetRightButton(true, "知道啦");
  96. return true;
  97. }
  98. else if (age < 18)
  99. {
  100. int preTotalMon = RoleDataManager.rechargeTotalMon + value;
  101. if (value > maxRechargeSingle || preTotalMon > maxRechargeTotal)
  102. {
  103. promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
  104. promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
  105. Alert.Show(promptStr)
  106. .SetRightButton(true, "知道啦");
  107. return true;
  108. }
  109. }
  110. return false;
  111. }
  112. private static void GetAntiValue(out string ageRangeStr, out int maxRechargeSingle, out int maxRechargeTotal) {
  113. int age = GameGlobal.userAge;
  114. if (age < 8)
  115. {
  116. ageRangeStr = "未满8周岁";
  117. maxRechargeSingle = 0;
  118. maxRechargeTotal = 0;
  119. }
  120. else if (age < 16)
  121. {
  122. ageRangeStr = "8周岁以上未满16周岁";
  123. maxRechargeSingle = 50;
  124. maxRechargeTotal = 200;
  125. }
  126. else
  127. {
  128. ageRangeStr = "16周岁以上未满18周岁";
  129. maxRechargeSingle = 100;
  130. maxRechargeTotal = 400;
  131. }
  132. }
  133. /// <summary>
  134. /// 防沉迷对象当日剩余可玩时间
  135. /// </summary>
  136. /// <returns></returns>
  137. private static int GetRemainGameMinutes()
  138. {
  139. var dateTime = TimeHelper.DateTimeNow();
  140. int hour = dateTime.Hour;
  141. if (hour >= 20 && hour < 21)
  142. {
  143. int minute = dateTime.Minute;
  144. return 60 - minute;
  145. }
  146. return 0;
  147. }
  148. }
  149. }