From ce7b04688ba33e90bff99530b4b48ddd5a9a7726 Mon Sep 17 00:00:00 2001 From: Salomo309 <109785084+Salomo309@users.noreply.github.com> Date: Sat, 11 May 2024 14:18:28 +0700 Subject: [PATCH] refactor: cheat, activate and deactivate done --- Assets/Scripts/Cheat/DebugController.cs | 32 ++++++++++++-- Assets/Scripts/Player/PlayerAttribute.cs | 43 +++++++++++++++++++ Assets/Scripts/Player/PlayerAttribute.cs.meta | 11 +++++ Assets/Scripts/Player/PlayerGold.cs | 14 ++++++ Assets/Scripts/Player/PlayerHealth.cs | 10 +++++ Assets/Scripts/Player/PlayerMovement.cs | 6 +++ 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/Player/PlayerAttribute.cs create mode 100644 Assets/Scripts/Player/PlayerAttribute.cs.meta diff --git a/Assets/Scripts/Cheat/DebugController.cs b/Assets/Scripts/Cheat/DebugController.cs index c76651f..35f82c3 100644 --- a/Assets/Scripts/Cheat/DebugController.cs +++ b/Assets/Scripts/Cheat/DebugController.cs @@ -14,6 +14,12 @@ public class DebugController : MonoBehaviour public static DebugCommand ONE_HIT_KILL; public static DebugCommand MOTHERLODE; public static DebugCommand DOUBLE_SPEED; + + public static DebugCommand DEACTIVATE_NO_DAMAGE; + public static DebugCommand DEACTIVATE_ONE_HIT_KILL; + public static DebugCommand DEACTIVATE_MOTHERLODE; + public static DebugCommand DEACTIVATE_DOUBLE_SPEED; + public static DebugCommand PET_FULL_HP; public static DebugCommand KILL_PET; public static DebugCommand ORB; @@ -56,7 +62,7 @@ public class DebugController : MonoBehaviour ONE_HIT_KILL = new DebugCommand("one_hit_kill", "Player Can Kill Enemy with One Hit.", "one_hit_kill", () => { - FindObjectOfType<PlayerShooting>().CheatOneHitKill(); + FindObjectOfType<PlayerAttribute>().CheatOneHitKill(); }); MOTHERLODE = new DebugCommand("motherlode", "Gain Resources.", "motherlode", () => @@ -69,6 +75,26 @@ public class DebugController : MonoBehaviour FindObjectOfType<PlayerMovement>().CheatDoubleSpeed(); }); + DEACTIVATE_NO_DAMAGE = new DebugCommand("deactivate_no_damage", "Player Has No Damage.", "deactivate_no_damage", () => + { + FindObjectOfType<PlayerHealth>().DeactivateCheatNoDamage(); + }); + + DEACTIVATE_ONE_HIT_KILL = new DebugCommand("deactivate_one_hit_kill", "Player Can Kill Enemy with One Hit.", "deactivate_one_hit_kill", () => + { + FindObjectOfType<PlayerAttribute>().DeactivateCheatOneHitKill(); + }); + + DEACTIVATE_MOTHERLODE = new DebugCommand("deactivate_motherlode", "Gain Resources.", "deactivate_motherlode", () => + { + FindObjectOfType<PlayerGold>().DeactivateCheatMotherlode(); + }); + + DEACTIVATE_DOUBLE_SPEED = new DebugCommand("deactivate_double_speed", "Double Player Speed.", "deactivate_double_speed", () => + { + FindObjectOfType<PlayerMovement>().DeactivateCheatDoubleSpeed(); + }); + PET_FULL_HP = new DebugCommand("pet_full_hp", "Restore Pet's Health to Full.", "pet_full_hp", () => { FindObjectOfType<PetHeatlh>().CheatPetFullHP(); @@ -76,12 +102,12 @@ public class DebugController : MonoBehaviour KILL_PET = new DebugCommand("kill_pet", "Kill Pet.", "kill_pet", () => { - FindObjectOfType<PlayerShooting>().CheatKillPet(); + FindObjectOfType<PlayerAttribute>().CheatKillPet(); }); ORB = new DebugCommand("orb", "Spawn Orb.", "orb", () => { - FindObjectOfType<PlayerShooting>().CheatOrb(); + FindObjectOfType<PlayerHealth>().CheatOrb(); }); SKIP_LEVEL = new DebugCommand("skip_level", "Skip Current Level.", "skip_level", () => diff --git a/Assets/Scripts/Player/PlayerAttribute.cs b/Assets/Scripts/Player/PlayerAttribute.cs new file mode 100644 index 0000000..7656ac2 --- /dev/null +++ b/Assets/Scripts/Player/PlayerAttribute.cs @@ -0,0 +1,43 @@ +using Nightmare; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAttribute : MonoBehaviour +{ + public bool isOneHitKill = false; + void Awake() + { + + } + + void Update() + { + + } + + public void CheatOneHitKill() + { + isOneHitKill = true; + FindObjectOfType<GunAttack>().damagePerShot = 9999; + FindObjectOfType<ShotgunAttack>().damagePerBullet = 9999; + FindObjectOfType<SwordAttack>().damagePerSlash = 9999; + } + + public void DeactivateCheatOneHitKill() + { + isOneHitKill = false; + FindObjectOfType<GunAttack>().damagePerShot = 20; + FindObjectOfType<ShotgunAttack>().damagePerBullet = 5; + FindObjectOfType<SwordAttack>().damagePerSlash = 40; + } + + + + public void CheatKillPet() + { + // Bunuh pet + // Misalnya: + // petHealth.TakeDamage(petHealth.CurrentHealth()); + } +} diff --git a/Assets/Scripts/Player/PlayerAttribute.cs.meta b/Assets/Scripts/Player/PlayerAttribute.cs.meta new file mode 100644 index 0000000..a44ded5 --- /dev/null +++ b/Assets/Scripts/Player/PlayerAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3e213799f809834ea32edb63b9f8361 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerGold.cs b/Assets/Scripts/Player/PlayerGold.cs index 8b759ed..a89c108 100644 --- a/Assets/Scripts/Player/PlayerGold.cs +++ b/Assets/Scripts/Player/PlayerGold.cs @@ -14,6 +14,14 @@ namespace Nightmare currentGold = startingGold; } + private void Update() + { + if (isMotherlode) + { + currentGold = int.MaxValue; + } + } + public void AddGold(int amount) { currentGold += amount; @@ -34,6 +42,12 @@ namespace Nightmare isMotherlode = true; currentGold = int.MaxValue; } + + public void DeactivateCheatMotherlode() + { + isMotherlode = false; + currentGold = 100; + } } } diff --git a/Assets/Scripts/Player/PlayerHealth.cs b/Assets/Scripts/Player/PlayerHealth.cs index c62ef58..2350fa0 100644 --- a/Assets/Scripts/Player/PlayerHealth.cs +++ b/Assets/Scripts/Player/PlayerHealth.cs @@ -125,5 +125,15 @@ namespace Nightmare { godMode = false; } + + public void CheatOrb() + { + currentHealth += 20; + + if (currentHealth > 100) + { + currentHealth = 100; + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 4633e11..6721b8d 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -124,5 +124,11 @@ namespace Nightmare isDoubleSpeed = true; speed = speed * 2; } + + public void DeactivateCheatDoubleSpeed() + { + isDoubleSpeed = false; + speed = speed / 2; + } } } \ No newline at end of file -- GitLab