CTT/Server/Hotfix/Game/System/Other/ActiveComponentSystem.cs

151 lines
5.2 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>();
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 "领取时间不对";
}
int dTime = TimeHelper.GetTodayDay(now) - data.lastGetSigninRewardDate;
if (dTime <= 0)
{
Log.Error($"{id.GetPlayerFormatName()} 重复领取");
return "系统错误,您已经领取过了啊";
}
int signInCountInMonth = data.signInCountInMonth;
if (dTime == 1)
{
//累计签到奖励
if (now.Month == now.AddDays(-1).Month)
{
signInCountInMonth++;
}
else
{
signInCountInMonth = 1;
}
}
else
{
signInCountInMonth = 1;
}
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 "背包已满";
}
data.lastGetSigninRewardDate = TimeHelper.GetTodayDay(now);
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;
}
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;
}
}
}