Ejemplo n.º 1
0
        public static void Update()
        {
            List <WoWUnit> availableUnits = (from u in ObjectManager.GetObjectsOfType <WoWUnit>(true, false)
                                             where !u.IsDead && u.Attackable && u.IsMe && !u.IsFriendly && u.Combat
                                             orderby u.DistanceSqr ascending
                                             select u).ToList();

            foreach (WoWUnit unit in availableUnits)
            {
                if (!DpsInfos.ContainsKey(unit.Guid))
                {
                    var di = new DpsInfo {
                        Unit = unit, CombatStart = DateTime.Now, StartHealth = unit.CurrentHealth
                    };

                    DpsInfos.Add(unit.Guid, di);
                }
                else
                {
                    DpsInfo di = DpsInfos[unit.Guid];

                    di.CurrentDps     = (di.StartHealth - unit.CurrentHealth) / (DateTime.Now - di.CombatStart).TotalSeconds;
                    di.CombatTimeLeft = new TimeSpan(0, 0, (int)(unit.CurrentHealth / di.CurrentDps));

                    // .NET makes a copy of the struct when we grab it out of the collection.
                    // Make sure we put the updated version back in!
                    DpsInfos[unit.Guid] = di;
                }
            }

            // Kill off any 'bad' units in our list.
            KeyValuePair <ulong, DpsInfo>[] removeUnits = DpsInfos.Where(kv => !kv.Value.Unit.IsValid).ToArray();
            for (int i = 0; i < removeUnits.Length; i++)
            {
                DpsInfos.Remove(removeUnits[i].Key);
            }
        }
Ejemplo n.º 2
0
        public static void Update()
        {
            List<WoWUnit> availableUnits = (from u in ObjectManager.GetObjectsOfType<WoWUnit>(true, false)
                                            where !u.IsDead && u.Attackable && u.IsMe && !u.IsFriendly && u.Combat
                                            orderby u.DistanceSqr ascending
                                            select u).ToList();

            foreach (WoWUnit unit in availableUnits)
            {
                if (!DpsInfos.ContainsKey(unit.Guid))
                {
                    var di = new DpsInfo { Unit = unit, CombatStart = DateTime.Now, StartHealth = unit.CurrentHealth };

                    DpsInfos.Add(unit.Guid, di);
                }
                else
                {
                    DpsInfo di = DpsInfos[unit.Guid];

                    di.CurrentDps = (di.StartHealth - unit.CurrentHealth) / (DateTime.Now - di.CombatStart).TotalSeconds;
                    di.CombatTimeLeft = new TimeSpan(0, 0, (int)(unit.CurrentHealth / di.CurrentDps));

                    // .NET makes a copy of the struct when we grab it out of the collection.
                    // Make sure we put the updated version back in!
                    DpsInfos[unit.Guid] = di;
                }
            }

            // Kill off any 'bad' units in our list.
            KeyValuePair<ulong, DpsInfo>[] removeUnits = DpsInfos.Where(kv => !kv.Value.Unit.IsValid).ToArray();
            for (int i = 0; i < removeUnits.Length; i++)
            {
                DpsInfos.Remove(removeUnits[i].Key);
            }
        }