コード例 #1
0
        public void ValidateMech(MechDef mechDef, Errors errors)
        {
            foreach (var location in MechDefBuilder.Locations)
            {
                var inventory  = mechDef.Inventory.Where(x => x.MountedLocation == location).Select(x => x.Def);
                var hardpoints = mechDef.Chassis.GetLocationDef(location).Hardpoints;

                var calc = new HardpointOmniUsageCalculator(inventory, hardpoints);

                if (calc.OmniFree < 0)
                {
                    if (errors.Add(MechValidationType.InvalidHardpoints, ErrorMessage(location)))
                    {
                        return;
                    }
                }
            }
        }
コード例 #2
0
        // TODO move to CC
        internal bool ValidateAddSimple(ChassisDef chassisDef, ChassisLocations location, MechComponentDef newComponentDef)
        {
            if (newComponentDef.ComponentType != ComponentType.Weapon)
            {
                return(true);
            }

            var chassisLocationDef = chassisDef.GetLocationDef(location);
            var hardpoints         = chassisLocationDef.Hardpoints;

            if (hardpoints == null)
            {
                // how can this happen? is this from the properties widget?
                //Control.mod.Logger.LogDebug($"hardpoints is null");
                return(true);
            }

            var calc = new HardpointOmniUsageCalculator(null, hardpoints);

            return(calc.CanAdd(newComponentDef));
        }