Beispiel #1
0
        private bool UpdateStashes()
        {
            var stashPanel        = GameController.Game.IngameState.ServerData.StashPanel;
            var stashNames        = new List <string>();
            var needUpdateAllInfo = false;

            _currentOpenedStashTab     = null;
            _currentOpenedStashTabName = "";


            for (var i = 0; i < stashPanel.TotalStashes; i++)
            {
                var stash = stashPanel.GetStashInventoryByIndex(i);

                var stashName = stashPanel.GetStashName(i);
                stashNames.Add(stashName);

                var visibleInventoryItems = stash?.VisibleInventoryItems;

                if (visibleInventoryItems == null)
                {
                    continue;
                }

                _currentOpenedStashTab     = stash;
                _currentOpenedStashTabName = stashName;

                if (stash.ItemCount != visibleInventoryItems.Count)
                {
                    continue;
                }

                StashTabData curStashData;

                var add = false;
                if (!_sData.StashTabs.TryGetValue(stashName, out curStashData))
                {
                    curStashData = new StashTabData();
                    add          = true;
                }

                if (curStashData.ItemsCount != stash.ItemCount)
                {
                    curStashData.StashTabItems = new List <StashItem>();
                    needUpdateAllInfo          = true;
                    foreach (var invItem in visibleInventoryItems)
                    {
                        var item         = invItem.Item;
                        var newStashItem = ProcessItem(item);

                        if (newStashItem == null)
                        {
                            continue;
                        }

                        curStashData.StashTabItems.Add(newStashItem);
                        newStashItem.StashName  = stashName;
                        newStashItem.InventPosX = invItem.InventPosX;
                        newStashItem.InventPosY = invItem.InventPosY;
                    }
                    curStashData.ItemsCount = (int)stash.ItemCount;
                }

                if (add && curStashData.ItemsCount > 0)
                {
                    _sData.StashTabs.Add(stashName, curStashData);
                }
                break;
            }

            if (!needUpdateAllInfo)
            {
                return(false);
            }

            foreach (var name in stashNames) //Delete stashes that doesn't exist
            {
                if (!_sData.StashTabs.ContainsKey(name))
                {
                    _sData.StashTabs.Remove(name);
                }
            }

            return(true);
        }
        public bool UpdateStashes()
        {
            var stashPanel        = GameController.Game.IngameState.ServerData.StashPanel;
            var stashNames        = new List <string>();
            var needUpdateAllInfo = false;

            _currentOpenedStashTab     = null;
            _currentOpenedStashTabName = "";

            for (var i = 0; i < stashPanel.TotalStashes; i++)
            {
                var stash = stashPanel.GetStashInventoryByIndex(i);

                var stashName = stashPanel.GetStashName(i);
                stashNames.Add(stashName);

                var visibleInventoryItems = stash?.VisibleInventoryItems;

                if (visibleInventoryItems == null)
                {
                    continue;
                }

                _currentOpenedStashTab     = stash;
                _currentOpenedStashTabName = stashName;

                //if (stash.ItemCount != visibleInventoryItems.Count)
                {
                    //LogMessage("No update stash coz: ItemCount", 4);
                    //continue;
                }

                StashTabData curStashData;

                var add = false;
                if (!_sData.StashTabs.TryGetValue(stashName, out curStashData))
                {
                    curStashData = new StashTabData();
                    add          = true;
                }

                //if (curStashData.ItemsCount != stash.ItemCount)//Temporary disabled. Trying to find a source of bug
                {
                    curStashData.StashTabItems = new List <StashItem>();
                    needUpdateAllInfo          = true;
                    foreach (var invItem in visibleInventoryItems)
                    {
                        var item         = invItem.Item;
                        var newStashItem = ProcessItem(item);

                        if (newStashItem == null)
                        {
                            continue;
                        }

                        curStashData.StashTabItems.Add(newStashItem);
                        newStashItem.StashName  = stashName;
                        newStashItem.InventPosX = invItem.InventPosX;
                        newStashItem.InventPosY = invItem.InventPosY;
                    }
                    curStashData.ItemsCount = (int)stash.ItemCount;
                }

                if (add && curStashData.ItemsCount > 0)
                {
                    _sData.StashTabs.Add(stashName, curStashData);
                }
                break;
            }


            /*
             * foreach (var name in stashNames)
             * {
             *  if (!_sData.StashTabs.ContainsKey(name)) //TODO: Define: What the f**k is this?
             *  {
             *      _sData.StashTabs.Remove(name);
             *  }
             * }
             */

            var allStashNames = stashPanel.AllStashNames;

            var keyTabs = _sData.StashTabs.Keys.ToList();//Delete stashes that doesn't exist

            foreach (var stashName in keyTabs)
            {
                if (!allStashNames.Contains(stashName))
                {
                    _sData.StashTabs.Remove(stashName);
                }
            }

            if (!needUpdateAllInfo)
            {
                return(false);
            }

            return(true);
        }
        public bool UpdateStashes()
        {
            var stashPanel = GameController.Game.IngameState.ServerData.StashPanel;

            if (stashPanel == null)
            {
                LogMessage("ServerData.StashPanel is null", 3);
                return(false);
            }

            var needUpdateAllInfo = false;

            _currentOpenedStashTab     = null;
            _currentOpenedStashTabName = "";

            for (var i = 0; i < stashPanel.TotalStashes; i++)
            {
                var stashName = stashPanel.GetStashName(i);

                if (Settings.OnlyAllowedStashTabs.Value)
                {
                    if (!Settings.AllowedStashTabs.Any(x => x.Name == stashName))
                    {
                        continue;
                    }
                }

                var stash = stashPanel.GetStashInventoryByIndex(i);

                var visibleInventoryItems = stash?.VisibleInventoryItems;
                if (visibleInventoryItems == null)
                {
                    continue;
                }

                _currentOpenedStashTab     = stash;
                _currentOpenedStashTabName = stashName;

                StashTabData curStashData = null;
                var          add          = false;

                if (!_sData.StashTabs.TryGetValue(stashName, out curStashData))
                {
                    curStashData = new StashTabData();
                    add          = true;
                }

                curStashData.StashTabItems = new List <StashItem>();
                needUpdateAllInfo          = true;

                foreach (var invItem in visibleInventoryItems)
                {
                    var item         = invItem.Item;
                    var newStashItem = ProcessItem(item);

                    if (newStashItem == null)
                    {
                        if (Settings.ShowRedRectangleAroundIgnoredItems)
                        {
                            Graphics.DrawFrame(invItem.GetClientRect(), 2, Color.Red);
                        }
                        continue;
                    }



                    newStashItem.StashName          = stashName;
                    newStashItem.InventPosX         = invItem.InventPosX;
                    newStashItem.InventPosY         = invItem.InventPosY;
                    newStashItem.BInPlayerInventory = false;
                    curStashData.StashTabItems.Add(newStashItem);
                }
                curStashData.ItemsCount = (int)stash.ItemCount;

                if (add && curStashData.ItemsCount > 0)
                {
                    _sData.StashTabs.Add(stashName, curStashData);
                }
            }

            List <string> workingTabs = null;

            if (Settings.OnlyAllowedStashTabs.Value)
            {
                workingTabs = Settings.AllowedStashTabs.Select(x => x.Name).ToList();
            }
            else
            {
                workingTabs = stashPanel.AllStashNames;
            }

            var keyTabs = _sData.StashTabs.Keys.ToList();//Delete stashes that doesn't exist

            foreach (var stashNameInUse in keyTabs)
            {
                if (!workingTabs.Contains(stashNameInUse))
                {
                    _sData.StashTabs.Remove(stashNameInUse);
                }
            }

            if (!needUpdateAllInfo)
            {
                return(false);
            }

            return(true);
        }
        public bool UpdateStashes()
        {
            var stashPanel = GameController.IngameState.IngameUi.StashElement;

            if (stashPanel == null)
            {
                LogMessage("ServerData.StashPanel is null", 3);
                return(false);
            }

            var needUpdateAllInfo = false;

            _currentOpenedStashTabName = "";
            _currentOpenedStashTab     = stashPanel.VisibleStash;

            if (_currentOpenedStashTab == null)
            {
                return(false);
            }

            for (var i = 0; i < stashPanel.TotalStashes; i++)
            {
                var stashName = stashPanel.GetStashName(i);

                if (Settings.OnlyAllowedStashTabs.Value)
                {
                    if (!Settings.AllowedStashTabs.Contains(i))
                    {
                        continue;
                    }
                }

                var stash = stashPanel.GetStashInventoryByIndex(i);

                var visibleInventoryItems = stash?.VisibleInventoryItems;

                if (visibleInventoryItems == null)
                {
                    continue;
                }

                if (_currentOpenedStashTab.Address == stash.Address)
                {
                    _currentOpenedStashTabName = stashName;
                }

                var add = false;

                if (!_sData.StashTabs.TryGetValue(stashName, out var curStashData))
                {
                    curStashData = new StashTabData();
                    add          = true;
                }

                var items = new List <StashItem>();
                needUpdateAllInfo = true;

                foreach (var invItem in visibleInventoryItems)
                {
                    var item         = invItem.Item;
                    var newStashItem = ProcessItem(item);

                    if (newStashItem == null)
                    {
                        if (Settings.ShowRedRectangleAroundIgnoredItems)
                        {
                            Graphics.DrawFrame(invItem.GetClientRect(), Color.Red, 2);
                        }

                        continue;
                    }

                    newStashItem.StashName          = stashName;
                    newStashItem.InventPosX         = invItem.InventPosX;
                    newStashItem.InventPosY         = invItem.InventPosY;
                    newStashItem.BInPlayerInventory = false;
                    items.Add(newStashItem);
                }

                if (_currentOpenedStashTab.Address == stash.Address)//in case tab was closed before we finish update
                {
                    curStashData.StashTabItems = items;
                    curStashData.ItemsCount    = (int)stash.ItemCount;
                }

                if (add && curStashData.ItemsCount > 0)
                {
                    _sData.StashTabs.Add(stashName, curStashData);
                }
            }

            if (!needUpdateAllInfo)
            {
                return(false);
            }

            return(true);
        }