少年修仙传客户端代码仓库
Client_PangDeRong
2018-10-09 680f85a1e7a86aa04473a7839e74c68537a0ca01
4074  【前端】限时抢购开发
2个文件已修改
6个文件已添加
447 ■■■■■ 已修改文件
System/OpenServerActivity/FlashRushToBuyCoolDown.cs 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/FlashRushToBuyCoolDown.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/FlashRushToBuyModel.cs 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/FlashRushToBuyModel.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/FlashRushToBuyWin.cs 138 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/OperationFlashRushToBuy.cs 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/OperationFlashRushToBuy.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/Welfare/OperationTimeHepler.cs 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/FlashRushToBuyCoolDown.cs
New file
@@ -0,0 +1,96 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Snxxz.UI
{
    public class FlashRushToBuyCoolDown : MonoBehaviour
    {
        [SerializeField] TimerBehaviour m_Time;
        [SerializeField] RectTransform m_ContainerAdvance;
        [SerializeField] Text m_AdvanceTime;
        private void OnEnable()
        {
            SecondEvent();
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            GlobalTimeEvent.Instance.secondEvent += SecondEvent;
            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
            OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;
        }
        private void DayResetEvent(int resetType)
        {
            SecondEvent();
        }
        private void SecondEvent()
        {
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase))
            {
                var operation = (operationBase as OperationFlashRushToBuy);
                bool inAdvance = false;
                var seconds = 0;
                if (operation.InAdvanceTime(TimeUtility.ServerNow))
                {
                    inAdvance = true;
                    seconds = operation.GetSecondsBeforeStart(TimeUtility.ServerNow);
                }
                else
                {
                    seconds = operation.GetResetSurplusTime();
                }
                m_ContainerAdvance.gameObject.SetActive(inAdvance);
                if (inAdvance)
                {
                    if (m_Time.gameObject.activeSelf)
                    {
                        DisplayTime(0);
                    }
                    DisplayAdvance(seconds);
                }
                else
                {
                    if (seconds * TimeSpan.TicksPerSecond >= TimeSpan.TicksPerDay || seconds <= 0)
                    {
                        if (m_Time.gameObject.activeSelf)
                        {
                            DisplayTime(0);
                        }
                    }
                    else
                    {
                        m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
                        if (!m_Time.gameObject.activeSelf)
                        {
                            DisplayTime(seconds);
                        }
                    }
                }
            }
        }
        private void OnDisable()
        {
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
            m_Time.gameObject.SetActive(false);
        }
        void DisplayTime(int seconds)
        {
            m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
            m_Time.Begin(seconds);
        }
        void DisplayAdvance(int seconds)
        {
            m_AdvanceTime.text = Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToHMS(seconds));
        }
    }
}
System/OpenServerActivity/FlashRushToBuyCoolDown.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 00bbdfc8d38efc7488d8dc83b041b07a
timeCreated: 1539088207
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/OpenServerActivity/FlashRushToBuyModel.cs
New file
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Snxxz.UI
{
    public class FlashRushToBuyModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
    {
        public override void Init()
        {
        }
        public void OnBeforePlayerDataInitialize()
        {
        }
        public void OnAfterPlayerDataInitialize()
        {
        }
        public void OnPlayerLoginOk()
        {
        }
        public override void UnInit()
        {
        }
    }
}
System/OpenServerActivity/FlashRushToBuyModel.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1155d8a33808d2640ab01bedff0bb06b
timeCreated: 1539086199
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/OpenServerActivity/FlashRushToBuyWin.cs
@@ -8,33 +8,161 @@
        [SerializeField] ScrollerController saleItemCtrl;
        [SerializeField] ScrollerController saleTimeCtrl;
        [SerializeField] Text opreationTimeText;
        [SerializeField] Image moneyIcon;
        [SerializeField] Text moneyNumText;
        StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
        FlashSaleModel model { get { return ModelCenter.Instance.GetModel<FlashSaleModel>(); } }
        #region Built-in
        protected override void BindController()
        {
        }
        protected override void AddListeners()
        {
        }
        protected override void OnPreOpen()
        {
            GlobalTimeEvent.Instance.secondEvent += SecondEvent;
            TimeMgr.Instance.OnDayEvent += OnDayEvent;
            OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            OperationTimeHepler.Instance.operationTimeUpdateEvent += OperationTimeUpdateEvent;
            CreateOperationTimes();
            Display();
        }
        protected override void OnAfterOpen()
        {
            model.SetDayRemind();
        }
        protected override void OnPreClose()
        {
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            TimeMgr.Instance.OnDayEvent -= OnDayEvent;
            OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
            storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
            OperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationTimeUpdateEvent;
        }
        protected override void OnAfterClose()
        {
        }
        #endregion
        private void CreateOperationTimes()
        {
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase))
            {
                OperationFlashRushToBuy operation = operationBase as OperationFlashRushToBuy;
                saleTimeCtrl.Refresh();
                for(int i = 0; i < operation.times.Count; i++)
                {
                    saleTimeCtrl.AddCell(ScrollerDataType.Header,i,CreateSaleItem);
                }
                saleTimeCtrl.Restart();
            }
        }
        public void CreateSaleItem(CellView cellView)
        {
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase))
            {
                OperationFlashRushToBuy operation = operationBase as OperationFlashRushToBuy;
                OperationFlashRushToBuy.FlashSale flashSale;
            }
        }
        private void OperationTimeUpdateEvent(Operation type)
        {
            if (type == Operation.FlashSale)
            {
                Display();
            }
        }
        private void RefreshBuyShopLimitEvent()
        {
            Display();
        }
        private void Display()
        {
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase))
            {
                OperationFlashRushToBuy operation = operationBase as OperationFlashRushToBuy;
                opreationTimeText.text = StringUtility.Contact(Language.Get("ExpActivity_Text1"), operation.ToDisplayTime());
                OperationFlashRushToBuy.FlashSale flashSale;
                if (operation.TryGetFlashSale(TimeUtility.ServerNow, out flashSale))
                {
                    if (flashSale.gifts.Length > 0)
                    {
                        var moneyType = flashSale.gifts[0].moneyType;
                        moneyIcon.SetIconWithMoneyType(moneyType);
                        moneyNumText.text = UIHelper.GetMoneyCnt(moneyType).ToString();
                    }
                }
            }
            GetSurplusTime();
        }
        private void OperationStartEvent(Operation type, int state)
        {
            if (type == Operation.FlashRushToBuy && state == 0)
            {
                Display();
            }
        }
        private void SecondEvent()
        {
            GetSurplusTime();
        }
        private void OnDayEvent()
        {
            Display();
        }
        private string GetSurplusTime()
        {
            OperationBase operationBase;
            OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase);
            var seconds = 0;
            var inAdvance = false;
            if (operationBase != null)
            {
                if (operationBase.InAdvanceTime(TimeUtility.ServerNow))
                {
                    inAdvance = true;
                    seconds = operationBase.GetSecondsBeforeStart(TimeUtility.ServerNow);
                }
                else
                {
                    OperationFlashRushToBuy operation = operationBase as OperationFlashRushToBuy;
                    seconds = operation.GetResetSurplusTime();
                }
            }
            if (seconds > 0)
            {
                if (inAdvance)
                {
                    return Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToDHMSCHS(seconds));
                }
                else
                {
                    return Language.Get("LimitGift1", TimeUtility.SecondsToDHMSCHS(seconds));
                }
            }
            else
            {
                return Language.Get("ActivityEnd");
            }
        }
    }
