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.
295 lines
10 KiB
295 lines
10 KiB
using System.Collections.Generic;
|
|
using ProtoCSStruct;
|
|
using Sog;
|
|
|
|
namespace Game
|
|
{
|
|
public static class MonthlyCardSvc
|
|
{
|
|
public static void CheckMonthCardOutTime(PlayerOnGame player, int nowTime)
|
|
{
|
|
var timeout = false;
|
|
for (var i = 0; i < player.RoleData.PayData.MonthlyCard.Count; i++)
|
|
{
|
|
ref var cardData = ref player.RoleData.PayData.MonthlyCard[i];
|
|
if (cardData.IsTimeOutCard)
|
|
continue;
|
|
if (cardData.ExpireTime < 0) //过滤掉永久卡
|
|
continue;
|
|
if (nowTime < cardData.ExpireTime)
|
|
continue;
|
|
cardData.IsTimeOutCard = true;
|
|
RecMonthlyCardBuff(player, cardData.CardId, true);
|
|
player.MakeDirty();
|
|
timeout = true;
|
|
}
|
|
|
|
if (timeout)
|
|
{
|
|
SyncInfo(player);
|
|
}
|
|
}
|
|
|
|
|
|
public static void OnBuySuccess(PlayerOnGame player, int itemId, uint payDiamond, uint addDiamond, uint money,
|
|
bool isPlayerFirstPay,
|
|
long payTime3Rd, ref CSPayGoogleSuccessRes csRes)
|
|
{
|
|
PayDiamondDesc dec = PayDiamondDescMgr.Instance.GetConfig(itemId);
|
|
if (dec == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (dec.vipCardType == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
PlayerDataSvc.ReCalcPlayerProp(player);
|
|
}
|
|
|
|
public static bool IsActive(PlayerOnGame player, int monthlyCardId)
|
|
{
|
|
var monthlyCard = player.RoleData.PayData.MonthlyCard;
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
|
|
for (int i = 0; i < monthlyCard.Count; i++)
|
|
{
|
|
if (monthlyCard[i].CardId == monthlyCardId && now < monthlyCard[i].ExpireTime)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private static bool IsActive(MonthlyCardData card)
|
|
{
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
return now < card.ExpireTime;
|
|
}
|
|
|
|
|
|
public static void GetDailyFreeReward(PlayerOnGame player)
|
|
{
|
|
var last = player.RoleData.PayData.LastMonthlyCardFreeAward;
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
var res = new CSCardGetDailyAwardRes();
|
|
var cmd = (int)CSGameMsgID.CardGetDailyAwardRes;
|
|
if (AppTime.IsSameDay(last, now))
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
player.RoleData.PayData.LastMonthlyCardFreeAward = now;
|
|
var rewardDesc = CommParamDescMgr.Instance.MonthlyDayAward;
|
|
var id = rewardDesc.str_val;
|
|
var val = rewardDesc.int_val;
|
|
UnifyOp op = new UnifyOp(player, BillChangeItemReason.MonthlyFree );
|
|
op.AddItem(id, val);
|
|
op.DoOp(sendGetItemMsg: true);
|
|
PlayerNotify.NotifyPlayerPayDataChange(player);
|
|
player.SendToClient(cmd, ref res);
|
|
player.MakeDirty();
|
|
}
|
|
|
|
//领取月卡每日奖励
|
|
public static void GetDailyReward(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSCardGetDailyAwardReq>();
|
|
var cardId = req.CardId;
|
|
if (req.IsFree)
|
|
{
|
|
GetDailyFreeReward(player);
|
|
return;
|
|
}
|
|
|
|
var res = new CSCardGetDailyAwardRes();
|
|
var isActive = IsActive(player, cardId);
|
|
var cmd = (int)CSGameMsgID.CardGetDailyAwardRes;
|
|
if (!isActive)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
|
|
ref var monthlyCard = ref player.RoleData.PayData.MonthlyCard;
|
|
var index = -1;
|
|
for (int i = 0; i < monthlyCard.Count; i++)
|
|
{
|
|
if (monthlyCard[i].CardId == cardId)
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
var now = GameServerUtils.GetTimeSecond();
|
|
if (AppTime.IsSameDay(monthlyCard[index].LastRewardTime, now))
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient(cmd, ref res);
|
|
return;
|
|
}
|
|
|
|
var cardDesc = MonthlyCardDescMgr.Instance.GetConfig(cardId);
|
|
var dailyReward = cardDesc.vipCardDailyReward;
|
|
UnifyOp unifyOp = new UnifyOp(player, BillChangeItemReason.MonthlyCard);
|
|
foreach (var reward in dailyReward)
|
|
{
|
|
unifyOp.AddGoods(reward.type, reward.id, reward.value);
|
|
}
|
|
|
|
unifyOp.DoOp(sendGetItemMsg: true);
|
|
player.RoleData.PayData.MonthlyCard[index].LastRewardTime = now;
|
|
res.Ret = CSErrCode.None;
|
|
SyncInfo(player);
|
|
player.MakeDirty();
|
|
player.SendToClient(cmd, ref res);
|
|
}
|
|
|
|
|
|
public static void SyncInfo(PlayerOnGame player)
|
|
{
|
|
var sync = new CSMonthlyCardInfoSync();
|
|
sync.MonthlyCard.CopyFrom(ref player.RoleData.PayData.MonthlyCard);
|
|
player.SendToClient((int)CSGameMsgID.MonthlyCardInfoSyn, ref sync);
|
|
}
|
|
|
|
//获取月卡有效时间
|
|
public static long GetMonthlyCardValidTime(int cardId)
|
|
{
|
|
var desc = MonthlyCardDescMgr.Instance.GetConfig(cardId);
|
|
if (desc == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var duration = desc.duration;
|
|
if (duration == 0)
|
|
{
|
|
int nowSec = (int)GameServerUtils.GetTimeSecond();
|
|
return -1 * AppTime.GetTodayStartTime(nowSec); //永久
|
|
}
|
|
|
|
return AppTime.SECONDS_ADAY * duration;
|
|
}
|
|
|
|
//激活月卡
|
|
public static void OnActiveMonthlyCard(PlayerOnGame player, int cardId)
|
|
{
|
|
if (!PayCommSvc.IsMonthlyCard(cardId))
|
|
{
|
|
return;
|
|
}
|
|
|
|
int nowSec = (int)GameServerUtils.GetTimeSecond();
|
|
long cardValidTime = GetMonthlyCardValidTime(cardId);
|
|
|
|
int index = PlayerPayUtil.GetMonthlyCardDataIndex(player, cardId);
|
|
if (index == -1)
|
|
{
|
|
ref var monthlyCard = ref player.RoleData.PayData.MonthlyCard;
|
|
if (monthlyCard.Count < monthlyCard.GetMaxCount())
|
|
{
|
|
var desc = MonthlyCardDescMgr.Instance.GetConfig(cardId);
|
|
|
|
var data = new MonthlyCardData
|
|
{
|
|
CardType = desc.cardType,
|
|
CardId = cardId,
|
|
// 减去一秒, 04:59:59结束
|
|
ExpireTime = (int)AppTime.GetTodayStartTime(nowSec) + (int)cardValidTime - 1,
|
|
LastRewardTime = 0,
|
|
IsTimeOutCard = false,
|
|
};
|
|
monthlyCard.Add(ref data);
|
|
}
|
|
else
|
|
{
|
|
// 没有空间, 理论上不可能, 除非策划加了一堆月卡没有告诉程序, 打错误日志人工处理
|
|
TraceLog.Error("PayCommSvc.OnPayMonthlyCardSucc uid {0} no card {1} space"
|
|
, player.UserID, (VipCardType)cardId);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ref var cardData = ref PlayerPayUtil.GetMonthlyCardDataByIndex(player, index);
|
|
cardData.IsTimeOutCard = false;
|
|
// 月卡过期从当天开始算, 没有过期接着往后加30天
|
|
if (nowSec > cardData.ExpireTime)
|
|
{
|
|
// 减去一秒, 04:59:59结束
|
|
cardData.ExpireTime = (int)AppTime.GetTodayStartTime(nowSec) + (int)cardValidTime - 1;
|
|
}
|
|
else
|
|
{
|
|
cardData.ExpireTime += (int)cardValidTime;
|
|
}
|
|
|
|
TraceLog.Trace("PayCommSvc.OnPayMonthlyCardSucc uid {0} card {1} expireTime {2}"
|
|
, player.UserID, (VipCardType)cardId, cardData.ExpireTime);
|
|
}
|
|
|
|
RecMonthlyCardBuff(player, cardId);
|
|
player.MakeDirty();
|
|
SyncInfo(player);
|
|
}
|
|
|
|
|
|
private static void RecMonthlyCardBuff(PlayerOnGame player, int cardId, bool timeout = false)
|
|
{
|
|
var desc = MonthlyCardDescMgr.Instance.GetConfig(cardId);
|
|
if (timeout)
|
|
{
|
|
//特殊处理
|
|
player.RoleData.PowerPointData.ExtMopTimes -= desc.addSweepTimes;
|
|
}
|
|
else
|
|
{
|
|
player.RoleData.PowerPointData.ExtMopTimes += desc.addSweepTimes;
|
|
}
|
|
|
|
//触发月卡带来的体力上限制
|
|
PlayerDataSvc.AddPower(player, 0);
|
|
RolePropUtil.RecalRoleProp(player, true);
|
|
}
|
|
|
|
|
|
//获取月卡权益
|
|
public static int GetMonthlyCardBuff(PlayerOnGame player, string buffId)
|
|
{
|
|
var configs = MonthlyCardDescMgr.Instance.ItemTable;
|
|
var sum = 0;
|
|
foreach (var desc in configs.Values)
|
|
{
|
|
if (!IsActive(player, desc.id)) continue;
|
|
desc.buffer.TryGetValue(buffId, out var ret);
|
|
sum += ret;
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
public static void CollectMonthlyProp(ref DBRoleData roleData, RoleProp roleProp)
|
|
{
|
|
ref var cards = ref roleData.PayData.MonthlyCard;
|
|
for (var i = 0; i < cards.Count; i++)
|
|
{
|
|
var card = cards[i];
|
|
if (IsActive(card))
|
|
{
|
|
var desc = MonthlyCardDescMgr.Instance.GetConfig(card.CardId);
|
|
if (desc != null && desc.luckPropUp != 0)
|
|
{
|
|
roleProp.AddProp(PropertyDef.Luck, desc.luckPropUp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|