Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Sandbox.Game.WorldEnvironment.Modules;
- using Sandbox.ModAPI.Ingame;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using VRage.Game;
- using VRage.Game.ModAPI.Ingame;
- namespace IngameScript
- {
- public partial class Program : MyGridProgram
- {
- class BPLearn
- {
- public IMyAssembler asm = null;
- static MyDefinitionId nop = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SteelPlate");
- List<MyProductionItem> lastQueue = new List<MyProductionItem>();
- List<MyInventoryItem> lastItems = new List<MyInventoryItem>();
- float lastProgress = -1;
- public void update()
- {
- if(asm.Mode == MyAssemblerMode.Assembly)
- {
- //MyProductionItem x;
- var curProg = asm.CurrentProgress;
- List<MyProductionItem> queue = new List<MyProductionItem>();
- List<MyInventoryItem> items = new List<MyInventoryItem>();
- asm.GetQueue(queue);
- asm.OutputInventory.GetItems(items);
- if (curProg < lastProgress && lastQueue.Count > 0)
- {
- //progress bar reset, and we had shit queued. check.
- MyDefinitionId bp = nop;
- bool hasbp = false;
- foreach (var item in lastQueue)
- {
- bool inqueue = false;
- foreach (var p in queue)
- {
- if(p.ItemId == item.ItemId && p.BlueprintId == item.BlueprintId)
- {
- inqueue = true;
- if (p.Amount < item.Amount)
- {
- //this item decreased. found the impostor
- hasbp = true;
- bp = item.BlueprintId;
- break;
- }
- }
- }
- if (hasbp)break;
- if (!inqueue)
- {
- hasbp = true;
- bp = item.BlueprintId;
- break;
- }
- }
- if(hasbp)
- {
- bool hasitem = false;
- MyDefinitionId itembp = nop;
- foreach (var i in items)
- {
- bool newitem = true;
- foreach (var o in lastItems)
- {
- if (o.Type == i.Type)
- {
- newitem = false;
- }
- if (o.Type == i.Type && o.Amount < i.Amount)
- {
- try
- {
- itembp = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition /" + i.Type.SubtypeId);
- hasitem = true;
- }
- catch(Exception e)
- {
- hasitem = false;
- }
- if (hasitem) break;
- }
- }
- if(newitem)
- {
- try
- {
- itembp = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition /" + i.Type.SubtypeId);
- hasitem = true;
- }
- catch (Exception e)
- {
- hasitem = false;
- }
- if (hasitem) break;
- }
- if (hasitem) break;
- }
- if(hasbp && hasitem)
- {
- log(bp.ToString() + " = " + itembp.ToString(), LT.LOG_N);
- }
- }
- }
- if (lastQueue.Count == 0) curProg = 0;
- lastProgress = curProg;
- lastQueue = queue;
- lastItems = items;
- }
- //if(assembler.
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement