CTT/Server/Hotfix/Game/Helper/ShopHelper.cs

47 lines
1.6 KiB
C#
Executable File

using Cal;
using Cal.DataTable;
using System;
using System.Collections.Generic;
using System.Text;
namespace ET
{
public class ShopHelper
{
public static void GetMarketList(Unit unit, out float discount, System.Collections.Generic.List<int> marketIdList)
{
try
{
PlayerData data = unit.GetComponent<PlayerData>();
DateTime lastDate = DateTimeOffset.FromUnixTimeMilliseconds(data.MarketLeastTime).UtcDateTime.Date;
if (DateTime.UtcNow >= lastDate.AddDays(1))
{
data.MarketLeastTime = TimeHelper.ClientNow();
data.MarketDiscount = RandomHelper.RandomFloat(0.85f, 1.15f);
int randomPeriod = RandomHelper.RandomNumber(1, 6);
while (randomPeriod == data.MarketPeriod)
{
randomPeriod = RandomHelper.RandomNumber(1, 6);
}
data.MarketPeriod = randomPeriod;
}
discount = data.MarketDiscount;
Shop shop = unit.Domain.GetComponent<Shop>();
List<(int, MarketBase)> list = shop.MarketPeriodDic[data.MarketPeriod];
if (list != null)
foreach ((int, MarketBase) item in list)
{
marketIdList.Add((int)item.Item2.Id);
}
}
catch (Exception e)
{
discount = 5;
Log.Error(e);
}
}
}
}