Files
AppleHillsProduction/Assets/Scripts/Minigames/FortFight/Projectiles/VacuumProjectile.cs

106 lines
3.8 KiB
C#
Raw Normal View History

2025-12-03 22:17:12 +01:00
using Core;
2025-12-02 23:56:13 +01:00
using UnityEngine;
namespace Minigames.FortFight.Projectiles
{
/// <summary>
/// Vacuum projectile - high mass, slides along ground after landing.
2025-12-03 22:17:12 +01:00
/// On floor/block impact: applies constant force to the right and destroys blocks.
2025-12-02 23:56:13 +01:00
/// </summary>
public class VacuumProjectile : ProjectileBase
{
private bool isSliding = false;
2025-12-03 22:17:12 +01:00
private int blocksDestroyed = 0;
private int maxBlocksToDestroy = 3;
private Vector2 slideDirection;
2025-12-02 23:56:13 +01:00
2025-12-03 22:17:12 +01:00
protected override void OnHit(Collision2D collision)
2025-12-02 23:56:13 +01:00
{
2025-12-03 22:17:12 +01:00
// If already sliding, count block destruction
if (isSliding)
2025-12-02 23:56:13 +01:00
{
2025-12-03 22:17:12 +01:00
var block = collision.gameObject.GetComponent<Fort.FortBlock>();
if (block != null)
{
// Spawn impact effect on each block hit
SpawnImpactEffect(collision.contacts[0].point);
// Get damage from settings
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
float blockDamage = settings?.VacuumBlockDamage ?? 999f;
// Deal high damage to destroy block instantly
block.TakeDamage(blockDamage);
blocksDestroyed++;
Logging.Debug($"[VacuumProjectile] Destroyed block {blocksDestroyed}/{maxBlocksToDestroy}");
if (blocksDestroyed >= maxBlocksToDestroy)
{
Logging.Debug("[VacuumProjectile] Destroyed max blocks - stopping");
DestroyProjectile();
}
}
// Don't destroy - keep sliding
return;
2025-12-02 23:56:13 +01:00
}
2025-12-03 22:17:12 +01:00
// First hit - spawn impact effect and start sliding
SpawnImpactEffect(collision.contacts[0].point);
Logging.Debug("[VacuumProjectile] Hit surface - starting slide");
StartSliding();
// Don't destroy - keep sliding!
2025-12-02 23:56:13 +01:00
}
/// <summary>
2025-12-03 22:17:12 +01:00
/// Start sliding behavior after hitting surface
2025-12-02 23:56:13 +01:00
/// </summary>
private void StartSliding()
{
if (isSliding) return;
isSliding = true;
2025-12-03 22:17:12 +01:00
// Get settings
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
if (settings != null)
{
maxBlocksToDestroy = settings.VacuumDestroyBlockCount;
}
// Determine slide direction based on horizontal velocity (preserve launch direction)
2025-12-02 23:56:13 +01:00
if (rb2D != null)
{
2025-12-03 22:17:12 +01:00
slideDirection = rb2D.linearVelocity.x >= 0 ? Vector2.right : Vector2.left;
2025-12-02 23:56:13 +01:00
2025-12-03 22:17:12 +01:00
rb2D.gravityScale = 0f;
rb2D.linearVelocity = Vector2.zero; // Stop all momentum
2025-12-02 23:56:13 +01:00
2025-12-03 22:17:12 +01:00
Logging.Debug($"[VacuumProjectile] Started sliding in direction: {slideDirection}");
2025-12-02 23:56:13 +01:00
}
}
2025-12-03 22:17:12 +01:00
private void FixedUpdate()
2025-12-02 23:56:13 +01:00
{
2025-12-03 22:17:12 +01:00
if (isSliding && rb2D != null)
{
// Set constant velocity in slide direction
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
float slideSpeed = settings?.VacuumSlideSpeed ?? 10f;
rb2D.linearVelocity = slideDirection * slideSpeed;
}
2025-12-02 23:56:13 +01:00
}
/// <summary>
2025-12-03 22:17:12 +01:00
/// Clean up when destroyed
2025-12-02 23:56:13 +01:00
/// </summary>
protected override void DestroyProjectile()
{
2025-12-03 22:17:12 +01:00
isSliding = false;
base.DestroyProjectile();
2025-12-02 23:56:13 +01:00
}
}
}