98 lines
4.4 KiB
C#
98 lines
4.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Cal.DataTable;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
public static class DropHelper
|
|||
|
{
|
|||
|
public static M2C_SendReward Drop(Unit unit, PlayerData playerData, BattleType battleType, int parentId,
|
|||
|
UnOrderMultiMap<long, (int, int)> rewordMap, float dropProperbility, string getSource, bool isLock = false)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
M2C_SendReward rewardRet = new M2C_SendReward();
|
|||
|
if (parentId == 0) return rewardRet;
|
|||
|
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();
|
|||
|
rewardRet.ItemList.Add(new RewardItem() { Id = itemId, Count = 1, ItemType = BagHelper.GetItemType(itemId) });
|
|||
|
rewordMap.Add(unit.Id, (itemId, itemCount));
|
|||
|
try
|
|||
|
{
|
|||
|
if (itemId == 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);
|
|||
|
}
|
|||
|
else if (itemId == 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);
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
if (AppConfig.inst.isTest)
|
|||
|
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】 掉落了【{BagHelper.GetName(itemId)}】X {itemCount}");
|
|||
|
}
|
|||
|
|
|||
|
return rewardRet;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Log.Error(e);
|
|||
|
return new M2C_SendReward();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static (int, int) GetItemFormSet(SonSet.Drop[] arr, float damagePercent, bool isKilled)
|
|||
|
{
|
|||
|
using ListComponent<int> listComponent = ListComponent<int>.Create();
|
|||
|
List<int> 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));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|