2021-04-13 20:39:32 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public static class DropHelper
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
public static void Drop(Unit unit, PlayerData playerData, BattleType battleType, int parentId,
|
|
|
|
|
UnOrderMultiMap<long, (int, int)> rewordMap, float dropProperbility, string getSource, bool isLock =false ,List<RewardItem> list=null)
|
2021-04-13 20:39:32 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
if (parentId == 0) return ;
|
2021-04-13 20:39:32 +08:00
|
|
|
|
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);
|
2021-05-05 13:36:19 +08:00
|
|
|
|
(int itemId, int itemCount) = GetItemFormSet(sonSet.DropArr, dropProperbility, false,out bool sonSetIsLock);
|
2021-09-07 16:20:46 +08:00
|
|
|
|
|
|
|
|
|
var domain = unit.Domain;
|
|
|
|
|
var serverItemLimit = domain.GetComponent<ServerItemLimitComponent>();
|
|
|
|
|
var canDrop=serverItemLimit.DropItem(itemId,ref itemCount);
|
|
|
|
|
if (!canDrop)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"{unit.Id.GetPlayerFormatName()}掉落达到上限,物品为{BagHelper.GetName(itemId)}");
|
|
|
|
|
itemId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 20:39:32 +08:00
|
|
|
|
if (itemId == 0) continue;
|
|
|
|
|
if (!isLock)
|
|
|
|
|
{
|
2021-05-05 13:36:19 +08:00
|
|
|
|
isLock = sonSetIsLock;
|
2021-04-13 20:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BagHelper.AddItem(unit, itemId, itemCount, isLock, getSource: getSource);
|
|
|
|
|
TaskHelper.UpdateTask(unit, itemId).Coroutine();
|
2021-05-15 14:29:48 +08:00
|
|
|
|
list?.Add(new RewardItem() { Id = itemId, Count = itemCount, ItemType = BagHelper.GetItemType(itemId) });
|
2021-04-15 00:12:07 +08:00
|
|
|
|
rewordMap?.Add(unit.Id, (itemId, itemCount));
|
2021-04-13 20:39:32 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
switch (itemId)
|
2021-04-13 20:39:32 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
case BagHelper.CoinId:
|
2021-04-13 20:39:32 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
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:
|
2021-04-13 20:39:32 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2021-04-13 20:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
// ignored
|
2021-04-13 20:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 13:36:19 +08:00
|
|
|
|
private static (int, int) GetItemFormSet(IReadOnlyList<SonSet.Drop> arr, float damagePercent, bool isKilled,out bool isLock)
|
2021-04-13 20:39:32 +08:00
|
|
|
|
{
|
|
|
|
|
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];
|
2021-05-05 13:36:19 +08:00
|
|
|
|
isLock = item.IsLock;
|
2021-04-13 20:39:32 +08:00
|
|
|
|
return (item._Id, RandomHelper.RandomNumber(item.MinCount, item.MaxCount + 1));
|
|
|
|
|
}
|
2022-05-29 23:02:28 +08:00
|
|
|
|
|
|
|
|
|
public static void SortRewordList(List<RewardItem> list)
|
|
|
|
|
{
|
|
|
|
|
using ListComponent<RewardItem> listComponent = ListComponent<RewardItem>.Create();
|
|
|
|
|
for (var i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
RewardItem rewardItem = list[i];
|
|
|
|
|
bool hasItem = false;
|
|
|
|
|
foreach (RewardItem item in listComponent.List)
|
|
|
|
|
{
|
|
|
|
|
if (item.Id == rewardItem.Id)
|
|
|
|
|
{
|
|
|
|
|
item.Count += rewardItem.Count;
|
|
|
|
|
hasItem = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!hasItem)
|
|
|
|
|
listComponent.List.Add(rewardItem);
|
|
|
|
|
}
|
|
|
|
|
list.Clear();
|
|
|
|
|
list.AddRange(listComponent.List);
|
|
|
|
|
}
|
2021-04-13 20:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|