summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/AI/AIRunTimeRandomIndex.cs
blob: f71486ce22400e46e2b763feea2687d50280fb66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using XUtliPoolLib;

namespace XMainClient
{
	internal class AIRunTimeRandomIndex
	{
		public int this[int index]
		{
			get
			{
				bool flag = index < 0 || index >= this.m_IndexList.Count;
				int result;
				if (flag)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("Random index out of range, try get ", index.ToString(), " but length = ", this.m_IndexList.Count.ToString(), null, null);
					result = 0;
				}
				else
				{
					result = this.m_IndexList[index];
				}
				return result;
			}
		}

		private List<int> m_IndexList = new List<int>();

		public void AppendIndex()
		{
			this.m_IndexList.Add(this.m_IndexList.Count);
		}

		public void Rand()
		{
			for (int i = this.m_IndexList.Count - 1; i > 0; i--)
			{
				int num = XSingleton<XCommon>.singleton.RandomInt(i + 1);
				bool flag = num == i;
				if (!flag)
				{
					int value = this.m_IndexList[num];
					this.m_IndexList[num] = this.m_IndexList[i];
					this.m_IndexList[i] = value;
				}
			}
		}
	}
}