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.
149 lines
4.9 KiB
149 lines
4.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ProtoCSStruct;
|
|
using Sog;
|
|
|
|
namespace Game
|
|
{
|
|
public static class FistPaymentEvent
|
|
{
|
|
public static void OnPlayerBorn(PlayerOnGame player)
|
|
{
|
|
}
|
|
|
|
public static void OnBuySuccess(PlayerOnGame player, int itemId, uint payDiamond, uint addDiamond, uint money,
|
|
bool isPlayerFirstPay, long payTime3Rd, ref CSPayGoogleSuccessRes csRes)
|
|
{
|
|
var desc = PayDiamondDescMgr.Instance.GetConfig(itemId);
|
|
if (desc == null || desc.goodsType != PayGoodsType.FirstPurchase)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ref var fistPaymentGift = ref player.RoleData.PayData.FistPaymentGift;
|
|
for (var i = 0; i < fistPaymentGift.Count; i++)
|
|
{
|
|
var id = fistPaymentGift[i].ItemId;
|
|
if (id == itemId)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
player.RoleData.PayData.FistPaymentGift.Add(new FistPaymentGift()
|
|
{ ItemId = itemId, Ctime = now, ReLoginNum = 1, UpdateTime = now });
|
|
SendReward(player, itemId); //默认把第一天得给领取了
|
|
player.MakeDirty();
|
|
}
|
|
|
|
public static void OnEnter(PlayerOnGame player)
|
|
{
|
|
OnNewDay(player);
|
|
}
|
|
|
|
public static void OnNewDay(PlayerOnGame player)
|
|
{
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
ref var paymentGift = ref player.RoleData.PayData.FistPaymentGift;
|
|
for (int i = 0; i < paymentGift.Count; i++)
|
|
{
|
|
ref var payment = ref paymentGift[i];
|
|
if (AppTime.IsSameDay(payment.UpdateTime, now))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
payment.ReLoginNum++;
|
|
payment.UpdateTime = now;
|
|
}
|
|
|
|
player.MakeDirty();
|
|
}
|
|
|
|
public static void Award(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSGatFistPaymentAwardReq>();
|
|
var itemId = req.ItemId;
|
|
SendReward(player, itemId);
|
|
}
|
|
|
|
private static void SendReward(PlayerOnGame player, int itemId)
|
|
{
|
|
var desc = PayDiamondDescMgr.Instance.GetConfig(itemId);
|
|
|
|
var cmd = (int)CSGameMsgID.FistPaymentAwardRes;
|
|
var res = new CSGatFistPaymentAwardRes();
|
|
if (desc is not { goodsType: PayGoodsType.FirstPurchase })
|
|
{
|
|
res.Ret = (int)CSErrCode.DescNotFound;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
|
|
var index = -1;
|
|
ref var fistPaymentGift = ref player.RoleData.PayData.FistPaymentGift;
|
|
for (var i = 0; i < fistPaymentGift.Count; i++)
|
|
{
|
|
var id = fistPaymentGift[i].ItemId;
|
|
if (id == itemId)
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (index == -1)
|
|
{
|
|
res.Ret = (int)CSErrCode.DescNotFound;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
|
|
|
|
ref var payment = ref fistPaymentGift[index];
|
|
var dayElapse = AppTime.GetDayElapse(now, payment.Ctime) + 1;
|
|
|
|
if (dayElapse < 0)
|
|
{
|
|
res.Ret = (int)CSErrCode.DescNotFound;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
|
|
var op = new UnifyOp(player, BillChangeItemReason.FirstPayment);
|
|
var group = SignRewardDescMgr.Instance.GetGroup(desc.SignType);
|
|
dayElapse = Math.Min(group.Count, payment.ReLoginNum);
|
|
for (var i = 1; i <= dayElapse; i++)
|
|
{
|
|
var gainDay = i;
|
|
if (payment.Record.Contains(gainDay))
|
|
{
|
|
continue;
|
|
}
|
|
var signDesc = SignRewardDescMgr.Instance.GetConfig(desc.SignType, gainDay);
|
|
var rd = signDesc.paySignItem;
|
|
foreach (var item in rd)
|
|
{
|
|
op.AddGoods(item.type, item.id, item.value);
|
|
}
|
|
payment.Record.Add(gainDay);
|
|
}
|
|
|
|
op.DoOp(sendGetItemMsg: true);
|
|
SyncData(player);
|
|
player.MakeDirty();
|
|
player.SendToClient(cmd, ref res);
|
|
}
|
|
|
|
private static void SyncData(PlayerOnGame player)
|
|
{
|
|
var sync = new CSFistPaymentInfoSync();
|
|
sync.FistPaymentGift.CopyFrom(ref player.RoleData.PayData.FistPaymentGift);
|
|
player.SendToClient((int)CSGameMsgID.FistPaymentInfoSync, ref sync);
|
|
}
|
|
}
|
|
}
|