106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
using Core;
|
|
using UnityEngine;
|
|
|
|
namespace Minigames.FortFight.Projectiles
|
|
{
|
|
/// <summary>
|
|
/// Vacuum projectile - high mass, slides along ground after landing.
|
|
/// On floor/block impact: applies constant force to the right and destroys blocks.
|
|
/// </summary>
|
|
public class VacuumProjectile : ProjectileBase
|
|
{
|
|
private bool isSliding = false;
|
|
private int blocksDestroyed = 0;
|
|
private int maxBlocksToDestroy = 3;
|
|
private Vector2 slideDirection;
|
|
|
|
protected override void OnHit(Collision2D collision)
|
|
{
|
|
// If already sliding, count block destruction
|
|
if (isSliding)
|
|
{
|
|
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;
|
|
}
|
|
|
|
// 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!
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start sliding behavior after hitting surface
|
|
/// </summary>
|
|
private void StartSliding()
|
|
{
|
|
if (isSliding) return;
|
|
|
|
isSliding = true;
|
|
|
|
// 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)
|
|
if (rb2D != null)
|
|
{
|
|
slideDirection = rb2D.linearVelocity.x >= 0 ? Vector2.right : Vector2.left;
|
|
|
|
rb2D.gravityScale = 0f;
|
|
rb2D.linearVelocity = Vector2.zero; // Stop all momentum
|
|
|
|
Logging.Debug($"[VacuumProjectile] Started sliding in direction: {slideDirection}");
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clean up when destroyed
|
|
/// </summary>
|
|
protected override void DestroyProjectile()
|
|
{
|
|
isSliding = false;
|
|
base.DestroyProjectile();
|
|
}
|
|
}
|
|
}
|
|
|