예제 #1
0
        public static void Updater(EventArgs args)
        {
            if (!MenuManager.IsEnable)
            {
                return;
            }
            if (Members.Updater.Sleeping)
            {
                return;
            }
            if (_fountain == null || !_fountain.IsValid)
            {
                _fountain = ObjectManager.GetEntities <Unit>()
                            .FirstOrDefault(x => x.Team == Me.Team && x.ClassID == ClassID.CDOTA_Unit_Fountain);
                if (_fountain != null)
                {
                    Log.Info($"[Init] fountain {_fountain.Team}");
                }
            }
            Members.Updater.Sleep(500);
            var inventory   = Me.Inventory.Items;
            var enumerable  = inventory as IList <Item> ?? inventory.ToList();
            var neededItems =
                enumerable.Where(
                    item =>
                    !Members.Items.Contains(item.StoredName()) &&
                    (item.IsDisable() || item.IsSilence() || item.IsShield() || item.IsInvis() ||
                     Members.WhiteList.Contains(item.GetItemId())));
            var spellsForUpdate =
                Me.Spellbook.Spells.Where(
                    x =>
                    !Members.Spells.Contains(x.StoredName()) &&
                    (x.IsDisable() || x.IsSilence() || x.IsInvis() || x.IsShield()));

            foreach (var spell in spellsForUpdate)
            {
                Members.Spells.Add(spell.StoredName());
                MenuManager.Menu.Item("abilityEnable")
                .GetValue <AbilityToggler>().Add(spell.StoredName());
                MenuManager.UpdateAbility(spell.StoredName());
                Printer.Print($"[NewAbility]: {spell.StoredName()} shi: {spell.IsShield()} dis: {spell.IsDisable()}");
                Log.Debug($"[NewAbility]: {spell.StoredName()} shield: {spell.IsShield()} disable: {spell.IsDisable()}");
            }
            foreach (var item in neededItems)
            {
                Members.Items.Add(item.StoredName());
                MenuManager.Menu.Item("itemEnable")
                .GetValue <AbilityToggler>().Add(item.StoredName());
                Printer.Print($"[NewItem]: {item.StoredName()}");
                Log.Debug($"[NewItem]: {item.StoredName()}");
                MenuManager.UpdateItem(item.StoredName());
            }
            var tempList   = enumerable.Select(neededItem => neededItem.StoredName()).ToList();
            var removeList = new List <string>();

            foreach (var item in Members.Items.Where(x => !tempList.Contains(x)))
            {
                MenuManager.Menu.Item("itemEnable")
                .GetValue <AbilityToggler>().Remove(item);
                MenuManager.RemoveItem(item);
                removeList.Add(item);
                Printer.Print($"[RemoveItem]: {item}");
            }
            foreach (var item in removeList)
            {
                Members.Items.Remove(item);
            }
        }