112 lines
4.3 KiB
C#
112 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using OrderManager;
|
|
using UnityEngine;
|
|
using Activity;
|
|
|
|
namespace Capsule.Pack.Manager
|
|
{
|
|
public class CapsulePackManager : Activity.AEventDataManager<CapsulePackData>, IOrderReplenishment,
|
|
IActivityEventRedPoint<CapsulePackData>
|
|
{
|
|
#region data
|
|
public override CapsulePackData RefreshData(FishingEvent eventConfig)
|
|
{
|
|
var data = base.RefreshData(eventConfig);
|
|
if (!data.IsActive) return data;
|
|
UITypes.CapsulePackPanel.SetType(data.MainConfig.UIPanel);
|
|
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(eventConfig.ID, UITypes.CapsulePackPanel, 0);
|
|
return data;
|
|
}
|
|
|
|
public EventToyMachineRound GetRoundConfig(CapsulePackData data)
|
|
{
|
|
var packConfig = data.GetPackConfig();
|
|
var roundConfig = Tables.TbEventToyMachineRound.GetOrDefault(packConfig.DropID);
|
|
if (roundConfig == null)
|
|
Debug.LogError($"配置错误 约定 dropId配置 roundID packConfig.ID {packConfig.ID}");
|
|
|
|
return roundConfig;
|
|
}
|
|
|
|
public void AddProgress(int index, CapsulePackData data, ref bool isRoundCompleted)
|
|
{
|
|
data.CurrentProgress.Add(index);
|
|
TryAddRoundCount(data, ref isRoundCompleted);
|
|
SaveData(data);
|
|
SetRedPoint(data);
|
|
}
|
|
|
|
private void TryAddRoundCount(CapsulePackData data, ref bool isRoundCompleted)
|
|
{
|
|
var roundConfig = GetRoundConfig(data);
|
|
if (data.CurrentProgress.Count != roundConfig.TotalDrawPerRound) return;
|
|
data.CurrentProgress?.Clear();
|
|
data.CurrentRoundCount += 1;
|
|
isRoundCompleted = true;
|
|
data.RefreshCache();
|
|
}
|
|
|
|
#endregion data
|
|
#region Red
|
|
|
|
private static string GetRedPointKey() => "eventCapsulePack.red";
|
|
|
|
private bool GetRedPointState(CapsulePackData data)
|
|
{
|
|
if (!data.IsActive) return false;
|
|
var packConfig = data.GetPackConfig();
|
|
var iapItem = Tables.TbIAPItemList?.GetOrDefault(packConfig.IAPID);
|
|
return iapItem == null;
|
|
}
|
|
|
|
public void SetRedPoint(CapsulePackData data)
|
|
{
|
|
RedPointManager.Instance?.SetRedPointState(GetRedPointKey(), GetRedPointState(data));
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void OnReplenish(ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift, RewardType rewardShowType, bool voucher = false)
|
|
{
|
|
if (buyType.extraPurcheData == null) return;
|
|
//判断是不是我的补单 CapsulePackData
|
|
if (!buyType.extraPurcheData.TryGetValue(nameof(CapsulePackData), out var value)) return;
|
|
//判断是不是同一期活动
|
|
if (!buyType.extraPurcheData.TryGetValue("EventID", out var eventIdjToken)) return;
|
|
var data = LoadData();
|
|
var eventID = (int)eventIdjToken;
|
|
if (eventID != data.EventID)
|
|
{
|
|
//todo 保底机制
|
|
return;
|
|
}
|
|
//判断是不是已经加过这个进度,加过的是为重复补单,走保底
|
|
if (!buyType.extraPurcheData.TryGetValue("Progress", out var progressjToken)) return;
|
|
var progress = (int)progressjToken;
|
|
if (progress > data.CurrentProgressCount)
|
|
{
|
|
//todo 保底机制
|
|
return;
|
|
}
|
|
if (!buyType.extraPurcheData.TryGetValue("DropID", out var dropIDjToken)) return;
|
|
var dropID = (int)dropIDjToken;
|
|
var itemDatas = GContext.container.Resolve<PlayerItemData>()
|
|
.GetItemDataByDropIdLureInflation(data.InflationRate, dropID);
|
|
if (itemDatas == null)
|
|
{
|
|
Debug.LogError($"itemDatas is null, dropID:{dropID}");
|
|
return;
|
|
}
|
|
GContext.Publish(new ShowData(itemDatas, RewardType.NormalOne));
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(itemDatas, null);
|
|
GContext.Publish(new ShowData());
|
|
var isRoundCompleted = false;
|
|
AddProgress((int)value, data, ref isRoundCompleted);
|
|
}
|
|
}
|
|
}
|