Finish work
This commit is contained in:
@@ -20,6 +20,9 @@ namespace Minigames.FortFight.Fort
|
||||
[SerializeField] private BlockSize size = BlockSize.Medium;
|
||||
[SerializeField] private bool isWeakPoint = false;
|
||||
|
||||
[Tooltip("Fixed HP value for this block (default: 10)")]
|
||||
[SerializeField] private float blockHp = 10f;
|
||||
|
||||
[Header("Weak Point Settings (if applicable)")]
|
||||
[Tooltip("Visual indicator shown in editor/game for weak points")]
|
||||
[SerializeField] private GameObject weakPointVisualIndicator;
|
||||
@@ -146,15 +149,8 @@ namespace Minigames.FortFight.Fort
|
||||
|
||||
private void CalculateHp()
|
||||
{
|
||||
// Get material config
|
||||
var materialConfig = CachedSettings.GetMaterialConfig(material);
|
||||
float baseMaterialHp = materialConfig?.baseHp ?? 20f;
|
||||
|
||||
// Get size config
|
||||
var sizeConfig = CachedSettings.GetSizeConfig(size);
|
||||
float sizeMultiplier = sizeConfig?.hpMultiplier ?? 1f;
|
||||
|
||||
maxHp = baseMaterialHp * sizeMultiplier;
|
||||
// Use fixed block HP value (default 10)
|
||||
maxHp = blockHp;
|
||||
currentHp = maxHp;
|
||||
|
||||
Logging.Debug($"[FortBlock] {gameObject.name} initialized: {material} {size}, HP: {maxHp}");
|
||||
|
||||
@@ -52,6 +52,10 @@ namespace Minigames.FortFight.Fort
|
||||
public int InitialBlockCount => initialBlockCount;
|
||||
public bool IsDefeated { get; private set; }
|
||||
|
||||
// Aliases for consistency
|
||||
public float MaxHp => maxFortHp;
|
||||
public float CurrentHp => currentFortHp;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private State
|
||||
@@ -171,6 +175,9 @@ namespace Minigames.FortFight.Fort
|
||||
RegisterBlock(block);
|
||||
}
|
||||
|
||||
// Step 3: Initialize current HP to match max HP (sum of all blocks)
|
||||
currentFortHp = maxFortHp;
|
||||
|
||||
initialBlockCount = blocks.Count;
|
||||
Logging.Debug($"[FortController] {fortName} - Initialized and registered {blocks.Count} blocks, Total HP: {maxFortHp:F0}");
|
||||
}
|
||||
@@ -181,7 +188,7 @@ namespace Minigames.FortFight.Fort
|
||||
/// </summary>
|
||||
private void RegisterWithManager()
|
||||
{
|
||||
Core.FortManager manager = FindFirstObjectByType<Core.FortManager>();
|
||||
Core.FortManager manager = Core.FortManager.Instance;
|
||||
|
||||
if (manager == null)
|
||||
{
|
||||
@@ -207,8 +214,9 @@ namespace Minigames.FortFight.Fort
|
||||
if (!blocks.Contains(block))
|
||||
{
|
||||
blocks.Add(block);
|
||||
|
||||
// Only add to max HP, current HP will be calculated once at end of initialization
|
||||
maxFortHp += block.MaxHp;
|
||||
currentFortHp += block.MaxHp;
|
||||
|
||||
// Subscribe to block events
|
||||
block.OnBlockDestroyed += HandleBlockDestroyed;
|
||||
@@ -259,9 +267,8 @@ namespace Minigames.FortFight.Fort
|
||||
// Remove from list
|
||||
blocks.Remove(block);
|
||||
|
||||
// Update current HP
|
||||
currentFortHp -= blockMaxHp;
|
||||
currentFortHp = Mathf.Max(0f, currentFortHp);
|
||||
// Recalculate HP by summing all remaining blocks (consistent calculation method)
|
||||
RecalculateFortHp();
|
||||
|
||||
// Notify listeners
|
||||
OnBlockDestroyed?.Invoke(block);
|
||||
@@ -279,7 +286,38 @@ namespace Minigames.FortFight.Fort
|
||||
private void HandleBlockDamaged(float currentBlockHp, float maxBlockHp)
|
||||
{
|
||||
// Block damaged but not destroyed
|
||||
// Could add visual feedback here if needed
|
||||
Logging.Debug($"[FortController] {fortName} - Block damaged! CurrentBlockHP: {currentBlockHp}/{maxBlockHp}");
|
||||
|
||||
// Recalculate current fort HP based on all block HP
|
||||
RecalculateFortHp();
|
||||
|
||||
// Notify UI to update
|
||||
int listenerCount = OnFortDamaged?.GetInvocationList()?.Length ?? 0;
|
||||
Logging.Debug($"[FortController] {fortName} - Firing OnFortDamaged event. HP: {HpPercentage:F1}%. Listeners: {listenerCount}");
|
||||
OnFortDamaged?.Invoke(0f, HpPercentage);
|
||||
|
||||
// Check defeat condition after damage
|
||||
CheckDefeatCondition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalculate total fort HP by summing all block HP
|
||||
/// </summary>
|
||||
private void RecalculateFortHp()
|
||||
{
|
||||
currentFortHp = 0f;
|
||||
foreach (var block in blocks)
|
||||
{
|
||||
if (block != null)
|
||||
{
|
||||
currentFortHp += block.CurrentHp;
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugInfo)
|
||||
{
|
||||
Logging.Debug($"[FortController] {fortName} - HP recalculated: {currentFortHp:F0}/{maxFortHp:F0} ({HpPercentage:F1}%)");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -288,17 +326,32 @@ namespace Minigames.FortFight.Fort
|
||||
|
||||
private void CheckDefeatCondition()
|
||||
{
|
||||
if (IsDefeated) return;
|
||||
if (IsDefeated)
|
||||
{
|
||||
Logging.Debug($"[FortController] {fortName} - Already defeated, skipping check");
|
||||
return;
|
||||
}
|
||||
|
||||
float defeatThreshold = CachedSettings?.FortDefeatThreshold ?? 0.3f;
|
||||
float defeatThresholdPercent = defeatThreshold * 100f;
|
||||
|
||||
// Defeat if HP below threshold
|
||||
if (HpPercentage < defeatThresholdPercent)
|
||||
Logging.Debug($"[FortController] {fortName} - Checking defeat: HP={currentFortHp:F1}/{maxFortHp:F1} ({HpPercentage:F1}%) vs threshold={defeatThresholdPercent:F1}%");
|
||||
|
||||
// Defeat if HP at or below threshold
|
||||
if (HpPercentage <= defeatThresholdPercent)
|
||||
{
|
||||
IsDefeated = true;
|
||||
Logging.Debug($"[FortController] {fortName} DEFEATED! Final HP: {HpPercentage:F1}% (threshold: {defeatThresholdPercent:F1}%)");
|
||||
|
||||
int listeners = OnFortDefeated?.GetInvocationList()?.Length ?? 0;
|
||||
Logging.Debug($"[FortController] {fortName} DEFEATED! Final HP: {HpPercentage:F1}% (threshold: {defeatThresholdPercent:F1}%). Firing event to {listeners} listeners...");
|
||||
|
||||
OnFortDefeated?.Invoke();
|
||||
|
||||
Logging.Debug($"[FortController] {fortName} - OnFortDefeated event fired");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Debug($"[FortController] {fortName} - Not defeated yet ({HpPercentage:F1}% >= {defeatThresholdPercent:F1}%)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user