Quellcode durchsuchen

[2.0.3.9] Added turret enemy to ships

Zariteis vor 4 Jahren
Ursprung
Commit
b25a2d80ae

BIN
Assets/Ship/brokenTurret.png


BIN
Assets/Ship/brokenTurretTop.png


BIN
Assets/Ship/droid.png


BIN
Assets/Ship/droid_v1.png


+ 36 - 0
Gadgets/Ship/ShipsGadget.Create.cs

@@ -146,6 +146,7 @@ namespace Subworlds
       {
         mainTexture = texture
       };
+      Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
       GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetChild(1).gameObject);
       Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
       gameObject.AddComponent<AttackDroidScript>();
@@ -167,6 +168,40 @@ namespace Subworlds
       GadgetCoreAPI.AddCustomResource("e/Subworlds/" + name, gameObject);
     }
 
+    private void CreateTurretEnemy(string name, Texture2D texture, Texture2D texture2)
+    {
+      GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("e/wisp"));
+      gameObject.name = name;
+      gameObject.transform.GetChild(0).GetChild(0).gameObject.name = name;
+      Renderer rendererHead = gameObject.transform.GetChild(0).GetChild(0).GetChild(0).GetComponentInChildren<Renderer>();
+      rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = texture2
+      };
+      Renderer rendererLegs = gameObject.transform.GetChild(0).GetChild(0).GetChild(1).GetComponentInChildren<Renderer>();
+      rendererLegs.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = texture
+      };
+      gameObject.transform.GetChild(0).GetChild(0).GetChild(1).localPosition = new Vector3(0, 0, 0.1f);
+
+      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      Component.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetComponent<Animation>());
+
+      gameObject.GetComponent<Rigidbody>().isKinematic = false;
+      gameObject.GetComponent<Rigidbody>().detectCollisions = false;
+
+      gameObject.AddComponent<BrokenTurretScript>();
+
+      gameObject.transform.GetChild(1).gameObject.SetActive(true);
+      gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
+
+      Collider collider = gameObject.transform.GetChild(3).GetComponent<Collider>();
+      collider.isTrigger = true;
+
+      GadgetCoreAPI.AddCustomResource("e/Subworlds/" + name, gameObject);
+    }
+
     private void CreateLaserHazard(string name, Texture2D texture)
     {
       GameObject gameObjectWisp = Object.Instantiate<GameObject>((GameObject)Resources.Load("e/wisp"));
@@ -210,6 +245,7 @@ namespace Subworlds
       gameObject.AddComponent<OldChestScript>();
       GadgetCoreAPI.AddCustomResource("obj/Subworlds/" + name, gameObject);
     }
