//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, January 08, 2019
|
//--------------------------------------------------------
|
using System;
|
using System.Collections.Generic;
|
|
using vnxbqy.UI;
|
using System.Linq;
|
|
|
public class ActionTypeClass
|
{
|
public int TemplateID; // 模板ID
|
public int CurTimes; //已完成次数
|
public int GotTimes; //已领取次数
|
}
|
public class WeekPartyDayInfoClass
|
{
|
public int DayIndex;//第X天
|
public int Point;//积分
|
public int AwardRecord;//领奖记录
|
public List<ActionTypeClass> ActionType;//领奖信息
|
}
|
public class TimeDayClass
|
{
|
public int Year;
|
public int Month;
|
public int Day;
|
public string TimeStr;
|
}
|
public class WeekPartyItemClass
|
{
|
public int NeedPoint; // 领奖需要积分
|
public int ItemID; // 物品ID
|
public int ItemCnt; // 物品数量
|
public int IsBind; // 是否绑定
|
}
|
|
public class WeekPartyDayClass
|
{
|
public int Day;
|
public int[] TemplateList;// 模板列表
|
public WeekPartyItemClass[] WeekPartyItem;//奖励列表
|
}
|
|
public class WeekPartyActionClass//模板信息
|
{
|
public int TemplateID; // 模板ID
|
public int ActionType; // 活动类别
|
public int TotalTimes; // 可完成的总次数,0表示不限次数
|
public int SingleTimes; // 单次领奖需要的次数
|
public int Point; // 单次领奖积分
|
public WeekPartyItemClass[] WeekPartyItem;//物品奖励列表
|
public string ItemJson;
|
}
|
public class OpenServiceAchievementModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public Dictionary<int, WeekPartyDayInfoClass> WeekPartyDayInfoDic = new Dictionary<int, WeekPartyDayInfoClass>();//每天领取奖励信息
|
public event Action WeekPartyDayInfoUpdate;//领奖记录变更
|
public TimeDayClass[] TimeDayBeginAndOver = new TimeDayClass[2];//开始和结束时间
|
public int LimitLV = 0;//限制等级
|
public Dictionary<int, WeekPartyDayClass> WeekPartyDayDic = new Dictionary<int, WeekPartyDayClass>();//每天的奖励信息
|
public Dictionary<int, WeekPartyActionClass> WeekPartyActionDic = new Dictionary<int, WeekPartyActionClass>();//活动模板信息
|
public Dictionary<int, Redpoint> RedPointDic = new Dictionary<int, Redpoint>();//红点
|
public event Action WeekPartyUpdate;//活动信息变更
|
private const int Redpoint_key = 214;//周狂欢红点
|
public Redpoint redPointStre = new Redpoint(2, Redpoint_key);
|
private const int Redpoint_key1 = 21401;//周狂欢红点
|
public Redpoint redPointStre1 = new Redpoint(Redpoint_key, Redpoint_key1);
|
private int _SelectedNow = 0;
|
private int ResetType = 0;// 重置类型,0-0点重置;1-5点重置
|
private int AdvanceMinutes = 0;//提前显示分钟
|
private bool isPreviewTime = false;
|
private bool isOpenNow = false;
|
public event Action IsOpenEvent;//功能是否开启
|
public event Action IsPreviewTimeUpdate;//功能是否提前开启
|
private int _JumpIndex = -1;//跳转选中值
|
public int JumpIndex
|
{
|
get { return _JumpIndex; }
|
set { _JumpIndex = value; }
|
}
|
|
|
public int SelectedNow//选中天
|
{
|
get { return _SelectedNow; }
|
set { _SelectedNow = value; }
|
}
|
|
private int _DayNow = 0;
|
public int DayNow//当前天
|
{
|
get { return _DayNow; }
|
set { _DayNow = value; }
|
}
|
|
private bool _IsOpen = false;//功能是否开启
|
public bool IsOpen
|
{
|
get { return _IsOpen; }
|
set { _IsOpen = value; }
|
}
|
public override void Init()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
WeekPartyDayInfoDic.Clear();
|
WeekPartyDayDic.Clear();
|
WeekPartyActionDic.Clear();
|
isOpenNow = false;
|
isPreviewTime = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
GetDayNow();//获取当前天数
|
SetRedPoint();
|
|
}
|
|
private void secondEvent()
|
{
|
bool _bool = IsPreviewTime();
|
if (_bool && !isPreviewTime)
|
{
|
isPreviewTime = true;
|
_IsOpen = true;
|
if (IsPreviewTimeUpdate != null)
|
{
|
IsPreviewTimeUpdate();
|
}
|
}
|
GetIsOpen();//判断功能是否开启
|
GetDayNow();
|
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void WeekPartyPlayerInfo(HAA0B_tagMCWeekPartyPlayerInfo info)
|
{
|
for (int i = 0; i < info.Count; i++)
|
{
|
var DayInfo = info.DayInfoList[i];
|
WeekPartyDayInfoClass WeekPartyDayInfo = new WeekPartyDayInfoClass();
|
WeekPartyDayInfo.DayIndex = (int)DayInfo.DayIndex;
|
WeekPartyDayInfo.Point = (int)DayInfo.Point;
|
WeekPartyDayInfo.AwardRecord = (int)DayInfo.AwardRecord;
|
if (WeekPartyDayInfoDic.ContainsKey((int)DayInfo.DayIndex))
|
{
|
var dit = WeekPartyDayInfoDic[(int)DayInfo.DayIndex];
|
dit.DayIndex = (int)DayInfo.DayIndex;
|
dit.Point = (int)DayInfo.Point;
|
dit.AwardRecord = (int)DayInfo.AwardRecord;
|
for (int j = 0; j < DayInfo.ACount; j++)
|
{
|
var taskList = DayInfo.TaskList[j];
|
int Index = dit.ActionType.FindIndex(s => s.TemplateID == taskList.TemplateID);
|
if (Index != -1)
|
{
|
dit.ActionType[Index].CurTimes = (int)taskList.CurTimes;
|
dit.ActionType[Index].GotTimes = (int)taskList.GotTimes;
|
}
|
else
|
{
|
ActionTypeClass ActionType = new ActionTypeClass();
|
ActionType.TemplateID = taskList.TemplateID;
|
ActionType.CurTimes = (int)taskList.CurTimes;
|
ActionType.GotTimes = (int)taskList.GotTimes;
|
dit.ActionType.Add(ActionType);
|
}
|
}
|
WeekPartyDayInfoDic[(int)DayInfo.DayIndex] = dit;
|
}
|
else
|
{
|
WeekPartyDayInfo.ActionType = new List<ActionTypeClass>();
|
for (int k = 0; k < DayInfo.ACount; k++)
|
{
|
var Task = DayInfo.TaskList[k];
|
ActionTypeClass ActionType = new ActionTypeClass();
|
ActionType.TemplateID = Task.TemplateID;
|
ActionType.CurTimes = (int)Task.CurTimes;
|
ActionType.GotTimes = (int)Task.GotTimes;
|
WeekPartyDayInfo.ActionType.Add(ActionType);
|
}
|
WeekPartyDayInfoDic.Add((int)DayInfo.DayIndex, WeekPartyDayInfo);
|
}
|
}
|
GetDayNow();//获取当前天数
|
SetRedPoint();
|
if (WeekPartyDayInfoUpdate != null)
|
{
|
WeekPartyDayInfoUpdate();
|
}
|
}
|
|
public void WeekPartyInfo(HAA0A_tagMCWeekPartyInfo info)
|
{
|
WeekPartyDayDic.Clear();
|
WeekPartyActionDic.Clear();
|
ResetType = info.ResetType;
|
string[] dateArray = info.StartDate.Split('-');
|
if (dateArray != null && dateArray.Length == 3)
|
{
|
TimeDayClass TimeDay = new TimeDayClass();
|
TimeDay.Year = int.Parse(dateArray[0].Trim());
|
TimeDay.Month = int.Parse(dateArray[1].Trim());
|
TimeDay.Day = int.Parse(dateArray[2].Trim());
|
TimeDay.TimeStr = info.StartDate;
|
TimeDayBeginAndOver[0] = TimeDay;
|
}
|
string[] dateArrayO = info.EndtDate.Split('-');
|
if (dateArrayO != null && dateArrayO.Length == 3)
|
{
|
TimeDayClass TimeDay = new TimeDayClass();
|
TimeDay.Year = int.Parse(dateArrayO[0].Trim());
|
TimeDay.Month = int.Parse(dateArrayO[1].Trim());
|
TimeDay.Day = int.Parse(dateArrayO[2].Trim());
|
TimeDay.TimeStr = info.EndtDate;
|
TimeDayBeginAndOver[1] = TimeDay;
|
}
|
LimitLV = info.LimitLV;
|
AdvanceMinutes = info.AdvanceMinutes;
|
for (int i = 0; i < info.DayCnt; i++)
|
{
|
int Index = i;
|
var DayInfo = info.DayInfoList[i];
|
WeekPartyDayClass WeekPartyDay = new WeekPartyDayClass();
|
WeekPartyDay.TemplateList = new int[DayInfo.ActCnt];
|
for (int k = 0; k < DayInfo.ActCnt; k++)
|
{
|
WeekPartyDay.TemplateList[k] = DayInfo.TemplateList[k];
|
}
|
WeekPartyDay.WeekPartyItem = new WeekPartyItemClass[DayInfo.PCount];
|
for (int p = 0; p < DayInfo.PCount; p++)
|
{
|
WeekPartyItemClass WeekPartyItem = new WeekPartyItemClass();
|
var Item = DayInfo.PItemInfo[p];
|
WeekPartyItem.NeedPoint = Item.NeedPoint;
|
WeekPartyItem.ItemID = (int)Item.ItemID;
|
WeekPartyItem.ItemCnt = (int)Item.ItemCnt;
|
WeekPartyItem.IsBind = (int)Item.IsBind;
|
WeekPartyDay.WeekPartyItem[p] = WeekPartyItem;
|
}
|
if (WeekPartyDayDic.ContainsKey(Index))
|
{
|
WeekPartyDayDic[Index] = WeekPartyDay;
|
}
|
else
|
{
|
WeekPartyDayDic.Add(Index, WeekPartyDay);
|
}
|
}// 每天模板
|
|
for (int i = 0; i < info.TCount; i++)
|
{
|
var ActionInfo = info.ActionInfo[i];
|
WeekPartyActionClass WeekPartyAction = new WeekPartyActionClass();
|
WeekPartyAction.TemplateID = (int)ActionInfo.TemplateID;
|
WeekPartyAction.ActionType = (int)ActionInfo.ActionType;
|
WeekPartyAction.TotalTimes = (int)ActionInfo.TotalTimes;
|
WeekPartyAction.SingleTimes = (int)ActionInfo.SingleTimes;
|
WeekPartyAction.Point = (int)ActionInfo.Point;
|
WeekPartyAction.WeekPartyItem = new WeekPartyItemClass[ActionInfo.Count];
|
for (int z = 0; z < ActionInfo.Count; z++)
|
{
|
var item = ActionInfo.ItemInfo[z];
|
WeekPartyItemClass WeekPartyItem = new WeekPartyItemClass();
|
WeekPartyItem.ItemID = (int)item.ItemID;
|
WeekPartyItem.ItemCnt = (int)item.ItemCnt;
|
WeekPartyItem.IsBind = item.IsBind;
|
WeekPartyItem.NeedPoint = 0;
|
WeekPartyAction.WeekPartyItem[z] = WeekPartyItem;
|
}
|
if (WeekPartyActionDic.ContainsKey((int)ActionInfo.TemplateID))
|
{
|
WeekPartyActionDic[(int)ActionInfo.TemplateID] = WeekPartyAction;
|
}
|
else
|
{
|
WeekPartyActionDic.Add((int)ActionInfo.TemplateID, WeekPartyAction);
|
}
|
}// 活动模板信息
|
GetDayNow();
|
SetRedPoint();
|
if (WeekPartyUpdate != null)
|
{
|
WeekPartyUpdate();
|
}
|
|
}
|
public int GetRewardNumber(int Day, int ID)//获取领奖次数
|
{
|
int Num = 0;
|
if (WeekPartyDayInfoDic.ContainsKey(Day))
|
{
|
var WeekPartyDay = WeekPartyDayInfoDic[Day];
|
|
for (int i = 0; i < WeekPartyDay.ActionType.Count; i++)
|
{
|
var ActionType = WeekPartyDay.ActionType[i];
|
if (ID == ActionType.TemplateID)
|
{
|
Num = ActionType.GotTimes;
|
}
|
}
|
}
|
return Num;
|
}
|
public int GetCarryOutNum(int Day, int ID)//获取已完成次数
|
{
|
int Num = 0;
|
if (WeekPartyDayInfoDic.ContainsKey(Day))
|
{
|
var WeekPartyDay = WeekPartyDayInfoDic[Day];
|
|
for (int i = 0; i < WeekPartyDay.ActionType.Count; i++)
|
{
|
var ActionType = WeekPartyDay.ActionType[i];
|
if (ID == ActionType.TemplateID)
|
{
|
Num = ActionType.CurTimes;
|
}
|
}
|
}
|
return Num;
|
}
|
|
public int GetPoint(int day)//获取某一天的积分
|
{
|
int Point = 0;
|
if (WeekPartyDayInfoDic.ContainsKey(day))
|
{
|
Point = WeekPartyDayInfoDic[day].Point;
|
}
|
return Point;
|
}
|
|
public void GetDayNow()//获取活动第几天
|
{
|
int Day = 0;
|
var time = TimeDayBeginAndOver[0];
|
if (TimeDayBeginAndOver.Length <= 0 || time == null)
|
{
|
return;
|
}
|
int hour = 0;
|
if (ResetType == 0)
|
{
|
hour = 0;
|
}
|
else
|
{
|
hour = 5;
|
}
|
DateTime time1 = new DateTime(time.Year, time.Month, time.Day, hour, 0, 0);
|
DateTime time2 = new DateTime(TimeUtility.ServerNow.Year, TimeUtility.ServerNow.Month, TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour, TimeUtility.ServerNow.Minute, TimeUtility.ServerNow.Second);
|
TimeSpan ts = time2.Subtract(time1);
|
Day = (int)ts.TotalDays;
|
if (Day <= 0)
|
{
|
Day = 0;
|
}
|
// DebugEx.LogError("输出当前的天数" + Day);
|
if (DayNow != Day && Day < 7)
|
{
|
DayNow = Day;
|
if (WeekPartyDayInfoUpdate != null)
|
{
|
WeekPartyDayInfoUpdate();
|
}
|
}
|
|
}
|
|
public void SendGetWeekParty(int day, int temdayplateID)//领取周狂欢活动奖励
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_WeekPartyAct;
|
getReward.DataEx = (uint)day;
|
string StrID = temdayplateID.ToString();
|
getReward.DataExStrLen = (byte)StrID.Length;
|
getReward.DataExStr = StrID;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
public void SendGetWeekPartyPoint(int day, int point)//领取周狂欢积分奖励
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_WeekPartyPoint;
|
getReward.DataEx = (uint)day;
|
string StrID = point.ToString();
|
getReward.DataExStrLen = (byte)StrID.Length;
|
getReward.DataExStr = StrID;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
|
public bool IsDayReward(int day, int index)//是否领取奖励
|
{
|
bool _bool = false;
|
int AwardRecord = 0;
|
foreach (var key in WeekPartyDayInfoDic.Keys)
|
{
|
if (key == day)
|
{
|
AwardRecord = WeekPartyDayInfoDic[key].AwardRecord;
|
}
|
}
|
_bool = MathUtility.GetBitValue((uint)AwardRecord, (ushort)index);
|
return _bool;
|
}
|
private void SetRedPoint()//红点设置
|
{
|
SetRedPointId();
|
foreach (var key in RedPointDic.Keys)
|
{
|
RedPointDic[key].state = RedPointState.None;
|
}
|
foreach (var key in RedPointDic.Keys)
|
{
|
RedPointDic[key].state = SetRedPointState(key);
|
}
|
}
|
private void SetRedPointId()//设置红点ID
|
{
|
if (RedPointDic.Count >= 7) { return; }
|
RedPointDic.Clear();
|
foreach (var key in WeekPartyDayInfoDic.Keys)
|
{
|
int RedPoint = Redpoint_key1 * 10 + key;
|
if (!RedPointDic.ContainsKey(key))
|
{
|
Redpoint redPointMountStare = new Redpoint(Redpoint_key1, RedPoint);
|
RedPointDic.Add(key, redPointMountStare);
|
}
|
}
|
|
}
|
List<WeekPartyItemClass> List = new List<WeekPartyItemClass>();
|
private RedPointState SetRedPointState(int day)//红点状态设置
|
{
|
if (!WeekPartyDayDic.ContainsKey(day) || !WeekPartyDayInfoDic.ContainsKey(day) || day > DayNow)
|
{
|
return RedPointState.None;
|
}
|
WeekPartyDayClass WeekPartyDay = new WeekPartyDayClass();
|
int point = WeekPartyDayInfoDic[day].Point;
|
foreach (var key in WeekPartyDayDic.Keys)
|
{
|
if (key == day)
|
{
|
WeekPartyDay = WeekPartyDayDic[key];
|
}
|
}
|
List.Clear();
|
for (int i = 0; i < WeekPartyDay.WeekPartyItem.Length; i++)
|
{
|
var item = WeekPartyDay.WeekPartyItem[i];
|
List.Add(item);
|
}
|
List.Sort(Compare);
|
|
for (int i = 0; i < List.Count; i++)//积分奖励
|
{
|
var item = List[i];
|
int type = i;
|
bool IsBool = IsDayReward(day, type);
|
if (point >= item.NeedPoint && !IsBool)
|
{
|
return RedPointState.GetReward;
|
}
|
}
|
for (int i = 0; i < WeekPartyDay.TemplateList.Length; i++)
|
{
|
var TemplateID = WeekPartyDay.TemplateList[i];
|
if (WeekPartyActionDic.ContainsKey(TemplateID))
|
{
|
var WeekPartyAction = WeekPartyActionDic[TemplateID];
|
int number = WeekPartyAction.TotalTimes / WeekPartyAction.SingleTimes;
|
int rewardNum = GetRewardNumber(day, TemplateID);//已领奖次数
|
int carryOutNum = GetCarryOutNum(day, TemplateID);//已完成次数
|
int TaypeNumber = 0;
|
if (carryOutNum - rewardNum > 0)
|
{
|
TaypeNumber = (carryOutNum - rewardNum) / WeekPartyAction.SingleTimes;
|
}
|
if (TaypeNumber > 0 && carryOutNum <= WeekPartyAction.TotalTimes)
|
{
|
return RedPointState.GetReward;
|
}
|
}
|
}
|
return RedPointState.None;
|
}
|
int Compare(WeekPartyItemClass x, WeekPartyItemClass y)//数组排列
|
{
|
if (x.NeedPoint.CompareTo(y.NeedPoint) != 0)
|
{
|
return x.NeedPoint.CompareTo(y.NeedPoint);
|
}
|
return 1;
|
}
|
public int GetWeekDay(int dayIndex)//获取周几
|
{
|
int weekDay = 1;
|
var time = TimeDayBeginAndOver[0];
|
if (TimeDayBeginAndOver.Length <= 0 || time == null)
|
{
|
return weekDay;
|
}
|
DateTime time1 = new DateTime(time.Year, time.Month, time.Day);
|
var time2 = time1.AddDays(dayIndex);
|
var dt = time2.DayOfWeek.ToString();
|
switch (dt)
|
{
|
case "Monday":
|
weekDay = 1;
|
break;
|
case "Tuesday":
|
weekDay = 2;
|
break;
|
case "Wednesday":
|
weekDay = 3;
|
break;
|
case "Thursday":
|
weekDay = 4;
|
break;
|
case "Friday":
|
weekDay = 5;
|
break;
|
case "Saturday":
|
weekDay = 6;
|
break;
|
case "Sunday":
|
weekDay = 0;
|
break;
|
}
|
return weekDay;
|
}
|
|
public void GetIsOpen()
|
{
|
var time1 = TimeDayBeginAndOver[0];
|
var time2 = TimeDayBeginAndOver[1];
|
if (TimeDayBeginAndOver.Length <= 0 || time1 == null || time2 == null)
|
{
|
return;
|
}
|
int hour = 0;
|
if (ResetType == 0)
|
{
|
hour = 0;
|
}
|
else
|
{
|
hour = 5;
|
}
|
DateTime timeStar = new DateTime(time1.Year, time1.Month, time1.Day, hour, 0, 0);
|
DateTime timeEnd = new DateTime(time2.Year, time2.Month, time2.Day, hour, 0, 0);
|
DateTime timeNow = new DateTime(TimeUtility.ServerNow.Year, TimeUtility.ServerNow.Month, TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour, TimeUtility.ServerNow.Minute, TimeUtility.ServerNow.Second);
|
int PlayerLv = PlayerDatas.Instance.baseData.LV;
|
if (PlayerLv >= LimitLV && timeNow >= timeStar && timeNow < timeEnd && !isOpenNow)
|
{
|
isOpenNow = true;
|
_IsOpen = true;
|
if (IsOpenEvent != null)
|
{
|
IsOpenEvent();
|
}
|
|
}
|
bool istimeBool = (timeNow < timeStar && !IsPreviewTime()) || (timeNow > timeEnd);
|
if (istimeBool && isOpenNow)
|
{
|
isOpenNow = false;
|
_IsOpen = false;
|
if (IsOpenEvent != null)
|
{
|
IsOpenEvent();
|
}
|
}
|
}
|
|
public bool IsJumpOpen()
|
{
|
bool Isbool = false;
|
if (LimitLV == 0)//活动未开启
|
{
|
SysNotifyMgr.Instance.ShowTip("OutofActivityTime");
|
return false;
|
}
|
else
|
{
|
if (PlayerDatas.Instance.baseData.LV < LimitLV)//等级未到达
|
{
|
SysNotifyMgr.Instance.ShowTip("NotEenoughGrade");
|
return Isbool;
|
}
|
}
|
if (_IsOpen)
|
{
|
Isbool = true;
|
}
|
return Isbool;
|
}
|
|
public bool IsPreviewTime()//是否再预览时间
|
{
|
bool _bool = false;
|
var time1 = TimeDayBeginAndOver[0];
|
var time2 = TimeDayBeginAndOver[1];
|
if (TimeDayBeginAndOver.Length <= 0 || time1 == null || time2 == null)
|
{
|
return _bool;
|
}
|
int hour = 0;
|
if (ResetType == 0)
|
{
|
hour = 0;
|
}
|
else
|
{
|
hour = 5;
|
}
|
DateTime timeStar = new DateTime(time1.Year, time1.Month, time1.Day, hour, 0, 0);
|
var TimeStar2 = timeStar.AddMinutes(-AdvanceMinutes);
|
DateTime timeNow = new DateTime(TimeUtility.ServerNow.Year, TimeUtility.ServerNow.Month, TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour, TimeUtility.ServerNow.Minute, TimeUtility.ServerNow.Second);
|
|
if (timeNow >= TimeStar2 && timeNow < timeStar)
|
{
|
_bool = true;
|
}
|
return _bool;
|
}
|
public bool IsOpenFeatures()
|
{
|
bool Isbool = false;
|
Isbool = (OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.OpenServiceAchievement)
|
|| OperationTimeHepler.Instance.SatisfyAdvanceCondition(Operation.OpenServiceAchievement));
|
return Isbool;
|
}
|
}
|
|
|
|
|
|