Пример #1
0
        private void CalculateMappingForLocation(ChassisLocations location, List <MechComponentRef> sortedComponentRefs)
        {
            var availablePrefabSets = GetAvailablePrefabSetsForLocation(location);
            var bestSelection       = new PrefabSelectionCandidate(availablePrefabSets);

            Control.Logger.Debug?.Log($"CalculateMappingForLocation chassisDef={chassisDef.Description.Id} location={location} availablePrefabSets={availablePrefabSets.JoinAsString()} sortedComponentRefs=[{sortedComponentRefs.Select(x => x.ComponentDefID).JoinAsString()}]");

            foreach (var componentRef in sortedComponentRefs)
            {
                var prefabIdentifier = componentRef.Def.PrefabIdentifier;
                var compatibleTerms  = HardpointFixFeature.Shared.GetCompatiblePrefabTerms(prefabIdentifier);

                Control.Logger.Debug?.Log($" componentRef={componentRef.ComponentDefID} prefabIdentifier={prefabIdentifier} compatibleTerms={compatibleTerms.JoinAsString()}");

                foreach (var compatibleTerm in compatibleTerms)
                {
                    var prefab = bestSelection.FreeSets
                                 .Select(x => x.GetPrefabByIdentifier(compatibleTerm))
                                 .FirstOrDefault(x => x != null);

                    if (prefab == null)
                    {
                        continue;
                    }

                    Control.Logger.Debug?.Log($"  prefab={prefab}");

                    var newMapping = new PrefabMapping(prefab, componentRef);
                    bestSelection = bestSelection.CreateWithoutPrefab(prefab, newMapping);

                    break;
                }
            }
            fallbackPrefabs[location] = bestSelection.FreeSets;
            Control.Logger.Debug?.Log($"Mappings for chassis {chassisDef.Description.Id} at {location} [{bestSelection.Mappings.JoinAsString()}]");
            foreach (var mapping in bestSelection.Mappings)
            {
                weaponMappings[mapping.MechComponentRef] = mapping.Prefab.Name;
            }

            CalculateBlanksForLocation(location);
        }
        internal PrefabSelectionCandidate CreateWithoutPrefab(Prefab exclude, PrefabMapping newMapping)
        {
            var blacklistedPrefabNames = FreeSets
                                         .Where(x => x.ContainsPrefab(exclude))
                                         .SelectMany(x => x)
                                         .Select(x => x.Name)
                                         .ToHashSet();

            var sets = FreeSets
                       .Select(x => x.CreateWithoutPrefabNames(blacklistedPrefabNames))
                       .Where(x => !x.IsEmpty)
                       .ToList();

            var mappings = new List <PrefabMapping>(Mappings)
            {
                newMapping
            };

            return(new PrefabSelectionCandidate(sets, mappings));
        }