From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XBag.cs | 189 ++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XBag.cs (limited to 'Client/Assets/Scripts/XMainClient/XBag.cs') diff --git a/Client/Assets/Scripts/XMainClient/XBag.cs b/Client/Assets/Scripts/XMainClient/XBag.cs new file mode 100644 index 00000000..f5e1e702 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XBag.cs @@ -0,0 +1,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 Items = new List(); + + private List _TempIndexList = new List(); + + private List _tempItemList = new List(); + + 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 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 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(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; + } + } +} -- cgit v1.1-26-g67d0