Files
2024-10-16 00:03:41 +08:00

54 lines
1.6 KiB
C#

using System;
using UnityEngine;
namespace Game.Data
{
/// <summary>
/// 通用随机单元
/// </summary>
public class RandomNode<T> where T : class
{
public int key; // 承载key
public T value; // 承载内容
public int count; // 最大数量
public int weight; // 随机权重
public int minRange; //至少抽取次数阈值
public int maxRange; //至多抽取次数阈值
public int curWeight; //当前的权重值,用于权重随机中的值比较。
public RandomNode(int key, T value, int count, int weight, int minRange, int maxRange)
{
this.key = key;
this.value = value;
this.count = count;
this.weight = weight;
this.minRange = minRange;
this.maxRange = maxRange;
}
public RandomNode(int key, T value, int count, int weight, string range)
{
this.key = key;
this.value = value;
this.count = count;
this.weight = weight;
if (range.Equals("-1", StringComparison.OrdinalIgnoreCase))
{
this.minRange = -1;
this.maxRange = -1;
}
else
{
var rs = range.Split(',');
this.minRange = int.Parse(rs[0]);
this.maxRange = int.Parse(rs.Length == 2 ? rs[1] : rs[0]);
}
}
public bool IsValid(int nowCount)
{
return this.count == -1 || nowCount < this.count;
}
}
}