AntiAddictionController.cs 6.7 KB

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