From 8c651c4f3f568b1dc1de3c24b1e14ff83e477afa Mon Sep 17 00:00:00 2001
From: hanifmz07 <13521157@std.stei.itb.ac.id>
Date: Sat, 11 May 2024 10:19:54 +0700
Subject: [PATCH] feat: add reload animation

---
 .../KepalaKerocoAnimator.controller           |  2 +-
 .../Art/Animations/KingAnimation.controller   |  2 +-
 .../Scripts/Mobs/KepalaKerocoBehaviour.cs     | 17 ++++++++++++++++-
 .../Assets/Code/Scripts/Mobs/KingBehaviour.cs | 19 +++++++++++++++++++
 .../Assets/Level/Scenes/TestJup3.unity        | 16 ++++++++++++++--
 5 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/IF3210-2024-Unity-AFK/Assets/Art/Animations/KepalaKerocoAnimator.controller b/IF3210-2024-Unity-AFK/Assets/Art/Animations/KepalaKerocoAnimator.controller
index ebfd3e4a..973a2a9b 100644
--- a/IF3210-2024-Unity-AFK/Assets/Art/Animations/KepalaKerocoAnimator.controller
+++ b/IF3210-2024-Unity-AFK/Assets/Art/Animations/KepalaKerocoAnimator.controller
@@ -434,7 +434,7 @@ AnimatorState:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_Name: reload
-  m_Speed: 1
+  m_Speed: 1.212121
   m_CycleOffset: 0
   m_Transitions:
   - {fileID: -1949820599851322477}
diff --git a/IF3210-2024-Unity-AFK/Assets/Art/Animations/KingAnimation.controller b/IF3210-2024-Unity-AFK/Assets/Art/Animations/KingAnimation.controller
index 009384a1..5089d4c2 100644
--- a/IF3210-2024-Unity-AFK/Assets/Art/Animations/KingAnimation.controller
+++ b/IF3210-2024-Unity-AFK/Assets/Art/Animations/KingAnimation.controller
@@ -91,7 +91,7 @@ AnimatorState:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_Name: reload
-  m_Speed: 1
+  m_Speed: 1.212121
   m_CycleOffset: 0
   m_Transitions:
   - {fileID: 6231556110780822070}
diff --git a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KepalaKerocoBehaviour.cs b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KepalaKerocoBehaviour.cs
index 796e5a81..b1c23aa6 100644
--- a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KepalaKerocoBehaviour.cs
+++ b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KepalaKerocoBehaviour.cs
@@ -42,6 +42,7 @@ public class NewBehaviourScript : MonoBehaviour
     {
         // Check for enemies in attack area
         Collider[] hitCollidersArea = Physics.OverlapSphere(transform.position, attackArea, targetLayer);
+        Debug.Log("hitCollidersArea length: " + hitCollidersArea.Length);
         if (hitCollidersArea.Length > 0)
         {
             // Chase the enemy and attack
@@ -54,6 +55,20 @@ public class NewBehaviourScript : MonoBehaviour
             Chase(MainPlayer.transform);
             Attack(MainPlayer.transform);
         }
+
+        ReloadAnimation();
+    }
+
+    private void ReloadAnimation()
+    {
+        if (gunSystem.IsReloading())
+        {
+            kepalaKerocoAnimator.SetBool(reloadAnimation, true);
+        }
+        else
+        {
+            kepalaKerocoAnimator.SetBool(reloadAnimation, false);
+        }
     }
 
     void Chase(Transform target)
@@ -113,7 +128,7 @@ public class NewBehaviourScript : MonoBehaviour
 
     void Attack(Transform target)
     {
-        float distanceAttack = Vector3.Distance(this.transform.position, target.position);
+        float distanceAttack = Vector3.Distance(transform.position, target.position);
         if (distanceAttack <= attackRange)
         {
             gunSystem.Shoot(target);
diff --git a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KingBehaviour.cs b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KingBehaviour.cs
index b7fd87bd..cce4225e 100644
--- a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KingBehaviour.cs
+++ b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Mobs/KingBehaviour.cs
@@ -74,10 +74,29 @@ public class KingBehaviour : MonoBehaviour
             {
                 if (!hitCrippleArea[i].GetComponent<CombatBehavior>())
                 {
+                    if (!hitCrippleArea[i].GetComponent<CombatBehavior>())
+                    {
+                        continue;
+                    }
+
                     hitCrippleArea[i].GetComponent<CombatBehavior>().TakeDamage(crippleDamage);
                 }
             }
         }
+
+        ReloadAnimation();
+    }
+
+    private void ReloadAnimation()
+    {
+        if (gunSystem.IsReloading())
+        {
+            kingAnimator.SetBool(reloadAnimation, true);
+        }
+        else
+        {
+            kingAnimator.SetBool(reloadAnimation, false);
+        }
     }
 
     void Chase(Transform target)
diff --git a/IF3210-2024-Unity-AFK/Assets/Level/Scenes/TestJup3.unity b/IF3210-2024-Unity-AFK/Assets/Level/Scenes/TestJup3.unity
index af4a63e5..cf9b01b4 100644
--- a/IF3210-2024-Unity-AFK/Assets/Level/Scenes/TestJup3.unity
+++ b/IF3210-2024-Unity-AFK/Assets/Level/Scenes/TestJup3.unity
@@ -6458,6 +6458,10 @@ PrefabInstance:
       propertyPath: targetLayer.m_Bits
       value: 8
       objectReference: {fileID: 0}
+    - target: {fileID: 348045508547534544, guid: c98aeaa500ff50d48ac11ae3f232869a, type: 3}
+      propertyPath: spawnKerocoCooldown
+      value: 300
+      objectReference: {fileID: 0}
     - target: {fileID: 356863305189137741, guid: c98aeaa500ff50d48ac11ae3f232869a, type: 3}
       propertyPath: m_Layer
       value: 8
@@ -6866,6 +6870,10 @@ PrefabInstance:
       propertyPath: spread
       value: 0.15
       objectReference: {fileID: 0}
+    - target: {fileID: 8404342860993974077, guid: c98aeaa500ff50d48ac11ae3f232869a, type: 3}
+      propertyPath: timeBetweenShooting
+      value: 100
+      objectReference: {fileID: 0}
     - target: {fileID: 8482937662095535414, guid: c98aeaa500ff50d48ac11ae3f232869a, type: 3}
       propertyPath: m_Layer
       value: 8
@@ -17191,6 +17199,10 @@ PrefabInstance:
       propertyPath: spread
       value: 0.15
       objectReference: {fileID: 0}
+    - target: {fileID: 5311998203450170466, guid: fe44ef7cfa14aeb4bafaab57bef8bcd7, type: 3}
+      propertyPath: m_Enabled
+      value: 0
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
     m_RemovedGameObjects: []
     m_AddedGameObjects: []
@@ -17359,11 +17371,11 @@ PrefabInstance:
       objectReference: {fileID: 294699695}
     - target: {fileID: 2169198251214934047, guid: 96674196a45debf4ba0a3fada63f2b22, type: 3}
       propertyPath: health
-      value: 10000
+      value: 1000000
       objectReference: {fileID: 0}
     - target: {fileID: 2169198251214934047, guid: 96674196a45debf4ba0a3fada63f2b22, type: 3}
       propertyPath: maxHealth
-      value: 10000
+      value: 1000000
       objectReference: {fileID: 0}
     - target: {fileID: 2495811754020454763, guid: 96674196a45debf4ba0a3fada63f2b22, type: 3}
       propertyPath: m_Enabled
-- 
GitLab