using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using GCGame.Table; public class ItemCDInfoCtr{ public static Dictionary itemCdInfoDic = new Dictionary(); public static ItemCDInfoCtr Instance; public static ItemCDInfoCtr GetInstance() { if (Instance == null) Instance = new ItemCDInfoCtr(); return Instance; } public static int GetCurServerTime() { return (int)(GCGame.Utils.GetServerDateTime() - GCGame.Utils.m_startTime).TotalSeconds; } //自己读CoolDownTime (缺点:CD中物品在再次上线的时候,如果还处在CD中,会重新开始计算CD) public static void AddItemCDInfo(int itemId) { Tab_UsableItem usabItem = TableManager.GetUsableItemByID(itemId, 0); if (usabItem == null) { return; } Tab_CoolDownTime coolDown = TableManager.GetCoolDownTimeByID(usabItem.CoolDownId, 0); if (coolDown == null) { return; } AddItemCDInfo(usabItem.CoolDownId, coolDown.CDTime / 1000); } public static void AddItemCDInfo(int CDId, int time) { if (itemCdInfoDic.ContainsKey(CDId)) { itemCdInfoDic[CDId] = GetCurServerTime() + time; } else { itemCdInfoDic.Add(CDId, GetCurServerTime() + time); } } public static int GetItemCDRemainTime(int itemId) { Tab_UsableItem usabItem = TableManager.GetUsableItemByID(itemId, 0); if (usabItem == null) { return -1; } Tab_CoolDownTime coolDown = TableManager.GetCoolDownTimeByID(usabItem.CoolDownId, 0); if (coolDown == null) { return -1; } if (itemCdInfoDic.ContainsKey(usabItem.CoolDownId) && itemCdInfoDic[usabItem.CoolDownId] - GetCurServerTime() > 0) { return itemCdInfoDic[usabItem.CoolDownId] - GetCurServerTime(); } else { return 0; } } }