Beispiel #1
0
        void LashProcess(ActData.AttackDef attackDef,
                         ref HitData hitData,
                         IActUnit target,
                         ActData.HeightStatusFlag targetHeightStatus,
                         bool processLash,
                         bool rotateOnHit)
        {
            int   AttackeeStraightTime = attackDef.AttackeeStraightTime;
            float AttackeeLashX        = attackDef.AttackeeLash.X;
            float AttackeeLashY        = attackDef.AttackeeLash.Y;
            float AttackeeLashZ        = attackDef.AttackeeLash.Z;
            int   AttackeeTime         = attackDef.AttackeeTime;

            ActData.AttackDef.Types.HitResultData hitResultData = null;
            switch (targetHeightStatus)
            {
            case ActData.HeightStatusFlag.Ground:
                hitResultData = attackDef.GroundHit;
                break;

            case ActData.HeightStatusFlag.LowAir:
                hitResultData = attackDef.LowAirHit;
                break;

            case ActData.HeightStatusFlag.HighAir:
                hitResultData = attackDef.HighAirHit;
                break;
            }

            if (hitResultData != null && hitResultData.Enabled)
            {
                AttackeeLashX        = hitResultData.AttackeeLash.X;
                AttackeeLashY        = hitResultData.AttackeeLash.Y;
                AttackeeLashZ        = hitResultData.AttackeeLash.Z;
                AttackeeTime         = hitResultData.AttackeeTime;
                AttackeeStraightTime = hitResultData.AttackeeStraightTime;
            }

            if (processLash)
            {
                // 非受击转向的时候,冲击速度需要转换为本地坐标。
                if (!rotateOnHit)
                {
                    Quaternion rotate = Quaternion.AngleAxis(mOrientation * Mathf.Rad2Deg + 180, Vector3.up);
                    if (mAttackDef.FramType != ActData.HitDefnitionFramType.CuboidType)
                    {
                        Vector3 targetToOwner = mPos - target.Position;
                        targetToOwner.y = 0;
                        rotate          = Quaternion.LookRotation(targetToOwner);
                    }
                    Vector3 lashVector = rotate * new Vector3(AttackeeLashX, AttackeeLashY, AttackeeLashZ);
                    lashVector = target.UGameObject.transform.InverseTransformDirection(lashVector);

                    AttackeeLashX = (short)lashVector.x;
                    AttackeeLashZ = (short)lashVector.z;
                }

                hitData.LashX    = (short)AttackeeLashX;
                hitData.LashY    = (short)AttackeeLashY;
                hitData.LashZ    = (short)AttackeeLashZ;
                hitData.LashTime = (short)AttackeeTime;
            }

            hitData.StraightTime = (short)AttackeeStraightTime;
        }
