Пример #1
0
        public virtual bool OnHit(DamageData damageData)
        {
            // 事件分发
            if (OnHitEvent != null)
            {
                OnHitEvent(damageData);
            }

            // buff刷新
            BuffController.TriggerBuffEvent(BuffEventType.OnHit, damageData);

            // 代理执行击中 add by TangJian 2019/5/10 17:20
            _hitAndHurtDelegate.Hit(damageData);

            // 空中击中对象, 自己浮空
            if (isGrounded == false)
            {
                if (damageData.itriggerDelegate is HurtAble && damageData.itriggerDelegate is IObjectController objectController)
                {
                    //击退 add by TangJian 2018/12/8 14:55
                    if (damageData.targetMoveBy.magnitude > 0.01f)
                    {
                        speed.y = (damageData.targetMoveBy *
                                   (1f - (objectController.IsDefending ? objectController.DefenseRepellingResistance : objectController.RepellingResistance))
                                   ).MoveByToSpeed().y;
                    }
                }
            }

            // 添加碰撞伤害
//            if (damageData.hitType == (int) HitType.Fly)
//            {
//                this.DelayToDo(0.1f, () =>
//                {
//                    if (damageData.hitGameObject.GetComponent<RoleController>() is IObjectController otherObjController)
//                    {
//                        var damageSize = new Vector3(1, 1, 1);
//                        HitType hittype = HitType.Fly;
//
//                        string damageControllerId = Tools.getOnlyId().ToString();
//                        string damageId = Tools.getOnlyId().ToString();
//
//                        var damageController = FrameEventMethods.RoleAtk((ITriggerDelegate) otherObjController, damageControllerId, damageId,
//                            _roleData.TeamId, FrameEventInfo.ParentType.Transform
//                            , PrimitiveType.Cube
//                            , Vector3.zero
//                            , damageSize
//                            , new Vector3(GetDirectionInt(), 0, 0)
//                            , hittype
//                            , Vector3.zero
//                            , DamageDirectionType.UseSpeed
//                            , DamageEffectType.Strike
//                            , AtkPropertyType.physicalDamage
//                            , 1
//                            , 1);
//
//                        damageController.SetId(damageControllerId);
//
//                        // 设计击飞攻击效果为其他
//                        damageController.damageData.HitEffectType = HitEffectType.Other;
//
//                        // 绑定到攻击对象的身上
//                        damageController.bindType = FrameEventInfo.RoleAtkFrameEventData.BindType.BindObjectController;
//                        damageController.ObjectController = otherObjController;
//
//                        damageController.NeedRemoveSelf = () => otherObjController.Speed.y <= 0 && otherObjController.IsGrounded();
//                    }
//
//                });
//            }
            return(true);
        }
Пример #2
0
        // 受伤 add by TangJian 2018/12/8 1:54
        public virtual bool Hurt(DamageData damageData)
        {
            Direction oldDirection = GetDirection();

            // 扣血 add by TangJian 2017/07/14 18:02:17
            if (IsDefending

                && damageData.ignoreShield == false // 不无视防御 add by TangJian 2019/4/3 17:16

                )
            {
                //方向判断
                AnimationSwitch(damageData, false, true);

                //体力判断
                {
                    // 伤害计算和扣血 add by TangJian 2019/4/2 16:44
                    float HurtNum = this.DoLoseHp(damageData.atk);

                    // 自身动画状态设置 add by TangJian 2019/4/2 16:44
                    {
                        if (animatorParams.ContainsKey("NoDefence"))
                        {
                            _animator.SetBool("NoDefence", true);
                        }

                        _animator.SetInteger("Defence_hurt_type", 3);
                        AnimManager.Instance.WeaponCremaShake(FrameEventInfo.CameraShakeType.mediumshape);
                        if (RoleData.Hp <= 0)
                        {
                            WeaponByDieAni(damageData.WeapondeadType, HurtNum);
                        }
                        else
                        {
                            _animator.SetTrigger("hurt");
                        }
                    }

                    // 额外效果 add by TangJian 2019/4/2 16:44
                    {
                        float   angle           = damageData.SpecialEffectRotation;
                        Bounds  bounds          = new Bounds(transform.position + RoleData.DefendBoundcenter, RoleData.DefendBoundsize);
                        Vector3 localPos        = transform.InverseTransformPoint(damageData.collideBounds.center);
                        Vector3 posse           = transform.position + localPos;
                        Vector3 overpos         = bounds.ClosestPoint(posse);
                        Vector3 moveOrientation = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
                        moveOrientation.y = Mathf.Abs(moveOrientation.y);
                    }
                }
            }
            else
            {
                // 伤害计算和扣血 add by TangJian 2019/4/2 16:44
                float HurtNum = this.DoLoseHp(damageData.atk);

                #region //2019.3.29// 动画状态机设置
                {
                    // 设置无视防御状态 add by TangJian 2019/4/3 17:50
                    if (damageData.ignoreShield)
                    {
                        RoleAnimator.SetTrigger("ignore_shield");
                    }

                    if (RoleData.Hp <= 0)
                    {
                        WeaponByDieAni(damageData.WeapondeadType, HurtNum);
                    }

                    //地面血迹 2019.3.29
                    AnimManager.Instance.PlayAnimEffect("BloodSubface", transform.position, 0, damageData.direction.x < 0, Vector3.right, transform);

                    //判断是否需要转身 2019.4.4
                    bool IsneedTurnback = RoleData.NeedTurnBack;
                    if (IsneedTurnback)
                    {
                        if (damageData.hitType != (int)HitType.Fly)
                        {
                            IsneedTurnback = false;
                        }
                    }
                    AnimationSwitch(damageData, IsneedTurnback);
                }
                #endregion

                // 额外动画
                {
                    // 播放掉血动画
                    if (HurtNum > 0)
                    {
                        this.PlayLoseHpAnim(HurtNum, damageData.isCritical);
                    }
                }

                // 使用代理实现受伤 add by TangJian 2019/5/10 17:56
                _hitAndHurtDelegate.Hurt(damageData);
            }

            // 霸体状态处理 add by TangJian 2018/12/8 14:56
            if (RoleData.IsSuperArmor)
            {
                SetDirection(oldDirection); // 霸体被攻击不转面 add by TangJian 2019/3/25 10:54
                _animator.SetBool("hurt", false);
            }
            else
            {
                if (OnHurtEvent != null)
                {
                    OnHurtEvent(damageData);
                }
            }

            //击退 add by TangJian 2018/12/8 14:55
            if (damageData.targetMoveBy.magnitude > 0.01f)
            {
                Speed = (damageData.targetMoveBy * (1f - (IsDefending ? RoleData.DefenseRepellingResistance : RoleData.RepellingResistance))).MoveByToSpeed();
            }

            // 触发受伤事件 add by TangJian 2018/05/14 20:09:38
            BuffController.TriggerBuffEvent(BuffEventType.OnHurt);
            return(true);
        }