Browse Source

[2.0.4.4] ReplaceComponent / size check for space subworld / enable event check for ships / log error fix

Zariteis 4 years ago
parent
commit
fadac36b44

+ 1 - 0
Core.cs

@@ -27,5 +27,6 @@ namespace Subworlds
     public static int lastBiome = -1;
     public static int lastBiome = -1;
 
 
     public static bool planetHasMeteors = false;
     public static bool planetHasMeteors = false;
+    public static bool planetHasPirates = false;
   }
   }
 }
 }

+ 2 - 2
Gadgets/CoreGadget.cs

@@ -6,10 +6,10 @@ using UnityEngine;
 
 
 namespace Subworlds
 namespace Subworlds
 {
 {
-  [Gadget("SubworldCore", LoadAfter: new string[] { "RecipeMenuCore" }, Dependencies: new string[] { "RecipeMenuCore" })]
+  [Gadget("SubworldCore", RequiredOnClients: true, LoadAfter: new string[] { "RecipeMenuCore" }, Dependencies: new string[] { "RecipeMenuCore" })]
   public class CoreGadget : Gadget<CoreGadget>
   public class CoreGadget : Gadget<CoreGadget>
   {
   {
-    public const string MOD_VERSION = "0.1"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "0.3"; // 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 CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
 
 
     protected override void LoadConfig()
     protected override void LoadConfig()

+ 5 - 2
Gadgets/Meteoroid/MeteoroidGadget.Create.cs

@@ -1,4 +1,5 @@
 using GadgetCore.API;
 using GadgetCore.API;
+using GadgetCore.Util;
 using Subworlds.Scripts;
 using Subworlds.Scripts;
 using UnityEngine;
 using UnityEngine;
 
 
@@ -132,8 +133,10 @@ namespace Subworlds
       {
       {
         mainTexture = texture
         mainTexture = texture
       };
       };
-      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
-      gameObject.AddComponent<SpaceJellyfishScript>();
+      //Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      //gameObject.AddComponent<SpaceJellyfishScript>();
+
+      gameObject.ReplaceComponent<WispScript, SpaceJellyfishScript>();
 
 
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);

+ 1 - 1
Gadgets/Meteoroid/MeteoroidGadget.Init.cs

@@ -7,7 +7,7 @@ using UnityEngine;
 
 
 namespace Subworlds
 namespace Subworlds
 {
 {
-  [Gadget("SubworldMeteoroid", LoadAfter: new string[] { "RecipeMenuCore", "SubworldCore" }, Dependencies: new string[] { "RecipeMenuCore", "SubworldCore" })]
+  [Gadget("SubworldMeteoroid", RequiredOnClients: true, LoadAfter: new string[] { "RecipeMenuCore", "SubworldCore" }, Dependencies: new string[] { "RecipeMenuCore", "SubworldCore" })]
   public partial class MeteroidGadget : Gadget<MeteroidGadget>
   public partial class MeteroidGadget : Gadget<MeteroidGadget>
   {
   {
     protected override void LoadConfig()
     protected override void LoadConfig()

+ 10 - 4
Gadgets/Ship/ShipsGadget.Create.cs

@@ -1,4 +1,5 @@
 using GadgetCore.API;
 using GadgetCore.API;
+using GadgetCore.Util;
 using Subworlds.Scripts;
 using Subworlds.Scripts;
 using UnityEngine;
 using UnityEngine;
 
 
@@ -148,8 +149,10 @@ namespace Subworlds
       };
       };
       Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
       Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
       GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetChild(1).gameObject);
       GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetChild(1).gameObject);
-      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
-      gameObject.AddComponent<AttackDroidScript>();
+      //Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      //gameObject.AddComponent<AttackDroidScript>();
+
+      gameObject.ReplaceComponent<WispScript, AttackDroidScript>();
 
 
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
@@ -187,13 +190,16 @@ namespace Subworlds
       };
       };
       gameObject.transform.GetChild(0).GetChild(0).GetChild(1).localPosition = new Vector3(0, 0, 0.1f);
       gameObject.transform.GetChild(0).GetChild(0).GetChild(1).localPosition = new Vector3(0, 0, 0.1f);
 
 
-      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      //Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
       Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
       Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
 
 
       gameObject.GetComponent<Rigidbody>().isKinematic = false;
       gameObject.GetComponent<Rigidbody>().isKinematic = false;
       gameObject.GetComponent<Rigidbody>().detectCollisions = false;
       gameObject.GetComponent<Rigidbody>().detectCollisions = false;
 
 
-      gameObject.AddComponent<BrokenTurretScript>();
+
+      gameObject.ReplaceComponent<WispScript, BrokenTurretScript>();
+
+      //gameObject.AddComponent<BrokenTurretScript>();
 
 
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).gameObject.SetActive(true);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
       gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);

