public void ClearSkill()
        {
            if (null != mCastSkillUi)
            {
                mCastSkillUi.OnCastEnd();
            }

            mSelectedSkillCfg = null;
            mCastCfg          = null;
        }
        public void OnKeyEvent(KeyCode code)
        {
            LogDC.LogEx("press  ", code);

            var currentSkill = Caster.GetSkill(code);

            mCastCfg          = new CastCfg();
            mCastCfg.mFromKey = code;

            int skillId;

            if (currentSkill != null)
            {
                skillId = mHeroCfg.GetNextSkill(code, currentSkill.GetSkillCfg().mId);
                mCastCfg.mIsSubSkill = true;
            }
            else
            {
                skillId = mHeroCfg.GetSkillId(code);
            }

            var skillCfg = SkillConfigMgr.Instance.GetSkillCfg(skillId);

            if (null == skillCfg)
            {
                LogDC.LogEx("no such skill: ", skillId);
                return;
            }

            //不需要目标 直接释放技能
            if (skillCfg.mTargetType == SkillTargetType.None)
            {
                mSelectedSkillCfg = skillCfg;
            }
            else
            {
                //选中某个技能 准备调参
                mSelectedSkillCfg = skillCfg;
                if (null != mCastSkillUi)
                {
                    mCastSkillUi.OnPrepareCast(mSelectedSkillCfg);
                }

                LogDC.LogEx("prepare skill ", skillId);
            }
        }
        private void HandleRightMouseBtn()
        {
            //1 非施法准备期 普攻 2 施法准备期 取消
            if (Input.GetMouseButtonDown(1))
            {
                //LogDC.Log("right btn click");

                //cancel skill
                if (IsPreparingCast())
                {
                    //LogDC.Log("cancel cast");
                    StopPreparingCast();
                    return;
                }

                //normal attack
                var mPos = Input.mousePosition;
                var ray  = Camera.main.ScreenPointToRay(mPos);
                if (Physics.Raycast(ray, out mCastTargetHit, 100))
                {
                    //LogDC.LogEx("cast obj ", mCastTargetHit.transform.gameObject.name);

                    var target = mCastTargetHit.transform.GetComponent <GameActor>();
                    //是目标
                    if (target != null)
                    {
                        var skillId  = mHeroCfg.GetSkillId(KeyCode.A);
                        var skillCfg = SkillConfigMgr.Instance.GetSkillCfg(skillId);
                        mCastCfg          = new CastCfg();
                        mCastCfg.mFromKey = KeyCode.A;
                        mSelectedSkillCfg = skillCfg;
                        PrepareCastSelectedSkill(mSelectedSkillCfg, mCastTargetHit.transform, Vector3.zero);
                    }
                }
            }
        }
Beispiel #4
0
        public bool Cast(SkillCfg skillCfg, CastCfg castCfg)
        {
            LogDC.LogEx("cast", skillCfg.mId);

            var skill = GetSkillSystem().CreateSkill(skillCfg);

            skill.SetCaster(this);
            skill.SetCastCfg(castCfg);

            /*
             * 判断是否可以释放
             * buff
             *   沉默
             *   晕眩
             * 能量
             * cd
             */

            var buffAllowCast = BuffAllowCast(skill);

            if (buffAllowCast.Error)
            {
                return(false);
            }

            var consumeEnough = ConsumeEnough(skill);

            if (consumeEnough.Error)
            {
                return(false);
            }

            if (CdEnough(skill).Error)
            {
                return(false);
            }

            switch (skillCfg.mTargetType)
            {
            case SkillTargetType.Actor:
            {
                foreach (var target in castCfg.mTargets)
                {
                    if (!skill.AllowCastTo(target))
                    {
                        return(false);
                    }
                }
                //面向目标
                var newForward = (castCfg.mTargets[0].GetTransform().position - CacheTransform.position).normalized;
                CacheTransform.forward = newForward;
                break;
            }

            case SkillTargetType.Position:
                GetActor().FaceTo((castCfg.mTargetPosition - CacheTransform.position).normalized);
                break;

            case SkillTargetType.Direction:
                GetActor().FaceTo(castCfg.mDirection);
                break;
            }

            var skillTf      = skill.GetTransform();
            var skillBirthTf = GetActor().GetActorPos(ActorPos.body_front);

            skillTf.position = skillBirthTf.position;
            skillTf.forward  = skillBirthTf.forward;


            skill.Create();

            return(true);
        }