Files
JJBB/Assets/Project/Script/GUI/ItemCdInfo/ItemCDInfoCtr.cs
2024-08-23 15:49:34 +08:00

78 lines
2.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using GCGame.Table;
public class ItemCDInfoCtr{
public static Dictionary<int, int> itemCdInfoDic = new Dictionary<int, int>();
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;
}
}
}