From 671567bb81f4a8d44c4e09c24ba83ad5cb097d69 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Tue, 17 Dec 2024 20:52:34 +0500 Subject: [PATCH] Working on slow down ability --- Assets/GameData/Action/Abilities.meta | 8 ++ .../Action/Abilities/SlowZoneAbility.asset | 19 +++ .../Abilities/SlowZoneAbility.asset.meta | 8 ++ Assets/Prefabs/Abilities.meta | 8 ++ .../Abilities/SlowDownZonePrefab.prefab | 122 ++++++++++++++++++ .../Abilities/SlowDownZonePrefab.prefab.meta | 7 + Assets/Prefabs/Character/PlayerAvatar.prefab | 18 +++ Assets/Scenes/BossRoom/DungeonEntrance.unity | 6 +- Assets/Scripts/Gameplay/Ability.cs | 39 ++++++ Assets/Scripts/Gameplay/Ability.cs.meta | 11 ++ Assets/Scripts/Gameplay/AbilitySystem.cs | 78 +++++++++++ Assets/Scripts/Gameplay/AbilitySystem.cs.meta | 11 ++ .../Character/ServerCharacterMovement.cs | 1 + .../RuntimeDataContainers/GameDataSource.cs | 2 + Assets/Scripts/Gameplay/SlowZoneAbility.cs | 35 +++++ .../Scripts/Gameplay/SlowZoneAbility.cs.meta | 11 ++ Assets/Scripts/Gameplay/SlowZonePrefab.cs | 72 +++++++++++ .../Scripts/Gameplay/SlowZonePrefab.cs.meta | 11 ++ .../Gameplay/UserInput/ClientInputSender.cs | 15 ++- 19 files changed, 478 insertions(+), 4 deletions(-) create mode 100644 Assets/GameData/Action/Abilities.meta create mode 100644 Assets/GameData/Action/Abilities/SlowZoneAbility.asset create mode 100644 Assets/GameData/Action/Abilities/SlowZoneAbility.asset.meta create mode 100644 Assets/Prefabs/Abilities.meta create mode 100644 Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab create mode 100644 Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab.meta create mode 100644 Assets/Scripts/Gameplay/Ability.cs create mode 100644 Assets/Scripts/Gameplay/Ability.cs.meta create mode 100644 Assets/Scripts/Gameplay/AbilitySystem.cs create mode 100644 Assets/Scripts/Gameplay/AbilitySystem.cs.meta create mode 100644 Assets/Scripts/Gameplay/SlowZoneAbility.cs create mode 100644 Assets/Scripts/Gameplay/SlowZoneAbility.cs.meta create mode 100644 Assets/Scripts/Gameplay/SlowZonePrefab.cs create mode 100644 Assets/Scripts/Gameplay/SlowZonePrefab.cs.meta diff --git a/Assets/GameData/Action/Abilities.meta b/Assets/GameData/Action/Abilities.meta new file mode 100644 index 0000000..aed468a --- /dev/null +++ b/Assets/GameData/Action/Abilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a56539f7f1d01564e96fc5270dbf94f7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameData/Action/Abilities/SlowZoneAbility.asset b/Assets/GameData/Action/Abilities/SlowZoneAbility.asset new file mode 100644 index 0000000..575327a --- /dev/null +++ b/Assets/GameData/Action/Abilities/SlowZoneAbility.asset @@ -0,0 +1,19 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e7350d0607d7cc46a92f7ff596ad88d, type: 3} + m_Name: SlowZoneAbility + m_EditorClassIdentifier: + abilityName: Slowdown Area + abilityKey: Slowdown + keybind: 113 + cooldownTime: 3 + slowZonePrefab: {fileID: 5818330108676053786, guid: 4979352732bf84b44a9c789bef80b18a, type: 3} diff --git a/Assets/GameData/Action/Abilities/SlowZoneAbility.asset.meta b/Assets/GameData/Action/Abilities/SlowZoneAbility.asset.meta new file mode 100644 index 0000000..d62052f --- /dev/null +++ b/Assets/GameData/Action/Abilities/SlowZoneAbility.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e4794e2f71f66a74486c797344695ce7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Abilities.meta b/Assets/Prefabs/Abilities.meta new file mode 100644 index 0000000..0aa4109 --- /dev/null +++ b/Assets/Prefabs/Abilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce2326204c1815d48a8b749dcea9caf2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab b/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab new file mode 100644 index 0000000..86830c5 --- /dev/null +++ b/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab @@ -0,0 +1,122 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5818330108676053786 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5066519206278508126} + - component: {fileID: 5158718991394562100} + - component: {fileID: 825873091886110301} + - component: {fileID: 8294231852451494523} + - component: {fileID: 7596904637393423818} + m_Layer: 0 + m_Name: SlowDownZonePrefab + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5066519206278508126 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5818330108676053786} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_ConstrainProportionsScale: 1 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &5158718991394562100 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5818330108676053786} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &825873091886110301 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5818330108676053786} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 2758e3f8ea8e3644c85864c0cc87f779, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!114 &8294231852451494523 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5818330108676053786} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + GlobalObjectIdHash: 4101054131 + InScenePlacedSourceGlobalObjectIdHash: 0 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 0 + AutoObjectParentSync: 1 +--- !u!114 &7596904637393423818 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5818330108676053786} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 16c014692584a9a438b902616cc2dd35, type: 3} + m_Name: + m_EditorClassIdentifier: + zoneRadius: 5 + slowDuration: 3 diff --git a/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab.meta b/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab.meta new file mode 100644 index 0000000..d5b70da --- /dev/null +++ b/Assets/Prefabs/Abilities/SlowDownZonePrefab.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4979352732bf84b44a9c789bef80b18a +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Character/PlayerAvatar.prefab b/Assets/Prefabs/Character/PlayerAvatar.prefab index 5f8ba82..051656d 100644 --- a/Assets/Prefabs/Character/PlayerAvatar.prefab +++ b/Assets/Prefabs/Character/PlayerAvatar.prefab @@ -219,6 +219,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} insertIndex: -1 addedObject: {fileID: 4727018541459492655} + - targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} + insertIndex: -1 + addedObject: {fileID: 7049454171559621213} m_SourcePrefab: {fileID: 100100000, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} --- !u!114 &741733315856861890 stripped MonoBehaviour: @@ -287,6 +290,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_ServerCharacter: {fileID: 741733315856861890} m_PhysicsWrapper: {fileID: 6116655102486013040} + m_AbilitySystem: {fileID: 7049454171559621213} --- !u!114 &4887850889182527394 MonoBehaviour: m_ObjectHideFlags: 0 @@ -649,6 +653,20 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &7049454171559621213 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6009713983291384756} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d1377d8a6afd7d4fbc33f3db37363bd, type: 3} + m_Name: + m_EditorClassIdentifier: + abilities: + - {fileID: 11400000, guid: e4794e2f71f66a74486c797344695ce7, type: 2} --- !u!4 &6009713983291384766 stripped Transform: m_CorrespondingSourceObject: {fileID: 4600110157238723791, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} diff --git a/Assets/Scenes/BossRoom/DungeonEntrance.unity b/Assets/Scenes/BossRoom/DungeonEntrance.unity index db9a4ab..9722d0d 100644 --- a/Assets/Scenes/BossRoom/DungeonEntrance.unity +++ b/Assets/Scenes/BossRoom/DungeonEntrance.unity @@ -294,8 +294,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 286165427} - - component: {fileID: 286165428} - component: {fileID: 286165429} + - component: {fileID: 286165428} m_Layer: 0 m_Name: Platforms m_TagString: Untagged @@ -379,7 +379,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &676920372 Transform: m_ObjectHideFlags: 0 @@ -1251,7 +1251,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &1463337823 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Gameplay/Ability.cs b/Assets/Scripts/Gameplay/Ability.cs new file mode 100644 index 0000000..f025550 --- /dev/null +++ b/Assets/Scripts/Gameplay/Ability.cs @@ -0,0 +1,39 @@ +using UnityEngine; + +public abstract class Ability : ScriptableObject +{ + [Header("Ability Settings")] + public string abilityName; + public string abilityKey; + public KeyCode keybind; // Key to activate the ability + public float cooldownTime; // Cooldown duration in seconds + + private float lastActivationTime; + + /// + /// Checks if the ability can be activated (e.g., not on cooldown). + /// + public bool CanActivate() + { + return Time.time >= lastActivationTime + cooldownTime; + } + + /// + /// Invokes the ability. + /// + /// The GameObject or player triggering this ability. + public void TryActivate(GameObject owner) + { + if (CanActivate()) + { + Activate(owner); + lastActivationTime = Time.time; + } + else + { + Debug.Log($"{abilityName} is on cooldown."); + } + } + + protected abstract void Activate(GameObject owner); // Logic for the specific ability +} diff --git a/Assets/Scripts/Gameplay/Ability.cs.meta b/Assets/Scripts/Gameplay/Ability.cs.meta new file mode 100644 index 0000000..dad66ed --- /dev/null +++ b/Assets/Scripts/Gameplay/Ability.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d2f9f4fdfd486f409d0defeead4992f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs b/Assets/Scripts/Gameplay/AbilitySystem.cs new file mode 100644 index 0000000..08f12f4 --- /dev/null +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; +using Unity.Netcode; +using UnityEngine; + +public class AbilitySystem : MonoBehaviour +{ + [Header("Assigned Abilities")] + public List abilities = new List(); + + private Ability activeAbility; // Tracks the currently active ability in "spawn mode" + private bool isAbilityActive = false; + + void Update() + { + // If ability mode is active, listen for mouse input to activate ability + if (isAbilityActive && Input.GetMouseButtonDown(0)) + { + UseActiveAbility(); + ToggleAbilityMode(activeAbility); + } + } + + /// + /// Activates ability by key (called externally). + /// + /// The key assigned to an ability. + public void ActivateAbilityByKey(string key) + { + foreach (var ability in abilities) + { + if (ability.abilityKey == key) + { + ToggleAbilityMode(ability); + return; + } + } + Debug.LogWarning($"No ability assigned to key {key}."); + } + + /// + /// Toggles the ability activation mode. + /// + /// The ability to toggle. + private void ToggleAbilityMode(Ability ability) + { + if (isAbilityActive && activeAbility == ability) + { + DeactivateAbilityMode(); + } + else + { + ActivateAbilityMode(ability); + } + } + + private void ActivateAbilityMode(Ability ability) + { + isAbilityActive = true; + activeAbility = ability; + Debug.Log($"Ability {ability.name} activated! Click to use."); + } + + private void DeactivateAbilityMode() + { + isAbilityActive = false; + activeAbility = null; + Debug.Log("Ability mode deactivated."); + } + + private void UseActiveAbility() + { + if (activeAbility != null) + { + activeAbility.TryActivate(gameObject); + DeactivateAbilityMode(); // Ability used, deactivate mode + } + } +} diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs.meta b/Assets/Scripts/Gameplay/AbilitySystem.cs.meta new file mode 100644 index 0000000..9ae9733 --- /dev/null +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d1377d8a6afd7d4fbc33f3db37363bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacterMovement.cs b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacterMovement.cs index c90b75a..79adf04 100644 --- a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacterMovement.cs +++ b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacterMovement.cs @@ -265,6 +265,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character return characterClass.Speed; } + /// /// Determines the appropriate MovementStatus for the character. The /// MovementStatus is used by the client code when animating the character. diff --git a/Assets/Scripts/Gameplay/GameplayObjects/RuntimeDataContainers/GameDataSource.cs b/Assets/Scripts/Gameplay/GameplayObjects/RuntimeDataContainers/GameDataSource.cs index 1b3ef07..59dc31b 100644 --- a/Assets/Scripts/Gameplay/GameplayObjects/RuntimeDataContainers/GameDataSource.cs +++ b/Assets/Scripts/Gameplay/GameplayObjects/RuntimeDataContainers/GameDataSource.cs @@ -81,6 +81,8 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects public Action DropActionPrototype => m_DropActionPrototype; public Action PickUpActionPrototype => m_PickUpActionPrototype; + public string SlowDownAbilityKey = "Slowdown"; + List m_AllActions; public Action GetActionPrototypeByID(ActionID index) diff --git a/Assets/Scripts/Gameplay/SlowZoneAbility.cs b/Assets/Scripts/Gameplay/SlowZoneAbility.cs new file mode 100644 index 0000000..f8fa86f --- /dev/null +++ b/Assets/Scripts/Gameplay/SlowZoneAbility.cs @@ -0,0 +1,35 @@ +using UnityEngine; +using Unity.Netcode; + +[CreateAssetMenu(menuName = "Abilities/Slow Zone Ability")] +public class SlowZoneAbility : Ability +{ + [Header("Slow Zone Settings")] + public GameObject slowZonePrefab; + + protected override void Activate(GameObject owner) + { + Camera mainCamera = Camera.main; + Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); + + if (Physics.Raycast(ray, out RaycastHit hit)) + { + Vector3 spawnPosition = hit.point; + + if (owner.TryGetComponent(out NetworkObject networkOwner)) + { + SpawnSlowZoneServerRpc(spawnPosition); + } + } + } + + + + [Rpc(SendTo.Server)] + private void SpawnSlowZoneServerRpc(Vector3 position) + { + GameObject slowZone = Instantiate(slowZonePrefab, position, Quaternion.identity); + slowZone.GetComponent().Spawn(); + Debug.Log($"Slow Zone spawned at {position}."); + } +} diff --git a/Assets/Scripts/Gameplay/SlowZoneAbility.cs.meta b/Assets/Scripts/Gameplay/SlowZoneAbility.cs.meta new file mode 100644 index 0000000..5f0338f --- /dev/null +++ b/Assets/Scripts/Gameplay/SlowZoneAbility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e7350d0607d7cc46a92f7ff596ad88d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/SlowZonePrefab.cs b/Assets/Scripts/Gameplay/SlowZonePrefab.cs new file mode 100644 index 0000000..7c7c221 --- /dev/null +++ b/Assets/Scripts/Gameplay/SlowZonePrefab.cs @@ -0,0 +1,72 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.BossRoom.Gameplay.GameplayObjects.Character; +using Unity.Netcode; +using UnityEngine; +using UnityEngine.AI; + +public class SlowZonePrefab : NetworkBehaviour +{ + [Header("Slow Zone Settings")] + public float zoneRadius = 5f; // Radius of the slow zone + public float slowDuration = 3f; // Duration of the slow effect + + private void Start() + { + // Start the process to slow down players when the zone is spawned + StartCoroutine(ApplySlowEffect()); + } + + private IEnumerator ApplySlowEffect() + { + // Run the logic once immediately + ApplySlowToPlayers(); + + // Optionally, repeat the check while the zone exists + yield return new WaitForSeconds(slowDuration); + + // Destroy the zone after applying the slow effect + Destroy(gameObject); + } + + private void ApplySlowToPlayers() + { + // Find all colliders in the zone + Collider[] hitColliders = Physics.OverlapSphere(transform.position, zoneRadius); + foreach (var collider in hitColliders) + { + if (collider.TryGetComponent(out var player)) + { + // Check if the player is NOT the crow + if (!player.IsCrow) + { + // Apply slow effect + StartCoroutine(SlowPlayer(player)); + Debug.Log($"{player.name} is slowed down!"); + } + } + } + } + + private IEnumerator SlowPlayer(ServerCharacter player) + { + // Halve the player's movement speed + player.GetComponent().speed /= 2; + // player.Movement.SetMovementSpeed(originalSpeed * slowMultiplier); + + // Wait for the slow duration + yield return new WaitForSeconds(slowDuration); + + // Restore the original speed + player.GetComponent().speed /= 2; + Debug.Log($"{player.name}'s speed is restored."); + Destroy(gameObject); + } + + // Debug visualization for the slow zone in the editor + private void OnDrawGizmos() + { + Gizmos.color = Color.cyan; + Gizmos.DrawWireSphere(transform.position, zoneRadius); + } +} diff --git a/Assets/Scripts/Gameplay/SlowZonePrefab.cs.meta b/Assets/Scripts/Gameplay/SlowZonePrefab.cs.meta new file mode 100644 index 0000000..081d4b4 --- /dev/null +++ b/Assets/Scripts/Gameplay/SlowZonePrefab.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 16c014692584a9a438b902616cc2dd35 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs index 9877091..8327754 100644 --- a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs +++ b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs @@ -8,6 +8,7 @@ using UnityEngine; using UnityEngine.AI; using UnityEngine.Assertions; using UnityEngine.EventSystems; +using UnityEngine.Serialization; namespace Unity.BossRoom.Gameplay.UserInput { @@ -117,6 +118,8 @@ namespace Unity.BossRoom.Gameplay.UserInput public System.Action action1ModifiedCallback; + public AbilitySystem m_AbilitySystem; + ServerCharacter m_TargetServerCharacter; void Awake() @@ -515,7 +518,17 @@ namespace Unity.BossRoom.Gameplay.UserInput { RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); } - + if (Input.GetKeyDown(KeyCode.Q)) + { + if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability + { + m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey); + } + else + { + Debug.Log("You must be the Crow to activate this ability."); + } + } if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) { //IsPointerOverGameObject() is a simple way to determine if the mouse is over a UI element. If it is, we don't perform mouse input logic,