Browse Source

[2.0.3.9] Added 'Broken Droid' enemy

Zariteis 4 years ago
parent
commit
12587e742d
7 changed files with 169 additions and 75 deletions
  1. BIN
      Assets/droid.png
  2. 0 74
      OldChestScript.cs
  3. 58 0
      Scripts/AttackDroidScript.cs
  4. 73 0
      Scripts/OldChestScript.cs
  5. 1 1
      ShipGenerator.cs
  6. 34 0
      Ships.cs
  7. 3 0
      Ships.csproj

BIN
Assets/droid.png


+ 0 - 74
OldChestScript.cs

@@ -1,74 +0,0 @@
-using GadgetCore.API;
-using Ships;
-using System;
-using System.Collections;
-using UnityEngine;
-
-public class OldChestScript : MonoBehaviour
-{
-  private bool opened = false;
-
-  private void Awake()
-  {
-    base.name = "chest";
-  }
-
-  private void Start()
-  {
-  }
-
-  [RPC]
-  private void Open()
-  {
-    if (!this.opened)
-    {
-      this.opened = true;
-      base.GetComponent<NetworkView>().RPC("OpenMat", RPCMode.AllBuffered, new object[0]);
-      this.DropItems();
-    }
-  }
-
-  private void DropItems()
-  {
-    base.GetComponent<NetworkView>().RPC("DropLocal", RPCMode.All, new object[0]);
-  }
-
-  [RPC]
-  private void DropLocal()
-  {
-    if (Menuu.curAugment == 12)
-      StartCoroutine(DropLocalLoot());
-    StartCoroutine(DropLocalLoot());
-  }
-
-  private IEnumerator DropLocalLoot()
-  {
-    yield return new WaitForSeconds(0.2f);
-    var item = GadgetCoreAPI.EmptyItem();
-    item.id = Core.itemOldTex.GetID();
-    GadgetCoreAPI.DropItemLocal(gameObject.transform.position, item);
-    yield return new WaitForSeconds(0.2f);
-    GadgetCoreAPI.SpawnExp(gameObject.transform.position, 2);
-    yield return new WaitForSeconds(0.2f);
-    GadgetCoreAPI.SpawnExp(gameObject.transform.position, 10);
-    yield return new WaitForSeconds(0.2f);
-    GadgetCoreAPI.SpawnExp(gameObject.transform.position, 20);
-    yield break;
-  }
-
-  private static Texture2D textureOldChestOpen = GadgetCoreAPI.LoadTexture2D("oldChestOpen.png");
-
-  [RPC]
-  private void OpenMat()
-  {
-    Menuu.characterStat[8]++;
-    GameScript.cadetValue += 2;
-    base.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/chest"), Menuu.soundLevel / 10f);
-    base.GetComponent<Collider>().enabled = false;
-    Renderer renderer = gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
-    renderer.material = new Material(Shader.Find("Unlit/Transparent"))
-    {
-      mainTexture = textureOldChestOpen
-    };
-  }
-}

+ 58 - 0
Scripts/AttackDroidScript.cs

@@ -0,0 +1,58 @@
+
+
+
+using System;
+using System.Collections;
+using UnityEngine;
+
+namespace Ships.Scripts
+{
+  class AttackDroidScript : EnemyScript
+  {
+    private Vector3 dir;
+    private bool attacking;
+
+    private void Awake()
+    {
+      base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
+    }
+
+    private void Update()
+    {
+      if (Network.isServer)
+      {
+        if (!this.attacking)
+        {
+          this.r.velocity = new Vector3(0f, 0f, 0f);
+          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;
+              this.r.velocity = new Vector3(0f, 0f, 0f);
+            }
+          }
+        }
+      }
+    }
+
+    private IEnumerator Attack()
+    {
+      gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
+      yield return new WaitForSeconds(0.55f);
+      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 = new Vector3(0f, 0f, 0f);
+      this.attacking = false;
+      yield break;
+    }
+  }
+}

+ 73 - 0
Scripts/OldChestScript.cs

