Guest User

Untitled

a guest
Sep 17th, 2018
8
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dictionary<string, int> missing = new Dictionary<string, int>();
  2. Dictionary<string, int> available = new Dictionary<string, int>();
  3. InventoryManager.GetAvailableComponents(ref available);
  4. GetMissingComponentsPotentialTargets<NaniteConstructionTargets>(missing, available);
  5. GetMissingComponentsPotentialTargets<NaniteProjectionTargets>(missing, available);
  6.  
  7. foreach (var item in missing)
  8. {
  9.     var def = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key));
  10.  
  11.     if (def == null)
  12.         continue;
  13.  
  14.    
  15.  
  16.     // If this is some sort of weird modded definition, then we need to find the vanilla definition (ug)
  17.     if (def.Results != null && def.Results[0].Amount > 1)
  18.     {
  19.         if (m_defCache.ContainsKey(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key)))
  20.         {
  21.             def = m_defCache[new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key)];
  22.         }
  23.         else
  24.         {
  25.             foreach (var defTest in MyDefinitionManager.Static.GetBlueprintDefinitions())
  26.             {
  27.                 if (defTest.Results != null && defTest.Results[0].Amount == 1 && defTest.Results[0].Id == new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key))
  28.                 {
  29.                     def = defTest;
  30.                     m_defCache.Add(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key), def);
  31.                     break;
  32.                 }
  33.             }
  34.         }
  35.        
  36.     }
  37.  
  38.  
  39.     bool found = false;
  40.     foreach (var assemblerTest in assemblerList)
  41.     {
  42.         foreach (var queueItem in assemblerTest.GetQueue())
  43.         {
  44.             if (queueItem.Blueprint == def && (int)queueItem.Amount >= item.Value)
  45.             {
  46.                 found = true;
  47.                 break;
  48.             }
  49.         }
  50.     }
  51.  
  52.     if (found)
  53.         continue;
  54.  
  55.     int blueprintCount = assemblerList.Sum(x => x.GetQueue().Sum(y => y.Blueprint == def ? (int)y.Amount : 0));
  56.     int availableCount = 0;
  57.     if (available.ContainsKey(item.Key))
  58.         availableCount = available[item.Key];
  59.  
  60.     if (blueprintCount >= item.Value - availableCount)
  61.     {
  62.         continue;
  63.     }
  64.  
  65.     var assemblers = assemblerList.Where(x => NaniteConstructionManager.AssemblerSettings.ContainsKey(x.EntityId) && NaniteConstructionManager.AssemblerSettings[x.EntityId].AllowFactoryUsage);
  66.  
  67.     foreach (var target in assemblers)
  68.     {
  69.         //if (!NaniteConstructionManager.AssemblerSettings.ContainsKey(target.EntityId))
  70.         //    continue;
  71.  
  72.         //if (!NaniteConstructionManager.AssemblerSettings[target.EntityId].AllowFactoryUsage)
  73.         //    continue;
  74.  
  75.         int amount = (int)Math.Max(((float)(item.Value - blueprintCount) / (float)assemblers.Count()), 1f);
  76.  
  77.        
  78.         Logging.Instance.WriteLine(string.Format("ASSEMBLER Queuing {0} {1} for factory {2} ({3})", amount, def.Id, m_constructionBlock.CustomName, blueprintCount));
  79.         //Logging.Instance.WriteLine("Value of target: " + target.ToString());
  80.         //Logging.Instance.WriteLine("Can target make this blueprint? (Def.ID value): " + target.CanUseBlueprint(def.Id));
  81.  
  82.         target.InsertQueueItem(0, def, amount);
  83.     }
  84. }
RAW Paste Data