169 lines
5.9 KiB
C#
Executable File
169 lines
5.9 KiB
C#
Executable File
using System;
|
|
using Cal.DataTable;
|
|
using ET.EventType;
|
|
|
|
namespace ET
|
|
{
|
|
public class ActiveComponentAwakeSystem: AwakeSystem<ActiveComponent>
|
|
{
|
|
public override void Awake(ActiveComponent self)
|
|
{
|
|
ActiveComponent.instance = self;
|
|
}
|
|
}
|
|
|
|
public static class ActiveComponentSystem
|
|
{
|
|
/// <summary>
|
|
/// 签到奖励
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="id"></param>
|
|
/// <param name="config"></param>
|
|
/// <returns>true = 已经领取</returns>
|
|
public static bool QuerySigninReward(this ActiveComponent self, Entity unit, out SignInRewardConfig config)
|
|
{
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
DateTime dateTime = DateTime.UtcNow;
|
|
int intDayDate = TimerHelper.GetIntDayDate(dateTime);
|
|
int currId = dateTime.DayOfYear;
|
|
if ((intDayDate <= data.lastGetSigninRewardDate))
|
|
{
|
|
config = SignInRewardConfigCategory.Instance.GetByDay(currId);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
config = SignInRewardConfigCategory.Instance.GetByDay(currId);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 签到奖励
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="unit"></param>
|
|
/// <param name="configId"></param>
|
|
/// <returns></returns>
|
|
public static string GetSigninReward(this ActiveComponent self, Entity unit, long configId)
|
|
{
|
|
long id = unit.Id;
|
|
SignInRewardConfig config = SignInRewardConfigCategory.Instance.Get(configId);
|
|
if (config == null)
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} CONFIG == NULL WHERE ID = {configId}");
|
|
return "系统错误";
|
|
}
|
|
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
var now = DateTime.UtcNow;
|
|
if (config.Year != now.Year || config.Month != now.Month || config.Day != now.Day)
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} {new DateTime(config.Year, config.Month, config.Day)} 领取时间不对:{now}");
|
|
return "领取时间不对";
|
|
}
|
|
|
|
int intDayDate = TimerHelper.GetIntDayDate(now);
|
|
if (intDayDate <= data.lastGetSigninRewardDate)
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} 重复领取");
|
|
return "系统错误,您已经领取过了啊";
|
|
}
|
|
|
|
using ListComponent<(int, long)> listComponent = ListComponent<(int, long)>.Create();
|
|
|
|
foreach (SignInRewardConfig.Rewards rewards in config.RewardsArr)
|
|
{
|
|
listComponent.List.Add((rewards._Id, rewards.Count));
|
|
}
|
|
|
|
if (!ItemComponent.Instance.CanAddItem(unit, listComponent.List))
|
|
{
|
|
return "背包已满";
|
|
}
|
|
|
|
int signInCountInMonth = data.signInCountInMonth;
|
|
|
|
//累计签到奖励
|
|
if (now.Month == TimerHelper.GetMonth(data.lastGetSigninRewardDate) && now.Year == TimerHelper.GetYear(data.lastGetSigninRewardDate))
|
|
{
|
|
signInCountInMonth++;
|
|
}
|
|
else
|
|
{
|
|
signInCountInMonth = 1;
|
|
}
|
|
|
|
data.lastGetSigninRewardDate = intDayDate;
|
|
data.signInCountInMonth = signInCountInMonth;
|
|
if (signInCountInMonth == 1)
|
|
{
|
|
data.signInGetRewardCountInMonthList.Clear();
|
|
}
|
|
|
|
foreach (SignInRewardConfig.Rewards rewards in config.RewardsArr)
|
|
{
|
|
BagHelper.AddItem(unit, rewards._Id, rewards.Count, true, getSource: "签到");
|
|
}
|
|
|
|
UnitHelper.SaveComponenet(data);
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 月签到奖励
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="unit"></param>
|
|
/// <param name="configId"></param>
|
|
/// <returns></returns>
|
|
public static string GetSigninInMonthReward(this ActiveComponent self, Entity unit, long configId)
|
|
{
|
|
long id = unit.Id;
|
|
SignInRewardMonth config = SignInRewardMonthCategory.Instance.Get(configId);
|
|
if (config == null)
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} CONFIG == NULL WHERE ID = {configId}");
|
|
return "系统错误";
|
|
}
|
|
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
var now = DateTime.UtcNow;
|
|
int times = data.signInCountInMonth;
|
|
if (data.signInGetRewardCountInMonthList.Contains(config.Times))
|
|
{
|
|
return "已领取";
|
|
}
|
|
if (config.Year != now.Year || config.Month != now.Month)
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} {new DateTime(config.Year, config.Month,0)} 领取时间不对:{now}");
|
|
return "领取时间不对";
|
|
}
|
|
|
|
if (config.Times > times)
|
|
{
|
|
return "系统错误";
|
|
}
|
|
|
|
using ListComponent<(int, long)> listComponent = ListComponent<(int, long)>.Create();
|
|
foreach (SignInRewardMonth.Rewards rewards in config.RewardsArr)
|
|
{
|
|
listComponent.List.Add((rewards._Id, rewards.Count));
|
|
}
|
|
|
|
if (!ItemComponent.Instance.CanAddItem(unit, listComponent.List))
|
|
{
|
|
return "背包已满";
|
|
}
|
|
|
|
data.signInGetRewardCountInMonthList.Add(config.Times);
|
|
|
|
foreach (SignInRewardMonth.Rewards rewards in config.RewardsArr)
|
|
{
|
|
BagHelper.AddItem(unit, rewards._Id, rewards.Count, true, getSource: "签到");
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |