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.
262 lines
9.5 KiB
262 lines
9.5 KiB
using ProtoCSStruct;
|
|
using Sog;
|
|
|
|
namespace Game
|
|
{
|
|
public static class PopPackageSvc
|
|
{
|
|
public static void OnRoleEnter(PlayerOnGame player)
|
|
{
|
|
InitOrReset(player);
|
|
}
|
|
|
|
public static void OnNewDayStart(PlayerOnGame player, bool notifyClient)
|
|
{
|
|
InitOrReset(player);
|
|
}
|
|
|
|
private static void InitOrReset(PlayerOnGame player)
|
|
{
|
|
ref var packageData = ref player.RoleData.PopPackageData;
|
|
var now = GameServerUtils.GetApp().GetTimeSecond();
|
|
if (AppTime.IsSameDay(now, packageData.RefreshTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (var i = 0; i < packageData.PopList.Count; i++)
|
|
{
|
|
var id = packageData.PopList[i].PopupId;
|
|
var desc = PopUpPackageDescMgr.Instance.GetConfigByInternal(id);
|
|
if (desc.popUpLimit != PackPopLimit.Daily)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
packageData.PopList.RemoveAt(i);
|
|
}
|
|
player.RoleData.ExtData.PopCostItemRecord.Clear();
|
|
|
|
SyncDataSync(player);
|
|
}
|
|
|
|
|
|
private static void PushPopPackage(PlayerOnGame player, int popPackageId)
|
|
{
|
|
var data = player.RoleData.PopPackageData.PopList;
|
|
for (var i = 0; i < data.Count; i++)
|
|
{
|
|
if (data[i].PopupId != popPackageId) continue;
|
|
var push = new PushPopPackage()
|
|
{
|
|
PopOne = data[i]
|
|
};
|
|
player.SendToClient((int)CSGameMsgID.PushPopPackage, ref push);
|
|
return;
|
|
}
|
|
}
|
|
|
|
public static void TriggerPopPackage(PlayerOnGame player, PackPopType type, int[] param = null)
|
|
{
|
|
if (!SystemUnlockSvc.IsUnlockSys(player,SystemUnlockId.PopPack))
|
|
{
|
|
return;
|
|
}
|
|
var totalPayMoney = player.RoleData.PayData.TotalPayMoney;
|
|
|
|
foreach (var kvDesc in PopUpPackageDescMgr.Instance.ItemTable)
|
|
{
|
|
var desc = kvDesc.Value;
|
|
if (desc.popType != type)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var conduction = false;
|
|
var index = GetPopPackageIndex(player, desc.InternalId);
|
|
if (index > -1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var chargeRange = desc.chargeRange;
|
|
var payCondition = true;
|
|
if (chargeRange.Length > 0)
|
|
{
|
|
var min = chargeRange[0];
|
|
var max = chargeRange[1] == -1 ? int.MaxValue : chargeRange[1];
|
|
payCondition = totalPayMoney >= min && totalPayMoney <= max;
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case PackPopType.LevelStage: //主线章节
|
|
{
|
|
var targetId = desc.popParams[0];
|
|
var battleId = player.RoleData.ChapterData.BattleId;
|
|
conduction = battleId >= int.Parse(targetId);
|
|
}
|
|
|
|
break;
|
|
case PackPopType.Gacha: //抽卡
|
|
{
|
|
var targetId = desc.popParams[0];
|
|
var num = desc.popParams[1];
|
|
for (var i = 0; i < player.RoleData.RecruitData.Count; i++)
|
|
{
|
|
var id = player.RoleData.RecruitData[i].PoolId;
|
|
var poolId = GachaDescMgr.Instance.GetConfigByInternal(id).id;
|
|
if (!poolId.Equals(targetId)) continue;
|
|
var count = player.RoleData.RecruitData[i].RecruitCount;
|
|
conduction = count >= int.Parse(num);
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case PackPopType.Level: //等级
|
|
{
|
|
conduction = player.RoleBase.Level >= int.Parse(desc.popParams[0]);
|
|
}
|
|
break;
|
|
case PackPopType.CombatPower: //战力
|
|
conduction = player.RoleBase.Power >= int.Parse(desc.popParams[0]);
|
|
break;
|
|
case PackPopType.WingsRefit: //翅膀改造
|
|
{
|
|
var targetId = int.Parse(desc.popParams[0]);
|
|
var targetRef = int.Parse(desc.popParams[1]);
|
|
var refit = player.RoleData.WingData.WingSkinList;
|
|
for (var i = 0; i < refit.Count; i++)
|
|
{
|
|
var one = refit[i];
|
|
if (targetId != one.DescId || targetRef != one.RefitId) continue;
|
|
conduction = true;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case PackPopType.Charge: //充值
|
|
conduction = totalPayMoney >= int.Parse(desc.popParams[0]);
|
|
break;
|
|
case PackPopType.ItemCost: //道具消耗
|
|
{
|
|
var itemId = param[0];
|
|
var itemCostNum = param[1];
|
|
var itemExistNum = param[2];
|
|
|
|
var targetCostId = desc.popParams[0];
|
|
var targetCostNum = int.Parse(desc.popParams[1]);
|
|
var targetExistNum = int.Parse(desc.popParams[1]);
|
|
var targetId = ItemDescMgr.Instance.GetConfig(targetCostId)?.InternalId;
|
|
if (targetId != itemId)
|
|
{
|
|
break;
|
|
}
|
|
var allCost = -1;
|
|
ref var popCostItemRecord = ref player.RoleData.ExtData.PopCostItemRecord;
|
|
var exist = false;
|
|
for (var i = 0; i < popCostItemRecord.Count; i++)
|
|
{
|
|
if (popCostItemRecord[i].Id != itemId) continue;
|
|
popCostItemRecord[i].Value += itemCostNum;
|
|
allCost = popCostItemRecord[i].Value;
|
|
exist = true;
|
|
break;
|
|
}
|
|
if (!exist)
|
|
{
|
|
popCostItemRecord.Add(new IDValue32() { Id = itemId, Value = itemCostNum });
|
|
}
|
|
|
|
conduction = allCost > targetCostNum && itemExistNum < targetExistNum;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
TraceLog.Trace("not support pop type {0}", type);
|
|
break;
|
|
}
|
|
|
|
if (!conduction)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!payCondition)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
AppendPopPackage(player, desc.InternalId);
|
|
}
|
|
}
|
|
|
|
|
|
public static bool IsPopPackageEffective(PlayerOnGame player, string packageId)
|
|
{
|
|
var desc = PopUpPackageDescMgr.Instance.GetConfig(packageId);
|
|
|
|
var index = GetPopPackageIndex(player, desc.InternalId);
|
|
if (index < 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ref var packageData = ref player.RoleData.PopPackageData.PopList;
|
|
|
|
var now = GameServerUtils.GetApp().GetTimeSecond();
|
|
return packageData[index].EndTime > now;
|
|
}
|
|
|
|
private static void AppendPopPackage(PlayerOnGame player, int popPackageId)
|
|
{
|
|
ref var packageData = ref player.RoleData.PopPackageData.PopList;
|
|
var packageDesc = PopUpPackageDescMgr.Instance.GetConfigByInternal(popPackageId);
|
|
var endTime = 0;
|
|
var ids = new RepeatedInt_8();
|
|
foreach (var kv in PayDiamondDescMgr.Instance.ItemTable)
|
|
{
|
|
var desc = kv.Value;
|
|
if (desc.popUpPackageType != packageDesc.id)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
endTime = desc.timeLimitParam;
|
|
ids.Add(desc.itemID);
|
|
}
|
|
|
|
var now = GameServerUtils.GetApp().GetTimeSecond();
|
|
packageData.Add(new PopPackageDataOne()
|
|
{
|
|
PopupId = popPackageId,
|
|
EndTime = now + endTime,
|
|
PayDiamondId = ids,
|
|
PopNUm = 1
|
|
});
|
|
SyncDataSync(player);
|
|
PushPopPackage(player, popPackageId);
|
|
}
|
|
|
|
private static int GetPopPackageIndex(PlayerOnGame player, int popId)
|
|
{
|
|
ref var packageData = ref player.RoleData.PopPackageData.PopList;
|
|
for (var i = 0; i < packageData.Count; i++)
|
|
{
|
|
if (packageData[i].PopupId != popId) continue;
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
private static void SyncDataSync(PlayerOnGame player)
|
|
{
|
|
ref var packageData = ref player.RoleData.PopPackageData.PopList;
|
|
var sync = new SyncPopPackage();
|
|
sync.PopList.CopyFrom(ref packageData);
|
|
player.SendToClient((int)CSGameMsgID.SyncPopPackage, ref sync);
|
|
}
|
|
}
|
|
}
|