/// <summary>
    /// Select a skill.
    /// </summary>
    /// <param name="skill"> The skill being selected. </param>
    public void SkillSelection(BaseSkill skill, SkillButton button)
    {
        if (ParticlesManager.m_Instance.m_ActiveSkill != null)        // || (ParticlesManager.m_Instance.m_ActiveSkill.m_Skill != null && ParticlesManager.m_Instance.m_ActiveSkill.m_Targets != null))
        {
            Debug.LogWarning($"<color=#9c4141>[Skill]</color> {ParticlesManager.m_Instance.m_ActiveSkill.m_Skill.m_SkillName} is currently active!");
            return;
        }
        // Don't allow progress if the character is an enemy (player can mouse over for info, but not use the skill)
        if (m_SelectedUnit.GetAllegiance() == Allegiance.Enemy)
        {
            return;
        }

        // Make sure the player has a unit selected.
        if (m_SelectedUnit != null)
        {
            // Check if the skill being cast is the heal skill.
            HealSkill hs = skill as HealSkill;
            if (hs != null)
            {
                // Check if this unit has Pestilence's passive (should be Pestilence but you never know).
                PestilencePassive pesPassive = m_SelectedUnit.GetPassiveSkill() as PestilencePassive;
                if (pesPassive != null)
                {
                    // If there is no heal resource remaining, output warning about it and leave function.
                    if (pesPassive.GetHealResource() < pesPassive.m_HealResourceCastCost)
                    {
                        Debug.LogWarning("Not enough heal resource for Pestilence to heal with.");
                        return;
                    }
                }
            }

            // Make sure the unit can afford to cast the skill and the skill isn't on cooldown before selecting it.
            // Just in case.
            if (m_SelectedUnit.GetActionPoints() >= skill.m_Cost && skill.GetCurrentCooldown() == 0)
            {
                foreach (SkillButton b in UIManager.m_Instance.m_SkillSlots)
                {
                    b.m_LightningImage.materialForRendering.SetFloat("_UIVerticalPan", 0);
                }
                button.m_LightningImage.materialForRendering.SetFloat("_UIVerticalPan", 1);

                // Update the GameManager's fields
                m_SelectedSkill  = skill;
                m_TargetingState = TargetingState.Skill;

                // Get the new affectable area.
                m_maxSkillRange = Grid.m_Instance.GetNodesWithinRadius(m_SelectedSkill.m_CastableDistance + m_SelectedSkill.m_AffectedRange, Grid.m_Instance.GetNode(m_SelectedUnit.transform.position), true);

                UpdateSkillPreview(null);
            }
        }
    }
Пример #2
0
    /// <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 + ".");
    }