using System; using System.Collections.Generic; using Cal.DataTable; namespace ET { public static class DropHelper { public static void Drop(Unit unit, PlayerData playerData, BattleType battleType, int parentId, UnOrderMultiMap rewordMap, float dropProperbility, string getSource, bool isLock =false ,List list=null) { try { if (parentId == 0) return ; Parentset parentSet = ParentsetCategory.Instance.Get(parentId); foreach (Parentset.Subset subSet in parentSet.SubsetArr) { int sonSetId = playerData.UpdateDrop(subSet._Id); SonSet sonSet = SonSetCategory.Instance.Get(sonSetId); (int itemId, int itemCount) = GetItemFormSet(sonSet.DropArr, dropProperbility, false); if (itemId == 0) continue; if (!isLock) { isLock = sonSet.IsLock; } BagHelper.AddItem(unit, itemId, itemCount, isLock, getSource: getSource); TaskHelper.UpdateTask(unit, itemId).Coroutine(); list?.Add(new RewardItem() { Id = itemId, Count = 1, ItemType = BagHelper.GetItemType(itemId) }); rewordMap?.Add(unit.Id, (itemId, itemCount)); try { switch (itemId) { case BagHelper.CoinId: { string sources = battleType switch { BattleType.MainStory => StatisticsTypes.CoinSources_MainStory, BattleType.TrialCopy => StatisticsTypes.CoinSources_TrialCopy, BattleType.Boss => StatisticsTypes.CoinSources_Boss, BattleType.IdleBattle => StatisticsTypes.CoinSources_IdleBattle, _ => null, }; if (sources != null) StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Coin, sources, (long) itemCount); break; } case BagHelper.GemId: { string sources = battleType switch { BattleType.MainStory => StatisticsTypes.GemSources_MainStory, BattleType.TrialCopy => StatisticsTypes.GemSources_TrialCopy, BattleType.Boss => StatisticsTypes.GemSources_Boss, _ => null, }; if (sources != null) StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Gem, sources, (long) itemCount); break; } } } catch (Exception) { // ignored } if (AppConfig.inst.isTest) Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】 掉落了【{BagHelper.GetName(itemId)}】X {itemCount}"); } } catch (Exception e) { Log.Error(e); } } private static (int, int) GetItemFormSet(IReadOnlyList arr, float damagePercent, bool isKilled) { using ListComponent listComponent = ListComponent.Create(); List weightList = listComponent.List; foreach (SonSet.Drop drop in arr) { if (drop._Id == 0) { float weight = isKilled? 0.5f * drop.Weight : drop.Weight; weight /= (damagePercent * damagePercent); weightList.Add(MathHelper.RoundToInt(weight)); } else weightList.Add(drop.Weight); } int index = MathHelper.GetProbabilityIndexByWeight(weightList); SonSet.Drop item = arr[index]; return (item._Id, RandomHelper.RandomNumber(item.MinCount, item.MaxCount + 1)); } } }