@@ -0,0 +1,73 @@
+using GadgetCore.API;
+using System.Collections;
+using UnityEngine;
+
+namespace Ships.Scripts
+{
+  public class OldChestScript : MonoBehaviour
+  {
+    private bool opened = false;
+
+    private void Awake()
+    {
+      base.name = "chest";
+    }
+
+    private void Start() { }
+
+    [RPC]
+    private void Open()
+    {
+      if (!this.opened)
+      {
+        this.opened = true;
+        base.GetComponent<NetworkView>().RPC("OpenMat", RPCMode.AllBuffered, new object[0]);
+        this.DropItems();
+      }
+    }
+
+    private void DropItems()
+    {
+      base.GetComponent<NetworkView>().RPC("DropLocal", RPCMode.All, new object[0]);
+    }
+
+    [RPC]
+    private void DropLocal()
+    {
+      if (Menuu.curAugment == 12)
+        StartCoroutine(DropLocalLoot());
+      StartCoroutine(DropLocalLoot());
+    }
+
+    private IEnumerator DropLocalLoot()
+    {
+      yield return new WaitForSeconds(0.2f);
+      var item = GadgetCoreAPI.EmptyItem();
+      item.id = Core.itemOldTex.GetID();
+      GadgetCoreAPI.DropItemLocal(gameObject.transform.position, item);
+      yield return new WaitForSeconds(0.2f);
+      GadgetCoreAPI.SpawnExp(gameObject.transform.position, 25);
+      yield return new WaitForSeconds(0.2f);
+      GadgetCoreAPI.SpawnExp(gameObject.transform.position, 10);
+      yield return new WaitForSeconds(0.2f);
+      GadgetCoreAPI.SpawnExp(gameObject.transform.position, 20);
+      yield break;
+    }
+
+    private static Texture2D textureOldChestOpen = GadgetCoreAPI.LoadTexture2D("oldChestOpen.png");
+
+    [RPC]
+    private void OpenMat()
+    {
+      Menuu.characterStat[8]++;
+      GameScript.cadetValue += 2;
+      base.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/chest"), Menuu.soundLevel / 10f);
+      base.GetComponent<Collider>().enabled = false;
+      Renderer renderer = gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
+      renderer.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = textureOldChestOpen
+      };
+    }
+  }
+}

+ 1 - 1
ShipGenerator.cs

@@ -1,5 +1,4 @@
 using GadgetCore.API;
-using Ships.API;
 using System;
 using System.Collections.Generic;
 using System.Reflection;
@@ -256,6 +255,7 @@ namespace Ships
               break;
             case ShipGeneratorObjectPoolType.FlyingEnemy:
               Network.Instantiate(Resources.Load("e/Ships/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/Ships/BrokenDroid"), 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/Ships/BrokenItemMod"), new Vector3(248f + 4 * e[0], -8f + 0.118f * 4 + 4 * e[1], 0.2f), Quaternion.identity, 0);

+ 34 - 0
Ships.cs

@@ -1,6 +1,7 @@
 using GadgetCore.API;
 using GadgetCore.Util;
 using RecipeMenuCore.API;
+using Ships.Scripts;
 using System.Collections;
 using System.Reflection;
 using UnityEngine;
@@ -137,6 +138,8 @@ namespace Ships
 
       CreateSliverEnemy("BrokenSliver", GadgetCoreAPI.LoadTexture2D("brokenSliverHead.png"), GadgetCoreAPI.LoadTexture2D("brokenSliverBody.png"), GadgetCoreAPI.LoadTexture2D("brokenSliverTail.png"));
 
+      CreateDroidEnemy("BrokenDroid", GadgetCoreAPI.LoadTexture2D("droid.png"));
+
       ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, "port5", "", null as Texture2D).Register("port5");
       TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("port5"), itemInfo).Register("port5");
 
@@ -324,6 +327,37 @@ namespace Ships
       GadgetCoreAPI.AddCustomResource("e/Ships/" + name, gameObject);
     }
 
+    private void CreateDroidEnemy(string name, Texture2D texture)
+    {
+      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 = texture
+      };
+      GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).GetChild(1).gameObject);
+      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      gameObject.AddComponent<AttackDroidScript>();
+
+      gameObject.transform.GetChild(1).gameObject.SetActive(true);
+      gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
+
+      AnimationClip clip = new AnimationClip
+      {
+        name = "spinn",
+        wrapMode = WrapMode.Once,
+        legacy = true
+      };
+      clip.SetCurve("", typeof(Transform), "localEulerAngles.z", AnimationCurve.Linear(0, 0, 0.5f, 360));
+      var animation = gameObject.transform.GetChild(0).gameObject.AddComponent<Animation>();
+      animation.AddClip(clip, "spinn");
+      animation.clip = clip;
+
+      GadgetCoreAPI.AddCustomResource("e/Ships/" + name, gameObject);
+    }
+
     private void CreateOldChest(string name, Texture texture)
     {
       GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("obj/chest"));

+ 3 - 0
Ships.csproj

@@ -252,6 +252,9 @@
     <None Update="Assets\dOldTecDroidTop.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="Assets\droid.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <None Update="Assets\entranceScrapYard.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>