Пример #1
0
        public void TraverseEquipment(EquipmentData equipment)
        {
            if (equipment.IsTaken || equipment.ReplacementOptions.Any(e => e.IsTaken))
            {
                equipment.CanAdd = true;
                equipment.ReplacementOptions.ForEach(e => e.CanAdd = true);
                equipment.GivenEquipment.ForEach(e => e.CanAdd     = true);
                equipment.GivenEquipment.Where(e => e.Equipment.IsGiven).ForEach(e => e.IsTaken = true);
            }

            else
            {
                equipment.CanAdd = equipment.ParentEquipment == null || (ParentEquipment != null && (equipment.ParentEquipment.IsTaken || equipment.ParentEquipment.ReplacementOptions.Any(e => e.IsTaken))); //top most equipment can never be not taken

                equipment.ReplacementOptions.ForEach(e =>
                {
                    e.CanAdd  = false;
                    e.IsTaken = false;
                    TraverseEquipment(e);
                });

                equipment.GivenEquipment.ForEach(e =>
                {
                    e.CanAdd  = false;
                    e.IsTaken = false;
                    TraverseEquipment(e);
                });
            }
        }
Пример #2
0
        public void SetData(Equipment e, EquipmentData parent)
        {
            Equipment       = e;
            ParentEquipment = parent;

            ReplacementOptions.ForEach(i => i.SetData(Equipment.ReplacementOptions.Single(ii => ii.Id == i.EquipmentId), this));
            GivenEquipment.ForEach(i => i.SetData(Equipment.GivenEquipment.Single(ii => ii.Id == i.EquipmentId), this));
            TraverseEquipment(this);
        }
Пример #3
0
        public EquipmentData(Equipment e, EquipmentData parent)
        {
            Equipment       = e;
            ParentEquipment = parent;

            EquipmentId        = e.Id;
            ReplacementOptions = Equipment.ReplacementOptions.Select(eq => new EquipmentData(eq, this)).ToList();
            GivenEquipment     = Equipment.GivenEquipment.Select(eq => new EquipmentData(eq, this)).ToList();

            IsTaken = Equipment.IsDefault || ((ParentEquipment?.IsTaken ?? false) && Equipment.IsGiven);
            TraverseEquipment(this);
        }
Пример #4
0
 private void SubscribeToEquipment(EquipmentData equipment)
 {
     equipment.ReplacementOptions.ForEach(e =>
     {
         e.PropertyChanged += EquipmentPropertyChanged;
         SubscribeToEquipment(e);
     });
     equipment.GivenEquipment.ForEach(e =>
     {
         e.PropertyChanged += EquipmentPropertyChanged;
         SubscribeToEquipment(e);
     });
 }
Пример #5
0
        private List <EquipmentData> GetAllEquipmentSubEquipment(EquipmentData e)
        {
            var allEquip = new List <EquipmentData>();

            allEquip.AddRange(e.GivenEquipment);
            allEquip.AddRange(e.ReplacementOptions);

            foreach (var ee in allEquip.ToList())
            {
                allEquip.AddRange(GetAllEquipmentSubEquipment(ee));
            }

            return(allEquip);
        }
Пример #6
0
 private int TotalEquipmentCost(EquipmentData equipment)
 {
     return((equipment.IsTaken ? equipment.Equipment.Cost : 0) + equipment.ReplacementOptions.Sum(TotalEquipmentCost) + equipment.GivenEquipment.Sum(TotalEquipmentCost));
 }