From c67e5f39ea55692849bb46c1593ba008f59c5f2b Mon Sep 17 00:00:00 2001
From: Maria Khelli <13520115@std.stei.itb.ac.id>
Date: Fri, 14 Apr 2023 17:11:36 +0700
Subject: [PATCH] feat: pet immortal and kill cheat

---
 Assets/Scenes/TestPetLich.unity |  6 +++++
 Assets/Scripts/Pet/PetHealth.cs | 43 ++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/Assets/Scenes/TestPetLich.unity b/Assets/Scenes/TestPetLich.unity
index f2e64d5..a61212c 100644
--- a/Assets/Scenes/TestPetLich.unity
+++ b/Assets/Scenes/TestPetLich.unity
@@ -213,6 +213,10 @@ PrefabInstance:
       propertyPath: weapon
       value: 
       objectReference: {fileID: 1003343662}
+    - target: {fileID: 6649821425492048567, guid: 50754b1bd29cde544bf7b1e78400a3fd, type: 3}
+      propertyPath: player
+      value: 
+      objectReference: {fileID: 624092162}
     - target: {fileID: 9140073484006322690, guid: 50754b1bd29cde544bf7b1e78400a3fd, type: 3}
       propertyPath: player
       value: 
@@ -800,6 +804,8 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   speed: 6
+  pet: 0
+  Pets: []
 --- !u!82 &624092164
 AudioSource:
   m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/Pet/PetHealth.cs b/Assets/Scripts/Pet/PetHealth.cs
index 0a079a0..207128f 100644
--- a/Assets/Scripts/Pet/PetHealth.cs
+++ b/Assets/Scripts/Pet/PetHealth.cs
@@ -16,6 +16,14 @@ public class PetHealth : MonoBehaviour, Attackable
     private Rigidbody rb;
     private AudioSource petAudio;
 
+    // For cheat
+    private bool isImmortal = false;
+    private bool isTyping = false;
+    private string CHEAT_CODE_KILL = "kill";
+    private string CHEAT_CODE_IMMORTAL = "imt";
+    private string cheat = "";
+    private float timer = 0f;
+
     // Start is called before the first frame update
     void Awake()
     {
@@ -30,7 +38,37 @@ public class PetHealth : MonoBehaviour, Attackable
     // Update is called once per frame
     void Update()
     {
-        // Do something
+        if (isTyping) {
+            if (Input.anyKey) {
+                cheat += Input.inputString;
+                // Debug.Log(cheat);
+                
+                if (cheat == CHEAT_CODE_KILL) {
+                    currentHealth = 0;
+                    TakeDamage(1);
+                    
+                    isTyping = false;
+                    // Debug.Log("Killed pet");
+                } else if (cheat == CHEAT_CODE_IMMORTAL) {
+                    isImmortal = !isImmortal;
+
+                    isTyping = false;
+                    // Debug.Log("Immortal: " + isImmortal);
+                }
+            }
+
+            timer += Time.deltaTime;
+            if (timer >= 3f) {
+                isTyping = false;
+                cheat = "";
+            }
+        } else {
+            if (Input.GetKeyDown("k") || Input.GetKeyDown("i")) {
+                cheat += Input.inputString;
+                isTyping = true;
+                timer = 0f;
+            }
+        }
     }
 
     public void TakeDamage(int amount)
@@ -38,6 +76,9 @@ public class PetHealth : MonoBehaviour, Attackable
         if (isDead)
             return;
 
+        if (isImmortal)
+            return;
+
         currentHealth -= (amount - armor);
         petAudio.Play();
         
-- 
GitLab