AntiAddictionController.cs 6.6 KB

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