Beispiel #2
0
        void Hit(IActUnit self, IActUnit target)
        {
            ActionStatus targetActionStatus = target.ActStatus;

            // hit target.
            self.OnHitTarget(target);

            // sound.

            /*
             * if (!string.IsNullOrEmpty(mData1.HitedSound) && mHitSoundCount < MAX_HIT_SOUND)
             * {
             *  if (mData1.HitedSoundIndex == -2)
             *  {
             *      mData1.HitedSoundIndex = SoundManager.Instance.GetSoundIndex(mData1.HitedSound);
             *      if (mData1.HitedSoundIndex < 0)
             *          Debug.LogError(string.Format("Fail to load hit sound: [{0}/{1}]", mOwner.UnitID, mData1.HitedSound));
             *  }
             *  if (mData1.HitedSoundIndex > 0)
             *      SoundManager.Instance.Play3DSound(mData1.HitedSoundIndex, mOwner.Position, 1.0f);
             *  mHitSoundCount++;
             * }*/

            // effect
            if (!string.IsNullOrEmpty(mAttackDef.HitedEffect))
            {
                Vector3 effectPos = target.Position;
                effectPos.y += targetActionStatus.Bounding.y * 0.5f;

                ActionSystem.Instance.EffectMgr.PlayEffect(mAttackDef.HitedEffect, mAttackDef.HitedEffectDuration * 0.001f,
                                                           null, effectPos,
                                                           0 == mAttackDef.BaseGround ? Quaternion.identity : Quaternion.Euler(0f, 0f, UnityEngine.Random.Range(0f, 360f)));
            }

            // do not process my hit result in pvp mode.
            //if (PvpClient.Instance != null && self.UnitType == EUnitType.EUT_LocalPlayer)
            //    return;

            HitData tmpHitData = new HitData();

            tmpHitData.TargetUUID = target.UUID;

            // 击中转向
            float targetRotate = target.Orientation;
            bool  rotateOnHit  = targetActionStatus.RotateOnHit;

            if (rotateOnHit)
            {
                if (mAttackDef.FramType == ActData.HitDefnitionFramType.CylinderType)
                {
                    float x      = target.Position.x - mPos.x;
                    float z      = target.Position.z - mPos.z;
                    float modify = Mathf.Atan2(x, 0);
                    targetRotate = modify + Mathf.PI;
                }
                else
                {
                    targetRotate = self.Orientation + Mathf.PI;
                }
            }

            NetCommon.Encode(
                target.Position,
                targetRotate,
                ref tmpHitData.HitX,
                ref tmpHitData.HitY,
                ref tmpHitData.HitZ,
                ref tmpHitData.HitDir);

            // 单位在墙边上的时候,近战攻击者需要反弹。
            bool bounceBack = mAttackDef.IsRemoteAttacks == 0 && target.OnTouchWall;

            // 单位处于非霸体状态,需要被击中移动~
            bool processLash = true;

            //受击动作
            ActData.HeightStatusFlag targetHeightStatus = targetActionStatus.HeightState;

            if (targetActionStatus.ActiveAction.SuperArmor || target.IsPabodyState)
            {
                // 设置受击者的霸体硬直时间?
                tmpHitData.HitAction = byte.MaxValue;

                // 单位处于霸体状态,不需要移动~
                processLash = false;

                // 攻击结果为霸体的情况系,非远程攻击的冲击速度转换为攻击者。受击者不受冲击速度影响
                bounceBack = mAttackDef.IsRemoteAttacks == 0;
            }
            else if (targetActionStatus.OnHit(mAttackDef.HitResult, mAttackDef.IsRemoteAttacks != 0))
            {
                tmpHitData.HitAction = (byte)targetActionStatus.ActiveAction.ActionCache;
            }

            // 处理buff的东东
            if (targetActionStatus.SkillItem != null && targetActionStatus.SkillItem.SkillInput != null)
            {
                targetActionStatus.SkillItem.SkillInput.OnHit(self);
            }

            // 设置攻击者的冲击速度及冲击时间。
            int     attackerLashTime = mAttackDef.AttackerTime;
            Vector3 attackerLash     = attackerLashTime == 0 ? self.ActStatus.Velocity : new Vector3(
                mAttackDef.AttackerLash.X * 0.01f,
                mAttackDef.AttackerLash.Y * 0.01f,
                mAttackDef.AttackerLash.Z * 0.01f);

            if (bounceBack)
            {
                attackerLash.x   = mAttackDef.AttackeeLash.X * 0.01f;
                attackerLash.z   = mAttackDef.AttackeeLash.Z * 0.01f;
                attackerLashTime = mAttackDef.AttackeeTime;
            }

            if (attackerLashTime > 0)
            {
                self.ActStatus.SetLashVelocity(
                    attackerLash.x,
                    attackerLash.y,
                    attackerLash.z,
                    attackerLashTime);
            }

            // 处理受击者的冲击速度~
            LashProcess(mAttackDef, ref tmpHitData, target, targetHeightStatus, processLash, rotateOnHit);

            // I was hited, tell the others.
            //if (self.UnitType == EUnitType.EUT_OtherPlayer && target.UnitType == EUnitType.EUT_LocalPlayer)
            //{
            //    if (target.ActStatus.Listener != null)
            //        target.ActStatus.Listener.OnHitData(tmpHitData);
            //}

            target.OnHit(tmpHitData, false);
        }