Example #1
0
 public void AddSendCache(NetworkMsg msg)
 {
     byte[] bytes = Serialization.SerializeData(msg, msg);
     if (bytes != null)
     {
         bytes = NetCommon.Encode(bytes);
         SendCache.Enqueue(bytes);
     }
 }
Example #2
0
    public void SendData(NetworkMsg msg)
    {
        int currentindx = 4;
        var tbuffer     = NetCommon.Encode(Serialization.Serialize(msg));

        Array.Copy(tbuffer, 0, BigRecivebuffer, currentindx, tbuffer.Length);
        currentindx += tbuffer.Length;


        if (currentindx > 4)
        {
            System.Buffer.BlockCopy(BitConverter.GetBytes(currentindx - 4), 0, BigRecivebuffer, 0, 4);

            clientSocket.SendData(BigRecivebuffer, currentindx);
        }
    }
Example #3
0
    public void SendGameData()
    {
        Queue <NetworkMsg> sendBuffer = robotGame.GetSendBuffer();
        int currentindx = 4;

        while (sendBuffer.Count > 0)
        {
            NetworkMsg msg = sendBuffer.Dequeue();

            var tbuffer = NetCommon.Encode(Serialization.Serialize(msg));
            Array.Copy(tbuffer, 0, BigRecivebuffer, currentindx, tbuffer.Length);
            currentindx += tbuffer.Length;
        }
        if (currentindx > 4)
        {
            System.Buffer.BlockCopy(BitConverter.GetBytes(currentindx - 4), 0, BigRecivebuffer, 0, 4);

            clientSocket.SendData(BigRecivebuffer, currentindx);
        }
    }
Example #4
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);
        }