Exemple #1
0
        public bool SaveBuffList(BuffList list)
        {
            try
            {
                BuffLists.Add(list);

                SaveBuffLists();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        private void Button_SaveBuffs_Click(object sender, RoutedEventArgs e)
        {
            if (_HbData == null)
            {
                return;
            }

            var inputDialog = new CustomInputDialog("Buff list name:", "mybuffs");

            if (inputDialog.ShowDialog() == true)
            {
                var bufflistname = inputDialog.DialogValue;
                if (!string.IsNullOrEmpty(bufflistname))
                {
                    bufflistname = bufflistname.ToLower().Trim();

                    // handle duplicate list names automatically
                    var check = _HbData.BuffLists.Where(x => x.Name.ToLower() == bufflistname).FirstOrDefault();
                    if (check != null)
                    {
                        int i = 1;
                        while (check != null)
                        {
                            i++;
                            var temp = bufflistname + i.ToString();
                            check = _HbData.BuffLists.Where(x => x.Name.ToLower() == temp).FirstOrDefault();
                        }
                    }

                    var buffs = new List <string>();
                    foreach (var item in Lb_Buffs.Items)
                    {
                        if (item.ToString().Contains(_ELITEAPI.Player.Name))
                        {
                            buffs.Add(item.ToString().Replace(_ELITEAPI.Player.Name + " ", "").Trim());
                        }
                    }

                    var bufflist = new BuffList
                    {
                        Name = bufflistname,
                        List = new Dictionary <string, List <string> > {
                            { "me", buffs }
                        }
                    };

                    var msg = new CustomMessageDialog("Saved!", "Buff List: '" + bufflistname + "' has been saved to [..healbot\\data\\buffLists.lua]");
                    if (_HbData.SaveBuffList(bufflist))
                    {
                        _HbData = new HealbotData(Settings.Default.WindowerPath);                         // reload the settings
                    }
                    else
                    {
                        msg = new CustomMessageDialog("ERROR", "An error occured while trying to save the set of buffs!" + Environment.NewLine + Environment.NewLine + "Buff list name: '" + bufflistname + "'");
                    }

                    msg.ShowDialog();
                }
            }
            else
            {
                var msg = new CustomMessageDialog("ERROR", "A name must be provided in order to save the buffs as a list in [..healbot\\data\\buffLists.lua]");
                msg.ShowDialog();
            }
        }
Exemple #3
0
        // BUFF LISTS
        private void GetBuffLists()
        {
            BuffLists = new List <BuffList>();
            var      path     = Path.Combine(WindowerPath, BuffListsLuaPath);
            string   luaItems = File.ReadAllText(path);
            Script   script   = new Script();
            DynValue res      = script.DoString(luaItems);
            var      keys     = new List <string>();

            foreach (DynValue dv in res.ToScalar().Table.Keys)
            {
                keys.Add(dv.ToString().Replace("\"", ""));
            }

            foreach (var key in keys)
            {
                var bl = new BuffList {
                    Name = key
                };
                var bl_check = BuffLists.Where(x => x.Name == key).FirstOrDefault();
                if (bl_check != null)
                {
                    bl = bl_check;
                }

                var dl = new Dictionary <string, List <string> >();
                foreach (var pair in res.ToScalar().Table.Get(key).Table.Pairs)
                {
                    var innerKey = key;
                    var tbl      = pair.Value.Table;
                    if (tbl != null)
                    {
                        innerKey = pair.Key.ToString().Replace("\"", "");
                        var l = new List <string>();
                        foreach (var iv in tbl.Values)
                        {
                            l.Add(iv.ToString().Replace("\"", ""));
                        }
                        dl.Add(innerKey, l);
                    }
                    else
                    {
                        innerKey = "me";
                        var val = pair.Value.ToString().Replace("\"", "");
                        if (bl.List.ContainsKey(innerKey))
                        {
                            bl.List[innerKey].Add(val);
                        }
                        else
                        {
                            dl.Add(innerKey, new List <string> {
                                val
                            });
                        }
                    }

                    bl.List = dl;
                }

                BuffLists.Add(bl);
            }
        }