Advertisement
spacechase0

harmony portia patch - skill test

Jan 14th, 2019
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1.     [HarmonyPatch(typeof(AutomataMachineMenuCtr))]
  2.     [HarmonyPatch("StartAutomata")]
  3.     public static class AutomataStartHook
  4.     {
  5.         public static bool Prefix(AutomataMachineMenuCtr __instance, CompoundItem ___curItem, AutomataMachineData ___machine, bool ___isWorktable)
  6.         {
  7.             func(__instance, ___curItem, ___machine, ___isWorktable);
  8.             return false;
  9.         }
  10.  
  11.         private static void func(AutomataMachineMenuCtr __instance, CompoundItem curItem, AutomataMachineData machine, bool isWorktable)
  12.         {
  13.             Module<AudioModule>.Self.PlayEffect2D(68, false, true, false);
  14.             if (!Module<CompoundManager>.Self.CheckMatEnough(curItem, OperateType.Compound, 1))
  15.             {
  16.                 UIUtils.ShowTips(0, TextMgr.GetStr(100402, -1), 2f, false, null);
  17.                 return;
  18.             }
  19.             if (machine.Data.fuelId != 0 && machine.Data.MaxFuel > 0 && machine.lastFuel_F <= 0f && machine.Data.plugType != 0 && !machine.PowerMachineWorking)
  20.             {
  21.                 UIUtils.ShowTips(0, TextMgr.GetStr(201377, -1), 2f, false, null);
  22.                 return;
  23.             }
  24.             int num = Module<CompoundManager>.Self.GetCompoundCount(curItem, OperateType.Compound);
  25.             int itemCount = machine.GetItemCount(curItem.itemId, 0);
  26.             num = ((num <= machine.Data.itemMaxCount - itemCount) ? num : (machine.Data.itemMaxCount - itemCount));
  27.             if (num <= 0 || Module<AutomataMgr>.Self.CheckListMax(machine.machineId, curItem.itemId, 0))
  28.             {
  29.                 UIUtils.ShowTips(0, TextMgr.GetStr(100500, -1), 2f, false, null);
  30.                 return;
  31.             }
  32.             float totalTime = __instance.GetTotalTime(curItem, machine);
  33.             string text = curItem.Name;
  34.             if (isWorktable)
  35.             {
  36.                 float num2 = Module<FeatureModule>.Self.ModifyFloat(FeatureType.WorkbenchMaterialCut, new object[]
  37.                 {
  38.                 0f
  39.                 });
  40.                 if (num2 > 0f)
  41.                 {
  42.                     text = text + "\n" + string.Format(TextMgr.GetStr(101343, -1), (int)(num2 * 100f));
  43.                 }
  44.             }
  45.             //////////
  46.             else
  47.             {
  48.                 float num2 = Module<FeatureModule>.Self.ModifyFloat(Mod.MACHINE_CRAFTING_FEATURE, new object[]
  49.                 {
  50.                 0f
  51.                 });
  52.                 if (num2 > 0f)
  53.                 {
  54.                     text = text + "\n" + string.Format(TextMgr.GetStr(101343, -1), (int)(num2 * 100f));
  55.                 }
  56.             }
  57.             var meth = __instance.GetType().GetMethod("StartAutomataResult", BindingFlags.NonPublic | BindingFlags.Instance);
  58.             Action<int> action = (Action<int>)Delegate.CreateDelegate(__instance.GetType(), __instance, meth);
  59.             //////////
  60.             /*
  61.             UIUtils.ShowNumberSelectMinMax(this.curItem.itemId, 0, Mathf.Max(num, 0), 1, TextMgr.GetStr(100401, -1), new Action<int>(this.StartAutomataResult), delegate
  62.             {
  63.             }, true, (int)totalTime, text);*/
  64.             UIUtils.ShowNumberSelectMinMax(curItem.itemId, 0, Mathf.Max(num, 0), 1, TextMgr.GetStr(100401, -1), action, delegate
  65.             {
  66.             }, true, (int)totalTime, text);
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement