103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
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
|
|
{
|
|
class ActiveComponentUpdatePerDay: AEvent<EventType.UpdatePer1DayOfMonth>
|
|
{
|
|
public override async ETTask Run(UpdatePer1DayOfMonth args)
|
|
{
|
|
ActiveComponent.instance.Clear();
|
|
}
|
|
}
|
|
|
|
/// <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>();
|
|
int currId = DateTime.UtcNow.DayOfYear;
|
|
config = SignInRewardConfigCategory.Instance.GetByDay(currId);
|
|
return data.lastGetSigninRewardDate >= TimeHelper.GetTodayDay();
|
|
}
|
|
|
|
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 "领取时间不对";
|
|
}
|
|
if (data.lastGetSigninRewardDate >= TimeHelper.GetTodayDay(now))
|
|
{
|
|
Log.Error($"{id.GetPlayerFormatName()} 重复领取");
|
|
return "系统错误,您已经领取过了啊";
|
|
}
|
|
|
|
data.lastGetSigninRewardDate = TimeHelper.GetTodayDay(now);
|
|
|
|
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 "背包已满";
|
|
}
|
|
|
|
foreach (SignInRewardConfig.Rewards rewards in config.RewardsArr)
|
|
{
|
|
BagHelper.AddItem(unit, rewards._Id, rewards.Count, true, getSource: "签到");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static bool GetOnLineReward(this ActiveComponent self, long id, out OnlineRewardBase config)
|
|
{
|
|
if (!self.SignInRewardDic.TryGetValue(id, out int currId))
|
|
{
|
|
self.SignInRewardDic[id] = currId = DateTime.UtcNow.DayOfYear;
|
|
config = OnlineRewardBaseCategory.Instance.Get(currId);
|
|
return false;
|
|
}
|
|
|
|
config = OnlineRewardBaseCategory.Instance.Get(currId);
|
|
return true;
|
|
}
|
|
|
|
public static void Clear(this ActiveComponent self)
|
|
{
|
|
self.SignInRewardDic.Clear();
|
|
}
|
|
}
|
|
} |