コード例 #1
0
    /// <summary>
    /// 创建一个新的技能
    /// </summary>
    /// <param name="skillID"></param>
    /// <returns></returns>
    private SkillBase CreateSkill(int skillID)
    {
        SkillCategory skillType = (SkillCategory)m_CfgSkillProxy.GetSkillGrow(skillID).CastWay;

        SkillBase newSkillInstance = null;

        switch (skillType)
        {
        case SkillCategory.Immediate:
        case SkillCategory.Immediate_Trigger:
            newSkillInstance = new SkillImmediate();
            break;

        case SkillCategory.Immediate_MultiShot:
            newSkillInstance = new SkillImmediateMultiShot();
            break;

        case SkillCategory.Chanting:
        case SkillCategory.Chanting_Trigger:
            newSkillInstance = new SkillChanting();
            break;

        case SkillCategory.Charge:
            newSkillInstance = new SkillCharging();
            break;

        case SkillCategory.AutoChannel:
            newSkillInstance = new SkillChannellingBeam(SkillChannellingBeam.ChannellingType.Auto);
            break;

        case SkillCategory.ManualChannel:
            newSkillInstance = new SkillChannellingBeam(SkillChannellingBeam.ChannellingType.Manual);
            break;

        case SkillCategory.RapidFire:
            newSkillInstance = new SkillRapidFire();
            break;

        case SkillCategory.Immediate_MultiShot_MultiTarget:
            newSkillInstance = new SkillImmediateMultiShot_MultiTarget();
            break;

        case SkillCategory.Immediate_MultiTarget:
            newSkillInstance = new SkillImmediate_MultiTarget();
            break;

        case SkillCategory.SelectSkillByBuff:
            newSkillInstance = new SkillSelectByBuff();
            break;

        case SkillCategory.MiningBeam:
            newSkillInstance = new SkillMiningBeam(SkillMiningBeam.ChannellingType.Manual);
            break;

        default:
            newSkillInstance = new SkillBase();
            break;
        }

        if (newSkillInstance == null)
        {
            return(null);
        }

        // FIXME 技能, 重构这部分代码
        // 消除动态分配, 弄一个池子
        if (m_Property.IsMain())
        {
            if (m_SkillProxy.GetSkillByID(skillID) != null)
            {
                newSkillInstance.Initialize(m_Property, m_SkillProxy.GetSkillByID(skillID), OnSkillStopped);
            }
            else
            {
                return(null);
            }
        }
        else
        {
            PlayerSkillVO skillVO = PlayerSkillVO.CreateSkillVO(skillID);
            if (skillVO != null)
            {
                newSkillInstance.Initialize(m_Property, skillVO, OnSkillStopped);
            }
            else
            {
                return(null);
            }
        }

        return(newSkillInstance);
    }