void SendStatePacket()
    {
        NetOutgoingMessage inputPacket = GetClient().CreateMessage();

        inputPacket.Write((UInt32)core.PacketType.kState, PacketTypeLengthBits);
        mDeliveryNotificationManager.WriteState(inputPacket);


        var characterState = new core.CharacterState();

        if (LocalCharacter != null)
        {
            characterState.location = LocalCharacter.GetPosition();
            characterState.velocity = LocalCharacter.GetVelocity();
        }
        characterState.timeStamp = core.Timing.sInstance.GetFrameStartTime();

        characterState.Write(inputPacket);

#if UNITY_EDITOR && USE_CLIENT_STATE_RECORD
        if (ACScrambleBattle.GetState().State == EACBattleState.PLAY)
        {
            System.IO.FileStream   fs = new System.IO.FileStream($"client_record", System.IO.FileMode.Append, System.IO.FileAccess.Write);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
            bw.Write((int)core.PacketType.kState);
            characterState.Write(bw);
            bw.Close();
            fs.Close();
        }
#endif

        inputPacket.Write((UInt32)AIStates.Count, (int)core.AIPlayer.MaxAIPlayerBit);
        foreach (var state in AIStates.Values)
        {
            state.Write(inputPacket);
        }

        //Debug.Log($"send location{characterState.location}, velocity{characterState.velocity}");


        SendMessage(inputPacket, NetDeliveryMethod.Unreliable);
    }
예제 #2
0
 void RecordRPC(ulong hash, object[] parameters)
 {
     if (ACScrambleBattle.GetState().State == EACBattleState.PLAY)
     {
         System.IO.FileStream   fs = new System.IO.FileStream($"client_record", System.IO.FileMode.Append, System.IO.FileAccess.Write);
         System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
         var buff = new NetBuffer();
         bw.Write((int)core.PacketType.kRPC);
         bw.Write(hash);
         for (int i = 0; i < parameters.Length; i++)
         {
             buff.WriteObjectPacked(parameters[i]);
         }
         bw.Write(buff.LengthBits);
         bw.Write(buff.Data.Length);
         bw.Write(buff.Data);
         bw.Close();
         fs.Close();
     }
 }