161 lines
4.2 KiB
C#
161 lines
4.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 玩家技能系统(召唤师技能)
|
|
/// 管理技能释放和冷却
|
|
/// </summary>
|
|
public class PlayerSkillSystem : MonoBehaviour
|
|
{
|
|
[Header("技能1:群体治疗")]
|
|
public Button skill1Button;
|
|
public Text skill1CooldownText;
|
|
public float skill1Cooldown = 20f;
|
|
public float skill1HealAmount = 100f;
|
|
private float skill1RemainingCooldown = 0f;
|
|
|
|
[Header("技能2:全屏AOE")]
|
|
public Button skill2Button;
|
|
public Text skill2CooldownText;
|
|
public float skill2Cooldown = 20f;
|
|
public float skill2Damage = 80f;
|
|
private float skill2RemainingCooldown = 0f;
|
|
|
|
private void Start()
|
|
{
|
|
// 绑定按钮点击事件
|
|
if (skill1Button != null)
|
|
{
|
|
skill1Button.onClick.AddListener(UseSkill1);
|
|
}
|
|
|
|
if (skill2Button != null)
|
|
{
|
|
skill2Button.onClick.AddListener(UseSkill2);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// 更新技能1冷却
|
|
if (skill1RemainingCooldown > 0)
|
|
{
|
|
skill1RemainingCooldown -= Time.deltaTime;
|
|
if (skill1Button != null)
|
|
{
|
|
skill1Button.interactable = false;
|
|
}
|
|
if (skill1CooldownText != null)
|
|
{
|
|
skill1CooldownText.text = Mathf.CeilToInt(skill1RemainingCooldown).ToString();
|
|
skill1CooldownText.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (skill1Button != null)
|
|
{
|
|
skill1Button.interactable = true;
|
|
}
|
|
if (skill1CooldownText != null)
|
|
{
|
|
skill1CooldownText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
// 更新技能2冷却
|
|
if (skill2RemainingCooldown > 0)
|
|
{
|
|
skill2RemainingCooldown -= Time.deltaTime;
|
|
if (skill2Button != null)
|
|
{
|
|
skill2Button.interactable = false;
|
|
}
|
|
if (skill2CooldownText != null)
|
|
{
|
|
skill2CooldownText.text = Mathf.CeilToInt(skill2RemainingCooldown).ToString();
|
|
skill2CooldownText.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (skill2Button != null)
|
|
{
|
|
skill2Button.interactable = true;
|
|
}
|
|
if (skill2CooldownText != null)
|
|
{
|
|
skill2CooldownText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用技能1:群体治疗
|
|
/// </summary>
|
|
public void UseSkill1()
|
|
{
|
|
if (skill1RemainingCooldown > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Debug.Log($"释放技能1:群体治疗(恢复 {skill1HealAmount} 生命)");
|
|
|
|
// 对所有友方单位施加治疗
|
|
BuffSystem.Instance.ApplyGroupHeal(skill1HealAmount);
|
|
|
|
// 开始冷却
|
|
skill1RemainingCooldown = skill1Cooldown;
|
|
|
|
// TODO: 播放技能特效
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用技能2:全屏AOE伤害
|
|
/// </summary>
|
|
public void UseSkill2()
|
|
{
|
|
if (skill2RemainingCooldown > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Debug.Log($"释放技能2:全屏AOE(造成 {skill2Damage} 伤害)");
|
|
|
|
// 对所有敌方单位造成伤害
|
|
var enemies = FindObjectsOfType<UnitBase>();
|
|
int hitCount = 0;
|
|
|
|
foreach (var unit in enemies)
|
|
{
|
|
var team = unit.GetComponent<UnitTeam>();
|
|
if (team != null && team.teamId == 1) // 敌方
|
|
{
|
|
var healthBar = unit.GetComponent<WorldHealthBar>();
|
|
if (healthBar != null && !healthBar.IsDead)
|
|
{
|
|
healthBar.TakeDamage(skill2Damage);
|
|
hitCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
Debug.Log($"全屏AOE命中 {hitCount} 个敌人");
|
|
|
|
// 开始冷却
|
|
skill2RemainingCooldown = skill2Cooldown;
|
|
|
|
// TODO: 播放技能特效
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置所有技能冷却(测试用)
|
|
/// </summary>
|
|
public void ResetAllCooldowns()
|
|
{
|
|
skill1RemainingCooldown = 0f;
|
|
skill2RemainingCooldown = 0f;
|
|
}
|
|
}
|