Advertisement
klassekatze

recipe learn

Oct 22nd, 2023
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. using Sandbox.Game.WorldEnvironment.Modules;
  2. using Sandbox.ModAPI.Ingame;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using VRage.Game;
  9. using VRage.Game.ModAPI.Ingame;
  10.  
  11. namespace IngameScript
  12. {
  13.     public partial class Program : MyGridProgram
  14.     {
  15.         class BPLearn
  16.         {
  17.             public IMyAssembler asm = null;
  18.  
  19.             static MyDefinitionId nop = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SteelPlate");
  20.  
  21.  
  22.             List<MyProductionItem> lastQueue = new List<MyProductionItem>();
  23.             List<MyInventoryItem> lastItems = new List<MyInventoryItem>();
  24.             float lastProgress = -1;
  25.             public void update()
  26.             {
  27.                 if(asm.Mode == MyAssemblerMode.Assembly)
  28.                 {
  29.                     //MyProductionItem x;
  30.  
  31.                     var curProg = asm.CurrentProgress;
  32.                    
  33.  
  34.  
  35.                     List<MyProductionItem> queue = new List<MyProductionItem>();
  36.                     List<MyInventoryItem> items = new List<MyInventoryItem>();
  37.  
  38.                     asm.GetQueue(queue);
  39.                     asm.OutputInventory.GetItems(items);
  40.                     if (curProg < lastProgress && lastQueue.Count > 0)
  41.                     {
  42.                         //progress bar reset, and we had shit queued. check.
  43.                         MyDefinitionId bp = nop;
  44.                         bool hasbp = false;
  45.  
  46.                         foreach (var item in lastQueue)
  47.                         {
  48.                             bool inqueue = false;
  49.                             foreach (var p in queue)
  50.                             {
  51.                                 if(p.ItemId == item.ItemId && p.BlueprintId == item.BlueprintId)
  52.                                 {
  53.                                     inqueue = true;
  54.                                     if (p.Amount < item.Amount)
  55.                                     {
  56.                                         //this item decreased. found the impostor
  57.                                         hasbp = true;
  58.                                         bp = item.BlueprintId;
  59.                                         break;
  60.                                     }
  61.                                 }
  62.                             }
  63.                             if (hasbp)break;
  64.                             if (!inqueue)
  65.                             {
  66.                                 hasbp = true;
  67.                                 bp = item.BlueprintId;
  68.                                 break;
  69.                             }
  70.                         }
  71.  
  72.                         if(hasbp)
  73.                         {
  74.                             bool hasitem = false;
  75.                             MyDefinitionId itembp = nop;
  76.                             foreach (var i in items)
  77.                             {
  78.                                 bool newitem = true;
  79.                                 foreach (var o in lastItems)
  80.                                 {
  81.                                     if (o.Type == i.Type)
  82.                                     {
  83.                                         newitem = false;
  84.                                     }
  85.                                     if (o.Type == i.Type && o.Amount < i.Amount)
  86.                                     {
  87.  
  88.                                         try
  89.                                         {
  90.                                             itembp = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition /" + i.Type.SubtypeId);
  91.                                             hasitem = true;
  92.                                         }
  93.                                         catch(Exception e)
  94.                                         {
  95.                                             hasitem = false;
  96.                                         }
  97.                                         if (hasitem) break;
  98.                                     }
  99.                                 }
  100.  
  101.                                 if(newitem)
  102.                                 {
  103.                                     try
  104.                                     {
  105.                                         itembp = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition /" + i.Type.SubtypeId);
  106.                                         hasitem = true;
  107.                                     }
  108.                                     catch (Exception e)
  109.                                     {
  110.                                         hasitem = false;
  111.                                     }
  112.                                     if (hasitem) break;
  113.                                 }
  114.  
  115.                                 if (hasitem) break;
  116.                             }
  117.                             if(hasbp && hasitem)
  118.                             {
  119.                                 log(bp.ToString() + " = " + itembp.ToString(), LT.LOG_N);
  120.                             }
  121.                         }
  122.                     }
  123.                     if (lastQueue.Count == 0) curProg = 0;
  124.  
  125.  
  126.                     lastProgress = curProg;
  127.                     lastQueue = queue;
  128.                     lastItems = items;
  129.                 }
  130.                 //if(assembler.
  131.             }
  132.         }
  133.     }
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement