Beispiel #1
0
 private static List <Serial> GetCurrentChars(StatusFormWrapperType type)
 {
     lock (SyncRoot)
     {
         return(World.Characters.Where(ch => type == StatusWrapper.GetWrapperType(ch.Serial) && ch.Serial != World.Player.Serial).OrderBy(ch => ch.GetDistance()).Select(ch => ch.Serial).ToList());
     }
 }
Beispiel #2
0
        protected void RefreshForms()
        {
            if (refreshing)
            {
                return;
            }

            if (InvokeRequired)
            {
                BeginInvoke(new ThreadStart(RefreshForms));
                return;
            }

            refreshing = true;
            try
            {
                List <Serial> refresSerials  = new List <Serial>();
                List <Serial> currentChars   = new List <Serial>();
                WindowManager defaultManager = WindowManager.GetDefaultManager();

                //lock (this.SyncRoot)
                //{
                for (int i = this.toDispatchSerials.Count - 1; i >= 0; i--)
                {
                    Serial s = this.toDispatchSerials[i];
                    if (StatusWrapper.GetWrapperType(s) == this.WrapperType)
                    {
                        currentChars.Add(s);
                    }


                    UOCharacter ch = new UOCharacter(s);

                    if (!ch.Exist || ch.Distance > 30)
                    {
                        this.toDispatchSerials.RemoveAt(i);
                    }
                }
                //  }

                List <StatusForm> forms = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => this.WrapperType == StatusWrapper.GetWrapperType(f.MobileId) && !currentChars.Contains(f.MobileId)).ToList();
                foreach (StatusForm sf in forms)
                {
                    if (sf.Manual)
                    {
                        currentChars.Insert(0, sf.MobileId);
                    }
                    else
                    {
                        currentChars.Add(sf.MobileId);
                    }
                }

                currentChars = SortChars(currentChars);

                List <Serial> dummy = new List <Serial>();
                dummy.AddRange(currentChars.ToArray());

                List <Serial> filteredSorted = new List <Serial>();
                filteredSorted.AddRange(currentChars.ToArray());
                filteredSorted = filteredSorted.Where(s => WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == s && (f.Keep || f.MouseHovering || f.Manual)).ToArray().Length > 0).ToList();

                Dictionary <Serial, int> order = new Dictionary <Serial, int>();

                for (int i = filteredSorted.Count - 1; i >= 0; i--)
                {
                    Serial s        = filteredSorted[i];
                    int    priority = 0;

                    StatusForm sf = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == s).FirstOrDefault();
                    if (sf != null)
                    {
                        if (sf.MouseHovering)
                        {
                            priority += 10000;
                        }

                        if (sf.Keep)
                        {
                            priority += 1000;
                        }

                        if (sf.Manual)
                        {
                            priority += 100;
                        }

                        if (!order.ContainsKey(s))
                        {
                            order.Add(s, priority);
                        }
                    }
                    else
                    {
                        filteredSorted.RemoveAt(i);
                    }
                }

                filteredSorted = filteredSorted.OrderByDescending(s => order[s]).ToList();

                currentChars = new List <Serial>();
                currentChars.AddRange(filteredSorted.ToArray());

                foreach (Serial s in dummy)
                {
                    if (!currentChars.Contains(s))
                    {
                        currentChars.Add(s);
                    }
                }

                int addCounter = 0;
                for (int i = 0; i < currentChars.Count && addCounter < this.MaxBars /*Math.Min(currentChars.Count, this.MaxBars)*/; i++)
                {
                    UOCharacter ch = new UOCharacter(currentChars[i]);
                    StatusForm  sf = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == ch.Serial).FirstOrDefault();

                    if (sf != null || this.Auto)
                    {
                        bool add = (sf == null || !sf.DisableWrapper) && ch.Distance < 25 && ch.Exist || sf != null && (sf.Keep || sf.IsNew || sf.MouseHovering) && !sf.DisableWrapper;

                        if (add)
                        {
                            addCounter++;
                            refresSerials.Add(ch.Serial);

                            if (sf == null)
                            {
                                defaultManager.CreateWindow(delegate()
                                {
                                    var f          = new StatusForm(ch.Serial);
                                    f.Transparency = true;
                                    return(f);
                                });
                            }
                        }
                        else if (sf != null && !sf.DisableWrapper && !sf.Keep && !sf.MouseHovering)
                        {
                            if (defaultManager.InvokeRequired)
                            {
                                defaultManager.BeginInvoke(sf.Close);
                            }
                            else
                            {
                                sf.Close();
                            }
                        }
                    }
                }

                if (this.Auto)//??
                {
                    List <StatusForm> delete = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(sf => sf.MobileId != World.Player.Serial && StatusWrapper.GetWrapperType(sf.MobileId) == this.WrapperType && !refresSerials.Contains(sf.MobileId) && !sf.DisableWrapper && !sf.Keep && !sf.MouseHovering).ToList();
                    foreach (StatusForm sf in delete)
                    {
                        if (defaultManager.InvokeRequired)
                        {
                            defaultManager.BeginInvoke(sf.Close);
                        }
                        else
                        {
                            sf.Close();
                        }
                    }
                }

                int y = this.Location.Y + this.Height;
                int x = this.Location.X;

                Dictionary <int, Serial> slots = new Dictionary <int, Serial>();
                List <int> slotPointer         = new List <int>();

                for (int i = 0; i < this.MaxBars; i++)
                {
                    int slotY = y + (i * StatusForm.DefaultHeight);
                    slotPointer.Add(slotY);
                    slots.Add(slotY, (Serial)Serial.Invalid);
                }

                StatusForm disabledSlot = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => refresSerials.Contains(f.MobileId) && f.MouseHovering).FirstOrDefault();

                if (disabledSlot != null && slots.ContainsKey(disabledSlot.Location.Y))
                {
                    slots[disabledSlot.Location.Y] = disabledSlot.MobileId;
                }

                // refresSerials = SortChars(refresSerials);

                for (int i = 0; i < refresSerials.Count; i++)
                {
                    Serial     s  = refresSerials[i];
                    StatusForm sf = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == s).FirstOrDefault();

                    if (sf != null)
                    {
                        for (int u = 0; u < slotPointer.Count; u++)
                        {
                            int    slotY  = slotPointer[u];
                            Serial slotId = slots[slotY];

                            if (!slotId.IsValid && slots.Values.Count(sv => sv == sf.MobileId) == 0 || slotId == sf.MobileId)
                            {
                                if (sf.Location.X != x || sf.Location.Y != slotY)
                                {
                                    sf.Location = new Point(x, slotPointer[u]);
                                    sf.Invalidate();
                                }

                                slots[slotY] = sf.MobileId;
                                break;
                            }
                        }
                    }
                }

                this.registeredSerials = refresSerials;
            }
            catch (Exception e)
            {
                Game.PrintMessage("Chyba v zalozkach", MessageType.Error);

                if (!errorOccured)
                {
                    Notepad.WriteLine("Chyba v zalozkach");
                    Notepad.WriteLine("" + e.Message);
                    Notepad.WriteLine();
                    Notepad.WriteLine("" + e.StackTrace);
                    Notepad.WriteLine("Inner: " + (e.InnerException != null ? e.InnerException.Message : ""));
                    Notepad.WriteLine();
                    Notepad.WriteLine((e.InnerException != null ? e.InnerException.StackTrace : ""));
                    errorOccured = true;
                }
            }
            finally
            {
                refreshing = false;
            }
        }
