Пример #1
0
    /// <summary>
    /// 添加材质特效和声音.
    /// </summary>
    /// <param name="owner">被添加特效和声音的单位</param>
    /// <param name="cdContainer">cd的容器, 该函数会检查并设置CD.</param>
    /// <param name="name">添加的类型(被击, 死亡等)</param>
    /// <param name="impactDamageType">impact的伤害类型</param>
    public static ErrorCode AddMaterialBehaviour(BattleUnit owner, HitMaterialEffectCdContainer cdContainer,
                                                 MaterialBehaviourDef name, ImpactDamageType impactDamageType, float dir
                                                 )
    {
        // 无效的伤害类型.
        if (impactDamageType >= ImpactDamageType.Count)
        {
            return(ErrorCode.Succeeded);
        }

        // CD中, 只有被击的材质特效有CD, 死亡材质特效没有CD.
        if (name == MaterialBehaviourDef.OnMaterialBeHit && cdContainer.IsCoolingDown(impactDamageType))
        {
            return(ErrorCode.CoolingDown);
        }

        uint materialID = owner.GetMaterialResourceID();

        if (materialID == uint.MaxValue)
        {
            ErrorHandler.Parse(ErrorCode.ConfigError, owner.dbgGetIdentifier() + " 没有材质!");
            return(ErrorCode.ConfigError);
        }

        MaterialTableItem material = DataManager.MaterialTable[materialID] as MaterialTableItem;

        if (material == null)
        {
            SkillUtilities.ResourceNotFound("material", materialID);
            return(ErrorCode.ConfigError);
        }

        if (name == MaterialBehaviourDef.OnMaterialBeHit)
        {
            cdContainer.StartCd(impactDamageType);
        }

        MaterialItem item = material.items[(int)impactDamageType];

        uint   effectID  = uint.MaxValue;
        uint   sound     = uint.MaxValue;
        string bindpoint = "";

        switch (name)
        {
        case MaterialBehaviourDef.OnMaterialBeHit:
            effectID  = item.hitEffect;
            bindpoint = material.hitEffectBindpoint;
            sound     = item.sound;
            // 被击材质特效在被击者身上播放.
/*				SkillClientBehaviour.AddEffect2Object(owner, effectID, bindpoint, dir);*/
            if (string.IsNullOrEmpty(bindpoint))
            {
                SkillClientBehaviour.AddSceneEffect(effectID, owner.GetPosition(), dir);
            }
            else
            {
                SkillClientBehaviour.AddEffect2Object(owner, effectID, bindpoint, dir);
            }
            break;

        case MaterialBehaviourDef.OnMaterialDie:
            effectID  = item.deathEffect;
            bindpoint = material.deathEffectBindpoint;
            if (string.IsNullOrEmpty(bindpoint))
            {
                SkillClientBehaviour.AddSceneEffect(effectID, owner.GetPosition(), dir);
            }
            else
            {
                SkillClientBehaviour.AddEffect2Object(owner, effectID, bindpoint, dir);
            }

            break;

        default:
            break;
        }

        if (sound != uint.MaxValue)
        {
            SkillClientBehaviour.PlaySound(sound);
        }

        return(ErrorCode.Succeeded);
    }