using vnxbqy.UI; using System; using System.Collections.Generic; using UnityEngine.UI; using System.Linq; using LitJson; using UnityEngine; public class LuckyCloudBuyModel : ILModel { public ILOpenServerActivityProxy activity; public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity1; public const int activityID = 2; public const Operation operationType = Operation.default18; // 幸运云购 public Redpoint redpoint = new Redpoint(MainRedPoint.XYYGRedPoint); public Dictionary luckyCloudCost = new Dictionary(); public int[] buyCntArr; //vip等级对应的次数 PackModel packModel { get { return ModelCenter.Instance.GetModelEx(); } } public event Action LuckyCloudBuyEvent; public int buyCntYet; //本轮购买次数 public int remainCnt; //本轮剩余开奖次数 public List buyersInfo = new List(); public int curRoundID; //当前轮次ID 发生变化则清空buyersInfo public int openHour; public int openMinute; public event Action LuckyCloudBuyStarNewRound; protected override void Init() { GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; ILOperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent; activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen); OpenServerActivityCenter.Instance.Register(activityID, activity, activityType); InitConfig(); } protected override void UnInit() { GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent; } public bool IsOpen() { return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType); } public bool IsAdvance() { return false; } public bool priorityOpen() { //红点 return redpoint.state == RedPointState.Simple; } void InitConfig() { luckyCloudCost.Clear(); var luckyCloudConfig = FuncConfigConfig.Get("LuckyCloudBuyCost"); var jsonObj = JsonMapper.ToObject(luckyCloudConfig.Numerical1); var keyList = jsonObj.Keys.ToList(); for (int i = 0; i < keyList.Count; i++) { int cnt = int.Parse(keyList[i]); luckyCloudCost[cnt] = JsonMapper.ToObject(jsonObj[i].ToJson()); } buyCntArr = JsonMapper.ToObject(luckyCloudConfig.Numerical2); var timeStr = luckyCloudConfig.Numerical3.Split('|'); openHour = int.Parse(timeStr[0]); openMinute = int.Parse(timeStr[1]); } public void OnBeforePlayerDataInitialize() { buyCntYet = 0; remainCnt = 0; curRoundID = 0; buyersInfo.Clear(); } public void OnPlayerLoginOk() { } private void operationTimeUpdateEvent(Operation type) { if (type == operationType) { OperationBase operationBase; if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase)) { return; } OperationLuckyCloudBuy operation = operationBase as OperationLuckyCloudBuy; if (curRoundID != operation.m_RoundID) { curRoundID = operation.m_RoundID; buyersInfo.Clear(); if (WindowCenter.Instance.IsOpen("LuckyCloudBuyWin")) { QueryBuyersInfo(); } LuckyCloudBuyStarNewRound?.Invoke(); } UpdateRedpoint(); } } public void UpdateRedpoint() { redpoint.state = RedPointState.None; OperationBase operationBase; if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase)) { return; } OperationLuckyCloudBuy operation = operationBase as OperationLuckyCloudBuy; } public void QueryBuyersInfo() { if (buyersInfo.Count > 0) return; var pack = new IL_CC005_tagCGQueryLuckyCloudBuyNumRec(); GameNetSystem.Instance.SendInfo(pack); } public void LuckyCloudBuy(int cnt) { if (packModel.GetEmptyGridCount(PackType.Item) == 0) { SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580"); return; } if (!luckyCloudCost.ContainsKey(cnt)) return; var moneyType = luckyCloudCost[cnt][0]; var money = (ulong)luckyCloudCost[cnt][1]; if (HeroControler.Instance.GetMoneyCntIL(moneyType) < money) { WindowCenter.Instance.OpenEx(); return; } //次数判断 跨服服务器几点后不限制购买次数 var now = ILTimeUtility.ServerCrossNow; if (now.Hour < openHour || (now.Hour == openHour && now.Minute < openMinute)) { if (buyCntYet + cnt > buyCntArr[Math.Min(buyCntArr.Length - 1, PlayerDatas.Instance.baseData.VIPLv)]) { SysNotifyMgr.Instance.ShowTip("LuckyCloudBuy1"); return; } } if (remainCnt < cnt) { SysNotifyMgr.Instance.ShowTip("LuckyCloudBuy2"); return; } var pack = new IL_CC110_tagCMLuckyCloudBuy(); pack.BuyCount = (ushort)cnt; GameNetSystem.Instance.SendInfo(pack); } public void UpdatePlayerLuckyCloudBuy(IL_HC108_tagMCLuckyCloudBuyPlayerInfo netPack) { buyCntYet = netPack.BuyCount; LuckyCloudBuyEvent?.Invoke(); } public void UpdateLuckyCloudBuyNumRecord(IL_HC013_tagGCLuckyCloudBuyNumRecInfo netPack) { remainCnt = netPack.RemainCount; for (int i = 0; i < netPack.Count; i++) { buyersInfo.Add(new RoundBuyInfo() { name = netPack.BuyNumRecList[i].PlayerName, num = netPack.BuyNumRecList[i].BuyNum, }); } LuckyCloudBuyEvent?.Invoke(); } public struct RoundBuyInfo { public string name; public int num; } #region 跨服分区开奖记录 public byte[] m_ZoneIDList; // 所有分区ID列表 public List m_LotteryRecList = new List(); public byte m_ZoneID; // 返回记录分区ID public byte selectZoneID { get { return m_ZoneID; } set { m_ZoneID = value; UpdateZoneID?.Invoke(); } } public event Action UpdateZoneID; public void UpdateLuckyCloudBuyLotteryRecInfo(IL_HC014_tagGCLuckyCloudBuyLotteryRecInfo netPack) { m_LotteryRecList.Clear(); m_ZoneIDList = netPack.ZoneIDList; for (int i = 0; i < netPack.LotteryRecList.Length; i++) { m_LotteryRecList.Add(new LotteryRecInfo() { SuperItemID = netPack.LotteryRecList[i].SuperItemID, SuperItemCount = netPack.LotteryRecList[i].SuperItemCount, PlayerName = netPack.LotteryRecList[i].PlayerName, LotteryNum = netPack.LotteryRecList[i].LotteryNum, LotteryTime = TimeUtility.GetTime(netPack.LotteryRecList[i].LotteryTime).ToString(), }); } selectZoneID = netPack.ZoneID; if (!WindowCenter.Instance.IsOpen("LuckyCloudAwardWin")) { WindowCenter.Instance.OpenIL(); } } public void QueryLuckyCloudAward(byte zoneID) { var pack = new IL_CC006_tagCGQueryLuckyCloudBuyLotteryRec(); pack.ZoneID = zoneID; GameNetSystem.Instance.SendInfo(pack); } public struct LotteryRecInfo { public uint SuperItemID; // 大奖物品ID public byte SuperItemCount; // 大奖物品个数 public string PlayerName; // 中奖玩家名 public ushort LotteryNum; // 开奖号码 public string LotteryTime; // 开奖时间戳,秒 } #endregion }