예제 #1
0
 public SpawnerPayload(ObjectManagement.SpawnerType spawnerType, int assetId, Vector3 position, float rotation, float scaleRatio)
 {
     this.Code        = OpCode.Spawn;
     this.spawnerType = spawnerType;
     this.assetId     = assetId;
     this.position    = position;
     this.rotation    = rotation;
     this.scaleRatio  = scaleRatio;
 }
예제 #2
0
        public BasePayload Read()
        {
            if (this.Stream.DataAvailable)
            {
                this.Stream.Read(this.Buffer, 0, 1);
                switch (this.Buffer[0])
                {
                case (byte)OpCode.Message:
                    this.Stream.Read(this.Buffer, 0, 4);
                    int msgLength = BitConverter.ToInt32(this.Buffer, 0);
                    this.Stream.Read(this.Buffer, 0, msgLength);
                    return(new Message(Encoding.UTF8.GetString(this.Buffer)));

                case (byte)OpCode.Ready:
                    return(new Ready());

                case (byte)OpCode.PlayerCoordinates:
                    this.Stream.Read(this.Buffer, 0, 12);
                    float xPlayer      = BitConverter.ToSingle(this.Buffer, 0);
                    float yPlayer      = BitConverter.ToSingle(this.Buffer, 4);
                    float zAnglePlayer = BitConverter.ToSingle(this.Buffer, 8);
                    return(new PlayerCoordinates(xPlayer, yPlayer, zAnglePlayer));

                case (byte)OpCode.Spawn:
                    this.Stream.Read(this.Buffer, 0, 25);
                    ObjectManagement.SpawnerType spawnerType = (ObjectManagement.SpawnerType) this.Buffer[0];
                    int   assetId    = BitConverter.ToInt32(this.Buffer, 1);
                    float x          = BitConverter.ToSingle(this.Buffer, 5);
                    float y          = BitConverter.ToSingle(this.Buffer, 9);
                    float z          = BitConverter.ToSingle(this.Buffer, 13);
                    float rotation   = BitConverter.ToSingle(this.Buffer, 17);
                    float scaleRatio = BitConverter.ToSingle(this.Buffer, 21);
                    return(new SpawnerPayload(spawnerType, assetId, new Vector3(x, y, z), rotation, scaleRatio));

                case (byte)OpCode.Death:
                    return(new Death());

                default:
                    return(null);
                }
            }

            return(null);
        }