You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.1 KiB
98 lines
3.1 KiB
using ProtoCSStruct;
|
|
using Sog;
|
|
|
|
namespace Game
|
|
{
|
|
//统一一些免费、每日免费,每周免费等等的奖励 得领取处理
|
|
public static class FreeRewardSvc
|
|
{
|
|
public static void OnEnter(PlayerOnGame player)
|
|
{
|
|
InitOrReset(player);
|
|
}
|
|
|
|
public static void OnNewDay(PlayerOnGame player, bool notify)
|
|
{
|
|
InitOrReset(player);
|
|
}
|
|
|
|
public static void PlayerBorn(PlayerOnGame player)
|
|
{
|
|
InitOrReset(player);
|
|
}
|
|
|
|
private static void InitOrReset(PlayerOnGame player)
|
|
{
|
|
ref var rewardData = ref player.RoleData.FreeRewardData;
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
|
|
var change = false;
|
|
if (rewardData.Daily.LastUpdateTime == 0)
|
|
{
|
|
rewardData.Daily.LastUpdateTime = now - AppTime.SECONDS_ADAY;
|
|
change = true;
|
|
}
|
|
|
|
if (!AppTime.IsSameDay(now, rewardData.Daily.LastUpdateTime))
|
|
{
|
|
rewardData.Daily.FreeIdList.Clear();
|
|
rewardData.Daily.LastUpdateTime = now;
|
|
change = true;
|
|
}
|
|
|
|
if (change)
|
|
{
|
|
player.MakeDirty();
|
|
SyncFreeData(player);
|
|
}
|
|
}
|
|
|
|
public static void OnFreeDayReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSFreeRewardReq>();
|
|
var type = req.Type;
|
|
var freeId = req.FreeId;
|
|
var desc = CommParamDescMgr.Instance.GetConfigByInternal(freeId);
|
|
ref var res = ref CSFreeRewardRes.Parser.GetMessageClear();
|
|
if (desc == null)
|
|
{
|
|
res.Ret = CSErrCode.DescNotFound;
|
|
player.SendToClient((int)CSGameMsgID.FreeRewardRes, ref res);
|
|
return;
|
|
}
|
|
switch (type)
|
|
{
|
|
case 0: //每日免费
|
|
{
|
|
|
|
ref var daily = ref player.RoleData.FreeRewardData.Daily;
|
|
if (daily.FreeIdList.Contains(freeId))
|
|
{
|
|
break;
|
|
}
|
|
daily.FreeIdList.Add(freeId);
|
|
var id = desc.str_val;
|
|
var val = desc.int_val;
|
|
var op = new UnifyOp(player, BillChangeItemReason.FreeRewardSvc);
|
|
op.AddItem(id, val);
|
|
op.DoOp(sendGetItemMsg: true);
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
SyncFreeData(player);
|
|
res.FreeId = freeId;
|
|
player.SendToClient((int)CSGameMsgID.FreeRewardRes, ref res);
|
|
player.MakeDirty();
|
|
}
|
|
|
|
private static void SyncFreeData(PlayerOnGame player)
|
|
{
|
|
var rewardData = player.RoleData.FreeRewardData;
|
|
ref var sync = ref CSFreeDataSync.Parser.GetMessageClear();
|
|
sync.Data.CopyFrom(ref rewardData);
|
|
player.SendToClient((int)CSGameMsgID.FreeRewardSync, ref sync);
|
|
}
|
|
}
|
|
}
|