Ejemplo n.º 1
0
        /// <summary>
        /// Updates the selected collection whenever an object is set to selected.
        /// </summary>
        /// <param name="args"></param>
        public void SyncSelectedItem(ChildElementPropertyChangedEventArgs args)
        {
            var item = args.ChildElement as LItem;

            if (item != null && args.PropertyName.ToString() == "IsSelected")
            {
                var match = _selectedItems.FirstOrDefault(i => i.Id == item.Id);
                if (match != null)
                {
                    if (!item.IsSelected)
                    {
                        // Remove
                        _selectedItems.Remove(match);
                        Logger.LogVerbose("Removed {0} ({2}) from Selected Items, NewSelectedCount={1}", item.Name, _selectedItems.Count, item.Id);
                    }
                    else
                    {
                        // Update Data
                    }
                }
                else if (match == null && item.IsSelected)
                {
                    _selectedItems.Add(item);
                    Logger.LogVerbose("Added {0} ({2}) to Selected Items, NewSelectedCount={1}", item.Name, _selectedItems.Count, item.Id);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the DisplayItems collection to match the Selected collection.
        /// </summary>
        public void UpdateSelectedItems()
        {
            if (_selectedItems == null || _displayItems == null || _collection == null || _collection.View == null || _collection.View.SourceCollection == null)
            {
                Logger.Log("Skipping UpdateSelectedItems due to Null");
                return;
            }

            // Prevent the collection from updating until outside of the using block.
            using (Collection.DeferRefresh())
            {
                var selectedDictionary = _selectedItems.DistinctBy(i => i.Id).ToDictionary(k => k.Id, v => v);
                var castView           = _collection.View.SourceCollection.Cast <LItem>();

                castView.ForEach(item =>
                {
                    // After XML settings load _selectedItems will contain LItem husks that are lacking useful information, just what was saved.
                    // We want to take the saved information and make an object that is fully populated and linked with the UI collection.

                    LItem selectedItem;

                    if (selectedDictionary.TryGetValue(item.Id, out selectedItem))
                    {
                        //if(!item.IsSelected)
                        //Logger.LogVerbose("Update: Selecting {0} ({1}) with {2} rules", item.Name, item.Id, item.Rules.Count);

                        selectedItem.Rules.ForEach(r =>
                        {
                            r.TrinityItemType = item.TrinityItemType;
                            r.ItemStatRange   = item.GetItemStatRange(r.ItemProperty);
                        });
                        item.IsSelected = true;
                        item.Rules      = selectedItem.Rules;
                        item.Ops        = selectedItem.Ops;

                        // Replacing the reference to automatically receive changes from UI.
                        _selectedItems.Remove(selectedItem);
                        _selectedItems.Add(item);
                    }
                    else
                    {
                        if (item.IsSelected)
                        {
                            Logger.LogVerbose("Update: Deselecting {0}", item.Name);
                            item.IsSelected = false;
                        }
                    }
                });
            }
        }
Ejemplo n.º 3
0
        public static async Task <bool> MoveTo(Vector3 location, string destinationName, float range = 10f)
        {
            while (ZetaDia.Me.IsFullyValid() && !ZetaDia.Me.IsInCombat && location.Distance2D(ZetaDia.Me.Position) > range)
            {
                Logger.LogVerbose("Moving to " + destinationName);
                PlayerMover.NavigateTo(location, destinationName);
                await Coroutine.Yield();
            }
            if (location.Distance2D(ZetaDia.Me.Position) <= range)
            {
                Navigator.PlayerMover.MoveStop();
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get a SkillMeta object
        /// </summary>
        /// <param name="skill"></param>
        /// <returns></returns>
        public static SkillMeta GetSkillMeta(Skill skill)
        {
            SkillMeta s;

            if (_skillMetas.TryGetValue(skill, out s))
            {
                return(s);
            }

            Logger.LogVerbose("GetSkillInfo found no SkillMeta for {0}", skill.Name);

            var newMeta = new SkillMeta(skill);

            SetSkillMeta(newMeta);

            return(newMeta);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Moves to somewhere.
        /// </summary>
        /// <param name="location">where to move to</param>
        /// <param name="destinationName">name of location for debugging purposes</param>
        /// <param name="range">how close it should get</param>
        public static async Task <bool> Execute(Vector3 location, string destinationName = "", float range = 10f)
        {
            while (ZetaDia.IsInGame && location.Distance(ZetaDia.Me.Position) >= range)
            {
                Logger.LogVerbose("Moving to " + destinationName);
                PlayerMover.NavigateTo(location, destinationName);
                await Coroutine.Yield();
            }

            var distance = location.Distance(ZetaDia.Me.Position);

            if (distance <= range)
            {
                Navigator.PlayerMover.MoveStop();
            }

            Logger.LogVerbose("MoveTo Finished. Distance={0}", distance);
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Moves to a position, finds actor by Id and interacts with it
        /// </summary>
        /// <param name="actorId">id of actor to interact with</param>
        /// <param name="range">how close to get</param>
        /// <param name="position">position from which to interact</param>
        /// <param name="interactLimit">maximum number of times to interact</param>
        public static async Task <bool> Execute(Vector3 position, int actorId, float range = -1f, int interactLimit = 5)
        {
            if (position == Vector3.Zero)
            {
                return(false);
            }

            if (interactLimit < 1)
            {
                interactLimit = 5;
            }
            if (range < 0)
            {
                range = 2f;
            }

            if (position.Distance(ZetaDia.Me.Position) > range)
            {
                if (!await MoveTo.Execute(position, position.ToString()))
                {
                    Logger.Log("MoveTo Failed for {0} Distance={1}", position, position.Distance(ZetaDia.Me.Position));
                    return(false);
                }
            }

            var actor = ZetaDia.Actors.GetActorsOfType <DiaObject>(true).FirstOrDefault(a => a.ActorSNO == actorId);

            if (actor == null)
            {
                Logger.LogVerbose("Interaction Failed: Actor not found with Id={0}", actorId);
                return(false);
            }

            var distance = position.Distance(ZetaDia.Me.Position);

            if (distance <= range || distance - actor.CollisionSphere.Radius <= range)
            {
                for (int i = 1; i <= interactLimit; i++)
                {
                    Logger.Log("Interacting with {0} ({1}) Attempt={2}", actor.Name, actor.ActorSNO, i);
                    if (actor.Interact() && i > 1)
                    {
                        break;
                    }

                    await Coroutine.Sleep(100);

                    await Coroutine.Yield();
                }
            }

            // Better to be redundant than failing to interact.

            Navigator.PlayerMover.MoveTowards(actor.Position);
            await Coroutine.Sleep(250);

            actor.Interact();

            Navigator.PlayerMover.MoveStop();
            await Coroutine.Sleep(1000);

            await Interact(actor);

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Moves to something and interacts with it
        /// </summary>
        /// <param name="obj">object to interact with</param>
        /// <param name="range">how close to get</param>
        /// <param name="interactLimit">maximum number of times to interact</param>
        public static async Task <bool> Execute(DiaObject obj, float range = -1f, int interactLimit = 5)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!obj.IsFullyValid())
            {
                return(false);
            }

            if (interactLimit < 1)
            {
                interactLimit = 5;
            }
            if (range < 0)
            {
                range = obj.CollisionSphere.Radius;
            }

            if (obj.Position.Distance(ZetaDia.Me.Position) > range)
            {
                if (!await MoveTo.Execute(obj.Position, obj.Name))
                {
                    Logger.Log("MoveTo Failed for {0} ({1}) Distance={2}", obj.Name, obj.ActorSNO, obj.Distance);
                    return(false);
                }
            }

            var distance = obj.Position.Distance(ZetaDia.Me.Position);

            if (distance <= range || distance - obj.CollisionSphere.Radius <= range)
            {
                for (int i = 1; i <= interactLimit; i++)
                {
                    Logger.LogVerbose("Interacting with {0} ({1}) Attempt={2}", obj.Name, obj.ActorSNO, i);
                    if (obj.Interact() && i > 1)
                    {
                        break;
                    }

                    await Coroutine.Sleep(500);

                    await Coroutine.Yield();
                }
            }

            // Better to be redundant than failing to interact.

            Navigator.PlayerMover.MoveTowards(obj.Position);
            await Coroutine.Sleep(500);

            obj.Interact();

            Navigator.PlayerMover.MoveStop();
            await Coroutine.Sleep(1000);

            await Interact(obj);

            return(true);
        }