Update double input issues, pigman is no longer unbound, limit his weapon access too
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Core;
|
||||
using System.Collections;
|
||||
using Core;
|
||||
using Core.Settings;
|
||||
using Input;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.FortFight.Projectiles
|
||||
@@ -7,15 +9,76 @@ namespace Minigames.FortFight.Projectiles
|
||||
/// <summary>
|
||||
/// Trash Bag projectile - splits into multiple smaller pieces on impact.
|
||||
/// Deals AOE damage in a forward cone.
|
||||
/// Can be manually detonated mid-flight by tapping.
|
||||
/// </summary>
|
||||
public class TrashBagProjectile : ProjectileBase
|
||||
public class TrashBagProjectile : ProjectileBase, ITouchInputConsumer
|
||||
{
|
||||
[Header("Trash Bag Specific")]
|
||||
[Tooltip("Prefab for individual trash pieces (small debris)")]
|
||||
[SerializeField] private GameObject trashPiecePrefab;
|
||||
|
||||
[Tooltip("Visual indicator showing tap-to-explode is available")]
|
||||
[SerializeField] private GameObject indicator;
|
||||
|
||||
private bool inputEnabled = false;
|
||||
private bool hasExploded = false;
|
||||
|
||||
public override void Launch(Vector2 direction, float force)
|
||||
{
|
||||
base.Launch(direction, force);
|
||||
|
||||
// Start activation delay coroutine for tap-to-explode
|
||||
StartCoroutine(ActivationDelayCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator ActivationDelayCoroutine()
|
||||
{
|
||||
// Get activation delay from settings (use TrashBag-specific or default to 0.3s)
|
||||
var settings = GameManager.GetSettingsObject<IFortFightSettings>();
|
||||
float activationDelay = settings?.CeilingFanActivationDelay ?? 0.3f; // Reuse CeilingFan delay setting
|
||||
|
||||
// Wait for delay
|
||||
yield return new WaitForSeconds(activationDelay);
|
||||
|
||||
// Enable input and show indicator (if not already exploded)
|
||||
if (!hasExploded && !AbilityActivated)
|
||||
{
|
||||
inputEnabled = true;
|
||||
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(true);
|
||||
}
|
||||
|
||||
// Only register with InputManager if NOT AI-controlled
|
||||
if (!IsAIControlled && InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
Logging.Debug("[TrashBagProjectile] Tap-to-explode now available (Player controlled)");
|
||||
}
|
||||
else if (IsAIControlled)
|
||||
{
|
||||
Logging.Debug("[TrashBagProjectile] AI-controlled projectile, input disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ActivateAbility()
|
||||
{
|
||||
base.ActivateAbility();
|
||||
|
||||
if (AbilityActivated && !hasExploded)
|
||||
{
|
||||
Logging.Debug("[TrashBagProjectile] Ability activated - manual detonation");
|
||||
ExplodeAtCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHit(Collision2D collision)
|
||||
{
|
||||
// Prevent double-explosion if already manually detonated
|
||||
if (hasExploded) return;
|
||||
|
||||
// Deal initial damage from trash bag itself
|
||||
var block = collision.gameObject.GetComponent<Fort.FortBlock>();
|
||||
if (block != null)
|
||||
@@ -28,19 +91,57 @@ namespace Minigames.FortFight.Projectiles
|
||||
var settings = GameManager.GetSettingsObject<IFortFightSettings>();
|
||||
int pieceCount = settings?.TrashBagPieceCount ?? 8;
|
||||
|
||||
Logging.Debug($"[TrashBagProjectile] Splitting into {pieceCount} pieces");
|
||||
Logging.Debug($"[TrashBagProjectile] Impact explosion - splitting into {pieceCount} pieces");
|
||||
|
||||
// Get contact normal and impact point
|
||||
Vector2 hitNormal = collision.contacts[0].normal;
|
||||
Vector2 impactPoint = collision.contacts[0].point;
|
||||
|
||||
// Spawn trash pieces (NOT parented, so they persist as debris)
|
||||
// Mark as exploded and spawn trash pieces
|
||||
hasExploded = true;
|
||||
SpawnTrashPieces(impactPoint, hitNormal);
|
||||
|
||||
// Destroy trash bag after spawning pieces
|
||||
DestroyProjectile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explode at current position (manual detonation)
|
||||
/// </summary>
|
||||
private void ExplodeAtCurrentPosition()
|
||||
{
|
||||
if (hasExploded) return;
|
||||
|
||||
hasExploded = true;
|
||||
|
||||
// Unregister from input immediately
|
||||
UnregisterFromInput();
|
||||
|
||||
// Hide indicator
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(false);
|
||||
}
|
||||
|
||||
// Get current position and use velocity as "hit normal" direction
|
||||
Vector2 explosionPoint = transform.position;
|
||||
Vector2 explosionDirection = rb2D.linearVelocity.normalized;
|
||||
if (explosionDirection == Vector2.zero)
|
||||
{
|
||||
explosionDirection = LaunchDirection;
|
||||
}
|
||||
|
||||
var settings = GameManager.GetSettingsObject<IFortFightSettings>();
|
||||
int pieceCount = settings?.TrashBagPieceCount ?? 8;
|
||||
Logging.Debug($"[TrashBagProjectile] Manual detonation - splitting into {pieceCount} pieces");
|
||||
|
||||
// Spawn trash pieces
|
||||
SpawnTrashPieces(explosionPoint, explosionDirection);
|
||||
|
||||
// Destroy the trash bag
|
||||
DestroyProjectile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn multiple trash pieces in a cone away from the hit surface.
|
||||
/// Uses hit normal + projectile momentum for realistic splash effect.
|
||||
@@ -103,6 +204,64 @@ namespace Minigames.FortFight.Projectiles
|
||||
Logging.Debug($"[TrashBagProjectile] Spawned trash piece {i} in direction {pieceDirection}");
|
||||
}
|
||||
}
|
||||
|
||||
#region ITouchInputConsumer Implementation
|
||||
|
||||
public void OnTap(Vector2 worldPosition)
|
||||
{
|
||||
// Only respond if input is enabled
|
||||
if (inputEnabled && !hasExploded && !AbilityActivated)
|
||||
{
|
||||
Logging.Debug("[TrashBagProjectile] Tap detected - activating manual detonation");
|
||||
|
||||
// Hide indicator
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(false);
|
||||
}
|
||||
|
||||
ActivateAbility();
|
||||
|
||||
// Unregister immediately after tap
|
||||
UnregisterFromInput();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHoldStart(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for trash bag
|
||||
}
|
||||
|
||||
public void OnHoldMove(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for trash bag
|
||||
}
|
||||
|
||||
public void OnHoldEnd(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for trash bag
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister from input manager
|
||||
/// </summary>
|
||||
private void UnregisterFromInput()
|
||||
{
|
||||
if (InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
inputEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void DestroyProjectile()
|
||||
{
|
||||
// Ensure we unregister from input before destruction
|
||||
UnregisterFromInput();
|
||||
base.DestroyProjectile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user