Beispiel #3
0
        protected void RefreshForms()
        {
            if (refreshing)
            {
                return;
            }

            if (InvokeRequired)
            {
                BeginInvoke(new ThreadStart(RefreshForms));
                return;
            }

            refreshing = true;
            try
            {
                List <Serial> refresSerials  = new List <Serial>();
                List <Serial> currentChars   = new List <Serial>();
                WindowManager defaultManager = WindowManager.GetDefaultManager();
//        IEnumerable<StatusForm> statusForms = defaultManager.OwnedWindows.OfType<StatusForm>();

                if (this.Auto)
                {
                    currentChars.AddRange(GetCurrentChars(this.WrapperType).ToArray());//World.Characters.Where(ch => this.WrapperType == StatusWrapper.GetWrapperType(ch.Serial) && ch.Serial != World.Player.Serial).OrderBy(ch => ch.GetDistance()).Select(ch => ch.Serial).ToList();
                }
                List <StatusForm> forms = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => this.WrapperType == StatusWrapper.GetWrapperType(f.MobileId) && !currentChars.Contains(f.MobileId)).ToList();
                foreach (StatusForm sf in forms)
                {
                    if (sf.Manual)
                    {
                        currentChars.Insert(0, sf.MobileId);
                    }
                    else
                    {
                        currentChars.Add(sf.MobileId);
                    }
                }

                for (int i = 0; i < Math.Min(currentChars.Count, this.MaxBars); i++)
                {
                    UOCharacter ch = new UOCharacter(currentChars[i]);
                    if (ch.Hits <= 0 || String.IsNullOrEmpty(ch.Name))
                    {
                        ch.RequestStatus(100);
                    }

                    StatusForm sf = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == ch.Serial).FirstOrDefault();

                    if (sf != null || this.Auto)
                    {
                        bool add = (sf == null || !sf.DisableWrapper) && ch.Distance < 25 && ch.Hits > 0 && ch.Exist || sf != null && (sf.Keep || sf.IsNew || sf.MouseHovering) && !sf.DisableWrapper;

                        if (add)
                        {
                            refresSerials.Add(ch.Serial);

                            if (sf == null)
                            {
                                defaultManager.CreateWindow(delegate()
                                {
                                    var f          = new StatusForm(ch.Serial);
                                    f.Transparency = true;
                                    return(f);
                                });
                            }
                        }
                        else if (sf != null && !sf.DisableWrapper && !sf.Keep && !sf.MouseHovering)
                        {
                            if (defaultManager.InvokeRequired)
                            {
                                defaultManager.BeginInvoke(sf.Close);
                            }
                            else
                            {
                                sf.Close();
                            }
                        }
                    }
                }

                if (this.Auto)
                {
                    List <StatusForm> delete = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(sf => sf.MobileId != World.Player.Serial && StatusWrapper.GetWrapperType(sf.MobileId) == this.WrapperType && !refresSerials.Contains(sf.MobileId) && !sf.DisableWrapper && !sf.Keep && !sf.MouseHovering).ToList();
                    foreach (StatusForm sf in delete)
                    {
                        if (defaultManager.InvokeRequired)
                        {
                            defaultManager.BeginInvoke(sf.Close);
                        }
                        else
                        {
                            sf.Close();
                        }
                    }
                }

                int y = this.Location.Y + this.Height;
                int x = this.Location.X;

                Dictionary <int, Serial> slots = new Dictionary <int, Serial>();
                List <int> slotPointer         = new List <int>();

                for (int i = 0; i < this.MaxBars; i++)
                {
                    int slotY = y + (i * StatusForm.DefaultHeight);
                    slotPointer.Add(slotY);
                    slots.Add(slotY, (Serial)Serial.Invalid);
                }

                StatusForm disabledSlot = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => refresSerials.Contains(f.MobileId) && f.MouseHovering).FirstOrDefault();

                if (disabledSlot != null && slots.ContainsKey(disabledSlot.Location.Y))
                {
                    slots[disabledSlot.Location.Y] = disabledSlot.MobileId;
                }

                refresSerials = SortChars(refresSerials);

                for (int i = 0; i < refresSerials.Count; i++)
                {
                    Serial     s  = refresSerials[i];
                    StatusForm sf = WindowManager.GetDefaultManager().OwnedWindows.OfType <StatusForm>().Where(f => f.MobileId == s).FirstOrDefault();

                    if (sf != null)
                    {
                        for (int u = 0; u < slotPointer.Count; u++)
                        {
                            int    slotY  = slotPointer[u];
                            Serial slotId = slots[slotY];

                            if (!slotId.IsValid && slots.Values.Count(sv => sv == sf.MobileId) == 0 || slotId == sf.MobileId)
                            {
                                if (sf.Location.X != x || sf.Location.Y != slotY)
                                {
                                    sf.Location = new Point(x, slotPointer[u]);
                                    sf.Invalidate();
                                }

                                slots[slotY] = sf.MobileId;
                                break;
                            }
                        }
                    }

                    ////if (sf != null)
                    ////{
                    //for (int u = 0; u < slotPointer.Count; u++)
                    //{
                    //  int slotY = slotPointer[u];
                    //  Serial slotId = slots[slotY];

                    //  if (!slotId.IsValid && slots.Values.Count(sv => sv == s) == 0 || slotId == s)
                    //  {


                    //    if (sf == null || sf.Location.X != x || sf.Location.Y != slotY)
                    //    {
                    //      if (sf == null)
                    //      {
                    //        sf = (StatusForm)defaultManager.CreateWindow(delegate ()
                    //        {
                    //          var f = new StatusForm(s);
                    //          f.Transparency = true;
                    //          f.Location = new Point(x, slotPointer[u]);
                    //          return f;
                    //        });
                    //      }
                    //      else
                    //      {
                    //        //??? co stim ????
                    //        sf.Location = new Point(x, slotPointer[u]);
                    //        if (defaultManager.InvokeRequired)
                    //        {
                    //          //do nothing?
                    //          defaultManager.BeginInvoke(sf.Invalidate);
                    //        }
                    //        else
                    //          sf.Invalidate();
                    //      }
                    //    }

                    //    slots[slotY] = sf.MobileId;
                    //    break;
                    //  }
                    //}
                    ////}
                }

                this.registeredSerials = refresSerials;
            }
            catch //(Exception e)
            {
                Game.PrintMessage("Chyba v zalozkach", MessageType.Error);
            }
            finally
            {
                refreshing = false;
            }
        }