示例#1
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);
        }
示例#2
0
        public static bool CanBeFieldedFF(MechDef mechdef)
        {
            if (SkipArmActuatorValidationAndFixingForMechDef(mechdef))
            {
                return(true);
            }

            if (IsIgnoreFullActuators(mechdef))
            {
                return(CanBeFielded(mechdef));
            }

            bool 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)
                    {
                        return(false);
                    }
                    total_slots = total_slots | a.Type;
                }

                if (total_slots < limit)
                {
                    return(false);
                }
                if (total_slots > limit)
                {
                    return(false);
                }
                return(true);
            }

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

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

            return(check_side(ChassisLocations.LeftArm, left) && check_side(ChassisLocations.RightArm, right));
        }
示例#3
0
        private static string GetComponentIdForSlot(ArmActuatorSlot slot)
        {
            switch (slot)
            {
            case ArmActuatorSlot.PartShoulder:
                return(ArmActuatorFeature.settings.DefaultCBTShoulder);

            case ArmActuatorSlot.PartUpper:
                return(ArmActuatorFeature.settings.DefaultCBTUpper);

            case ArmActuatorSlot.PartLower:
                return(ArmActuatorFeature.settings.DefaultCBTDefLower);

            case ArmActuatorSlot.PartHand:
                return(ArmActuatorFeature.settings.DefaultCBTDefHand);

            default:
                return(null);
            }
        }
示例#4
0
        private static void add_full_actuators(MechDef mechdef)
        {
            void process_location(ChassisLocations location)
            {
                var total_slots = mechdef.Inventory.Where(i => i.MountedLocation == location && i.Is <ArmActuator>())
                                  .Select(i => i.GetComponent <ArmActuator>())
                                  .Aggregate(ArmActuatorSlot.None, (current, item) => current | item.Type);

                //if not present any actuators
                if (total_slots == ArmActuatorSlot.None)
                {
                    //add shoulder, and upper
                    AddDefaultToInventory(mechdef, null, location, ArmActuatorSlot.PartShoulder, ref total_slots);
                    AddDefaultToInventory(mechdef, null, location, ArmActuatorSlot.PartUpper, ref total_slots);

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

                    foreach (var item in mechdef.Inventory.Where(i => i.MountedLocation == location &&
                                                                 i.Is <ArmActuator>()).Select(i => i.GetComponent <ArmActuator>()))
                    {
                        if (item.MaxSlot < max)
                        {
                            max = item.MaxSlot;
                        }
                    }

                    var builder = new MechDefBuilder(mechdef);
                    if (max >= ArmActuatorSlot.PartLower && !total_slots.HasFlag(ArmActuatorSlot.PartLower))
                    {
                        var def = UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Get(ArmActuatorFeature.settings.DefaultCBTLower);
                        if (def == null)
                        {
                            return;
                        }
                        if (!builder.Add(def, location))
                        {
                            return;
                        }
                    }

                    if (max >= ArmActuatorSlot.PartHand && !total_slots.HasFlag(ArmActuatorSlot.PartHand))
                    {
                        var def = UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Get(ArmActuatorFeature.settings.DefaultCBTHand);
                        builder.Add(def, location);
                    }
                    mechdef.SetInventory(builder.Inventory.ToArray());
                }
                else
                {
                    //recheck and add if needed shoulder and arm
                    AddDefaultToInventory(mechdef, null, location, ArmActuatorSlot.PartShoulder, ref total_slots);
                    AddDefaultToInventory(mechdef, null, location, ArmActuatorSlot.PartUpper, ref total_slots);
                }
            }

            process_location(ChassisLocations.RightArm);
            process_location(ChassisLocations.LeftArm);
        }
示例#5
0
        internal static void AddDefaultToInventory(MechDef mechdef, SimGameState simgame, ChassisLocations location, ArmActuatorSlot slot, ref ArmActuatorSlot totalSlots)
        {
            bool add_item(string id, ref ArmActuatorSlot total_slot)
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(false);
                }

                var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, UnityGameInstance.BattleTechGame.DataManager, simgame);

                if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0)
                {
                    DefaultHelper.AddInventory(id, mechdef, location, ComponentType.Upgrade, simgame);
                    total_slot = total_slot | actuator.Type;
                    return(true);
                }

                return(false);
            }

            CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- adding {slot} to {totalSlots}");
            if (totalSlots.HasFlag(slot))
            {
                CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present");
                return;
            }

            if (add_item(GetDefaultActuator(mechdef, location, slot), ref totalSlots))
            {
                return;
            }

            add_item(GetDefaultActuator(null, location, slot), ref totalSlots);
        }
示例#6
0
        public static string GetDefaultActuator(MechDef mech, ChassisLocations location, ArmActuatorSlot slot)
        {
            if (location != ChassisLocations.RightArm && location != ChassisLocations.LeftArm)
            {
                return(null);
            }

            if (mech == null || !mech.Chassis.Is <ArmActuatorSupport>(out var support))
            {
                return(GetComponentIdForSlot(slot));
            }

            switch (slot)
            {
            case ArmActuatorSlot.PartShoulder:
                return(support.GetShoulder(location));

            case ArmActuatorSlot.PartUpper:
                return(support.GetUpper(location));

            case ArmActuatorSlot.PartLower:
                return(support.GetLower(location));

            case ArmActuatorSlot.PartHand:
                return(support.GetHand(location));

            default:
                return(null);
            }
        }
示例#7
0
        public static bool CanBeFielded(MechDef mechdef)
        {
            if (SkipArmActuatorValidationAndFixingForMechDef(mechdef))
            {
                return(true);
            }

            bool 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)
                    {
                        return(false);
                    }

                    //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)
                {
                    return(false);
                }

                //if not have shoulder
                if (!slots.HasFlag(ArmActuatorSlot.PartShoulder))
                {
                    return(false);
                }

                //if not have upper
                if (!slots.HasFlag(ArmActuatorSlot.PartUpper))
                {
                    return(false);
                }

                //if have hand but not lower
                if (slots.HasFlag(ArmActuatorSlot.PartHand) && !slots.HasFlag(ArmActuatorSlot.PartLower))
                {
                    return(false);
                }

                return(true);
            }

            return(check_location(ChassisLocations.LeftArm) && check_location(ChassisLocations.RightArm));
        }
示例#8
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);
        }