using System;
using ET;
using UnityEngine;
namespace GFGGame
{
public class AntiAddictionController
{
public static bool CheckAntiAddiction(int onlineTimeSecs, int onlineDurationSecs, int onlineDurationSecsDay)
{
if (!GameGlobal.antiAddiction)
{
return false;
}
Debug.LogFormat("init onlineTimeSecs {0} onlineDurationSecs {1} onlineDurationSecsDay{2}", onlineTimeSecs, onlineDurationSecs, onlineDurationSecsDay);
int age = GameGlobal.userAge;
if (age < 18)
{
int remainMinutes = GetRemainGameMinutes();
if (remainMinutes <= 0)
{
string promptStr = "您属于未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏,目前已超出健康游戏体验时间,将强制游戏下线。";
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦", (object data) =>
{
GameController.QuitToLoginView(false);
});
return true;
}
else
{
string ageRangeStr = null;
int maxRechargeSingle = 0;
int maxRechargeTotal = 0;
GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
string promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏,目前游戏剩余{1}分钟。";
promptStr = String.Format(promptStr, ageRangeStr, remainMinutes);
if (age < 8)
{
promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
}
else
{
promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
}
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦");
}
}
return false;
}
public static bool CheckOnlineTime(int onlineTimeSecs, int onlineDurationSecs, int onlineDurationSecsDay)
{
if (!GameGlobal.antiAddiction)
{
return false;
}
Debug.LogFormat("update onlineTimeSecs {0} onlineDurationSecs {1} onlineDurationSecsDay{2}", onlineTimeSecs, onlineDurationSecs, onlineDurationSecsDay);
int age = GameGlobal.userAge;
if (age < 18)
{
int remainMinutes = GetRemainGameMinutes();
if (remainMinutes <= 0)
{
string promptStr = "您属于未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏。目前已超出健康游戏体验时间,将强制游戏下线。";
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦", (object data) =>
{
GameController.QuitToLoginView(false);
});
return true;
}
}
return false;
}
public static bool CheckAntiAddictionRecharge(int value)
{
if (!GameGlobal.antiAddiction)
{
return false;
}
string promptStr = "";
if (GameGlobal.isVisitor)
{
promptStr += "您当前为游客模式,已被纳入防沉迷系统,在此模式下不能充值和付费消费。";
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦");
return true;
}
string ageRangeStr = null;
int maxRechargeSingle = 0;
int maxRechargeTotal = 0;
GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。";
promptStr = String.Format(promptStr, ageRangeStr);
int age = GameGlobal.userAge;
if (age < 8)
{
promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦");
return true;
}
else if (age < 18)
{
int preTotalMon = RoleDataManager.rechargeTotalMon + value;
if (value > maxRechargeSingle || preTotalMon > maxRechargeTotal)
{
promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
AlertSystem.Show(promptStr)
.SetRightButton(true, "知道啦");
return true;
}
}
return false;
}
private static void GetAntiValue(out string ageRangeStr, out int maxRechargeSingle, out int maxRechargeTotal)
{
int age = GameGlobal.userAge;
if (age < 8)
{
ageRangeStr = "未满8周岁";
maxRechargeSingle = 0;
maxRechargeTotal = 0;
}
else if (age < 16)
{
ageRangeStr = "8周岁以上未满16周岁";
maxRechargeSingle = 50;
maxRechargeTotal = 200;
}
else
{
ageRangeStr = "16周岁以上未满18周岁";
maxRechargeSingle = 100;
maxRechargeTotal = 400;
}
}
///
/// 防沉迷对象当日剩余可玩时间
///
///
private static int GetRemainGameMinutes()
{
var dateTime = TimeHelper.DateTimeNow();
int hour = dateTime.Hour;
if (hour >= 20 && hour < 21)
{
int minute = dateTime.Minute;
return 60 - minute;
}
return 0;
}
}
}