/// <summary> /// Activate one of the unit's skills. /// </summary> /// <param name="skill"> The skill to activate. </param> public void ActivateSkill(BaseSkill skill, Node castLocation) { Debug.Log($"<color=#9c4141>[Skill] </color>{PlayerManager.m_Instance.GetSelectedUnit().name} casts {skill.m_SkillName}" + $" {(castLocation.unit ? $"at {castLocation.unit.name}" : "")} ({castLocation.m_NodeHighlight.name})"); // Doing my own search cause List.Find is gross. for (int i = 0; i < m_Skills.Count; ++i) { // Check if the unit has the skill being cast. if (m_Skills[i].m_SkillName == skill.m_SkillName) { skill.m_AffectedNodes = Grid.m_Instance.GetNodesWithinRadius(m_Skills[i].m_AffectedRange, castLocation, true); skill.m_CastNode = castLocation; if (m_PassiveSkill != null) { DamageSkill ds = skill as DamageSkill; // Check if skill being cast is a damage skill. if (ds != null) { // Make sure the skill knows what units it will affect, so we can check them for the passive. List <Unit> hitUnits = ds.FindAffectedUnits(); if (m_PassiveSkill.GetAffectSelf() == false) { // Check which units meet the prerequisits for the unit's passive. foreach (Unit u in hitUnits) { foreach (InflictableStatus status in m_StatusEffects) { if (status.CheckPrecondition(TriggerType.OnDealDamage) == true) { status.TakeEffect(this); } } // Add extra damage to the skill from status effect (if there is any). if (m_DealExtraDamage > 0) { ds.AddExtraDamage(m_DealExtraDamage); } if (m_PassiveSkill.CheckPrecondition(TriggerType.OnDealDamage, u)) { m_PassiveSkill.TakeEffect(u); } if (m_PassiveSkill.CheckPrecondition(TriggerType.OnDealDamage)) { m_PassiveSkill.TakeEffect(); } } } else { if (m_PassiveSkill.CheckPrecondition(TriggerType.OnDealDamage, this)) { m_PassiveSkill.TakeEffect(this); } if (m_PassiveSkill.CheckPrecondition(TriggerType.OnDealDamage)) { m_PassiveSkill.TakeEffect(this); } } } HealSkill hs = skill as HealSkill; if (hs != null) { PestilencePassive pp = m_PassiveSkill as PestilencePassive; if (pp != null) { pp.UseHealResource(); StatusEffectTooltipManager.m_Instance.UpdatePassive(); } } } if (skill.m_IsMagic) { // TODO Play cast system } skill.CastSkill(); transform.LookAt(castLocation.worldPosition); // Play skill animation m_animator.SetTrigger("TriggerSkill"); // Play the damage sound effect. //FMODUnity.RuntimeManager.PlayOneShot(m_Skills[i].m_CastEvent, transform.position); return; } } Debug.LogError("Skill " + skill.m_SkillName + " couldn't be found in " + gameObject.name + "."); }