181 lines
5.9 KiB
C#
181 lines
5.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using Newtonsoft.Json;
|
|
using OrderManager;
|
|
using UI.Wheel;
|
|
using UnityEngine;
|
|
|
|
namespace UI.HookWheel
|
|
{
|
|
public class HookWheelManager : AEventDataManager<HookWheelData>,IOrderReplenishment
|
|
{
|
|
public List<ItemData> GetProgressRewards()
|
|
{
|
|
return GContext.container.Resolve<PlayerItemData>()
|
|
.GetItemDataByDropIdAndTypeLureInflation(Data.InflationRate, GetWheelRound().ProgressRewardDropID);
|
|
}
|
|
|
|
#region event
|
|
|
|
protected override int EventType => 9;
|
|
protected override int EventSubType => 8;
|
|
|
|
#endregion event
|
|
|
|
#region data
|
|
|
|
protected override void InitData(int eventId)
|
|
{
|
|
base.InitData(eventId);
|
|
Data.CurrentRoundCount = 0;
|
|
Data.RefreshCache();
|
|
Data.InflationRate = GContext.container.Resolve<PlayerData>().InflationRate;
|
|
SaveData();
|
|
if(Data.IsActive)
|
|
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(eventId, UITypes.EventHookWheelPopupPanel, 0);
|
|
}
|
|
|
|
private List<IWheelReward> _rewards = new();
|
|
|
|
private IEnumerable<IWheelReward> RemainRewards => _rewards.Where(r =>
|
|
!(Data.CurrentProgress?.Contains(r.Index) ?? true)
|
|
&& Data.CurrentProgressCount + 1 >= r.RoundLimit);
|
|
|
|
public List<IWheelReward> GetEventRewards()
|
|
{
|
|
if (Data == null)
|
|
return null;
|
|
var roundConfig = GetWheelRound();
|
|
if (roundConfig == null)
|
|
return null;
|
|
|
|
if (_rewards == null)
|
|
_rewards = new List<IWheelReward>();
|
|
else
|
|
_rewards.Clear();
|
|
|
|
foreach (var id in roundConfig.WheelRewardList)
|
|
{
|
|
var rewardConfig = Tables.TbEventHookWheelReward.Get(id);
|
|
if (rewardConfig == null || _rewards.Find(x => x.Index == rewardConfig.Index) != null)
|
|
continue;
|
|
_rewards.Add(new EventHookWheelRewardAdapter(rewardConfig, Data.InflationRate));
|
|
}
|
|
|
|
return _rewards;
|
|
}
|
|
|
|
private int _totalWeight;
|
|
private readonly List<int> weightRanges = new();
|
|
|
|
private void CalculateWeights()
|
|
{
|
|
_totalWeight = RemainRewards.Sum(r => r.Weight);
|
|
BuildWeightRanges();
|
|
}
|
|
|
|
private void BuildWeightRanges()
|
|
{
|
|
weightRanges.Clear();
|
|
var currentWeight = 0;
|
|
|
|
foreach (var reward in RemainRewards)
|
|
{
|
|
currentWeight += reward.Weight;
|
|
weightRanges.Add(currentWeight);
|
|
}
|
|
}
|
|
|
|
// 根据权重随机获取奖励
|
|
public int GetRandomRewardIndex()
|
|
{
|
|
CalculateWeights();
|
|
if (_totalWeight <= 0)
|
|
{
|
|
Debug.LogError("总权重为0");
|
|
return 0;
|
|
}
|
|
|
|
var randomValue = Random.Range(0, _totalWeight);
|
|
|
|
for (var i = 0; i < weightRanges.Count; i++)
|
|
if (randomValue < weightRanges[i])
|
|
return _rewards.IndexOf(RemainRewards.ElementAt(i));
|
|
|
|
return _rewards.IndexOf(RemainRewards.LastOrDefault());
|
|
}
|
|
|
|
public Pack GetPackConfig()
|
|
{
|
|
var packManager =
|
|
Data.Tables?.TbEventPackManager.GetOrDefault(Data.WheelMain.PackManagerID[Data.CurrentRoundCount]);
|
|
if (packManager == null)
|
|
{
|
|
Debug.LogError(
|
|
$"HookWheelManager GetPackConfig packManager is null EventPackManagerID {JsonConvert.SerializeObject(Data.WheelMain.PackManagerID)} {Data.CurrentRoundCount}");
|
|
return null;
|
|
}
|
|
|
|
var vipLevel = GContext.container.Resolve<PlayerData>().PriceLv;
|
|
var packList = packManager.VIPPackList[vipLevel];
|
|
var maxCount = Data.CurrentProgressCount < packList.Count ? Data.CurrentProgressCount : packList.Count - 1;
|
|
var packConfigID = packManager.VIPPackList[vipLevel][maxCount];
|
|
return Data.Tables?.TbPack.GetOrDefault(packConfigID);
|
|
}
|
|
|
|
private EventHookWheelRound GetWheelRound()
|
|
{
|
|
var packConfig = GetPackConfig();
|
|
var wheelRound = packConfig.DropID;
|
|
var wheelRoundConfig = Tables.TbEventHookWheelRound.GetOrDefault(wheelRound);
|
|
if (wheelRoundConfig == null)
|
|
Debug.LogError($"配置错误 约定 dropId配置 hookwheelRoundID packConfig.ID {packConfig.ID}");
|
|
|
|
return wheelRoundConfig;
|
|
}
|
|
|
|
public void AddProgress(int index)
|
|
{
|
|
Data.ShowProgress.Add(index);
|
|
Data.CurrentProgress.Add(index);
|
|
AddRoundCount();
|
|
SaveData();
|
|
}
|
|
|
|
private void AddRoundCount()
|
|
{
|
|
var wheelRound = GetWheelRound();
|
|
if (Data.ShowProgress.Count != wheelRound.TotalDrawPerRound) return;
|
|
GContext.Publish(new DeferredRewardStashService.EventStashDrop
|
|
{
|
|
DropId = wheelRound.ProgressRewardDropID,
|
|
Inflate = Data.InflationRate
|
|
});
|
|
Data.CurrentProgress?.Clear();
|
|
Data.CurrentRoundCount += 1;
|
|
Data.IsRoundCompleted = true;
|
|
Data.RefreshCache();
|
|
}
|
|
|
|
public void ForceActive()
|
|
{
|
|
if (Data == null) return;
|
|
Data.IsForceActive = true;
|
|
SaveData();
|
|
}
|
|
|
|
#endregion data
|
|
|
|
public void OnReplenish(ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift, RewardType rewardShowType,
|
|
bool voucher = false)
|
|
{
|
|
if(buyType.extraPurcheData==null) return;
|
|
if (!buyType.extraPurcheData.TryGetValue(nameof(HookWheelData), out var value)) return;
|
|
AddProgress((int)value);
|
|
}
|
|
}
|
|
} |