Esempio n. 1
0
        public ChassisLocations this[MechDef mechdef, MechComponentDef itemdef]
        {
            get
            {
                if (mechdef == null || itemdef == null)
                {
                    return(ChassisLocations.None);
                }

                if (!Locations.TryGetValue(mechdef.ChassisID, out var mech_locations))
                {
                    mech_locations = new Dictionary <string, ChassisLocations>();
                    Locations[mechdef.ChassisID] = mech_locations;
                }

                if (!mech_locations.TryGetValue(itemdef.Description.Id, out var location))
                {
                    if (itemdef.Is <EquipLocations>(out var el))
                    {
                        var info = GetAllowedLocations(mechdef, el.Tag);
                        if (info == null)
                        {
                            if (Tags.TryGetValue(el.Tag, out var record))
                            {
                                var ut = mechdef.GetUnitTypes();
                                if (record.UnitTypes == null || record.UnitTypes.Length == 0 || ut == null)
                                {
                                    location = itemdef.AllowedLocations & record.Default;
                                }
                                else
                                {
                                    var lr = record.UnitTypes.FirstOrDefault(i => ut.Contains(i.UnitType));
                                    location = itemdef.AllowedLocations & (lr?.Location ?? record.Default);
                                }
                            }
                            else
                            {
                                location = itemdef.AllowedLocations;
                            }
                        }
                        else
                        {
                            location = info.Locations;
                        }
                    }
                    else
                    {
                        location = itemdef.AllowedLocations;
                    }
                    mech_locations[itemdef.Description.Id] = location;
                }

                return(location);
            }
        }