internal static ArmorLocation GetPassthroughLocation(
            ArmorLocation location,
            AttackDirection attackDirection
            )
        {
            try
            {
                if (ComponentExplosionsFeature.IsInternalExplosion && currentMech != null)
                {
                    var chassisLocation = MechStructureRules.GetChassisLocationFromArmorLocation(location);
                    var properties      = ComponentExplosionsFeature.Shared.GetCASEProperties(currentMech, (int)chassisLocation);
                    if (properties != null)
                    {
                        currentMech.PublishFloatieMessage("EXPLOSION CONTAINED");

                        //Control.mod.Logger.LogDebug($"prevented explosion pass through from {Mech.GetAbbreviatedChassisLocation(chassisLocation)}");

                        return(ArmorLocation.None); // CASE redirects damage, so lets redirect it to none
                    }
                }
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }

            return(MechStructureRules.GetPassthroughLocation(location, attackDirection));
        }
Exemple #2
0
        public static MechComponent GetComponentFromRoll(AbstractActor me, int location, float random)
        {
            List <MechComponent> list = ListComponentsAtLocation(me, location);

            if (me is Mech mech)
            {
                if ((list.IsNullOrEmpty() || list.All(e => e.DamageLevel >= ComponentDamageLevel.Destroyed)) && Settings.CritLocationTransfer)
                {
                    ArmorLocation newLocation = MechStructureRules.GetPassthroughLocation(MechStructureRules.GetArmorFromChassisLocation((ChassisLocations)location) & FrontArmours, AttackDirection.FromFront);
                    if (newLocation != ArmorLocation.None)
                    {
                        Verbo("Crit list empty at {0} of {1}, transferring crit to {2}", (ChassisLocations)location, me, newLocation);
                        ChassisLocations chassis = MechStructureRules.GetChassisLocationFromArmorLocation(newLocation);
                        return(GetComponentFromRoll(me, (int)chassis, random));
                    }
                }
                else if (!Settings.CritIgnoreEmptySlots)
                {
                    int MinSlots = mech.MechDef.GetChassisLocationDef((ChassisLocations)location).InventorySlots;
                    if (DebugLog && MinSlots > list.Count)
                    {
                        Verbo("Padding list to {0} with empty slots", MinSlots);
                    }
                    for (int i = list.Count; i < MinSlots; i++)
                    {
                        list.Add(null);
                    }
                }
            }
            int           slot   = (int)(list.Count * random);
            MechComponent result = slot < list.Count ? list[slot] : null;

            if (DebugLog)
            {
                Verbo("Slot roll {0}, slot count {1}, slot {2}, component {3} status {4}", random, list.Count, slot, result, result?.DamageLevel);
            }
            AttackLog.LogCritComp(result, slot);
            return(result);
        }