using GadgetCore.API;
using HarmonyLib;
using System.Reflection;
using UnityEngine;

namespace Subworlds.Patches
{

  [HarmonyPatch(typeof(DroidManager))]
  [HarmonyPatch("UA")]
  [HarmonyGadget("SubworldCore")]
	public static class Patch_DroidManager_UA
	{
		public static readonly MethodInfo RPCMethod = typeof(DroidManager).GetMethod("UA", BindingFlags.Public | BindingFlags.Instance);

		[HarmonyPostfix]
    public static void Postfix(DroidManager __instance, ref int[] d, GameObject[] ___droid, GameObject[] ___droidHead, GameObject[] ___droidBody)
		{
			for (int i = 0; i < 3; i++)
			{
				if (d[i] >= 1000)
				{
					___droid[i].transform.parent = null;
					___droid[i].SetActive(true);
					___droidHead[i].GetComponent<Renderer>().material = GadgetCoreAPI.GetDroidHeadMaterial(d[i] - 1000);
					___droidBody[i].GetComponent<Renderer>().material = GadgetCoreAPI.GetDroidBodyMaterial(d[i] - 1000);
				}
				else
				{
					___droid[i].SetActive(false);
					___droid[i].transform.parent = __instance.transform;
				}
			}
		}
  }
}