Added slowdown

main
Hazim Bin Ijaz 1 month ago
parent eb4c66732f
commit 281bb6e87c

@ -97,7 +97,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 4101054131
GlobalObjectIdHash: 725408325
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1

@ -8,31 +8,9 @@ public abstract class Ability : ScriptableObject
public KeyCode keybind; // Key to activate the ability
public float cooldownTime; // Cooldown duration in seconds
private float lastActivationTime;
/// <summary>
/// Checks if the ability can be activated (e.g., not on cooldown).
/// </summary>
public bool CanActivate()
{
return Time.time >= lastActivationTime + cooldownTime;
}
/// <summary>
/// Invokes the ability.
/// </summary>
/// <param name="owner">The GameObject or player triggering this ability.</param>
public void TryActivate(GameObject owner)
public void ActivateAbility(GameObject owner)
{
if (CanActivate())
{
Activate(owner);
lastActivationTime = Time.time;
}
else
{
Debug.Log($"{abilityName} is on cooldown.");
}
Activate(owner);
}
protected abstract void Activate(GameObject owner); // Logic for the specific ability

@ -1,5 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class AbilitySystem : MonoBehaviour
@ -10,37 +10,39 @@ public class AbilitySystem : MonoBehaviour
private Ability activeAbility; // Tracks the currently active ability in "spawn mode"
private bool isAbilityActive = false;
private HashSet<Ability> abilitiesOnCooldown = new HashSet<Ability>();
void Update()
{
// If ability mode is active, listen for mouse input to activate ability
if (isAbilityActive && Input.GetMouseButtonDown(0))
{
UseActiveAbility();
ToggleAbilityMode(activeAbility);
}
}
/// <summary>
/// Activates ability by key (called externally).
/// Activates an ability by its keybind.
/// </summary>
/// <param name="key">The key assigned to an ability.</param>
public void ActivateAbilityByKey(string key)
{
foreach (var ability in abilities)
{
if (ability.abilityKey == key)
{
ToggleAbilityMode(ability);
if (!abilitiesOnCooldown.Contains(ability))
{
ToggleAbilityMode(ability);
}
else
{
Debug.Log($"{ability.abilityName} is on cooldown.");
}
return;
}
}
Debug.LogWarning($"No ability assigned to key {key}.");
}
/// <summary>
/// Toggles the ability activation mode.
/// </summary>
/// <param name="ability">The ability to toggle.</param>
private void ToggleAbilityMode(Ability ability)
{
if (isAbilityActive && activeAbility == ability)
@ -57,7 +59,7 @@ public class AbilitySystem : MonoBehaviour
{
isAbilityActive = true;
activeAbility = ability;
Debug.Log($"Ability {ability.name} activated! Click to use.");
Debug.Log($"Ability {ability.abilityName} activated! Click to use.");
}
private void DeactivateAbilityMode()
@ -71,8 +73,23 @@ public class AbilitySystem : MonoBehaviour
{
if (activeAbility != null)
{
activeAbility.TryActivate(gameObject);
DeactivateAbilityMode(); // Ability used, deactivate mode
activeAbility.ActivateAbility(gameObject);
StartCoroutine(StartCooldown(activeAbility));
DeactivateAbilityMode();
}
}
/// <summary>
/// Starts the cooldown coroutine for the ability.
/// </summary>
private IEnumerator StartCooldown(Ability ability)
{
abilitiesOnCooldown.Add(ability);
Debug.Log($"{ability.abilityName} is now on cooldown for {ability.cooldownTime} seconds.");
yield return new WaitForSeconds(ability.cooldownTime);
abilitiesOnCooldown.Remove(ability);
Debug.Log($"{ability.abilityName} is off cooldown.");
}
}

@ -249,9 +249,32 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
m_Rigidbody.rotation = transform.rotation;
}
private float speedModifier = 1.0f;
/// <summary>
/// Adjusts the character's speed by applying a multiplier.
/// </summary>
/// <param name="modifier">The speed modifier (e.g., 0.5 for half speed, 2.0 for double speed).</param>
public void SetSpeedModifier(float modifier)
{
speedModifier = Mathf.Clamp(modifier, 0.1f, 10.0f); // Prevent extreme values
}
/// <summary>
/// Resets the speed modifier back to normal speed.
/// </summary>
public void ResetSpeedModifier()
{
speedModifier = 1.0f;
}
/// <summary>
/// Retrieves the speed for this character's class.
/// </summary>
/// <summary>
/// Retrieves the adjusted speed for this character's class.
/// </summary>
private float GetBaseMovementSpeed()
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
@ -262,7 +285,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
#endif
CharacterClass characterClass = GameDataSource.Instance.CharacterDataByType[m_CharLogic.CharacterType];
Assert.IsNotNull(characterClass, $"No CharacterClass data for character type {m_CharLogic.CharacterType}");
return characterClass.Speed;
return characterClass.Speed * speedModifier;
}

@ -38,12 +38,12 @@ public class SlowZonePrefab : NetworkBehaviour
if (collider.TryGetComponent<ServerCharacter>(out var player))
{
// Check if the player is NOT the crow
if (!player.IsCrow)
{
// if (!player.IsCrow)
// {
// Apply slow effect
StartCoroutine(SlowPlayer(player));
Debug.Log($"{player.name} is slowed down!");
}
// }
}
}
}
@ -51,14 +51,14 @@ public class SlowZonePrefab : NetworkBehaviour
private IEnumerator SlowPlayer(ServerCharacter player)
{
// Halve the player's movement speed
player.GetComponent<NavMeshAgent>().speed /= 2;
player.Movement.SetSpeedModifier(0.2f);
// player.Movement.SetMovementSpeed(originalSpeed * slowMultiplier);
// Wait for the slow duration
yield return new WaitForSeconds(slowDuration);
// Restore the original speed
player.GetComponent<NavMeshAgent>().speed /= 2;
player.Movement.ResetSpeedModifier();
Debug.Log($"{player.name}'s speed is restored.");
Destroy(gameObject);
}

Loading…
Cancel
Save