Beispiel #1
0
    public void StartAttack(SkillBase skill, ActorBase actor, DBSkillAttackConf attackConf)
    {
        //Debug.Log("Do attack: " + attackConf.ID);
        isAttackObjectMoving = false;
        isAllDamageEnd       = false;
        isEffectPlayEnd      = false;

        this.skill = skill;

        damageConfArray = new DBSkillDamageConf[attackConf.damages.Length];
        for (int i = 0; i < attackConf.damages.Length; i++)
        {
            damageConfArray[i] = DBSkillDamageTable.GetRecord(attackConf.damages[i]);
        }

        if (!string.IsNullOrEmpty(attackConf.attackObjectName))
        {
            eo = EffectManager.GetEffect(attackConf.attackObjectName, null);
            eo.effectObject.gameObject.SetActive(attackConf.attackObjectAppearTime <= 0);            //需要倒计时显示的话,先隐藏
            X2DEffect effect = eo.x2dEffect;
            if (effect != null)
            {
                effect.Play();
                Vector3 pos = Vector3.zero;
                pos.x = attackConf.attackObjectAppearPos.x;
                pos.y = attackConf.attackObjectAppearPos.y;
                pos   = actor.objectbase.GetFaceBasedPos(pos);

                if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.FollowCaster)
                {
                    eo.effectObject.transform.parent        = actor.transform;
                    eo.effectObject.transform.localRotation = Quaternion.identity;
                    eo.effectObject.realLocalPos            = pos;
                }
                else
                {
                    eo.effectObject.realPos = actor.objectbase.realLocalPos + pos;
                }
                eo.effectObject.isFacingRight = actor.objectbase.isFacingRight;

                //攻击物体移动
                if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.AutoMove_Vector)
                {
                    //向量移动
                    isAttackObjectMoving     = true;
                    attackObjectMoveTimer    = 0;
                    attackObjectMoveDuration = attackConf.attackObjectMoveDuration;
                    //
                    attackObjectMoveCurve    = AnimationCurveCollection.GetAnimationCurve(attackConf.attackObjectMoveVectorCurve);
                    attackObjectMoveVector   = attackConf.attackObjectMoveVector;
                    attackObjectMoveStartPos = eo.effectObject.realLocalPos;
                    if (!eo.effectObject.isFacingRight)
                    {
                        attackObjectMoveVector.x = -attackObjectMoveVector.x;
                    }
                }
                else if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.AutoMove_Speed)
                {
                    //曲线移动
                    isAttackObjectMoving     = true;
                    attackObjectMoveTimer    = 0;
                    attackObjectMoveDuration = attackConf.attackObjectMoveDuration;
                    //
                    attackObjectMoveSpeed = attackConf.attackObjectMoveSpeed;
                    if (!eo.effectObject.isFacingRight)
                    {
                        attackObjectMoveSpeed.x = -attackObjectMoveSpeed.x;
                    }
                }
            }
        }

        //音效
        if (!string.IsNullOrEmpty(attackConf.actorCastSoundName))
        {
            actor.audioSource.clip = ResourceLoader.LoadCharactorSound(attackConf.actorCastSoundName);
            actor.audioSource.Play();
        }

        this.actor      = actor;
        this.attackConf = attackConf;
        damageTimer     = 0f;
        attackTimer     = 0f;
        attackTimes     = 0;
        showTimer       = 0;
        damageIndex     = 0;
        isFinished      = false;
        isCurDamageEnd  = false;
        isBuffEnabled   = false;
        isInCollision   = false;
        isLifeTimeEnd   = false;
        isShowed        = false;
    }
 void Awake()
 {
     instance = this;
     Init();
 }
 void OnDestroy()
 {
     instance = null;
 }
    public void Show(DBSkillInfoConf skillInfoConf)
    {
        nameLabel.text          = skillInfoConf.skillNameText;
        cdLabel.text            = skillInfoConf.cd + "秒";
        castTimeLabel.text      = skillInfoConf.castTime == 0 ? "瞬发" : skillInfoConf.castTime + "秒";
        castCombinKeyLabel.text = skillInfoConf.castCombianKey;
        descLabel.text          = skillInfoConf.instruction;

        DBSkillConf skillConf = DBSkillTable.GetRecord(skillInfoConf.skillID, false);

        if (skillConf == null)
        {
            //没有伤害的技能
            attributeLabel.text = "";
            return;
        }

        List <DBSkillDamageConf> damageList = new List <DBSkillDamageConf>();

        //跳过伤害为0的攻击
        for (int i = 0; i < skillConf.attackList.Count; i++)
        {
            for (int j = 0; j < skillConf.attackList[i].damages.Length; j++)
            {
                DBSkillDamageConf damageConf = DBSkillDamageTable.GetRecord(skillConf.attackList[i].damages[j]);
                if (damageConf.damagePercent > 0)
                {
                    damageList.Add(damageConf);
                }
            }
        }

        if (damageList.Count == 0)
        {
            attributeLabel.text = "";
        }
        else if (damageList.Count == 1)
        {
            attributeLabel.text = string.Format("造成{0}%攻击力的伤害", damageList[0].damagePercent);
        }
        else
        {
            string text = "";
            for (int i = 0; i < damageList.Count; i++)
            {
                DBSkillDamageConf damageConf = damageList[i];
                string            damageText = "";
                if (damageConf.times <= 1)
                {
                    damageText = string.Format("造成{0}%攻击力的伤害", damageConf.damagePercent);
                }
                else
                {
                    damageText = string.Format("每次造成{0}%攻击力的伤害", damageConf.damagePercent);
                }

                if (string.IsNullOrEmpty(damageConf.desc))
                {
                    text += string.Format(" 第{0}段,进行{1}次攻击,{2}\n", i + 1, damageConf.times, damageText);
                }
                else
                {
                    text += string.Format(" 第{0}段,{1}, 进行{2}次攻击,{3}\n", i + 1, damageConf.desc, damageConf.times, damageText);
                }
            }
            attributeLabel.text = text;
        }
    }