summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XBag.cs
blob: f5e1e702af487995f86306f19e9cb10bbf9d1e1b (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;

namespace XMainClient
{
	internal class XBag
	{
		public XItem this[int key]
		{
			get
			{
				return this.Items[key];
			}
			set
			{
				this.Items[key] = value;
			}
		}

		public int Count
		{
			get
			{
				return this.Items.Count;
			}
		}

		private List<XItem> Items = new List<XItem>();

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

		private List<XItem> _tempItemList = new List<XItem>();

		public void Clear()
		{
			this.Items.Clear();
		}

		public void AddItem(XItem item, bool bSort)
		{
			this.Items.Add(item);
			if (bSort)
			{
				this.SortItem();
			}
		}

		public void RemoveItem(ulong uid)
		{
			int index;
			bool flag = this.FindItem(uid, out index);
			if (flag)
			{
				this.Items.RemoveAt(index);
			}
		}

		public void RemoveIndex(int index)
		{
			this.Items.RemoveAt(index);
		}

		public bool FindItem(ulong uid, out int index)
		{
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].uid == uid;
				if (flag)
				{
					index = i;
					return true;
				}
			}
			index = -1;
			return false;
		}

		public bool FindItemByID(int id, out List<int> index)
		{
			this._TempIndexList.Clear();
			index = this._TempIndexList;
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].itemID == id;
				if (flag)
				{
					index.Add(i);
				}
			}
			bool flag2 = index.Count == 0;
			return !flag2;
		}

		public bool FindItemByID(int id, out List<XItem> lst)
		{
			this._tempItemList.Clear();
			lst = this._tempItemList;
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].itemID == id;
				if (flag)
				{
					lst.Add(this.Items[i]);
				}
			}
			bool flag2 = lst.Count == 0;
			return !flag2;
		}

		public int GetItemCount(int id)
		{
			int num = 0;
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].itemID == id;
				if (flag)
				{
					num += this.Items[i].itemCount;
				}
			}
			return num;
		}

		public int GetItemCountByUid(ulong uid)
		{
			int result = 0;
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].uid == uid;
				if (flag)
				{
					result = this.Items[i].itemCount;
					break;
				}
			}
			return result;
		}

		public int GetItemCount(int id, bool isBind)
		{
			int num = 0;
			for (int i = 0; i < this.Items.Count; i++)
			{
				bool flag = this.Items[i].itemID == id && this.Items[i].bBinding == isBind;
				if (flag)
				{
					num += this.Items[i].itemCount;
				}
			}
			return num;
		}

		public void SortItem()
		{
			this.Items.Sort(new Comparison<XItem>(XBag.ItemSortCompare));
		}

		private static int ItemSortCompare(XItem item1, XItem item2)
		{
			bool flag = item1.itemConf == null;
			int result;
			if (flag)
			{
				result = 1;
			}
			else
			{
				bool flag2 = item2.itemConf == null;
				if (flag2)
				{
					result = -1;
				}
				else
				{
					bool flag3 = item1.itemConf.SortID == item2.itemConf.SortID;
					if (flag3)
					{
						result = -item1.uid.CompareTo(item2.uid);
					}
					else
					{
						result = -item1.itemConf.SortID.CompareTo(item2.itemConf.SortID);
					}
				}
			}
			return result;
		}
	}
}