internal static void Postfix(MechValidationLevel validationLevel, DataManager dataManager, MechDef mechDef, ref Dictionary <MechValidationType, List <Text> > __result)
 {
     if (validationLevel == MechValidationLevel.MechLab)
     {
         MechValidationRules.ValidateMechInventorySlots(dataManager, mechDef, ref __result);
     }
 }
Exemplo n.º 2
0
        public void ValidateMech(Dictionary <MechValidationType, List <string> > errors,
                                 MechValidationLevel validationLevel, MechDef mechDef)
        {
            var slots   = new MechDefSlots(mechDef);
            var missing = slots.Missing;

            if (missing > 0)
            {
                errors[MechValidationType.InvalidInventorySlots]
                .Add($"RESERVED SLOTS: Mech requires {missing} additional free slots");
            }
        }
 public static void Postfix(Dictionary <MechValidationType, List <Text> > __result,
                            MechValidationLevel validationLevel, MechDef mechDef)
 {
     Validator.ValidateMech(__result, validationLevel, mechDef);
     foreach (var component in mechDef.Inventory)
     {
         foreach (var validator in component.GetComponents <IMechValidate>())
         {
             validator.ValidateMech(__result, validationLevel, mechDef, component);
         }
     }
 }
Exemplo n.º 4
0
        public static void Postfix(Dictionary <MechValidationType, List <Text> > __result,
                                   MechValidationLevel validationLevel, MechDef mechDef)
        {
            try
            {
                if (mechDef == null)
                {
                    return;
                }
                if (Control.Settings.IgnoreValidationTags != null && Control.Settings.IgnoreValidationTags.Length > 0)
                {
                    foreach (var tag in Control.Settings.IgnoreValidationTags)
                    {
                        if ((mechDef.Chassis.ChassisTags != null && mechDef.Chassis.ChassisTags.Contains(tag)) ||
                            (mechDef.MechTags != null && mechDef.MechTags.Contains(tag)))
                        {
                            Control.LogDebug(DType.MechValidation, $"Validation {mechDef.Description.Id} Ignored by {tag}");
                            foreach (var pair in __result)
                            {
                                pair.Value.Clear();
                            }
                            return;
                        }
                    }
                }


                Validator.ValidateMech(__result, validationLevel, mechDef);
                foreach (var component in mechDef.Inventory)
                {
                    foreach (var validator in component.GetComponents <IMechValidate>())
                    {
                        validator.ValidateMech(__result, validationLevel, mechDef, component);
                    }

                    if (component.Is <IAllowedLocations>(out var locations) &&
                        (component.MountedLocation & locations.GetLocationsFor(mechDef)) <= ChassisLocations.None)
                    {
                        __result[MechValidationType.InvalidInventorySlots].Add(
                            new Localize.Text(Control.Settings.Message.Base_LocationDestroyed,
                                              component.Def.Description.Name, component.MountedLocation, component.Def.Description.UIName));
                    }
                }
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
Exemplo n.º 5
0
        internal static void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors,
                                          MechValidationLevel validationLevel, MechDef mechDef)
        {
            foreach (var validator in mech_validators)
            {
                validator(errors, validationLevel, mechDef);
            }

            var sizes = mechDef.Inventory.Select(cref =>
                                                 new { location = cref.MountedLocation, size = cref.Def.InventorySize })
                        .GroupBy(i => i.location)
                        .Select(i => new { location = i.Key, size = i.Sum(a => a.size) }).ToList();

            foreach (var size in sizes)
            {
                if (mechDef.GetChassisLocationDef(size.location).InventorySlots < size.size)
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text($"{size.location} no space left, remove excess equipment"));
                }
            }
        }
Exemplo n.º 6
0
 public void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef, MechComponentRef componentRef)
 {
     if (mechDef.Chassis.Tonnage < Min && mechDef.Chassis.Tonnage > Max)
     {
         if (Min == Max)
         {
             errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                      $"{Def.Description.Name.ToUpper()} designed for {Min}t 'Mech"));
         }
         else
         {
             errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                      $"{Def.Description.Name.ToUpper()} designed for {Min}t-{Max}t 'Mech"));
         }
     }
 }
