zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/Other/ActiveComponentSystem.cs

103 lines
3.6 KiB
C#
Raw Normal View History

2021-05-17 00:19:52 +08:00
using System;
using Cal.DataTable;
2021-05-21 22:50:06 +08:00
using ET.EventType;
2021-05-17 00:19:52 +08:00
namespace ET
2021-05-05 13:36:19 +08:00
{
2021-05-17 00:19:52 +08:00
public class ActiveComponentAwakeSystem: AwakeSystem<ActiveComponent>
2021-05-05 13:36:19 +08:00
{
public override void Awake(ActiveComponent self)
{
ActiveComponent.instance = self;
}
}
public static class ActiveComponentSystem
{
2021-05-21 22:50:06 +08:00
class ActiveComponentUpdatePerDay: AEvent<EventType.UpdatePer1DayOfMonth>
2021-05-17 00:19:52 +08:00
{
2021-05-21 22:50:06 +08:00
public override async ETTask Run(UpdatePer1DayOfMonth args)
2021-05-17 00:19:52 +08:00
{
2021-05-21 22:50:06 +08:00
ActiveComponent.instance.Clear();
2021-05-17 00:19:52 +08:00
}
2021-05-21 22:50:06 +08:00
}
2021-05-17 00:19:52 +08:00
2021-05-21 22:50:06 +08:00
/// <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;
2021-05-17 00:19:52 +08:00
config = SignInRewardConfigCategory.Instance.GetByDay(currId);
2021-05-21 22:50:06 +08:00
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;
2021-05-17 00:19:52 +08:00
}
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;
}
2021-05-21 22:50:06 +08:00
public static void Clear(this ActiveComponent self)
{
self.SignInRewardDic.Clear();
}
2021-05-05 13:36:19 +08:00
}
}