Example #1
0
        private async void Delay(float ms, Entity actor)
        {
            int step = (int)(0.2 * 1000 / ms);      // 延迟释放攻击,与动画配合
            List <Collider2D> HurtTargets = new List <Collider2D>();

            do
            {
                step++;
                await Task.Delay((int)ms);

                if (step == SkillInternal * 500 / ms)
                {
                    HurtTargets.Clear();
                }
                Collider2D[] cols = Physics2D.OverlapCircleAll(actor.transform.position, actor.GetComponent <Entity>().GetCapability <Attack>().Range);
                if (cols.Length > 0)
                {
                    List <GameObject> Targets = new List <GameObject>();
                    foreach (var c in cols)
                    {
                        if (c.transform.CompareTag(actor.transform.GetComponent <WeaponController>().AttackTag) && !HurtTargets.Contains(c))
                        {
                            Targets.Add(c.gameObject);
                            HurtTargets.Add(c);
                        }
                    }
                    if (Targets.Count != 0)
                    {
                        HealthModifier     healthModifier     = new HealthModifier(-Damage);
                        MoveTowardFragment moveTowardFragment = new MoveTowardFragment();
                        foreach (var t in Targets)
                        {
                            moveTowardFragment.Direction    = (t.transform.position - actor.transform.position);
                            moveTowardFragment.InternalTime = 0.2f;
                            moveTowardFragment.Speed        = HitPower;
                            moveTowardFragment.TakeEffect(t.GetComponent <Entity>());
                            healthModifier.TakeEffect(t.GetComponent <Entity>());
                        }
                    }
                }
            } while (step < SkillInternal * 1000 / ms);
        }
Example #2
0
        public override void TakeAction(Entity entity)
        {
            if (SkillType == "RotateAttackSkill")
            {
                //TODO 技能持续时间暂定1s,等待完善,调整后记得调weapon上的动画时间
                float SkillInternal = 3f;

                // 暂停自动攻击
                StopAutoAttackFragment stopAutoAttackFragment = new StopAutoAttackFragment(SkillInternal);
                stopAutoAttackFragment.TakeEffect(entity);

                // 范围攻击
                AreaAttackFragment areaAttackFragment = new AreaAttackFragment();
                areaAttackFragment.Damage        = 35;
                areaAttackFragment.SkillInternal = SkillInternal;
                areaAttackFragment.HitPower      = 0.4f;
                areaAttackFragment.TakeEffect(entity);

                // 移速增加
                SpeedChangeMoveFragment speedChangeMoveFragment = new SpeedChangeMoveFragment();
                speedChangeMoveFragment.InternalTime = SkillInternal;
                speedChangeMoveFragment.TakeEffect(entity);

                // 动画表示
                RotateAttackAnimatorFragment rotateAttackAnimatorFragment = new RotateAttackAnimatorFragment();
                rotateAttackAnimatorFragment.InteralTime = SkillInternal;
                rotateAttackAnimatorFragment.TakeEffect(entity);

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0;
                audioPlayFragment.TakeEffect(entity);
                audioPlayFragment.PlayInternal = SkillInternal / 2;
                audioPlayFragment.TakeEffect(entity);

                //格挡子弹

                entity.transform.GetChild(2).gameObject.SetActive(true);
                entity.StartCoroutine(CloseCircleCollider(SkillInternal, entity));
            }
            else if (SkillType == "BombSkill")
            {
                // 动画展示
                AnimatorParameterFragment animatorFragment = new AnimatorParameterFragment();
                animatorFragment.Animator = entity.transform.GetChild(0).GetComponent <Animator>();
                animatorFragment.Name     = "Throw";
                animatorFragment.TakeEffect();

                // 扔一个水弹
                BombFragment bombFragement = new BombFragment();
                bombFragement.AttackTag   = "Enemies";
                bombFragement.BulletSpeed = 1f;
                bombFragement.TargetPos   = TouchPoint;
                bombFragement.Damage      = 30;
                bombFragement.TakeEffect(entity);

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0f;
                audioPlayFragment.TakeEffect(entity);
            }
            else if (SkillType == "RushSkill")
            {
                int SkillInternal = 1;

                // 冲刺
                MoveTowardFragment moveTowardFragment = new MoveTowardFragment();
                moveTowardFragment.InternalTime = SkillInternal;
                moveTowardFragment.Direction    = TouchPoint - new Vector2(entity.transform.position.x, entity.transform.position.y);
                moveTowardFragment.Speed        = 0.4f;
                moveTowardFragment.TakeEffect(entity);

                // 暂停移动输入
                StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(SkillInternal);
                stopPlayerMovementFragment.TakeEffect(entity);

                // 暂停自动攻击
                StopAutoAttackFragment stopAutoAttackFragment = new StopAutoAttackFragment(SkillInternal);
                stopAutoAttackFragment.TakeEffect(entity);

                // 将武器指向冲刺方向(武器附上击退效果)
                RushAttackFragment rushFragment = new RushAttackFragment();
                rushFragment.RushDir      = TouchPoint - (Vector2)entity.transform.position;
                rushFragment.InternalTime = SkillInternal;
                rushFragment.TakeEffect(entity);

                // 武器动画
                RushAttackAnimatorFragment weaponAnimatorFragment = new RushAttackAnimatorFragment();
                weaponAnimatorFragment.InteralTime = SkillInternal;
                weaponAnimatorFragment.TakeEffect(entity);

                // 人物动画
                AnimatorParameterFragment animatorFragment = new AnimatorParameterFragment();
                animatorFragment.Animator = entity.transform.GetChild(0).GetComponent <Animator>();
                animatorFragment.Name     = "Rush";
                animatorFragment.TakeEffect();

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0f;
                audioPlayFragment.TakeEffect(entity);

                entity.transform.GetChild(2).gameObject.SetActive(true);
                entity.StartCoroutine(CloseCircleCollider(SkillInternal, entity));
            }
            else
            {
                throw new ArgumentException("SkillType is out of consider.");
            }
        }