System/OpenServerActivity/OperationFlashRushToBuy.cs
New file
@@ -0,0 +1,103 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class OperationFlashRushToBuy : OperationBase
    {
        public List<FlashSale> flashShops = new List<FlashSale>();
        public bool TryGetFlashSale(DateTime time, out FlashSale flashSale)
        {
            flashSale = default(FlashSale);
            var index = IndexOfTime(time, inAdvanceMinute > 0 ? -1 : 0);
            index = Mathf.Min(index, flashShops.Count - 1);
            if (index >= 0)
            {
                flashSale = flashShops[index];
            }
            return index >= 0;
        }
        public override bool SatisfyOpenCondition()
        {
            return PlayerDatas.Instance.baseData.LV >= limitLv;
        }
        public override void Reset()
        {
            base.Reset();
            flashShops.Clear();
        }
        public override string ToDisplayTime()
        {
            var textBuilder = OperationTimeHepler.textBuilder;
            textBuilder.Length = 0;
            textBuilder.Append(startDate.ToDisplay());
            if (startDate != endDate)
            {
                textBuilder.Append("—");
                textBuilder.Append(endDate.ToDisplay());
            }
            return textBuilder.ToString();
        }
        public void ParsePackage(HAA11_tagMCSpringSaleInfo package)
        {
            for (int i = 0; i < package.ShopCount; i++)
            {
                var flashShop = new FlashSale();
                var shop = package.ShopInfo[i];
                flashShop.gifts = new FlashSaleGift[shop.GiftbagCount];
                for (int k = 0; k < shop.GiftbagCount; k++)
                {
                    var gift = new FlashSaleGift();
                    var pakGift = shop.GiftbagInfo[k];
                    gift.id = (int)pakGift.GiftID;
                    gift.limitNum = pakGift.BuyCountLimit;
                    gift.moneyNumber = (int)pakGift.MoneyNumber;
                    gift.moneyType = pakGift.MoneyType;
                    gift.moneyOriginal = (int)pakGift.MoneyOriginal;
                    gift.items = new FlashSaleItem[pakGift.GiftItemCount];
                    for (int q = 0; q < pakGift.GiftItemCount; q++)
                    {
                        var item = new FlashSaleItem();
                        item.itemId = (int)pakGift.ItemInfo[q].ItemID;
                        item.isBind = pakGift.ItemInfo[q].IsBind;
                        item.itemCount = pakGift.ItemInfo[q].ItemCount;
                        item.isMainItem = pakGift.ItemInfo[q].IsMainItem == 1;
                        gift.items[q] = item;
                    }
                    flashShop.gifts[k] = gift;
                }
                flashShops.Add(flashShop);
            }
        }
        public struct FlashSale
        {
            public FlashSaleGift[] gifts;
        }
        public struct FlashSaleGift
        {
            public int id;
            public int limitNum;
            public int moneyType;
            public int moneyNumber;
            public int moneyOriginal;
            public FlashSaleItem[] items;
        }
        public struct FlashSaleItem
        {
            public int itemId;
            public int itemCount;
            public int isBind;
            public bool isMainItem;
        }
    }
}
System/OpenServerActivity/OperationFlashRushToBuy.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6b7d522af470b8a42b9127be5090cb6f
timeCreated: 1539088859
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/Welfare/OperationTimeHepler.cs
@@ -223,6 +223,45 @@
        }
        /// <summary>
        /// 限时抢购
        /// </summary>
        /// <param name="package"></param>
        public void UpdateFlashRushToBuy(HAA11_tagMCSpringSaleInfo package)
        {
            OperationBase operationBase = null;
            operationDict.TryGetValue(Operation.FlashRushToBuy, out operationBase);
            if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
            {
                ForceStopOperation(Operation.FlashRushToBuy);
            }
            else
            {
                if (operationBase == null)
                {
                    operationBase = new OperationFlashRushToBuy();
                    operationDict.Add(Operation.FlashRushToBuy, operationBase);
                }
                OperationFlashRushToBuy operation = operationBase as OperationFlashRushToBuy;
                operation.Reset();
                operation.limitLv = package.LimitLV;
                operation.startDate = ParseOperationDate(package.StartDate);
                operation.endDate = ParseOperationDate(package.EndtDate);
                operation.dayReset = package.IsDayReset == 1;
                operation.inAdvanceMinute = package.AdvanceMinutes;
                for (int i = 0; i < package.ActivityTimeCount; i++)
                {
                    operation.times.Add(ParseOperationTime(package.ActivityTime[i].StartTime,
                        package.ActivityTime[i].EndtTime));
                }
                operation.ParsePackage(package);
                if (operationTimeUpdateEvent != null)
                {
                    operationTimeUpdateEvent(Operation.FlashRushToBuy);
                }
            }
        }
        /// <summary>
        /// 限时礼包
        /// </summary>
        /// <param name="package"></param>
@@ -643,11 +682,12 @@
    {
        MultipleExp,
        ConsumeRebate,
        FlashSale,
        FlashSale,//限时特惠
        BossReborn,
        GiftPackage,
        FairyCeremony, //仙界盛典
        MultipRealmPoint, //N倍修行点
        FlashRushToBuy, //限时抢购
        max,
    }
}