+
     private void CreateBaseBlock(string name, Texture2D texture, float w, float h)
     {
       var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk"));

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

@@ -115,6 +115,7 @@ namespace Subworlds
       // Create Enemies
       CreateSliverEnemy("BrokenSliver", GadgetCoreAPI.LoadTexture2D("Ship/brokenSliverHead.png"), GadgetCoreAPI.LoadTexture2D("Ship/brokenSliverBody.png"), GadgetCoreAPI.LoadTexture2D("Ship/brokenSliverTail.png"));
       CreateDroidEnemy("BrokenDroid", GadgetCoreAPI.LoadTexture2D("Ship/droid.png"));
+      CreateTurretEnemy("Turret", GadgetCoreAPI.LoadTexture2D("Ship/brokenTurret.png"), GadgetCoreAPI.LoadTexture2D("Ship/brokenTurretTop.png"));
 
       // Create Hazards
       CreateLaserHazard("LaserHazard", GadgetCoreAPI.LoadTexture2D("Ship/brokenLaser.png"));

+ 9 - 3
Generator/ShipGenerator.cs

@@ -287,7 +287,11 @@ namespace Subworlds
           switch ((ShipGeneratorObjectPoolType)e[2])
           {
             case ShipGeneratorObjectPoolType.SmallObject:
-              if (random.Next(30) == 0)
+              if (random.Next(20) == 0)
+                Network.Instantiate(Resources.Load("e/Subworlds/BrokenDroid"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.1f + 4 * e[1], 0f), Quaternion.identity, 0);
+              else if (random.Next(2) == 0)
+                Network.Instantiate(Resources.Load("e/Subworlds/Turret"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.52f + 4 * e[1], 0f), Quaternion.identity, 0);
+              else if (random.Next(30) == 0)
                 networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenItemMod"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 4 * e[1], 0.2f), Quaternion.identity, 0);
               else if (random.Next(4) == 0)
                 networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenCrates1"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 4 * e[1], 0.2f), Quaternion.identity, 0);
@@ -313,8 +317,10 @@ namespace Subworlds
                 networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenPirate6"), new Vector3(248f + 4 * e[0], -5.75f + 0.118f + 4 * e[1], 0.2f), Quaternion.identity, 0);
               break;
             case ShipGeneratorObjectPoolType.FlyingEnemy:
-              Network.Instantiate(Resources.Load("e/Subworlds/BrokenSliver"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.1f + 4 * e[1], 0f), Quaternion.identity, 0);
-              Network.Instantiate(Resources.Load("e/Subworlds/BrokenDroid"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.1f + 4 * e[1], 0f), Quaternion.identity, 0);
+              if (random.Next(4) == 0)
+                Network.Instantiate(Resources.Load("e/Subworlds/BrokenDroid"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.1f + 4 * e[1], 0f), Quaternion.identity, 0);
+              else
+                Network.Instantiate(Resources.Load("e/Subworlds/BrokenSliver"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 1.1f + 4 * e[1], 0f), Quaternion.identity, 0);
               break;
             case ShipGeneratorObjectPoolType.BrokenItemMod:
               networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenItemMod"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 4 * e[1], 0.2f), Quaternion.identity, 0);

+ 2 - 1
Patches/Patch_Chunk_OnDestroy.cs

@@ -13,10 +13,11 @@ namespace Subworlds.Patches
     [HarmonyPriority(1010)]
     public static void Prefix(Chunk __instance, ref GameObject[] ___networkStuff)
     {
+      Core.planetHasMeteors = false;
       Core.shipPorterPlaced = false;
       Core.meteorPorterPlaced = false;
 
-      if (GameScript.townBiome != Core.meteroidPlanet.GetID() && GameScript.townBiome != Core.shipPlanet.GetID())
+      if (GameScript.townBiome != Core.meteroidPlanet?.GetID() && GameScript.townBiome != Core.shipPlanet?.GetID())
         Core.lastBiome = GameScript.townBiome;
 
       if (___networkStuff.Length > 40)

+ 4 - 2
Scripts/AttackDroidScript.cs

@@ -14,6 +14,8 @@ namespace Subworlds.Scripts
 
     private void Awake()
     {
+      base.trig[0] = gameObject.transform.GetChild(1).gameObject;
+      base.trig[1] = gameObject.transform.GetChild(2).gameObject;
       base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
     }
 
@@ -48,8 +50,8 @@ namespace Subworlds.Scripts
       this.dir = this.target.transform.position - this.t.position;
       this.dir.Normalize();
       yield return new WaitForSeconds(0.05f);
-      this.r.velocity = this.dir * (35f);
-      yield return new WaitForSeconds(0.9f);
+      this.r.velocity = this.dir * (30f);
+      yield return new WaitForSeconds(1.1f);
       this.r.velocity = new Vector3(0f, 0f, 0f);
       this.attacking = false;
       yield break;

+ 80 - 0
Scripts/BrokenTurretScript.cs

@@ -0,0 +1,80 @@
+using System.Collections;
+using UnityEngine;
+
+namespace Subworlds.Scripts
+{
+  class BrokenTurretScript : EnemyScript
+  {
+    private Vector3 dir;
+    private bool attacking;
+
+    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);
+    }
+
+    private void Update()
+    {
+      if (Network.isServer)
+      {
+        if (!this.attacking)
+        {
+          if (this.target)
+          {
+            if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
+            {
+              this.attacking = true;
+              base.StartCoroutine(this.Attack());
+            }
+            else
+            {
+              this.target = null;
+            }
+          }
+        }
+      }
+    }
+
+    private int z = 0;
+
+    private IEnumerator Seach(int count)
+    {
+      for (int i = 0; i < count; i++)
+      {
+        this.dir = this.target.transform.position - this.t.position;
+        this.dir.Normalize();
+        var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
+        var diffAngle = (z - newRotation + 180) % 360 - 180;
+
+        z = (int)(z - diffAngle / 6f);
+
+        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);
+
+        yield return new WaitForSeconds(0.01f);
+      }
+    }
+
+    private IEnumerator Attack()
+    {
+      yield return Seach(100 + Random.Range(0, 30));
+
+
+      for (int i = 0; i < 3; i++)
+      {
+        var pos = this.target.transform.position;
+        yield return new WaitForSeconds(0.125f);
+        var p = (GameObject)Network.Instantiate(Resources.Load("proj/pirateproj"), this.t.position, Quaternion.identity, 0);
+        p.SendMessage("EnemySet", pos, SendMessageOptions.DontRequireReceiver);
+        yield return new WaitForSeconds(0.125f);
+        yield return Seach(10);
+      }
+
+      this.attacking = false;
+      yield break;
+    }
+  }
+}

+ 14 - 4
Subworlds.csproj

@@ -42,6 +42,7 @@
     <None Remove="Assets\a16.png" />
     <None Remove="Assets\brokenLazer.png" />
     <None Remove="Assets\d17b.png" />
+    <None Remove="Assets\Meteoroid\droid.png" />
     <None Remove="Assets\Meteoroid\planetSpace.png" />
     <None Remove="Assets\Meteoroid\stars.png" />
     <None Remove="Assets\planetScrapYardPrev.png" />
@@ -399,6 +400,12 @@
     <None Update="Assets\Meteoroid\icon.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="Assets\Meteoroid\jelly.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\Meteoroid\jellyLegs.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <None Update="Assets\Meteoroid\meteor1.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
@@ -573,6 +580,12 @@
     <None Update="Assets\Ship\brokenTeleporter.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="Assets\Ship\brokenTurret.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\Ship\brokenTurretTop.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <None Update="Assets\Ship\button.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
@@ -624,7 +637,7 @@
     <None Update="Assets\Ship\planetShipPrev.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
-    <None Update="Assets\Ship\recipesOldTec.png">
+    <None Update="Assets\Core\recipesOldTec.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
     <None Update="Assets\Ship\shipAEntranceBG.png">
@@ -726,7 +739,4 @@
       <EmbedInteropTypes>false</EmbedInteropTypes>
     </Reference>
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Assets\Core\" />
-  </ItemGroup>
 </Project>