+ 1 - 1
Gadgets/Ship/ShipsGadget.Init.cs

@@ -3,7 +3,7 @@ using UnityEngine;
 
 
 namespace Subworlds
 namespace Subworlds
 {
 {
-  [Gadget("SubworldShip", LoadAfter: new string[] { "RecipeMenuCore", "SubworldCore" }, Dependencies: new string[] { "RecipeMenuCore", "SubworldCore" })]
+  [Gadget("SubworldShip", RequiredOnClients: true, LoadAfter: new string[] { "RecipeMenuCore", "SubworldCore" }, Dependencies: new string[] { "RecipeMenuCore", "SubworldCore" })]
   public partial class SubworldsGadget : Gadget<SubworldsGadget>
   public partial class SubworldsGadget : Gadget<SubworldsGadget>
   {
   {
     protected override void LoadConfig()
     protected override void LoadConfig()

+ 6 - 30
Generator/MeteroidGenerator.cs

@@ -20,8 +20,8 @@ namespace Subworlds
     public static readonly FieldInfo networkStuffField = typeof(Chunk).GetField("networkStuff", BindingFlags.NonPublic | BindingFlags.Instance);
     public static readonly FieldInfo networkStuffField = typeof(Chunk).GetField("networkStuff", BindingFlags.NonPublic | BindingFlags.Instance);
     public static readonly FieldInfo tempField = typeof(Chunk).GetField("temp", BindingFlags.NonPublic | BindingFlags.Instance);
     public static readonly FieldInfo tempField = typeof(Chunk).GetField("temp", BindingFlags.NonPublic | BindingFlags.Instance);
 
 
-    private static int W = 128 + 64;
-    private static int H = 128 - 32;
+    private static int W = 128;
+    private static int H = 64;
 
 
     private static float GetSizeForPixels(int px)
     private static float GetSizeForPixels(int px)
     {
     {
@@ -142,7 +142,7 @@ namespace Subworlds
 
 
     public static void PopulateWorld(Chunk chunk)
     public static void PopulateWorld(Chunk chunk)
     {
     {
-      var networkStuff = new GameObject[400];
+      var networkStuff = new GameObject[1000];
       networkStuffField.SetValue(chunk, networkStuff);
       networkStuffField.SetValue(chunk, networkStuff);
 
 
       int temp = (int)tempField.GetValue(chunk);
       int temp = (int)tempField.GetValue(chunk);
@@ -198,33 +198,6 @@ namespace Subworlds
           x = Mathf.Min(x + random.Next(5) - 2, W);
           x = Mathf.Min(x + random.Next(5) - 2, W);
           y = Mathf.Min(y + random.Next(5) - 2, H);
           y = Mathf.Min(y + random.Next(5) - 2, H);
         }
         }
-        //while (addLoopPortal && overflow < 5000)
-        //{
-        //  overflow++;
-        //  bool noGen = false;
-        //  for (int xOff = -1; xOff < 2; xOff++)
-        //    for (int yOff = -1; yOff < 4; yOff++)
-        //      if (!CheckGeneration(x + xOff, y + yOff, genSpots))
-        //        noGen = true;
-        //  if (!noGen)
-        //  {
-        //    for (int xOff = -1; xOff < 2; xOff++)
-        //      for (int yOff = -1; yOff < 4; yOff++)
-        //        MarkGeneration(x + xOff, y + yOff, genSpots);
-        //    networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("z/Subworlds/BaseBlockNormal"), new Vector3(242 + 4 * x - 60, y * 4 - 60, 5), Quaternion.identity, 0);
-        //    temp++;
-        //    var i = (GameObject)Network.Instantiate((GameObject)Resources.Load("portal"), new Vector3(242 + x * 4 - 60, y * 4 - 60 + GetSizeForPixels(54) + 1.451f + 1, 0f), Quaternion.identity, 0);
-        //    var iUA = i.transform.GetChild(0).gameObject;
-        //    i.GetComponent<NetworkView>().RPC("Activate", RPCMode.All, new object[0]);
-        //    iUA.GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { SpawnerScript.curBiome, 0, 4 });
-        //    i.transform.parent = GameScript.endPortal[0].transform;
-        //    networkStuff[temp] = i;
-        //    temp++;
-        //    break;
-        //  }
-        //  x = Mathf.Min(x + random.Next(5) - 2, W);
-        //  y = Mathf.Min(y + random.Next(5) - 2, H);
-        //}
       }
       }
       {
       {
         int r = 0;
         int r = 0;
@@ -232,6 +205,9 @@ namespace Subworlds
 
 
         while (overflow < 15000 && r < 700)
         while (overflow < 15000 && r < 700)
         {
         {
+          if (temp > networkStuff.Length - 20)
+            break;
+
           overflow++;
           overflow++;
           int i = random.Next(6);
           int i = random.Next(6);
           int x = random.Next(W);
           int x = random.Next(W);

+ 1 - 0
Patches/Patch_Chunk_OnDestroy.cs

@@ -14,6 +14,7 @@ namespace Subworlds.Patches
     public static void Prefix(Chunk __instance, ref GameObject[] ___networkStuff)
     public static void Prefix(Chunk __instance, ref GameObject[] ___networkStuff)
     {
     {
       Core.planetHasMeteors = false;
       Core.planetHasMeteors = false;
+      Core.planetHasPirates = false;
       Core.shipPorterPlaced = false;
       Core.shipPorterPlaced = false;
       Core.meteorPorterPlaced = false;
       Core.meteorPorterPlaced = false;
 
 

+ 1 - 1
Patches/Patch_Chunk_SpawnBiomeSlot.cs

@@ -24,7 +24,7 @@ namespace Subworlds.Patches
         transform = ___spawnSpot[i].transform;
         transform = ___spawnSpot[i].transform;
 
 
       int num = UnityEngine.Random.Range(0, 100);
       int num = UnityEngine.Random.Range(0, 100);
-      if (num < 30 && !Core.shipPorterPlaced)
+      if (num < 30 && !Core.shipPorterPlaced && Core.planetHasPirates)
       {
       {
         Core.shipPorterPlaced = true;
         Core.shipPorterPlaced = true;
         if (a == 0 || a == 1 || a == 2 || a == 3 || a == 4 || a == 5)
         if (a == 0 || a == 1 || a == 2 || a == 3 || a == 4 || a == 5)

+ 17 - 0
Patches/Patch_GameScript_SpacePirates.cs

@@ -0,0 +1,17 @@
+using GadgetCore.API;
+using HarmonyLib;
+
+namespace Subworlds.Patches
+{
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("SpacePirates")]
+  [HarmonyGadget("SubworldCore")]
+  public static class Patch_GameScript_SpacePirates
+  {
+    [HarmonyPrefix]
+    public static void Prefix(GameScript __instance)
+    {
+      Core.planetHasPirates = true;
+    }
+  }
+}

+ 3 - 0
Scripts/AttackDroidScript.cs

@@ -17,6 +17,9 @@ namespace Subworlds.Scripts
       base.trig[0] = gameObject.transform.GetChild(1).gameObject;
       base.trig[0] = gameObject.transform.GetChild(1).gameObject;
       base.trig[1] = gameObject.transform.GetChild(2).gameObject;
       base.trig[1] = gameObject.transform.GetChild(2).gameObject;
       base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
       base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
+
+      var network = gameObject.GetComponent<NetworkEnemyBasic>();
+      network.isPirate = true;
     }
     }
 
 
     private void Update()
     private void Update()

+ 0 - 1
Scripts/BrokenLaserScript.cs

@@ -8,7 +8,6 @@ namespace Subworlds.Scripts
     private Renderer r;
     private Renderer r;
     private GameObject hazard;
     private GameObject hazard;
     public int anim;
     public int anim;
-    public int activeCount;
 
 
     public bool active;
     public bool active;
 
 

+ 25 - 18
Scripts/BrokenTurretScript.cs

@@ -10,27 +10,32 @@ namespace Subworlds.Scripts
 
 
     private void Awake()
     private void Awake()
     {
     {
-      base.trig[0] = gameObject.transform.GetChild(1).gameObject;
-      base.trig[1] = gameObject.transform.GetChild(2).gameObject;
-      base.Initialize(130, 7, 80, new int[] { 25, 25, 52 }, 60);
+      trig[0] = gameObject.transform.GetChild(1).gameObject;
+      trig[1] = gameObject.transform.GetChild(2).gameObject;
+      Initialize(130, 7, 80, new int[] { 25, 25, 52 }, 60);
+
+      var network = gameObject.GetComponent<NetworkEnemyBasic>();
+      network.isPirate = true;
+
+      canKnockback = false;
     }
     }
 
 
     private void Update()
     private void Update()
     {
     {
       if (Network.isServer)
       if (Network.isServer)
       {
       {
-        if (!this.attacking)
+        if (!attacking)
         {
         {
-          if (this.target)
+          if (target)
           {
           {
-            if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
+            if (Mathf.Abs(target.transform.position.x - t.position.x) < 45f)
             {
             {
-              this.attacking = true;
-              base.StartCoroutine(this.Attack());
+              attacking = true;
+              StartCoroutine(Attack());
             }
             }
             else
             else
             {
             {
-              this.target = null;
+              target = null;
             }
             }
           }
           }
         }
         }
@@ -43,8 +48,8 @@ namespace Subworlds.Scripts
     {
     {
       for (int i = 0; i < count; i++)
       for (int i = 0; i < count; i++)
       {
       {
-        this.dir = this.target.transform.position - this.t.position;
-        this.dir.Normalize();
+        dir = target.transform.position - t.position;
+        dir.Normalize();
         var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         var diffAngle = (z - newRotation + 180) % 360 - 180;
         var diffAngle = (z - newRotation + 180) % 360 - 180;
 
 
@@ -60,27 +65,29 @@ namespace Subworlds.Scripts
 
 
     private IEnumerator Attack()
     private IEnumerator Attack()
     {
     {
-      yield return Seach(100 + Random.Range(0, 30));
+      yield return Seach(Random.Range(0, 100));
 
 
 
 
       for (int i = 0; i < 3; i++)
       for (int i = 0; i < 3; i++)
       {
       {
-        this.dir = this.target.transform.position - this.t.position;
-        this.dir.Normalize();
+        dir = target.transform.position - t.position;
+        dir.Normalize();
         var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         z = (int) newRotation;
         z = (int) newRotation;
         z = (z + 360) % 360;
         z = (z + 360) % 360;
         gameObject.transform.GetChild(0).GetChild(0).GetChild(0).localEulerAngles = new Vector3(0, ((z + 360 - 90) % 360) > 180 ? 0 : 180, ((z + 360 - 90) % 360) > 180 ? z : 180 - z);
         gameObject.transform.GetChild(0).GetChild(0).GetChild(0).localEulerAngles = new Vector3(0, ((z + 360 - 90) % 360) > 180 ? 0 : 180, ((z + 360 - 90) % 360) > 180 ? z : 180 - z);
-        var pos = this.target.transform.position;
+        var pos = target.transform.position;
         var dist = 2.1f;
         var dist = 2.1f;
-        var endPosition = new Vector3(this.t.position.x + Mathf.Cos((Mathf.PI / 180) * z) * dist, this.t.position.y + Mathf.Sin((Mathf.PI / 180) * z) * dist, this.t.position.z);
+        var endPosition = new Vector3(t.position.x + Mathf.Cos((Mathf.PI / 180) * z) * dist, t.position.y + Mathf.Sin((Mathf.PI / 180) * z) * dist, t.position.z);
         var p = (GameObject)Network.Instantiate(Resources.Load("proj/pirateproj"), endPosition, Quaternion.identity, 0);
         var p = (GameObject)Network.Instantiate(Resources.Load("proj/pirateproj"), endPosition, Quaternion.identity, 0);
         p.SendMessage("EnemySet", pos, SendMessageOptions.DontRequireReceiver);
         p.SendMessage("EnemySet", pos, SendMessageOptions.DontRequireReceiver);
-        yield return new WaitForSeconds(0.625f);
+        yield return new WaitForSeconds(1.625f);
         yield return Seach(10);
         yield return Seach(10);
       }
       }
 
 
-      this.attacking = false;
+      yield return Seach(200 + Random.Range(0, 200));
+
+      attacking = false;
       yield break;
       yield break;
     }
     }
   }
   }