public void Add(int id, int weight) { WeightRandomCountData item = new WeightRandomCountData(id) { weight = weight }; this.list.Add(item); this.allweight += weight; }
public int GetRandom() { this.ran = GameLogic.Random(0, this.allweight); int num = 0; int count = this.list.Count; while (num < count) { WeightRandomCountData data = this.list[num]; if (this.ran < data.weight) { if (data.GetCanRandom(this.randomindex, this.maxcontinuecount)) { data.RandomSelf(++this.randomindex); return(data.id); } return(this.GetRandom()); } this.ran -= data.weight; num++; } throw new Exception(Utils.FormatString("WeightRandom.GetRandom Weight Random Error!!!", Array.Empty <object>())); }