AntiAddictionController.cs 7.9 KB

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