You've already forked taptap2024_GJ_chidouren
76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using Game;
|
|
using Game.Data;
|
|
|
|
namespace System.RandomPool
|
|
{
|
|
public class WeightRandomPool
|
|
{
|
|
private class WeightCommonRandomPool : CommonRandomPool<WeightNode>
|
|
{
|
|
public WeightCommonRandomPool (CommonPoolConfig<WeightNode> config, int poolId, int seedId) : base (config, poolId, seedId)
|
|
{
|
|
config.poolContents = new Dictionary<int, List<RandomNode<WeightNode>>> ();
|
|
config.poolContents[0] = new List<RandomNode<WeightNode>> ();
|
|
config.poolLevelWeight = new Dictionary<int, int> ();
|
|
config.poolLevelWeight[0] = 100;
|
|
|
|
this._poolId = poolId;
|
|
this._seedId = seedId;
|
|
this._randomGroups = new Dictionary<int, CommonRandomGroup<WeightNode>>();
|
|
CommonRandomGroup<WeightNode> randomGroup = new CommonRandomGroup<WeightNode> (poolId);
|
|
this._randomGroups[0] = randomGroup;
|
|
this._randomGroups[0].SetMask(-1);
|
|
|
|
this._levelRandom = new LevelRandom(config.poolLevelWeight , new List<int>(this._randomGroups.Keys));
|
|
}
|
|
}
|
|
|
|
public class WeightNode
|
|
{
|
|
public int Id;
|
|
public int Weight;
|
|
}
|
|
|
|
private WeightCommonRandomPool _weightCommonRandomPool;
|
|
|
|
public int ValidRofCount => this._weightCommonRandomPool.ValidRofCount;
|
|
|
|
public WeightRandomPool ()
|
|
{
|
|
CommonPoolConfig<WeightNode> config = new CommonPoolConfig<WeightNode> ();
|
|
config.poolLevelWeight = new Dictionary<int, int> ();
|
|
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<WeightNode> (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<int> disableKeys = null)
|
|
{
|
|
return this._weightCommonRandomPool.RandomItem (-1 , 0 , disableKeys)?.Id ?? -1;
|
|
}
|
|
|
|
public List<int> RandomNodes (int count , IList<int> disableKeys = null , bool isSin = false , int mask = -1)
|
|
{
|
|
List<int> ids = new List<int> ();
|
|
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;
|
|
}
|
|
|
|
}
|
|
} |