using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
using LitJson;
|
|
namespace vnxbqy.UI
|
{
|
|
public class SetPrivateModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk
|
{
|
DailyQuestModel dailyModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public List<int> hangUpPushlist = new List<int>();
|
public event Action RefreshFreeTimeAct;
|
public Dictionary<int, List<string>> pushAtcivityKeyDict = new Dictionary<int, List<string>>();
|
public const string VIPEXPERIENCERECORD = "VipExperienceRecord";
|
public override void Init()
|
{
|
hangUpPushlist.Clear();
|
hangUpPushlist.Add((int)PushNotifyType.FreeTime);
|
hangUpPushlist.Add((int)PushNotifyType.BossRefresh);
|
hangUpPushlist.Add((int)PushNotifyType.PrivateChat);
|
hangUpPushlist.Add((int)PushNotifyType.TJDead);
|
hangUpPushlist.Add((int)PushNotifyType.TJWGTimeNoEnough);
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
|
}
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
SetActivityPushKey();
|
InitPushNotifyStr();
|
SetActivityPush();
|
LocalSave.SetBool(VIPEXPERIENCERECORD, vipModel.IsVipExperience());
|
//vipModel.OnVipTimeEvent -= SetVipPushNotifyByVipExperience;
|
//vipModel.OnVipTimeEvent += SetVipPushNotifyByVipExperience;
|
//GlobalTimeEvent.Instance.minuteEvent -= RefreshDailyQuest;
|
//GlobalTimeEvent.Instance.minuteEvent += RefreshDailyQuest;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void SetActivityPushKey()
|
{
|
pushAtcivityKeyDict.Clear();
|
List<int> dailyIdlist = dailyModel.GetDailyQuests(DailyQuestModel.DailyQuestCategory.TimeLimit);
|
for (int i = 0; i < dailyIdlist.Count; i++)
|
{
|
List<string> keylist = new List<string>();
|
pushAtcivityKeyDict.Add(dailyIdlist[i], keylist);
|
SetPushKeylist(dailyIdlist[i], keylist);
|
}
|
}
|
|
private void SetPushKeylist(int dailyId, List<string> keylist)
|
{
|
DailyQuestOpenTime dailyQuestOpenTime;
|
dailyModel.TryGetOpenTime(dailyId, out dailyQuestOpenTime);
|
|
for (int weekDay = 0; weekDay < 7; weekDay++)
|
{
|
var hourMinutelist = dailyQuestOpenTime.GetHourMinuteByWeek(weekDay);
|
if (hourMinutelist != null)
|
{
|
for (int j = 0; j < hourMinutelist.Count; j++)
|
{
|
var key = StringUtility.Contact(dailyId, weekDay, hourMinutelist[j].hourBegin);
|
keylist.Add(key);
|
}
|
}
|
}
|
}
|
|
#region 处理服务器数据
|
public Dictionary<int, bool> pushSetDict = new Dictionary<int, bool>();
|
public int startHour { get; set; }
|
public int startMinute { get; set; }
|
public int endHour { get; set; }
|
public int endMinute { get; set; }
|
|
public void SetServerPushModel(HB202_tagMCPushNotificationsSetting setting)
|
{
|
pushSetDict.Clear();
|
int switchBtnLength = dailyModel.GetDailyQuests(DailyQuestModel.DailyQuestCategory.TimeLimit).Count + hangUpPushlist.Count;
|
for (int i = 0; i < switchBtnLength; i++)
|
{
|
bool isOpen = MathUtility.GetBitValue(setting.OnoffBit, (ushort)i);
|
pushSetDict.Add(i, isOpen);
|
}
|
AnalysisFreeTime(setting.TimeStr);
|
}
|
|
private void AnalysisFreeTime(string timeStr)
|
{
|
string[] timeArray = timeStr.Split('-');
|
for (int i = 0; i < timeArray.Length; i++)
|
{
|
string[] hourAndMinute = timeArray[i].Split(':');
|
if (i == 0)
|
{
|
startHour = int.Parse(hourAndMinute[0]);
|
startMinute = int.Parse(hourAndMinute[1]);
|
}
|
else if (i == 1)
|
{
|
endHour = int.Parse(hourAndMinute[0]);
|
endMinute = int.Parse(hourAndMinute[1]);
|
}
|
}
|
}
|
|
private string GetContactFreeTime()
|
{
|
return StringUtility.Contact(startHour.ToString("D2"), ":", startMinute.ToString("D2"), "-", endHour.ToString("D2"), ":", endMinute.ToString("D2"));
|
}
|
|
public void SendPushNotifyQuest(int pushSet)
|
{
|
string freeTimeStr = GetContactFreeTime();
|
CB205_tagCMPushNotificationsSetting setting = new CB205_tagCMPushNotificationsSetting();
|
setting.OnoffBit = (uint)pushSet;
|
setting.TimeLen = (byte)freeTimeStr.Length;
|
setting.TimeStr = freeTimeStr;
|
GameNetSystem.Instance.SendInfo(setting);
|
}
|
|
public void SetActivityPush()
|
{
|
List<int> dailyIdlist = GetOpenDailyIdlist(true);
|
for (int i = 0; i < dailyIdlist.Count; i++)
|
{
|
bool isOpen = GetSwitchStateByIndex(GetSwitchIndexById(dailyIdlist[i], dailyIdlist));
|
if (isOpen)
|
{
|
List<JsonData> pushNotifylist = GetPushJsonData(dailyIdlist[i]);
|
for (int j = 0; j < pushNotifylist.Count; j++)
|
{
|
ynmbxxjUtil.Instance.GeTui_SendLocalMessage(pushNotifylist[j]);
|
}
|
}
|
}
|
}
|
|
public void RemoveActivityPush(int dailyId)
|
{
|
List<string> keylist = pushAtcivityKeyDict[dailyId];
|
for (int i = 0; i < keylist.Count; i++)
|
{
|
ynmbxxjUtil.Instance.GeTui_RemoveLocalMessage(keylist[i]);
|
}
|
}
|
|
public void RemoveActivityPushByKey(int dailyId, string pushKey)
|
{
|
if (pushAtcivityKeyDict[dailyId].Contains(pushKey))
|
{
|
ynmbxxjUtil.Instance.GeTui_RemoveLocalMessage(pushKey);
|
}
|
}
|
|
public void AddActivityPush(int dailyId)
|
{
|
var config = DailyQuestConfig.Get(dailyId);
|
if (config == null || !FuncOpen.Instance.IsFuncOpen(config.UnLockFuncID)) return;
|
|
List<JsonData> pushNotifylist = GetPushJsonData(dailyId);
|
for (int j = 0; j < pushNotifylist.Count; j++)
|
{
|
ynmbxxjUtil.Instance.GeTui_SendLocalMessage(pushNotifylist[j]);
|
}
|
}
|
|
|
public List<JsonData> GetPushJsonData(int dailyId)
|
{
|
var config = DailyQuestConfig.Get(dailyId);
|
string content = Language.Get("SetUpPrivate102", UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName).TrimEnd(), config.Title);
|
List<JsonData> pushNotifylist = new List<JsonData>();
|
List<string> pushKeylist = null;
|
List<int> pushNotifyTimelist = GetPushNotifyTime(dailyId, out pushKeylist);
|
for (int i = 0; i < pushNotifyTimelist.Count; i++)
|
{
|
if (i < pushKeylist.Count)
|
{
|
JsonData _params = new JsonData();
|
_params["code"] = 2005;
|
_params["id"] = pushKeylist[i];// id 重要, 标示每个通知的更新或者移除
|
_params["title"] = Language.Get("SetUpPrivate103");// 推送标题
|
_params["subtitle"] = "";// 副标题
|
_params["content"] = content;// 具体内容
|
_params["badge"] = -1;// 角标
|
// 以下为决定应该多久后弹出此通知
|
System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
long ret = System.Convert.ToInt64(ts.TotalSeconds) + pushNotifyTimelist[i];// 表示3秒后
|
_params["fireTime"] = ret;
|
pushNotifylist.Add(_params);
|
}
|
}
|
|
return pushNotifylist;
|
}
|
|
private List<int> GetPushNotifyTime(int dailyId, out List<string> pushKey)
|
{
|
List<int> pushDelaySecond = new List<int>();
|
pushKey = new List<string>();
|
DailyQuestOpenTime dailyQuestOpenTime;
|
dailyModel.TryGetOpenTime(dailyId, out dailyQuestOpenTime);
|
|
for (int weekDay = 0; weekDay < 7; weekDay++)
|
{
|
var hourMinutelist = dailyQuestOpenTime.GetHourMinuteByWeek(weekDay);
|
if (hourMinutelist != null)
|
{
|
int day = weekDay > 0 ? weekDay : 7;
|
int curDay = (int)TimeUtility.ServerNow.DayOfWeek > 0 ? (int)TimeUtility.ServerNow.DayOfWeek : 7;
|
int remainDay = day - curDay;
|
if (remainDay < 0)
|
{
|
remainDay = 7 + remainDay;
|
}
|
for (int i = 0; i < hourMinutelist.Count; i++)
|
{
|
int remainHour = hourMinutelist[i].hourBegin - TimeUtility.ServerNow.Hour;
|
int remainMinute = hourMinutelist[i].minuteBegin - TimeUtility.ServerNow.Minute;
|
if (remainDay <= 0)
|
{
|
if (remainHour < 0)
|
{
|
remainDay = 7;
|
}
|
else if (remainHour == 0 && remainMinute < 0)
|
{
|
remainDay = 7;
|
}
|
}
|
int remainSecond = remainDay * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60;
|
if (remainSecond > 120)
|
{
|
string key = StringUtility.Contact(dailyId, weekDay, hourMinutelist[i].hourBegin);
|
pushKey.Add(key);
|
pushDelaySecond.Add(remainSecond);
|
}
|
}
|
}
|
|
}
|
|
return pushDelaySecond;
|
}
|
|
#endregion
|
|
StringBuilder pushSB = new StringBuilder();
|
public void InitPushNotifyStr()
|
{
|
int playerLv = PlayerDatas.Instance.baseData.LV;
|
if (playerLv > 1)
|
return;
|
|
pushSB.Length = 0;
|
List<int> indexlist = pushSetDict.Keys.ToList();
|
for (int i = indexlist.Count - 1; i > -1; i--)
|
{
|
if (i < hangUpPushlist.Count)
|
{
|
if (vipModel.IsVipActive() || vipModel.IsVipExperience())
|
{
|
pushSetDict[indexlist[i]] = true;
|
}
|
else
|
{
|
pushSetDict[indexlist[i]] = false;
|
}
|
}
|
else
|
{
|
pushSetDict[indexlist[i]] = true;
|
}
|
|
if (pushSetDict[indexlist[i]])
|
{
|
pushSB.Append("1");
|
}
|
else
|
{
|
pushSB.Append("0");
|
}
|
}
|
|
int pushSet = Convert.ToInt32(pushSB.ToString(), 2);
|
SendPushNotifyQuest(pushSet);
|
}
|
|
public void SetVipPushNotify(int vipLv)
|
{
|
pushSB.Length = 0;
|
List<int> indexlist = pushSetDict.Keys.ToList();
|
for (int i = indexlist.Count - 1; i > -1; i--)
|
{
|
if (i < hangUpPushlist.Count)
|
{
|
if (vipLv > 0
|
&& !vipModel.IsVipExperience())
|
{
|
pushSetDict[indexlist[i]] = true;
|
}
|
else if (vipLv < 1
|
&& !vipModel.IsVipExperience())
|
{
|
pushSetDict[indexlist[i]] = false;
|
}
|
}
|
|
if (pushSetDict[indexlist[i]])
|
{
|
pushSB.Append("1");
|
}
|
else
|
{
|
pushSB.Append("0");
|
}
|
}
|
int pushSet = Convert.ToInt32(pushSB.ToString(), 2);
|
SendPushNotifyQuest(pushSet);
|
}
|
|
public void SetVipPushNotifyByVipExperience()
|
{
|
bool recordVipExper = LocalSave.GetBool(VIPEXPERIENCERECORD);
|
pushSB.Length = 0;
|
List<int> indexlist = pushSetDict.Keys.ToList();
|
for (int i = indexlist.Count - 1; i > -1; i--)
|
{
|
if (i < hangUpPushlist.Count)
|
{
|
if (vipModel.IsVipExperience()
|
&& !recordVipExper
|
&& PlayerDatas.Instance.baseData.VIPLv < 1)
|
{
|
pushSetDict[indexlist[i]] = true;
|
}
|
else if (!vipModel.IsVipExperience()
|
&& PlayerDatas.Instance.baseData.VIPLv < 1)
|
{
|
pushSetDict[indexlist[i]] = false;
|
}
|
}
|
|
if (pushSetDict[indexlist[i]])
|
{
|
pushSB.Append("1");
|
}
|
else
|
{
|
pushSB.Append("0");
|
}
|
}
|
int pushSet = Convert.ToInt32(pushSB.ToString(), 2);
|
SendPushNotifyQuest(pushSet);
|
LocalSave.SetBool(VIPEXPERIENCERECORD, vipModel.IsVipExperience());
|
}
|
|
public void RefreshPushSet(int switchIndex, bool isOpen)
|
{
|
pushSB.Length = 0;
|
List<int> indexlist = pushSetDict.Keys.ToList();
|
for (int i = indexlist.Count - 1; i > -1; i--)
|
{
|
if (indexlist[i] == switchIndex)
|
{
|
pushSetDict[indexlist[i]] = isOpen;
|
}
|
if (pushSetDict[indexlist[i]])
|
{
|
pushSB.Append("1");
|
}
|
else
|
{
|
pushSB.Append("0");
|
}
|
}
|
int pushSet = Convert.ToInt32(pushSB.ToString(), 2);
|
SendPushNotifyQuest(pushSet);
|
}
|
|
List<int> openDailylist = new List<int>();
|
public List<int> GetOpenDailyIdlist(bool isFunclimit = false)
|
{
|
openDailylist.Clear();
|
var quests = dailyModel.GetDailyQuests(DailyQuestModel.DailyQuestCategory.TimeLimit);
|
for (int i = 0; i < quests.Count; i++)
|
{
|
DailyQuestOpenTime dailyQuestOpenTime;
|
dailyModel.TryGetOpenTime(quests[i], out dailyQuestOpenTime);
|
var config = DailyQuestConfig.Get(quests[i]);
|
if (isFunclimit)
|
{
|
if (dailyQuestOpenTime.IsValidServerOpenTime() && FuncOpen.Instance.IsFuncOpen(config.UnLockFuncID))
|
{
|
openDailylist.Add(quests[i]);
|
}
|
}
|
else
|
{
|
if (dailyQuestOpenTime.IsValidServerOpenTime())
|
{
|
openDailylist.Add(quests[i]);
|
}
|
}
|
|
}
|
return openDailylist;
|
}
|
|
public bool GetSwitchStateByIndex(int index)
|
{
|
if (pushSetDict.ContainsKey(index))
|
{
|
return pushSetDict[index];
|
}
|
return false;
|
}
|
|
public void GetDailyInfoById(int id, out string title, out string week, out List<string> times)
|
{
|
var config = DailyQuestConfig.Get(id);
|
DailyQuestOpenTime dailyQuestOpenTime;
|
dailyModel.TryGetOpenTime(id, out dailyQuestOpenTime);
|
week = dailyQuestOpenTime.ToOpenTimeString();
|
title = config.Title;
|
times = new List<string>();
|
|
var hourMinutelist = dailyQuestOpenTime.GetNormalHourMinutes();
|
if (hourMinutelist != null)
|
{
|
if (id == (int)DailyQuestType.FairyFeast
|
|| id == (int)DailyQuestType.FairyLeague)
|
{
|
var time = StringUtility.Contact(hourMinutelist[0].hourBegin > 9 ? hourMinutelist[0].hourBegin.ToString() : "0" + hourMinutelist[0].hourBegin, ":",
|
hourMinutelist[0].minuteBegin > 9 ? hourMinutelist[0].minuteBegin.ToString() : "0" + hourMinutelist[0].minuteBegin);
|
times.Add(time);
|
}
|
else
|
{
|
for (int j = 0; j < hourMinutelist.Count; j++)
|
{
|
var time = StringUtility.Contact(hourMinutelist[j].hourBegin > 9 ? hourMinutelist[j].hourBegin.ToString() : "0" + hourMinutelist[j].hourBegin, ":",
|
hourMinutelist[j].minuteBegin > 9 ? hourMinutelist[j].minuteBegin.ToString() : "0" + hourMinutelist[j].minuteBegin);
|
times.Add(time);
|
}
|
}
|
}
|
}
|
|
public int GetSwitchIndexById(int id, List<int> quests)
|
{
|
for (int i = 0; i < quests.Count; i++)
|
{
|
if (quests[i] == id)
|
{
|
return i + hangUpPushlist.Count;
|
}
|
}
|
return -1;
|
}
|
|
/// <summary>
|
/// type 1 开始时间 2 结束时间
|
/// </summary>
|
/// <param name="type"></param>
|
public void SetRefreshFreeTimeEvent(int type, int hour, int minute)
|
{
|
switch (type)
|
{
|
case 1:
|
startHour = hour;
|
startMinute = minute;
|
break;
|
case 2:
|
endHour = hour;
|
endMinute = minute;
|
break;
|
}
|
pushSB.Length = 0;
|
List<int> indexlist = pushSetDict.Keys.ToList();
|
for (int i = indexlist.Count - 1; i > -1; i--)
|
{
|
if (pushSetDict[indexlist[i]])
|
{
|
pushSB.Append("1");
|
}
|
else
|
{
|
pushSB.Append("0");
|
}
|
}
|
int pushSet = Convert.ToInt32(pushSB.ToString(), 2);
|
SendPushNotifyQuest(pushSet);
|
if (RefreshFreeTimeAct != null)
|
{
|
RefreshFreeTimeAct();
|
}
|
}
|
|
|
private void RefreshDailyQuest()
|
{
|
var quests = dailyModel.GetDailyQuests(DailyQuestModel.DailyQuestCategory.TimeLimit);
|
foreach (var dailyQuest in dailyModel.GetDailyQuests())
|
{
|
var isUnLocked = TestDailyQuestUnLock(dailyQuest);
|
if (isUnLocked)
|
{
|
CheckActivityOpenTime(dailyQuest, quests);
|
}
|
}
|
}
|
|
public bool TestDailyQuestUnLock(int _dailyQuestId)
|
{
|
switch ((DailyQuestType)_dailyQuestId)
|
{
|
case DailyQuestType.FairyLeague:
|
case DailyQuestType.FairyFeast:
|
case DailyQuestType.FairyTask:
|
var _dailyConfig = DailyQuestConfig.Get(_dailyQuestId);
|
return (_dailyConfig.UnLockFuncID == 0 || FuncOpen.Instance.IsFuncOpen(_dailyConfig.UnLockFuncID));
|
case DailyQuestType.RuneTowerSweep:
|
return ModelCenter.Instance.GetModel<RuneTowerModel>().yesterdayPassFloor > 0;
|
default:
|
var dailyConfig = DailyQuestConfig.Get(_dailyQuestId);
|
return dailyConfig.UnLockFuncID == 0 || FuncOpen.Instance.IsFuncOpen(dailyConfig.UnLockFuncID);
|
}
|
}
|
|
|
public void CheckActivityOpenTime(int dailyId, List<int> quests)
|
{
|
|
bool isOpen = GetSwitchStateByIndex(GetSwitchIndexById(dailyId, quests));
|
|
if (!isOpen)
|
return;
|
|
DailyQuestOpenTime openTime;
|
dailyModel.TryGetOpenTime(dailyId, out openTime);
|
var dayOfWeek = (int)TimeUtility.ServerNow.DayOfWeek;
|
var hourMinutes = openTime.GetHourMinuteByWeek(dayOfWeek);
|
if (hourMinutes != null)
|
{
|
for (int i = 0; i < hourMinutes.Count; i++)
|
{
|
var minutes = TimeUtility.ServerNow.Hour * 60 + TimeUtility.ServerNow.Minute;
|
float minuteOffset = (hourMinutes[i].hourBegin * 60 + hourMinutes[i].minuteBegin) - minutes;
|
if (minuteOffset <= 2 && minuteOffset > 0)
|
{
|
string key = StringUtility.Contact(dailyId, dayOfWeek, hourMinutes[i].hourBegin);
|
RemoveActivityPushByKey(dailyId, key);
|
}
|
}
|
}
|
}
|
|
public enum PushNotifyType
|
{
|
FreeTime = 0, //免打扰时间开关
|
BossRefresh = 1, //关注BOSS
|
PrivateChat = 2, //私聊
|
TJDead = 3, //脱机死亡
|
TJWGTimeNoEnough, //脱机外挂时间不足
|
//后续IL开发添加预设
|
default1,
|
default2,
|
default3,
|
default4,
|
default5,
|
default6,
|
default7,
|
default8,
|
default9,
|
default10,
|
}
|
}
|
}
|