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

namespace LoopPortal.Patches
{

  [HarmonyPatch(typeof(SpawnerScript))]
  [HarmonyPatch("DestroyWorld")]
  [HarmonyGadget("LoopPortal")]
  public static class Patch_SpawnerScript_DestroyWorld
  {
    [HarmonyPrefix]
    public static void Prefix(SpawnerScript __instance, int a)
    {
      if (Network.isServer)
      {
        GameObject gameObject = Core.portalObject;
        if (gameObject != null)
        {
          Network.RemoveRPCs(gameObject.GetComponent<NetworkView>().viewID);
          Network.RemoveRPCs(gameObject.transform.GetChild(0).gameObject.gameObject.GetComponent<NetworkView>().viewID);
          Network.Destroy(gameObject.gameObject);
        }
      }
    }
  }
}
