Compare commits
No commits in common. 'dev-hazimBeforeMerge' and 'main' have entirely different histories.
dev-hazimB
...
main
@ -1,29 +1,28 @@
|
|||||||
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public abstract class Ability : ScriptableObject
|
public abstract class Ability : ScriptableObject
|
||||||
{
|
{
|
||||||
public string abilityKey;
|
[Header("Ability Settings")]
|
||||||
public string abilityName;
|
public string abilityName;
|
||||||
|
public string abilityKey;
|
||||||
[Header("Common Ability Settings")]
|
public KeyCode keybind; // Key to activate the ability
|
||||||
|
public float cooldownTime; // Cooldown duration in seconds
|
||||||
public float abilityRadius;
|
public float abilityRadius;
|
||||||
public float abilityMagnitude;
|
|
||||||
public float abilityDuration;
|
public float abilityDuration;
|
||||||
public float abilityCooldownTime;
|
public float abilityMagnitude;
|
||||||
[Header("Ability Prefab")]
|
|
||||||
public GameObject prefab;
|
|
||||||
|
|
||||||
/// <summary>
|
[SerializeField]
|
||||||
/// Executes the ability's specific behavior.
|
private GameObject abilityPrefab; // Prefab associated with this ability
|
||||||
/// </summary>
|
|
||||||
public abstract void Execute(ServerCharacter character, Vector3 targetPosition);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the prefab associated with this ability.
|
|
||||||
/// </summary>
|
|
||||||
public GameObject GetPrefab()
|
public GameObject GetPrefab()
|
||||||
{
|
{
|
||||||
return prefab;
|
return abilityPrefab;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void ActivateAbility(GameObject owner)
|
||||||
|
{
|
||||||
|
Activate(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void Activate(GameObject owner); // Logic for the specific ability
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
||||||
using UnityEngine;
|
|
||||||
using Unity.Netcode;
|
|
||||||
|
|
||||||
[CreateAssetMenu(menuName = "Abilities/DashNCrash")]
|
|
||||||
public class DashNCrashAbility : Ability
|
|
||||||
{
|
|
||||||
[Header("Dash Settings")]
|
|
||||||
public float dashSpeed = 10f;
|
|
||||||
public float dashDuration = 0.5f;
|
|
||||||
|
|
||||||
|
|
||||||
public override void Execute(ServerCharacter character, Vector3 targetPosition)
|
|
||||||
{
|
|
||||||
Debug.Log($"Executing DashNCrash for character {character.OwnerClientId} at {targetPosition}.");
|
|
||||||
|
|
||||||
// Start the dash
|
|
||||||
character.Movement.StartDash(targetPosition, dashSpeed, dashDuration);
|
|
||||||
|
|
||||||
// Delay spawning the slow zone until after the dash
|
|
||||||
character.StartCoroutine(SpawnSlowZoneAfterDash(character, targetPosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator SpawnSlowZoneAfterDash(ServerCharacter character, Vector3 position)
|
|
||||||
{
|
|
||||||
yield return new WaitForSeconds(dashDuration + 0.25f);
|
|
||||||
|
|
||||||
// Spawn the slow zone prefab at the dash's end position
|
|
||||||
var prefab = GetPrefab();
|
|
||||||
if (prefab != null)
|
|
||||||
{
|
|
||||||
GameObject instance = Instantiate(prefab, character.transform.position, Quaternion.identity);
|
|
||||||
var networkObject = instance.GetComponent<NetworkObject>();
|
|
||||||
|
|
||||||
if (networkObject != null)
|
|
||||||
{
|
|
||||||
networkObject.Spawn();
|
|
||||||
Debug.Log($"Slow Zone spawned at {position}.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError("Slow Zone prefab must have a NetworkObject component.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
||||||
using Unity.Netcode;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(SphereCollider))]
|
|
||||||
public class DashNCrashPrefab : NetworkBehaviour
|
|
||||||
{
|
|
||||||
[Header("Slow Zone Settings")]
|
|
||||||
public Ability Ability;
|
|
||||||
public GameObject visualEffectPrefab; // Prefab for visualizing the area
|
|
||||||
|
|
||||||
private HashSet<ServerCharacter> affectedPlayers = new HashSet<ServerCharacter>();
|
|
||||||
private SphereCollider zoneCollider;
|
|
||||||
private GameObject visualEffectInstance;
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
zoneCollider = GetComponent<SphereCollider>();
|
|
||||||
|
|
||||||
// Spawn the visual effect
|
|
||||||
if (visualEffectPrefab)
|
|
||||||
{
|
|
||||||
visualEffectInstance = Instantiate(visualEffectPrefab, transform.position, Quaternion.identity);
|
|
||||||
visualEffectInstance.transform.localScale = Vector3.one * Ability.abilityRadius * 2f; // Adjust scale to match the radius
|
|
||||||
}
|
|
||||||
|
|
||||||
// Automatically destroy after the ability duration
|
|
||||||
StartCoroutine(DelayedDestroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
|
||||||
{
|
|
||||||
if (other.TryGetComponent<ServerCharacter>(out var player))
|
|
||||||
{
|
|
||||||
if (!player.IsCrow && affectedPlayers.Add(player)) // Only affect non-crow players
|
|
||||||
{
|
|
||||||
player.Movement.SetSpeedModifier(Ability.abilityMagnitude);
|
|
||||||
Debug.Log($"{player.name} entered the slow zone. Speed reduced.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTriggerExit(Collider other)
|
|
||||||
{
|
|
||||||
if (other.TryGetComponent<ServerCharacter>(out var player))
|
|
||||||
{
|
|
||||||
if (affectedPlayers.Remove(player))
|
|
||||||
{
|
|
||||||
player.Movement.ResetSpeedModifier();
|
|
||||||
Debug.Log($"{player.name} exited the slow zone. Speed restored.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
// Restore speed for all players when the zone is destroyed
|
|
||||||
foreach (var player in affectedPlayers)
|
|
||||||
{
|
|
||||||
player.Movement.ResetSpeedModifier();
|
|
||||||
Debug.Log($"{player.name}'s speed restored due to slow zone destruction.");
|
|
||||||
}
|
|
||||||
|
|
||||||
affectedPlayers.Clear();
|
|
||||||
|
|
||||||
// Destroy the visual effect
|
|
||||||
if (visualEffectInstance)
|
|
||||||
{
|
|
||||||
Destroy(visualEffectInstance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator DelayedDestroy()
|
|
||||||
{
|
|
||||||
yield return new WaitForSeconds(Ability.abilityDuration);
|
|
||||||
|
|
||||||
if (IsServer)
|
|
||||||
{
|
|
||||||
DespawnZone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DespawnZone()
|
|
||||||
{
|
|
||||||
if (IsServer)
|
|
||||||
{
|
|
||||||
var networkObject = GetComponent<NetworkObject>();
|
|
||||||
if (networkObject != null)
|
|
||||||
{
|
|
||||||
networkObject.Despawn(true); // Despawn and destroy on the server
|
|
||||||
Debug.Log("SlowZonePrefab has been despawned and destroyed.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError("SlowZonePrefab is missing a NetworkObject component!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using Unity.Netcode;
|
|
||||||
|
|
||||||
public class PlayerScoreComponent : NetworkBehaviour
|
|
||||||
{
|
|
||||||
public int CurrentScore { get; private set; }
|
|
||||||
|
|
||||||
public override void OnNetworkSpawn()
|
|
||||||
{
|
|
||||||
if (IsOwner && IsClient)
|
|
||||||
{
|
|
||||||
Debug.Log($"[PlayerScoreComponent] Requesting score initialization for Player {OwnerClientId}");
|
|
||||||
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId);
|
|
||||||
}
|
|
||||||
// For the server player (host), ensure the PlayerScoreComponent is registered properly
|
|
||||||
if (IsServer && OwnerClientId == NetworkManager.Singleton.LocalClientId)
|
|
||||||
{
|
|
||||||
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateScore(int newScore)
|
|
||||||
{
|
|
||||||
CurrentScore = newScore;
|
|
||||||
Debug.Log($"[PlayerScoreComponent] Player {OwnerClientId} score updated to {newScore}.");
|
|
||||||
UpdateScoreUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateScoreUI()
|
|
||||||
{
|
|
||||||
// Update the player's score display in the UI.
|
|
||||||
Debug.Log($"[PlayerScoreComponent] Updated score UI for Player {OwnerClientId}: {CurrentScore}");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a73f85cd904406945a2192aaecb2c310
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,167 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Unity.Multiplayer.Samples.BossRoom;
|
|
||||||
using UnityEngine;
|
|
||||||
using Unity.Netcode;
|
|
||||||
|
|
||||||
public class ScoreManager : NetworkBehaviour
|
|
||||||
{
|
|
||||||
public static ScoreManager Instance { get; private set; }
|
|
||||||
|
|
||||||
private Dictionary<ulong, int> playerScores = new Dictionary<ulong, int>();
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
if (Instance != null && Instance != this)
|
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Instance = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnNetworkSpawn()
|
|
||||||
{
|
|
||||||
if (IsServer)
|
|
||||||
{
|
|
||||||
StartCrowPenaltyCoroutineServerRpc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ServerRpc(RequireOwnership = false)]
|
|
||||||
public void InitializePlayerScoreServerRpc(ulong ownerClientId)
|
|
||||||
{
|
|
||||||
if (!playerScores.ContainsKey(ownerClientId))
|
|
||||||
{
|
|
||||||
playerScores[ownerClientId] = 200;
|
|
||||||
Debug.Log($"[ScoreManager] Player {ownerClientId} initialized with a starting score of 200.");
|
|
||||||
UpdatePlayerScoreClientRpc(ownerClientId, 200);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"[ScoreManager] Player {ownerClientId} already initialized.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void UpdatePlayerScore(ulong ownerClientId, int newScore)
|
|
||||||
{
|
|
||||||
if (playerScores.ContainsKey(ownerClientId))
|
|
||||||
{
|
|
||||||
playerScores[ownerClientId] = newScore;
|
|
||||||
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {newScore}.");
|
|
||||||
UpdatePlayerScoreClientRpc(ownerClientId, newScore);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddPlayerScore(ulong ownerClientId, int newScore)
|
|
||||||
{
|
|
||||||
if (playerScores.ContainsKey(ownerClientId))
|
|
||||||
{
|
|
||||||
playerScores[ownerClientId] += newScore;
|
|
||||||
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {playerScores[ownerClientId]}.");
|
|
||||||
UpdatePlayerScoreClientRpc(ownerClientId, playerScores[ownerClientId]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SubtractPlayerScore(ulong ownerClientId, int scoreToSubtract)
|
|
||||||
{
|
|
||||||
if (playerScores.ContainsKey(ownerClientId))
|
|
||||||
{
|
|
||||||
int value = Mathf.Max(0, playerScores[ownerClientId] - scoreToSubtract);
|
|
||||||
playerScores[ownerClientId] = value;
|
|
||||||
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {playerScores[ownerClientId]}.");
|
|
||||||
UpdatePlayerScoreClientRpc(ownerClientId, playerScores[ownerClientId]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int GetPlayerScore(ulong ownerClientId)
|
|
||||||
{
|
|
||||||
if (playerScores.TryGetValue(ownerClientId, out var score))
|
|
||||||
{
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}.");
|
|
||||||
return 0; // Default score
|
|
||||||
}
|
|
||||||
|
|
||||||
[ServerRpc]
|
|
||||||
public void StartCrowPenaltyCoroutineServerRpc()
|
|
||||||
{
|
|
||||||
StartCoroutine(ApplyCrowPenaltyCoroutine());
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator ApplyCrowPenaltyCoroutine()
|
|
||||||
{
|
|
||||||
yield return new WaitUntil(() => PlatformManager.Instance != null && PlatformManager.Instance.AreAllPlatformsOccupied());
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var modifications = new List<KeyValuePair<ulong, int>>();
|
|
||||||
|
|
||||||
foreach (var entry in playerScores)
|
|
||||||
{
|
|
||||||
var ownerClientId = entry.Key;
|
|
||||||
var score = entry.Value;
|
|
||||||
|
|
||||||
// Check if the player is the crow
|
|
||||||
if (CrowManager.Instance != null && CrowManager.Instance.GetCurrentCrow().OwnerClientId == ownerClientId)
|
|
||||||
{
|
|
||||||
var newScore = score - 2;
|
|
||||||
modifications.Add(new KeyValuePair<ulong, int>(ownerClientId, newScore));
|
|
||||||
Debug.Log($"[ScoreManager] Applied crow penalty to Player {ownerClientId}. New score: {newScore}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the modifications after the iteration
|
|
||||||
foreach (var modification in modifications)
|
|
||||||
{
|
|
||||||
UpdatePlayerScore(modification.Key, modification.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the next penalty application
|
|
||||||
yield return new WaitForSeconds(5f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ClientRpc]
|
|
||||||
public void UpdatePlayerScoreClientRpc(ulong ownerClientId, int newScore)
|
|
||||||
{
|
|
||||||
Debug.Log($"[ScoreManager] Received score update for Player {ownerClientId}: {newScore}");
|
|
||||||
var playerScoreComponent = FindPlayerScoreComponent(ownerClientId);
|
|
||||||
if (playerScoreComponent != null)
|
|
||||||
{
|
|
||||||
playerScoreComponent.UpdateScore(newScore);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"[ScoreManager] Could not find PlayerScoreComponent for Player {ownerClientId}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private PlayerScoreComponent FindPlayerScoreComponent(ulong ownerClientId)
|
|
||||||
{
|
|
||||||
foreach (var scoreComponent in FindObjectsOfType<PlayerScoreComponent>())
|
|
||||||
{
|
|
||||||
if (scoreComponent.OwnerClientId == ownerClientId)
|
|
||||||
{
|
|
||||||
return scoreComponent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Debug.LogError($"[ScoreManager] Could not find PlayerScoreComponent for Player {ownerClientId}");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c42f66f946855da4b99f79c5bde1d545
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu(menuName = "Abilities/Slow Zone Ability")]
|
||||||
|
public class SlowZoneAbility : Ability
|
||||||
|
{
|
||||||
|
protected override void Activate(GameObject owner)
|
||||||
|
{
|
||||||
|
// No direct logic here, spawning is handled in AbilitySystem
|
||||||
|
Debug.Log($"SlowZoneAbility activated by {owner.name}.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
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 Ability Ability;
|
||||||
|
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(Ability.abilityDuration);
|
||||||
|
|
||||||
|
// Destroy the zone after applying the slow effect
|
||||||
|
DespawnZone();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplySlowToPlayers()
|
||||||
|
{
|
||||||
|
// Find all colliders in the zone
|
||||||
|
Collider[] hitColliders = Physics.OverlapSphere(transform.position, Ability.abilityRadius);
|
||||||
|
foreach (var collider in hitColliders)
|
||||||
|
{
|
||||||
|
if (collider.TryGetComponent<ServerCharacter>(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.Movement.SetSpeedModifier(Ability.abilityMagnitude);
|
||||||
|
|
||||||
|
// Wait for the slow duration
|
||||||
|
yield return new WaitForSeconds(Ability.abilityDuration);
|
||||||
|
|
||||||
|
// Restore the original speed
|
||||||
|
player.Movement.ResetSpeedModifier();
|
||||||
|
Debug.Log($"{player.name}'s speed is restored.");
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DespawnZone()
|
||||||
|
{
|
||||||
|
if (IsServer)
|
||||||
|
{
|
||||||
|
var networkObject = GetComponent<NetworkObject>();
|
||||||
|
if (networkObject != null)
|
||||||
|
{
|
||||||
|
networkObject.Despawn(true); // Despawn and destroy on the server
|
||||||
|
Debug.Log("SlowZonePrefab has been despawned and destroyed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("SlowZonePrefab is missing a NetworkObject component!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug visualization for the slow zone in the editor
|
||||||
|
private void OnDrawGizmos()
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.cyan;
|
||||||
|
Gizmos.DrawWireSphere(transform.position, Ability.abilityRadius);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue