using UnityEngine;
namespace Minigames.DivingForPictures
{
///
/// Collision behavior that handles damage from mobile obstacles.
/// Uses trigger-based collision detection with shared immunity state.
///
public class ObstacleCollision : PlayerCollisionBehavior
{
[Header("Damage Settings")]
[Tooltip("Base damage amount dealt by obstacles")]
[SerializeField] private float baseDamage = 1f;
[Tooltip("Whether to use the obstacle's individual damage value or the base damage")]
[SerializeField] private bool useObstacleDamageValue = true;
protected override void HandleCollisionResponse(Collider2D obstacle)
{
float damageAmount = baseDamage;
// Try to get damage from the obstacle component if enabled
if (useObstacleDamageValue)
{
FloatingObstacle obstacleComponent = obstacle.GetComponent();
if (obstacleComponent != null)
{
damageAmount = obstacleComponent.Damage;
// Mark the obstacle as having dealt damage to prevent multiple hits
obstacleComponent.MarkDamageDealt();
}
}
// Apply damage (this could be extended to integrate with a health system)
ApplyDamage(damageAmount);
Debug.Log($"[ObstacleCollision] Player took {damageAmount} damage from obstacle {obstacle.gameObject.name}");
}
///
/// Applies damage to the player
/// Override this method to integrate with your health/damage system
///
/// Amount of damage to apply
protected virtual void ApplyDamage(float damage)
{
// For now, just log the damage
// In a full implementation, this would reduce player health, trigger UI updates, etc.
Debug.Log($"[ObstacleCollision] Applied {damage} damage to player");
// TODO: Integrate with health system when available
// Example: playerHealth.TakeDamage(damage);
}
///
/// Override to prevent input blocking during damage immunity
/// Since obstacles pass through the player, we don't want to block input
///
protected override void OnImmunityStart()
{
Debug.Log($"[ObstacleCollision] Damage immunity started for {damageImmunityDuration} seconds");
// Don't block input for obstacle damage - let player keep moving
// The shared immunity system will handle the collision prevention
}
///
/// Override to handle immunity end
///
protected override void OnImmunityEnd()
{
Debug.Log($"[ObstacleCollision] Damage immunity ended");
// No special handling needed - shared immunity system handles collider re-enabling
}
///
/// Public method to set base damage at runtime
///
public void SetBaseDamage(float damage)
{
baseDamage = damage;
}
///
/// Public method to toggle between base damage and obstacle-specific damage
///
public void SetUseObstacleDamage(bool useObstacleDamage)
{
useObstacleDamageValue = useObstacleDamage;
}
}
}