Exemplo n.º 7
0
 public void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef, MechComponentRef componentRef)
 {
     if (mechDef.Chassis.Tonnage < Min && mechDef.Chassis.Tonnage > Max)
     {
         if (Min == Max)
         {
             errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(Control.Settings.Message.Tonnage_ValidateAllow, componentRef.Def.Description.UIName, Min));
         }
         else
         {
             errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(Control.Settings.Message.Tonnage_ValidateLimit, componentRef.Def.Description.UIName, Min, Max));
         }
     }
 }
        public void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationlevel, MechDef mechdef)
        {
            var weapons_per_location = mechdef.Inventory
                                       .Select(i => new { location = i.MountedLocation, item = i, wcat = i.GetWeaponCategory() })
                                       .Where(i => !i.wcat.Is_NotSet)

                                       .GroupBy(i => i.location)
                                       .Select(i => new { location = i.Key, items = i.ToList() })
                                       .ToList();

            foreach (var w_location in weapons_per_location)
            {
                var hardpoints = mechdef.GetAllHardpoints(w_location.location, mechdef.Inventory.ToInvItems());

                foreach (var recrd in w_location.items)
                {
                    if (HardpointsByID.TryGetValue(recrd.wcat.ID, out var hpInfo))
                    {
                        var nearest = hardpoints.FirstOrDefault(i => i.Total > i.Used && i.hpInfo.CompatibleID.Contains(hpInfo.WeaponCategory.ID));
                        if (nearest != null)
                        {
                            nearest.Used += 1;
                        }
                        else
                        {
                            errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                                     Control.Settings.Message.Base_AddNotEnoughHardpoints,
                                                                                     mechdef.Description.UIName, recrd.item.Def.Description.Name,
                                                                                     recrd.item.Def.Description.UIName,
                                                                                     recrd.wcat.Name, recrd.wcat.FriendlyName,
                                                                                     w_location.location
                                                                                     ));
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationlevel, MechDef mechdef)
        {
            foreach (var item in mechdef.Inventory)
            {
                var location = item.Is <IAllowedLocations>(out var al)
                    ? al.GetLocationsFor(mechdef)
                    : item.Def.AllowedLocations;

                if ((location & item.MountedLocation) <= ChassisLocations.None)
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(
                        new Text(Control.Settings.Message.Base_ValidateWrongLocation, item.Def.Description.Name)
                        );
                }
            }
        }
Exemplo n.º 10
0
        public void ValidateMech(Dictionary <MechValidationType, List <Text> > errorMessages, MechValidationLevel validationLevel, MechDef mechDef)
        {
            var errors = new Errors();

            validator.ValidateMech(mechDef, errors);
            errors.Populate(errorMessages);
        }
Exemplo n.º 11
0
 public void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef, MechComponentRef componentRef)
 {
     if (Links?.Any(link => !mechDef.Inventory.Any(i =>
                                                   i.MountedLocation == link.Location && i.ComponentDefID == link.ComponentDefId)) == true)
     {
         errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text($"{Def.Description.Name} have critical errors, reinstall it to fix"));
     }
 }
Exemplo n.º 12
0
        public void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef, MechComponentRef componentRef)
        {
            if (Invalid)
            {
                errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                         string.Format(string.IsNullOrEmpty(ErrorInvalid) ? "{0} is placeholder, remove it" : ErrorInvalid, Def.Description.Name)));
            }

            if (componentRef.DamageLevel == ComponentDamageLevel.Destroyed && (NotDestroyed || NotBroken))
            {
                errors[MechValidationType.StructureDestroyed].Add(new Localize.Text(
                                                                      string.Format(string.IsNullOrEmpty(ErrorItemBroken) ? "{0} is destroyed, replace it" : ErrorItemDestroyed, Def.Description.Name)));
            }

            if (componentRef.DamageLevel == ComponentDamageLevel.Penalized && NotBroken)
            {
                errors[MechValidationType.StructureDestroyed].Add(new Localize.Text(
                                                                      string.Format(string.IsNullOrEmpty(ErrorItemBroken) ? "{0} is damaged, repair it" : ErrorItemBroken, Def.Description.Name)));
            }
        }
Exemplo n.º 13
0
        public static void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationlevel, MechDef mechdef)
        {
            if (SkipArmActuatorValidationAndFixingForMechDef(mechdef))
            {
                return;
            }

            void check_location(ChassisLocations location)
            {
                //occupied slots
                var slots = ArmActuatorSlot.None;

                //list of actuators in location
                var actuators = from item in mechdef.Inventory
                                where item.MountedLocation == location &&
                                item.Is <ArmActuator>()
                                select item.GetComponent <ArmActuator>();


                //get max avaliable actuator
                ArmActuatorSlot max = mechdef.Chassis.Is <ArmActuatorSupport>(out var support)
                    ? support.GetLimit(location)
                    : ArmActuatorSlot.PartHand;

                foreach (var actuator in actuators)
                {
                    // if more then 1 actuator occupy 1 slot
                    if ((slots & actuator.Type) != 0)
                    {
                        errors[MechValidationType.InvalidInventorySlots]
                        .Add(new Text($"{location} have more then one {actuator.Type} actuator"));
                    }

                    //correcting max slot if actuator has limits
                    if (max > actuator.MaxSlot)
                    {
                        max = actuator.MaxSlot;
                    }

                    //save actuator to slots
                    slots = slots | actuator.Type;
                }

                if (ArmActuatorFeature.settings.ExtendHandLimit)
                {
                    if (max == ArmActuatorSlot.PartHand)
                    {
                        max = ArmActuatorSlot.Hand;
                    }

                    if (max == ArmActuatorSlot.PartUpper)
                    {
                        max = ArmActuatorSlot.Upper;
                    }

                    if (max == ArmActuatorSlot.PartLower)
                    {
                        max = ArmActuatorSlot.Lower;
                    }
                }

                // if not support hand/lower
                if (slots > max)
                {
                    errors[MechValidationType.InvalidInventorySlots]
                    .Add(new Text($"{location} cannot support more then {max} actuator"));
                }

                //if not have shoulder
                if (!slots.HasFlag(ArmActuatorSlot.PartShoulder))
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} missing Shoulder"));
                }

                //if not have upper
                if (!slots.HasFlag(ArmActuatorSlot.PartUpper))
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} missing Upper Arm"));
                }

                //if have hand but not lower
                if (slots.HasFlag(ArmActuatorSlot.PartHand) && !slots.HasFlag(ArmActuatorSlot.PartLower))
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} missing Lower Arm"));
                }
            }

            check_location(ChassisLocations.LeftArm);
            check_location(ChassisLocations.RightArm);
        }
Exemplo n.º 14
0
 internal void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationLevel, MechDef mechDef)
 {
     ValidateMech(out var error, mechDef, ChassisLocations.None, errors: errors);
 }
Exemplo n.º 15
0
        public static void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef)
        {
            var linked = mechDef.Inventory
                         .Select(i => i.GetComponent <AutoLinked>())
                         .Where(i => i != null && i.Links != null)
                         .SelectMany(i => i.Links, (a, b) => new { custom = a, link = b }).ToList();

            if (linked.Count > 0)
            {
                var inv = mechDef.Inventory.ToList();

                foreach (var item in linked)
                {
                    var found = inv.FirstOrDefault(i =>
                                                   i.ComponentDefID == item.link.ComponentDefId && i.MountedLocation == item.link.Location);

                    if (found == null)
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Text(
                                                                                 Control.Settings.Message.Linked_Validate,
                                                                                 mechDef.Description.UIName, item.custom.Def.Description.Name,
                                                                                 item.custom.Def.Description.UIName,
                                                                                 item.link.Location));
                    }
                    else
                    {
                        inv.Remove(found);
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// validate mech and fill errors
        /// </summary>
        /// <param name="errors">errors by category</param>
        /// <param name="validationLevel"></param>
        /// <param name="mechDef">mech to validate</param>
        internal void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors,
                                   MechValidationLevel validationLevel, MechDef mechDef)
        {
            var items_by_category = mechDef.Inventory
                                    .Select(item => new { item, def = item.Def.GetComponents <Category>() })
                                    .Where(@t => @t.def != null)
                                    .SelectMany(@t => t.def.Select(item => new
            {
                category = item.CategoryDescriptor,
                itemdef  = @t.item.Def,
                itemref  = @t.item,
                mix      = item.GetTag()
            }))
                                    .GroupBy(i => i.category)
                                    .ToDictionary(i => i.Key, i => i.ToList());


            //fcache.Clear();

            //check each "required" category
            foreach (var category in GetCategories().Where(i => i.Required))
            {
                if (!items_by_category.ContainsKey(category) || items_by_category[category].Count < category.MinEquiped)
                {
                    if (category.MinEquiped == 1)
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(category.ValidateRequred, category.DisplayName.ToUpper(), category.DisplayName)));
                    }
                    else
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(category.ValidateMinimum, category.DisplayName.ToUpper(), category.DisplayName, category.MinEquiped)));
                    }
                }
            }

            foreach (var pair in items_by_category)
            {
                //check if too mant items of same category
                if (pair.Key.MaxEquiped > 0 && pair.Value.Count > pair.Key.MaxEquiped)
                {
                    if (pair.Key.MaxEquiped == 1)
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(pair.Key.ValidateUnique,
                                                                                                             pair.Key.DisplayName.ToUpper(), pair.Key.DisplayName)));
                    }
                    else
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(pair.Key.ValidateMaximum,
                                                                                                             pair.Key.DisplayName.ToUpper(), pair.Key.DisplayName, pair.Key.MaxEquiped)));
                    }
                }

                //check if cateory mix tags
                if (!pair.Key.AllowMixTags)
                {
                    string def = pair.Value[0].mix;

                    bool flag = pair.Value.Any(i => i.mix != def);
                    if (flag)
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(pair.Key.ValidateMixed,
                                                                                                             pair.Key.DisplayName.ToUpper(), pair.Key.DisplayName)));
                    }
                }

                // check count items per location
                if (pair.Key.MaxEquipedPerLocation > 0)
                {
                    var max = pair.Value.GroupBy(i => i.itemref.MountedLocation).Max(i => i.Count());
                    if (max > pair.Key.MaxEquipedPerLocation)
                    {
                        if (pair.Key.MaxEquipedPerLocation == 1)
                        {
                            errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(pair.Key.ValidateUniqueLocation,
                                                                                                                 pair.Key.DisplayName.ToUpper(), pair.Key.DisplayName)));
                        }
                        else
                        {
                            errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.Format(pair.Key.ValidateMaximumLocation,
                                                                                                                 pair.Key.DisplayName.ToUpper(), pair.Key.DisplayName, pair.Key.MaxEquipedPerLocation)));
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        internal static void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationLevel, MechDef mechDef)
        {
            foreach (var item in mechDef.Inventory)
            {
                var f = item.Flags <CCFlags>();

                if (f.Invalid)
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                             Control.Settings.Message.Flags_InvaildComponent, item.Def.Description.Name, item.Def.Description.UIName));
                }

                if (item.DamageLevel == ComponentDamageLevel.Destroyed && (f.NotBroken || f.NotDestroyed))
                {
                    errors[MechValidationType.StructureDestroyed].Add(new Localize.Text(
                                                                          Control.Settings.Message.Flags_DestroyedComponent, item.Def.Description.Name, item.Def.Description.UIName));
                }

                if (item.DamageLevel == ComponentDamageLevel.Penalized && f.NotBroken)
                {
                    errors[MechValidationType.StructureDestroyed].Add(new Localize.Text(
                                                                          Control.Settings.Message.Flags_DamagedComponent, item.Def.Description.Name, item.Def.Description.UIName));
                }
            }
        }
