using System; using System.Collections; using System.Collections.Generic; using System.Text; using UnityEngine; public class VirtualPackManager : GameSystemManager { // Dictionary> virtualPackItems // = new Dictionary>(); // Dictionary> m_VirtualItemPool // = new Dictionary>(); // Dictionary virtualPackCapacityDict = new Dictionary(); // public event Action virtualPackRefresh; // int getA206Count = 0; //收到了几次A206包 Dictionary noPackItemCountDict = new Dictionary(); //无需背包的物品数量刷新,自动转化为数值 public event Action OnNoPackItemCountRefresh; public void OnBeforePlayerDataInitialize() { // foreach (var packType in virtualPackItems.Keys) // { // var pool = m_VirtualItemPool[packType]; // var items = virtualPackItems[packType]; // foreach (var item in items) // { // pool.Release(item); // } // } // virtualPackItems.Clear(); noPackItemCountDict.Clear(); } public override void Init() { base.Init(); ParseConfig(); // m_VirtualItemPool.Add(PackType.GatherSoul, new ObjectPool(OnGetItem, OnReleaseItem)); // m_VirtualItemPool.Add(PackType.RunePack, new ObjectPool(OnGetItem, OnReleaseItem)); DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize; } public override void Release() { base.Release(); DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize; } void ParseConfig() { // virtualPackCapacityDict.Add(PackType.RunePack, int.Parse(funcConfig.Numerical1)); } // public bool IsVirtualPack(PackType packType) // { // switch (packType) // { // case PackType.GatherSoul: // case PackType.RunePack: // return true; // } // return false; // } // public int GetPackCapacity(PackType packType) // { // if (virtualPackCapacityDict.ContainsKey(packType)) // { // return virtualPackCapacityDict[packType]; // } // return 0; // } // public int GetPackRemainCount(PackType packType) // { // var capacity = GetPackCapacity(packType); // return capacity - GetPackItemCount(packType); // } // public int GetPackItemCount(PackType packType) // { // if (virtualPackItems.ContainsKey(packType)) // { // return virtualPackItems[packType].Count; // } // return 0; // } // public int GetItemCountById(PackType packType, int id) // { // var count = 0; // List list; // if (TryGetItems(packType, out list)) // { // for (int i = 0; i < list.Count; i++) // { // VirtualPackItem item; // if (TryGetItem(packType, list[i], out item) // && item.id == id) // { // count++; // } // } // } // return count; // } // public void GetItemIndexs(PackType packType, ref List list) // { // list.Clear(); // List _list; // if (virtualPackItems.TryGetValue(packType, out _list)) // { // for (int i = 0; i < _list.Count; i++) // { // list.Add(_list[i].index); // } // } // } // public bool TryGetItems(PackType packType, out List list) // { // list = new List(); // List _list; // if (virtualPackItems.TryGetValue(packType, out _list)) // { // for (int i = 0; i < _list.Count; i++) // { // list.Add(_list[i].index); // } // return true; // } // return false; // } // public bool TryGetItem(PackType packType, int packIndex, out T item) where T : VirtualPackItem // { // item = default(T); // if (virtualPackItems.ContainsKey(packType)) // { // var _index = virtualPackItems[packType].FindIndex((x) => // { // return x.index == packIndex; // }); // if (_index != -1) // { // item = virtualPackItems[packType][_index] as T; // } // return _index != -1; // } // return false; // } // public void OnReceiveServerPack(HA204_tagMCVPackRefresh package) // { // var packType = (PackType)package.PackType; // if (!IsVirtualPack(packType)) // { // return; // } // List list; // if (!virtualPackItems.TryGetValue(packType, out list)) // { // list = new List(); // virtualPackItems.Add(packType, list); // } // SetVirtualItem(packType, ref list, package.VPacklItemList); // if (virtualPackRefresh != null) // { // virtualPackRefresh((PackType)package.PackType); // } // } // public void OnReceiveServerPack(HA205_tagMCVPackClear package) // { // var packType = (PackType)package.PackType; // if (!IsVirtualPack(packType)) // { // return; // } // List list; // if (virtualPackItems.TryGetValue(packType, out list)) // { // var pool = m_VirtualItemPool[packType]; // for (int i = 0; i < package.Count; i++) // { // var index = package.ItemPlaceList[i]; // var items = list.FindAll((x) => // { // return x.index == index; // }); // foreach (var item in items) // { // list.Remove(item); // pool.Release(item); // } // } // if (virtualPackRefresh != null) // { // virtualPackRefresh(packType); // } // } // } public void UpdateAutoItemCountRefresh(HA206_tagMCAutoItemCountRefresh netPack) { for (int i = 0; i < netPack.Count; i++) { noPackItemCountDict[(int)netPack.ItemCountList[i].ItemID] = (int)netPack.ItemCountList[i].ItemCount; } OnNoPackItemCountRefresh?.Invoke(); } public int GetNoPackItemCount(int id) { if (noPackItemCountDict.ContainsKey(id)) { return noPackItemCountDict[id]; } return 0; } public Dictionary GetAllNoPackItem() { return noPackItemCountDict; } // void SetVirtualItem(PackType packType, ref List list, HA204_tagMCVPackRefresh.tagMCVPackItem[] items) // { // var pool = m_VirtualItemPool[packType]; // for (int i = 0; i < items.Length; i++) // { // var item = list.Find((x) => // { // return x.index == items[i].ItemPlace; // }); // if (item != null) // { // item.Release(); // } // else // { // if (pool.inactivedCount > 0) // { // item = pool.Get(); // list.Add(item); // } // } // if (item == null) // { // item = VirtualPackItem.Get(packType); // list.Add(item); // } // item.ParsePackItem(items[i].ItemPlace, items[i].ItemData); // } // } // static void OnGetItem(VirtualPackItem item) // { // } // static void OnReleaseItem(VirtualPackItem item) // { // item.Release(); // } } public abstract class VirtualPackItem { public int index { get; private set; } public int id { get; private set; } public int level { get; private set; } protected string dataString { get; set; } protected static StringBuilder sb = new StringBuilder(); public virtual void ParsePackItem(int index, uint data) { this.index = index; dataString = data.ToString(); int delta = 10 - dataString.Length; sb.Length = 0; sb.Append('0', delta); dataString = dataString.Insert(0, sb.ToString()); id = int.Parse(dataString.Substring(5, 5)); level = int.Parse(dataString.Substring(2, 3)) + 1; } public virtual void Release() { dataString = null; } public static VirtualPackItem Get(PackType packType) { // switch (packType) // { // case PackType.RunePack: // return new RuneItem(); // } return null; } } public struct VirtualItem { public PackType packType; public int itemId; public int index; public int level; }