成就系统 巨大修改 新的ui 黑白效果 等一堆

This commit is contained in:
2026-01-23 18:43:23 +08:00
parent f3ece026ca
commit 0e47864569
256 changed files with 134131 additions and 31192 deletions
+105 -4
View File
@@ -57,6 +57,12 @@ public class EnemyCombatant : MonoBehaviour, ICombatant
// notify listeners (UI/manager) that enemy revived
OnEnemyRevived?.Invoke(this);
// Notify SkillBuilder so ally skills with OnEnemyRevive can react
if (Application.isPlaying && SkillBuilder.Instance != null)
{
SkillBuilder.Instance.TriggerOnEnemyRevive(this);
}
// Trigger primary skill on revive if defined and trigger condition matches
TryTriggerPrimarySkill(SkillDefinition.SkillTrigger.OnEnemyRevive);
}
@@ -182,14 +188,109 @@ public class EnemyCombatant : MonoBehaviour, ICombatant
private void Die()
{
if (isDead) return;
isDead = true;
// notify listeners before possibly being reused
// Notify SkillBuilder so allies can react to each enemy death BEFORE listeners that may reuse this Enemy instance
if (Application.isPlaying)
{
// prefer singleton instance but fallback to scene lookup if singleton is null (robustness for scene initialization order)
if (SkillBuilder.Instance != null)
{
SkillBuilder.Instance.TriggerOnEnemyDead(this);
}
else
{
var sb = FindObjectOfType<SkillBuilder>();
if (sb != null)
{
Debug.LogWarning("[EnemyCombatant] SkillBuilder.Instance was null on Die(); using FindObjectOfType fallback");
sb.TriggerOnEnemyDead(this);
}
else
{
Debug.LogWarning("[EnemyCombatant] Die(): no SkillBuilder found to notify TriggerOnEnemyDead");
}
}
}
// Trigger primary skill on death if configured (enemy's own skill)
TryTriggerPrimarySkill(SkillDefinition.SkillTrigger.OnEnemyDead);
// notify listeners (UI/manager) that enemy died AFTER triggering skills so they operate on the current instance
OnEnemyDied?.Invoke(this);
// Trigger primary skill on death if configured
TryTriggerPrimarySkill(SkillDefinition.SkillTrigger.OnEnemyDead);
// Check whether all enemies are now defeated. Use currentHP/IsDead to determine status.
if (Application.isPlaying)
{
try
{
var all = GameObject.FindObjectsOfType<EnemyCombatant>(true);
bool anyAlive = false;
foreach (var e in all)
{
if (e == null) continue;
// treat an enemy as alive if its currentHP > 0 and not flagged dead
if (e.currentHP > 0 && !e.IsDead)
{
anyAlive = true; break;
}
}
if (!anyAlive)
{
// notify SkillBuilder about all enemies defeated
if (SkillBuilder.Instance != null)
{
SkillBuilder.Instance.TriggerOnAllEnemiesDefeated();
Debug.Log("[EnemyCombatant] All enemies defeated -> TriggerOnAllEnemiesDefeated fired via singleton");
}
else
{
var sb = FindObjectOfType<SkillBuilder>();
if (sb != null)
{
sb.TriggerOnAllEnemiesDefeated();
Debug.LogWarning("[EnemyCombatant] SkillBuilder.Instance was null when firing AllEnemiesDefeated; used FindObjectOfType fallback");
}
else
{
Debug.LogWarning("[EnemyCombatant] All enemies defeated but no SkillBuilder found to notify");
}
}
}
}
catch (Exception ex)
{
Debug.LogError($"[EnemyCombatant] Error while checking all-enemies-defeated: {ex}");
}
}
// Finally mark dead so further damage/heal is ignored
isDead = true;
}
// Utility: expose a read-only status
public bool IsDead => isDead;
// New: allow EffectSystem/SkillBuilder to adjust enemy max HP safely
public void SetMaxHP(int newMax, bool keepCurrentRatio = true)
{
if (newMax < 1) newMax = 1;
float ratio = maxHP > 0 ? (float)currentHP / maxHP : 1f;
maxHP = newMax;
if (keepCurrentRatio)
currentHP = Mathf.Clamp(Mathf.RoundToInt(ratio * maxHP), 0, maxHP);
else
currentHP = Mathf.Clamp(currentHP, 0, maxHP);
}
// New: allow adjusting enemy max mana (mirror of AllyCombatant)
public void SetMaxMana(int newMax, bool keepCurrentRatio = true)
{
if (newMax < 1) newMax = 1;
float ratio = maxMana > 0 ? (float)currentMana / maxMana : 1f;
maxMana = newMax;
if (keepCurrentRatio)
currentMana = Mathf.Clamp(Mathf.RoundToInt(ratio * maxMana), 0, maxMana);
else
currentMana = Mathf.Clamp(currentMana, 0, maxMana);
}
}