Exemplo n.º 18
0
 public void ValidateMech(Dictionary <MechValidationType, List <Localize.Text> > errors, MechValidationLevel validationLevel, MechDef mechDef, MechComponentRef componentRef)
 {
     if (mechDef.Chassis.Tonnage != Tonnage)
     {
         errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                  $"{Def.Description.Name} designed for {Tonnage}t mech"));
     }
 }
Exemplo n.º 19
0
        public static void ValidateMechFF(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationlevel, MechDef mechdef)
        {
            if (SkipArmActuatorValidationAndFixingForMechDef(mechdef))
            {
                return;
            }

            if (IsIgnoreFullActuators(mechdef))
            {
                ValidateMech(errors, validationlevel, mechdef);
                return;
            }

            void check_side(ChassisLocations location, ArmActuatorSlot limit)
            {
                var total_slots = ArmActuatorSlot.None;

                foreach (var item in mechdef.Inventory.Where(i => i.MountedLocation == location && i.Is <ArmActuator>()))
                {
                    var a = item.GetComponent <ArmActuator>();
                    if ((a.Type & total_slots) != 0)
                    {
                        errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} have more then one {a.Type} actuator"));
                    }
                    total_slots = total_slots | a.Type;
                }

                if (total_slots < limit)
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} dont have {(ArmActuatorSlot)(limit - total_slots):G} actuator"));
                }
                else if (total_slots > limit)
                {
                    errors[MechValidationType.InvalidInventorySlots].Add(new Text($"{location} dont support {(ArmActuatorSlot)(total_slots - limit):G} actuator"));
                }
            }

            ArmActuatorSlot left  = ArmActuatorSlot.Hand;
            ArmActuatorSlot right = ArmActuatorSlot.Hand;

            if (mechdef.Chassis.Is <ArmActuatorSupport>(out var support))
            {
                left  = support.LeftLimit;
                right = support.RightLimit;
            }

            check_side(ChassisLocations.LeftArm, left);
            check_side(ChassisLocations.RightArm, right);
        }
Exemplo n.º 20
0
 internal static void CheckWeapons(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationLevel, MechDef mechDef)
 {
     if (!CheckWeaponsFielded(mechDef))
     {
         errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(Control.Settings.Message.WrongWeaponCount, Control.Settings.MaxWeaponCount));
     }
 }