using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class Skill : MonoBehaviour { protected Character self; public int manaCost; public int movementCost; public int damage; protected SkillManager skillManager; protected BuffManager buffManager; protected List alliesInRange = new List(); protected List enemiesInRange = new List(); protected CharacterUIManager characterUIManager; public string description; public string skillName; private void Awake() { self = transform.parent.parent.GetComponent(); skillManager = transform.parent.GetComponent(); buffManager = self.transform.Find("BuffManager").GetComponent(); characterUIManager = transform.parent.parent.Find("CharacterUI").GetComponent(); Revise(); } public void SetRotation(Vector2 direction) { if(direction == Vector2.up) transform.localEulerAngles = new Vector3(0,0,180); if(direction == Vector2.right) transform.localEulerAngles = new Vector3(0,0,90); if(direction == Vector2.down) transform.localEulerAngles = new Vector3(0,0,0); if(direction == Vector2.left) transform.localEulerAngles = new Vector3(0,0,-90); } protected void Update() { if(Input.GetKeyDown("c")) { gameObject.SetActive(false); transform.parent.Find("SkillsGUI").gameObject.SetActive(true); } if(Input.GetKeyDown("z")) { if(ApplyRequestion()) { self.ChangeMovement(-movementCost); self.ChangeMana(-manaCost); skillManager.currentSkill.RemoveSkillState(); ApplySkill(); ApplySkillState(); } else characterUIManager.FloatingString("状态不满足"); gameObject.SetActive(false); self.SetIsUsingSkill(false); self.weaponManager.gameObject.SetActive(true); } } //关闭显示攻击范围 protected void OnTriggerExit2D(Collider2D other) { if(other.gameObject.layer == 8) { Cell cell = other.gameObject.GetComponent(); cell.SetMask(false); if(cell.currentCharacter != null) { if(self.groupNumber != cell.currentCharacter.groupNumber) enemiesInRange.Remove(cell.currentCharacter); else alliesInRange.Remove(cell.currentCharacter); } } } protected void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.layer == 8) { Cell cell = other.gameObject.GetComponent(); if(cell.currentCharacter != null) { if(self.groupNumber != cell.currentCharacter.groupNumber) enemiesInRange.Add(cell.currentCharacter); else alliesInRange.Add(cell.currentCharacter); } } } protected void OnTriggerStay2D(Collider2D other) { //技能有不同的攻击范围,选中角色时,可显示技能的攻击范围 //显示攻击范围 if(other.gameObject.layer == 8) { other.gameObject.GetComponent().SetMask(true); } } protected virtual bool ApplyRequestion() { if(enemiesInRange != null && self.GetCurrentMovement() >= movementCost && self.GetCurrentMana() >= manaCost) return true; return false; } public abstract void ApplySkill(); public abstract void ApplySkillState(); public abstract void RemoveSkillState(); protected abstract void Revise(); }