Ejemplo n.º 1
0
        private void _changePriority(HealerRule obj)
        {
            if (obj == null)
            {
                return;
            }
            ObservableCollection <HealerRule> collection = SpellHealerRules.Any(r => r.Equals(obj)) ? SpellHealerRules : ItemHealerRules;

            //fix priority
            int max = collection.Count - 1;

            if (obj.Priority > max)
            {
                obj.Priority = max;
            }

            //finds the item where the priority is the same as current item
            HealerRule oldPriorityItem = collection.FirstOrDefault(r => !r.Equals(obj) && r.Priority == obj.Priority);
            //checks if the olditem is the last based on priority or if the olditem.Priority is bigger than the currentItem
            bool increaseValue = oldPriorityItem?.Priority >= max || collection.Any(r => r.Priority == obj.Priority + 1);

            //checks if there
            if (oldPriorityItem == null)
            {
                return;
            }
            oldPriorityItem.Priority = increaseValue ? obj.Priority - 1 : obj.Priority + 1;
        }
Ejemplo n.º 2
0
 private void _deleteRule(HealerRule obj)
 {
     if (_spellHealerRules.Any(r => r.Equals(obj)))
     {
         SpellHealerRules.Where(r => r.Priority > obj.Priority).ToList().ForEach(r => r.Priority--);
         SpellHealerRules.Remove(obj);
     }
     else
     {
         ItemHealerRules.Where(r => r.Priority > obj.Priority).ToList().ForEach(r => r.Priority--);
         ItemHealerRules.Remove(obj);
     }
 }