Quellcode durchsuchen

[2.0.7.4] Network nest shake

Zariteis vor 1 Jahr
Ursprung
Commit
e9716e535f
3 geänderte Dateien mit 45 neuen und 24 gelöschten Zeilen
  1. 8 2
      MonsterNests.cs
  2. 0 4
      Patches/Patch_Chunk_SpawnBiomeSlot.cs
  3. 37 18
      Patches/Patch_ObjectScript_Die.cs

+ 8 - 2
MonsterNests.cs

@@ -1,8 +1,7 @@
-using UnityEngine;
 using GadgetCore.API;
-using GadgetCore.Util;
 using GadgetCore.API.ConfigMenu;
 using MonsterNests.Scripts;
+using UnityEngine;
 
 namespace MonsterNests
 {
@@ -12,6 +11,8 @@ namespace MonsterNests
     public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
     public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
 
+    public const string RPCMonsterNestsShake = "MonsterNestsShake";
+
     protected override void LoadConfig()
     {
       Config.Load();
@@ -77,6 +78,11 @@ namespace MonsterNests
 
       AlterObjectAncientCrystal(Core.objectAncientCrystal, textureAncientCrystalTop);
       AlterObjectAncientCrystal(Core.objectAncientCrystalCM, textureAncientCrystalCMTop);
+
+      GadgetCoreAPI.RegisterCustomRPC(RPCMonsterNestsShake, (e) =>
+      {
+        InstanceTracker.GameScript.StartCoroutine(Patches.Patch_ObjectScript_Die.Shake());
+      });
     }
 
     private void AlterObjectSpike(ObjectInfo info, Texture2D texture)

+ 0 - 4
Patches/Patch_Chunk_SpawnBiomeSlot.cs

@@ -1,9 +1,5 @@
 using GadgetCore.API;
-using GadgetCore.Util;
 using HarmonyLib;
-using System.Collections;
-using System.Threading;
-using System.Windows.Threading;
 using UnityEngine;
 
 namespace MonsterNests.Patches

+ 37 - 18
Patches/Patch_ObjectScript_Die.cs

@@ -1,9 +1,6 @@
 using GadgetCore.API;
-using GadgetCore.Util;
 using HarmonyLib;
 using System.Collections;
-using System.Threading;
-using System.Windows.Threading;
 using UnityEngine;
 
 namespace MonsterNests.Patches
@@ -20,83 +17,105 @@ namespace MonsterNests.Patches
       if (___id == Core.objectBugspotBig.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 10, 6, "e/wasp", 0.1f));
+        }
       }
       if (___id == Core.objectBugTree.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 10, 3, "e/wasp", 0.2f));
+        }
       }
       else if (___id == Core.objectSpikePlant.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 0, 12, "haz/vinegas", 0.1f));
+        }
       }
       else if (___id == Core.objectSpikePlantCM.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 0, 6, "e/sliver", 0.3f));
+        }
       }
       else if (___id == Core.objectSpiderEgg.GetID() || ___id == Core.objectSpiderEggCM.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 4, 10, "e/rockspider", 0.3f));
+        }
       }
       else if (___id == Core.objectWizShroom.GetID() || ___id == Core.objectSpiderEggCM.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
-        Network.Instantiate(Resources.Load("e/Shroomwizard"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 5f, 0f), Quaternion.identity, 0);
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
+          Network.Instantiate(Resources.Load("e/Shroomwizard"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 5f, 0f), Quaternion.identity, 0);
+        }
       }
       else if (___id == Core.objectGoldenShroom.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           Network.Instantiate(Resources.Load("e/MonsterNests/goldenShroom"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
+        }
       }
       else if (___id == Core.objectAncientCrystal.GetID() || ___id == Core.objectAncientCrystalCM.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           Network.Instantiate(Resources.Load("e/golem"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
+        }
       }
       else if (___id == Core.objectPlagueNest.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
-        if (Network.isServer) ;
-        //Network.Instantiate(Resources.Load("e/plaguebeast"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
+        if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
+          //Network.Instantiate(Resources.Load("e/plaguebeast"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
+        }
       }
       else if (___id == Core.objectFrozenWisp.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 5, 6, "e/wisp", 0.35f));
+        }
       }
       else if (___id == Core.objectMolten.GetID())
       {
         GameScript.cadetValue += 34;
-        __instance.StartCoroutine(Shake());
         if (Network.isServer)
+        {
+          GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
           __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 5, 6, "e/wyvern", 0.35f));
+        }
       }
     }
 
-    private static IEnumerator Shake()
+    public static IEnumerator Shake()
     {
       Camera.main.GetComponent<Animation>().Play("shake");
       yield return new WaitForSeconds(1.0f);