using System.Collections.Generic; using Game; using Game.Data; namespace System.RandomPool { public class WeightRandomPool { private class WeightCommonRandomPool : CommonRandomPool { public WeightCommonRandomPool (CommonPoolConfig config, int poolId, int seedId) : base (config, poolId, seedId) { config.poolContents = new Dictionary>> (); config.poolContents[0] = new List> (); config.poolLevelWeight = new Dictionary (); config.poolLevelWeight[0] = 100; this._poolId = poolId; this._seedId = seedId; this._randomGroups = new Dictionary>(); CommonRandomGroup randomGroup = new CommonRandomGroup (poolId); this._randomGroups[0] = randomGroup; this._randomGroups[0].SetMask(-1); this._levelRandom = new LevelRandom(config.poolLevelWeight , new List(this._randomGroups.Keys)); } } public class WeightNode { public int Id; public int Weight; } private WeightCommonRandomPool _weightCommonRandomPool; public int ValidRofCount => this._weightCommonRandomPool.ValidRofCount; public WeightRandomPool () { CommonPoolConfig config = new CommonPoolConfig (); config.poolLevelWeight = new Dictionary (); this._weightCommonRandomPool = new WeightCommonRandomPool (config , 0 , 0); } public void PutNode (int id , int weight , int minRange = -1, int maxRange = -1) { this._weightCommonRandomPool.PutNode (new RandomNode (id , new WeightNode () { Id = id, Weight = weight } , -1 , weight , minRange , maxRange) , 0); } public void ResetNode (int id , int weight) { this._weightCommonRandomPool.ResetNodeWeight (0 ,id , weight); } public int RandomNode (IList disableKeys = null) { return this._weightCommonRandomPool.RandomItem (-1 , 0 , disableKeys)?.Id ?? -1; } public List RandomNodes (int count , IList disableKeys = null , bool isSin = false , int mask = -1) { List ids = new List (); var randomItems = this._weightCommonRandomPool.RandomItems (mask , count, isSin , null , disableKeys); for (var index = 0; index < randomItems.Count; index++) { var randomItem = randomItems[index]; ids.Add (randomItem.Id); } return ids; } } }