|
@@ -0,0 +1,151 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using Excel2Json;
|
|
|
+using Fort23.UTool;
|
|
|
+using GameLogic.Bag;
|
|
|
+using Utility;
|
|
|
+
|
|
|
+namespace GameLogic.Player
|
|
|
+{
|
|
|
+ public class DropManager : Singleton<DropManager>
|
|
|
+ {
|
|
|
+ public Random Random = new Random();
|
|
|
+
|
|
|
+
|
|
|
+ private Map<int, List<DropCountConfig>> dropCountGroupDic = new Map<int, List<DropCountConfig>>();
|
|
|
+ private Map<int, int> maxWight = new Map<int, int>();
|
|
|
+
|
|
|
+ public DropManager()
|
|
|
+ {
|
|
|
+ Random = new Random(System.DateTime.Now.Millisecond);
|
|
|
+ DropCountConfig[] allDropCountConfigs = ConfigComponent.Instance.GetAll<DropCountConfig>();
|
|
|
+ for (int i = 0; i < allDropCountConfigs.Length; i++)
|
|
|
+ {
|
|
|
+ DropCountConfig dropCountConfig = allDropCountConfigs[i];
|
|
|
+ if (dropCountGroupDic.TryGetValue(dropCountConfig.ID, out var list))
|
|
|
+ {
|
|
|
+ maxWight[dropCountConfig.ID] += dropCountConfig.weight;
|
|
|
+ list.Add(dropCountConfig);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ list = new List<DropCountConfig>();
|
|
|
+ list.Add(dropCountConfig);
|
|
|
+ dropCountGroupDic.Add(dropCountConfig.ID, list);
|
|
|
+ maxWight.Add(dropCountConfig.ID, dropCountConfig.weight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ItemInfo> DropItem(int dropId)
|
|
|
+ {
|
|
|
+ DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(dropId);
|
|
|
+ if (dropConfig.ID <= 0)
|
|
|
+ {
|
|
|
+ LogTool.Error("没有这个掉落组" + dropId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dropConfig.dropType == 1)
|
|
|
+ {
|
|
|
+ return DropItemFor1(dropConfig);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return DropItemFor2(dropConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ItemInfo> DropItemFor1(DropConfig dropConfig)
|
|
|
+ {
|
|
|
+ List<ItemInfo> itemInfos = new List<ItemInfo>();
|
|
|
+ for (int i = 0; i < dropConfig.dropGroupID.Length; i++)
|
|
|
+ {
|
|
|
+ int dropGroupId = dropConfig.dropGroupID[i];
|
|
|
+ DropGroupConfig dropGroupConfig = ConfigComponent.Instance.Get<DropGroupConfig>(dropGroupId);
|
|
|
+ int odd = Random.Next(0, 1000);
|
|
|
+ if (odd <= dropGroupConfig.dropRate)
|
|
|
+ {
|
|
|
+ DropItemConfig(itemInfos, dropGroupConfig.dropItemID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return itemInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DropItemConfig(List<ItemInfo> itemInfos, int[] dropItemID)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < dropItemID.Length; i++)
|
|
|
+ {
|
|
|
+ DropItemConfig dropItemConfig = ConfigComponent.Instance.Get<DropItemConfig>(dropItemID[i]);
|
|
|
+ for (int j = 0; j < dropItemConfig.itemID.Length; j++)
|
|
|
+ {
|
|
|
+ int c = 0;
|
|
|
+ if (dropItemConfig.dropCountGoupID > 0)
|
|
|
+ {
|
|
|
+ DropCountConfig dropCountConfig = GetCountBl(dropItemConfig.dropCountGoupID);
|
|
|
+ c = (dropItemConfig.dropMaxV * dropCountConfig.proportion) / 100;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ c = Random.Next(dropItemConfig.dropMinV, dropItemConfig.dropMaxV + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ ItemInfo itemInfo = new ItemInfo(dropItemConfig.itemID[j], c);
|
|
|
+ itemInfos.Add(itemInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DropCountConfig GetCountBl(int dropCountGroupID)
|
|
|
+ {
|
|
|
+ if (dropCountGroupDic.TryGetValue(dropCountGroupID, out var dropCountGroupConfig))
|
|
|
+ {
|
|
|
+ int wight = maxWight[dropCountGroupID];
|
|
|
+ int currWight = Random.Next(0, wight);
|
|
|
+ int addWidght = 0;
|
|
|
+ for (int i = 0; i < dropCountGroupConfig.Count; i++)
|
|
|
+ {
|
|
|
+ DropCountConfig dropCountConfig = dropCountGroupConfig[i];
|
|
|
+ addWidght += dropCountConfig.weight;
|
|
|
+ if (currWight <= addWidght)
|
|
|
+ {
|
|
|
+ return dropCountConfig;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LogTool.Error("没有掉落的数量" + dropCountGroupID);
|
|
|
+
|
|
|
+ return default;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ItemInfo> DropItemFor2(DropConfig dropConfig)
|
|
|
+ {
|
|
|
+ List<ItemInfo> itemInfos = new List<ItemInfo>();
|
|
|
+ int allRate = 0;
|
|
|
+ for (int i = 0; i < dropConfig.dropGroupID.Length; i++)
|
|
|
+ {
|
|
|
+ int dropGroupId = dropConfig.dropGroupID[i];
|
|
|
+ DropGroupConfig dropGroupConfig = ConfigComponent.Instance.Get<DropGroupConfig>(dropGroupId);
|
|
|
+ allRate += dropGroupConfig.dropRate;
|
|
|
+ }
|
|
|
+
|
|
|
+ int currWight = Random.Next(0, allRate);
|
|
|
+ int addWidght = 0;
|
|
|
+ for (int i = 0; i < dropConfig.dropGroupID.Length; i++)
|
|
|
+ {
|
|
|
+ int dropGroupId = dropConfig.dropGroupID[i];
|
|
|
+ DropGroupConfig dropGroupConfig = ConfigComponent.Instance.Get<DropGroupConfig>(dropGroupId);
|
|
|
+ addWidght += dropGroupConfig.dropRate;
|
|
|
+ if (currWight <= addWidght)
|
|
|
+ {
|
|
|
+ DropItemConfig(itemInfos, dropGroupConfig.dropItemID);
|
|
|
+ return itemInfos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return itemInfos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|